blob: e2d055bc4a48924fcca9c4c44c8049ce6bdc51a9 [file] [log] [blame]
landley4f344e32006-10-05 16:18:03 -04001/* vi: set ts=4 :*/
landley09ea7ac2006-10-30 01:38:00 -05002/* lib.h - header file for lib directory
3 *
4 * Copyright 2006 Rob Landley <rob@landley.net>
5 */
landley4f344e32006-10-05 16:18:03 -04006
Rob Landley1521a9e2006-11-25 16:06:55 -05007// libc generally has this, but the headers are screwed up
8ssize_t getline(char **lineptr, size_t *n, FILE *stream);
9
Rob Landley0a04b3e2006-11-03 00:05:52 -050010// llist.c
11void llist_free(void *list, void (*freeit)(void *data));
12void *llist_pop(void *list); // actually void **list, but the compiler's dumb
13
14struct string_list {
15 struct string_list *next;
16 char str[0];
17};
18
Rob Landley8324b892006-11-19 02:49:22 -050019struct arg_list {
20 struct arg_list *next;
21 char *arg;
22};
23
Rob Landleyd25f7e42007-02-03 14:11:26 -050024struct dirtree {
Rob Landley720fc262007-02-04 19:14:58 -050025 struct dirtree *next, *child, *parent;
Rob Landleyd25f7e42007-02-03 14:11:26 -050026 struct stat st;
27 char name[];
28};
29
Rob Landley8324b892006-11-19 02:49:22 -050030// args.c
31void get_optflags(void);
32
landleycd9dfc32006-10-18 18:38:16 -040033// functions.c
landley09ea7ac2006-10-30 01:38:00 -050034void verror_msg(char *msg, int err, va_list va);
35void error_msg(char *msg, ...);
36void perror_msg(char *msg, ...);
landley4f344e32006-10-05 16:18:03 -040037void error_exit(char *msg, ...);
landley09ea7ac2006-10-30 01:38:00 -050038void perror_exit(char *msg, ...);
Rob Landley055cfcb2007-01-14 20:20:06 -050039void usage_exit(void);
landley4f344e32006-10-05 16:18:03 -040040void strlcpy(char *dest, char *src, size_t size);
41void *xmalloc(size_t size);
landleycd9dfc32006-10-18 18:38:16 -040042void *xzalloc(size_t size);
43void xrealloc(void **ptr, size_t size);
landley4f344e32006-10-05 16:18:03 -040044void *xstrndup(char *s, size_t n);
Rob Landleyfa98d012006-11-02 02:57:27 -050045void *xstrdup(char *s);
landley00f87f12006-10-25 18:38:37 -040046char *xmsprintf(char *format, ...);
Rob Landley24d1d452007-01-20 18:04:20 -050047void xprintf(char *format, ...);
48void xputc(char c);
49void xflush(void);
landley09ea7ac2006-10-30 01:38:00 -050050void xexec(char **argv);
Rob Landleyd3e9d642007-01-08 03:25:47 -050051void xaccess(char *path, int flags);
Rob Landley1322beb2007-01-07 22:51:12 -050052int xcreate(char *path, int flags, int mode);
53int xopen(char *path, int flags);
landley4f344e32006-10-05 16:18:03 -040054FILE *xfopen(char *path, char *mode);
Rob Landley90163772007-01-18 21:54:08 -050055ssize_t readall(int fd, void *buf, size_t len);
56ssize_t writeall(int fd, void *buf, size_t len);
57size_t xread(int fd, void *buf, size_t len);
58void xreadall(int fd, void *buf, size_t len);
59void xwrite(int fd, void *buf, size_t len);
landley00f87f12006-10-25 18:38:37 -040060char *xgetcwd(void);
Rob Landleyd25f7e42007-02-03 14:11:26 -050061void xstat(char *path, struct stat *st);
Rob Landleyfa98d012006-11-02 02:57:27 -050062char *xabspath(char *path);
Rob Landley0a04b3e2006-11-03 00:05:52 -050063struct string_list *find_in_path(char *path, char *filename);
landley09ea7ac2006-10-30 01:38:00 -050064void utoa_to_buf(unsigned n, char *buf, unsigned buflen);
65void itoa_to_buf(int n, char *buf, unsigned buflen);
66char *utoa(unsigned n);
67char *itoa(int n);
Rob Landleyf5757162007-02-16 21:08:22 -050068long atolx(char *c);
Rob Landleye2580db2007-01-23 13:20:38 -050069off_t fdlength(int fd);
Rob Landleyd25f7e42007-02-03 14:11:26 -050070struct dirtree *read_dirtree_node(char *path);
Rob Landley720fc262007-02-04 19:14:58 -050071struct dirtree *read_dirtree(char *path, struct dirtree *parent);
landley4f344e32006-10-05 16:18:03 -040072
landleycd9dfc32006-10-18 18:38:16 -040073// getmountlist.c
landley4f344e32006-10-05 16:18:03 -040074struct mtab_list {
75 struct mtab_list *next;
landley09ea7ac2006-10-30 01:38:00 -050076 struct stat stat;
77 struct statvfs statvfs;
landley4f344e32006-10-05 16:18:03 -040078 char *dir;
79 char *device;
80 char type[0];
81};
82
83struct mtab_list *getmountlist(int die);
84
Rob Landley6000f132007-01-18 22:00:12 -050085void bunzipStream(int src_fd, int dst_fd);