/* string file format */ #ifndef STRFF_H #define STRFF_H #include #include enum strff_type { STRFF_TYPE_NONE = 0, STRFF_TYPE_BRACKET, STRFF_TYPE_EQUAL }; struct strff { buffer b; char buf[1024]; int fd; enum strff_type fieldtype; }; void strff_open(struct strff *, int fd); void strff_close(struct strff *); /* * seeks for a field with the specified key in the file. * sets cursor position ofc. * strff_read can be used to get the value. * key may not contain '['. * if key not found, sets errno to ENOKEY * return: 1 if found, 0 on error. */ int strff_seek(struct strff *, char *key); /* * reads n bytes into buf. * return: bytes read, 0 on end-of-field, -1 on error. */ int strff_read(struct strff *, size_t buflen, char buf[buflen]); /* * same as strff_read but reads the whole value into sa * return: 1 on success, 0 on error. */ int strff_read_sa(struct strff *, stralloc *sa); /* * wrapper around strff_seek and strff_read_sa. */ int strff_get(struct strff *, char *key, stralloc *sa); #endif