From 224290d4eb951d422e2c47308bc116e7ae744507 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 29 Mar 2016 08:13:56 -0400 Subject: [PATCH] core/file: file->f_name can be a pointer I'm only setting this to a static string, so it doesn't make sense to store this as a char array. Let's use a string pointer instead. Signed-off-by: Anna Schumaker --- core/file.c | 9 ++++----- include/core/file.h | 12 +++++------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/core/file.c b/core/file.c index 89a08a02..ea27adc2 100644 --- a/core/file.c +++ b/core/file.c @@ -9,8 +9,7 @@ #define REPORT_ERROR(fname) \ printf("%s (%s:%d): %s: %s\n", __func__, __FILE__, __LINE__, fname, strerror(errno)) - -static gchar *__file_path(gchar *name) +static gchar *__file_path(const gchar *name) { return g_strjoin("/", g_get_user_data_dir(), OCARINA_NAME, name, NULL); } @@ -33,12 +32,12 @@ void file_init(struct file *file, const gchar *name, unsigned int version) file->f_version = version; file->f_prev = 0; file->f_file = NULL; - g_strlcpy(file->f_name, (name == NULL) ? "" : name, FILE_MAX_LEN); + file->f_name = name; } gchar *file_path(struct file *file) { - if (strlen(file->f_name) != 0) + if (string_length(file->f_name) != 0) return __file_path(file->f_name); return g_strdup(""); } @@ -94,7 +93,7 @@ static bool __file_open_write(struct file *file) bool file_open(struct file *file, enum open_mode mode) { - if ((strlen(file->f_name) == 0) || (file->f_file != NULL)) + if ((string_length(file->f_name) == 0) || (file->f_file != NULL)) return false; if (mode == OPEN_READ) diff --git a/include/core/file.h b/include/core/file.h index e7bd7f4b..994dee54 100644 --- a/include/core/file.h +++ b/include/core/file.h @@ -28,19 +28,17 @@ #include -#define FILE_MAX_LEN 16 - enum open_mode { OPEN_READ, OPEN_WRITE, }; struct file { - enum open_mode f_mode; /* The file's current open mode. */ - unsigned int f_version; /* The file's current data version. */ - unsigned int f_prev; /* The file's on-disk data version. */ - FILE *f_file; /* The file's IO stream. */ - gchar f_name[FILE_MAX_LEN]; /* The file's basename. */ + enum open_mode f_mode; /* The file's current open mode. */ + unsigned int f_version; /* The file's current data version. */ + unsigned int f_prev; /* The file's on-disk data version. */ + FILE *f_file; /* The file's IO stream. */ + const gchar *f_name; /* The file's basename. */ }; #define FILE_INIT(fname, version) \