#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <glib.h>
#include <libnsbmp.h>
#include <bmpfile.h>
MMUTIL_SAFE_FREE(bitmap);
}
-static unsigned char *__load_file(const char *path, size_t * data_size)
+static gboolean __load_file(const char *path, unsigned char **data, size_t * data_size)
{
FILE *fd;
struct stat sb;
- unsigned char *buffer;
+ void *buffer = NULL;
size_t size;
size_t n;
if (MM_UTIL_ERROR_NONE != mm_util_safe_fopen(path, "rb", &fd)) {
mm_util_error("mm_util_safe_fopen failed");
- return NULL;
+ return FALSE;
}
if (stat(path, &sb)) {
mm_util_error("file stat failed");
mm_util_safe_fclose(fd);
- return NULL;
+ return FALSE;
}
size = sb.st_size;
if (!buffer) {
mm_util_error("Unable to allocate %lld bytes", (long long)size);
mm_util_safe_fclose(fd);
- return NULL;
+ return FALSE;
}
n = fread(buffer, 1, size, fd);
mm_util_error("file read failed");
MMUTIL_SAFE_FREE(buffer);
mm_util_safe_fclose(fd);
- return NULL;
+ return FALSE;
}
mm_util_safe_fclose(fd);
*data_size = size;
- return buffer;
+ *data = buffer;
+
+ return TRUE;
}
static void __print_error(const char *context, bmp_result code)
if (MMUTIL_STRING_VALID(file_path)) {
mm_util_sec_debug("read from file [%s]", file_path);
- data = __load_file(file_path, &size);
- if (data == NULL)
+ if (!__load_file(file_path, &data, &size))
return MM_UTIL_ERROR_INVALID_OPERATION;
} else {
mm_util_debug("read from memory");