core/file: Rework REPORT_ERROR() function
I want to be able to print any message as an error message without relying on errno. Let's handle this by introducing REPORT_ERRNO() to look up the right error message for a given errno. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
ee4f0d4c89
commit
fe6f31b1e5
11
core/file.c
11
core/file.c
|
@ -7,8 +7,9 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#define REPORT_ERROR(fname) \
|
#define REPORT_ERROR(fname, error) \
|
||||||
printf("%s (%s:%d): %s: %s\n", __func__, __FILE__, __LINE__, fname, strerror(errno))
|
g_printerr("%s (%s:%d): %s: %s\n", __func__, __FILE__, __LINE__, fname, error)
|
||||||
|
#define REPORT_ERRNO(fname) REPORT_ERROR(fname, strerror(errno))
|
||||||
|
|
||||||
static gchar *__file_path(const gchar *name)
|
static gchar *__file_path(const gchar *name)
|
||||||
{
|
{
|
||||||
|
@ -20,7 +21,7 @@ static FILE *__file_open(gchar *path, const gchar *mode)
|
||||||
FILE *ret = g_fopen(path, mode);
|
FILE *ret = g_fopen(path, mode);
|
||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
REPORT_ERROR(path);
|
REPORT_ERRNO(path);
|
||||||
g_free(path);
|
g_free(path);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +32,7 @@ static bool __file_mkdir()
|
||||||
int ret = g_mkdir_with_parents(dir, 0755);
|
int ret = g_mkdir_with_parents(dir, 0755);
|
||||||
|
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
REPORT_ERROR(dir);
|
REPORT_ERRNO(dir);
|
||||||
g_free(dir);
|
g_free(dir);
|
||||||
return ret == 0;
|
return ret == 0;
|
||||||
}
|
}
|
||||||
|
@ -187,6 +188,6 @@ int file_writef(struct file *file, const char *fmt, ...)
|
||||||
va_end(argp);
|
va_end(argp);
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
REPORT_ERROR(file->f_name);
|
REPORT_ERRNO(file->f_name);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue