-
Notifications
You must be signed in to change notification settings - Fork 0
/
abstract_file.h
38 lines (34 loc) · 1.36 KB
/
abstract_file.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef ABSTRACT_FILE_H
#define ABSTRACT_FILE_H
#include <glib.h>
#include <stdint.h> /* for file_id_t */
#include <semaphore.h>
#include "lock.h"
typedef uint64_t file_id_t;
#define MAX_FILE_NAME_LENGTH 256
#define FILE_ID_SEPARATOR "#"
#define FIS FILE_ID_SEPARATOR
#define FIS_LENGTH 1
typedef struct AbstractFile
{
file_id_t id;
/* The file name
Previously stored in in the TagTable under the "name" tag but moved for
easier access. File names don't have to be unique to the file. */
char name[MAX_FILE_NAME_LENGTH];
sem_t file_lock;
} AbstractFile;
void abstract_file_init (AbstractFile *f, const char *name);
void abstract_file_destroy (AbstractFile *f);
char *abstract_file_to_string (AbstractFile *f, char buffer[MAX_FILE_NAME_LENGTH]);
const char *abstract_file_get_name (AbstractFile *f);
void _set_name (AbstractFile *f, const char *new_name);
int file_id_cmp (AbstractFile *f1, AbstractFile *f2);
int file_name_cmp (AbstractFile *f1, AbstractFile *f2);
int file_name_str_cmp (AbstractFile *f, char *name);
file_id_t get_file_id (AbstractFile *f);
void set_file_id (AbstractFile *f, file_id_t);
#define set_name(_f,_n) _set_name((AbstractFile*)_f,_n)
#define abstract_file_lock(__f) lock_acquire(&((AbstractFile*)__f)->file_lock, 1)
#define abstract_file_unlock(__f) lock_release(&((AbstractFile*)__f)->file_lock)
#endif /* ABSTRACT_FILE_H */