Introduce mg_calloc

This commit is contained in:
Sergey Lyubka committed 2025-06-24 10:52:44 +01:00
1 parent 5f1f4a0df8
commit 074ef5197b
26 files changed
+259 -313

No files matched your search

+6 -6
View File
@@ -3,12 +3,12 @@
#include "str.h"
struct mg_fd *mg_fs_open(struct mg_fs *fs, const char *path, int flags) {
struct mg_fd *fd = (struct mg_fd *) calloc(1, sizeof(*fd));
struct mg_fd *fd = (struct mg_fd *) mg_calloc(1, sizeof(*fd));
if (fd != NULL) {
fd->fd = fs->op(path, flags);
fd->fs = fs;
if (fd->fd == NULL) {
free(fd);
mg_free(fd);
fd = NULL;
}
}
@@ -18,7 +18,7 @@ struct mg_fd *mg_fs_open(struct mg_fs *fs, const char *path, int flags) {
void mg_fs_close(struct mg_fd *fd) {
if (fd != NULL) {
fd->fs->cl(fd->fd);
free(fd);
mg_free(fd);
}
}
@@ -27,10 +27,10 @@ struct mg_str mg_file_read(struct mg_fs *fs, const char *path) {
void *fp;
fs->st(path, &result.len, NULL);
if ((fp = fs->op(path, MG_FS_READ)) != NULL) {
result.buf = (char *) calloc(1, result.len + 1);
result.buf = (char *) mg_calloc(1, result.len + 1);
if (result.buf != NULL &&
fs->rd(fp, (void *) result.buf, result.len) != result.len) {
free((void *) result.buf);
mg_free((void *) result.buf);
result.buf = NULL;
}
fs->cl(fp);
@@ -66,7 +66,7 @@ bool mg_file_printf(struct mg_fs *fs, const char *path, const char *fmt, ...) {
data = mg_vmprintf(fmt, &ap);
va_end(ap);
result = mg_file_write(fs, path, data, strlen(data));
free(data);
mg_free(data);
return result;
}