#ifndef EXTERN_DISK_H
#define EXTERN_DISK_H

#ifdef DISK_C

# ifdef NDEBUG
#  define FILE_PREV_NULL(fs)
#  define FILE_PREV_COPY(fs, tag)
# else
#  define FILE_PREV_NULL(fs) *(fs)->prev_tags[(fs)->prefix_tags.used] = 0
#  define FILE_PREV_COPY(fs, tag) \
    memcpy((fs)->prev_tags[(fs)->prefix_tags.used], tag, strlen(tag) + 1)
# endif

#endif

#define FILE_TAG_TYPE_USTRING "us"
#define FILE_TAG_TYPE_SSTRING "ss"
#define FILE_TAG_TYPE_STRING FILE_TAG_TYPE_SSTRING

#define FILE_TAG_TYPE_INT "si"
#define FILE_TAG_TYPE_UINT "ui"

#define FILE_TAG_TYPE_LONG "sl"
#define FILE_TAG_TYPE_ULONG "ul"

#define FILE_TAG_TYPE_BITFLAG "bf"

#define FILE_TAG_TYPE_DOUBLE "dl"

#define FILE_TAG_TYPE_TIMESTAMP "ti"

#define FILE_TAG_TYPE_OBJECT "ob" /* for start_section etc... */


#define FILE_IO_VERSION(x) ((x)->version)
#define FILE_IO_CREATED(x) (!(x)->found_on_disk)


extern void file_ops_setup(file_io *);
extern void file_section_beg(const char *, file_io *);
extern void file_section_end(file_io *);

/* input */

extern int file_read_open(const char *, file_io *);
extern void file_read_close(file_io *);

extern int file_get_string(const char *, char *, size_t, file_io *);
extern void *file_get_malloc(const char *, size_t *, file_io *);
extern unsigned int file_get_unsigned_int(const char *, file_io *);
extern int file_get_int(const char *, file_io *);
extern unsigned long file_get_unsigned_long(const char *, file_io *);
extern long file_get_long(const char *, file_io *);
extern int file_get_bitflag(const char *, file_io *);
extern double file_get_double(const char *, file_io *);
extern time_t file_get_time_t(const char *, file_io *);

/* output */

extern int file_write_open(const char *, int, file_io *);
extern void file_write_close(file_io *);

extern void file_put_string(const char *, const char *, file_io *);
extern void file_put_unsigned_int(const char *, unsigned int, file_io *);
extern void file_put_int(const char *, int, file_io *);
extern void file_put_unsigned_long(const char *, unsigned long, file_io *);
extern void file_put_long(const char *, long, file_io *);
extern void file_put_bitflag(const char *, int, file_io *);
extern void file_put_double(const char *, double, file_io *);
extern void file_put_time_t(const char *, time_t, file_io *);


#endif
