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 <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-03-29 08:13:56 -04:00
parent 427319b72e
commit 224290d4eb
2 changed files with 9 additions and 12 deletions

View File

@ -9,8 +9,7 @@
#define REPORT_ERROR(fname) \ #define REPORT_ERROR(fname) \
printf("%s (%s:%d): %s: %s\n", __func__, __FILE__, __LINE__, fname, strerror(errno)) printf("%s (%s:%d): %s: %s\n", __func__, __FILE__, __LINE__, fname, strerror(errno))
static gchar *__file_path(const gchar *name)
static gchar *__file_path(gchar *name)
{ {
return g_strjoin("/", g_get_user_data_dir(), OCARINA_NAME, name, NULL); 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_version = version;
file->f_prev = 0; file->f_prev = 0;
file->f_file = NULL; 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) 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 __file_path(file->f_name);
return g_strdup(""); 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) 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; return false;
if (mode == OPEN_READ) if (mode == OPEN_READ)

View File

@ -28,19 +28,17 @@
#include <stdbool.h> #include <stdbool.h>
#define FILE_MAX_LEN 16
enum open_mode { enum open_mode {
OPEN_READ, OPEN_READ,
OPEN_WRITE, OPEN_WRITE,
}; };
struct file { struct file {
enum open_mode f_mode; /* The file's current open mode. */ enum open_mode f_mode; /* The file's current open mode. */
unsigned int f_version; /* The file's current data version. */ unsigned int f_version; /* The file's current data version. */
unsigned int f_prev; /* The file's on-disk data version. */ unsigned int f_prev; /* The file's on-disk data version. */
FILE *f_file; /* The file's IO stream. */ FILE *f_file; /* The file's IO stream. */
gchar f_name[FILE_MAX_LEN]; /* The file's basename. */ const gchar *f_name; /* The file's basename. */
}; };
#define FILE_INIT(fname, version) \ #define FILE_INIT(fname, version) \