core/file: Add a C-style initializer macro
I eventually intend to remove the file_init() function, once everything has been converted to C. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
cf6364f5d1
commit
08394c3168
|
@ -43,6 +43,14 @@ struct file {
|
|||
gchar f_name[FILE_MAX_LEN]; /* The file's basename. */
|
||||
};
|
||||
|
||||
#define FILE_INIT(fname, version) \
|
||||
{ \
|
||||
.f_mode = OPEN_READ, \
|
||||
.f_version = version, \
|
||||
.f_prev = 0, .f_file = NULL, \
|
||||
.f_name = fname, \
|
||||
}
|
||||
|
||||
|
||||
/* Initialize a new file object. */
|
||||
void file_init(struct file *, const gchar *, unsigned int);
|
||||
|
|
|
@ -48,10 +48,9 @@ static void test_empty()
|
|||
|
||||
static void test_file()
|
||||
{
|
||||
struct file file;
|
||||
struct file file = FILE_INIT("file.txt", 0);
|
||||
gchar *filepath = test_data_file("file.txt");
|
||||
|
||||
file_init(&file, "file.txt", 0);
|
||||
test_verify_constructor(&file, filepath);
|
||||
test_equal(file_exists(&file), (bool)false);
|
||||
test_equal(test_data_file_exists(NULL), (bool)false);
|
||||
|
@ -86,13 +85,11 @@ static void test_file()
|
|||
|
||||
static void test_io()
|
||||
{
|
||||
struct file fout, fin;
|
||||
struct file fout = FILE_INIT("file.txt", 1);
|
||||
struct file fin = FILE_INIT("file.txt", 0);
|
||||
char *res = NULL;
|
||||
unsigned int i;
|
||||
|
||||
file_init(&fout, "file.txt", 1);
|
||||
file_init(&fin, "file.txt", 0);
|
||||
|
||||
test_equal(file_open(&fout, OPEN_WRITE), (bool)true);
|
||||
file_writef(&fout, "1 ABCDE\n");
|
||||
file_writef(&fout, "2 FGHIJ KLMNO\n");
|
||||
|
|
Loading…
Reference in New Issue