landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 1 | /* vi: set ts=4 :*/ |
landley | 09ea7ac | 2006-10-30 01:38:00 -0500 | [diff] [blame] | 2 | /* lib.h - header file for lib directory |
| 3 | * |
| 4 | * Copyright 2006 Rob Landley <rob@landley.net> |
| 5 | */ |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 6 | |
Rob Landley | 1521a9e | 2006-11-25 16:06:55 -0500 | [diff] [blame] | 7 | // libc generally has this, but the headers are screwed up |
| 8 | ssize_t getline(char **lineptr, size_t *n, FILE *stream); |
| 9 | |
Rob Landley | 0a04b3e | 2006-11-03 00:05:52 -0500 | [diff] [blame] | 10 | // llist.c |
| 11 | void llist_free(void *list, void (*freeit)(void *data)); |
| 12 | void *llist_pop(void *list); // actually void **list, but the compiler's dumb |
| 13 | |
| 14 | struct string_list { |
| 15 | struct string_list *next; |
| 16 | char str[0]; |
| 17 | }; |
| 18 | |
Rob Landley | 8324b89 | 2006-11-19 02:49:22 -0500 | [diff] [blame] | 19 | struct arg_list { |
| 20 | struct arg_list *next; |
| 21 | char *arg; |
| 22 | }; |
| 23 | |
Rob Landley | d25f7e4 | 2007-02-03 14:11:26 -0500 | [diff] [blame] | 24 | struct dirtree { |
Rob Landley | 720fc26 | 2007-02-04 19:14:58 -0500 | [diff] [blame^] | 25 | struct dirtree *next, *child, *parent; |
Rob Landley | d25f7e4 | 2007-02-03 14:11:26 -0500 | [diff] [blame] | 26 | struct stat st; |
| 27 | char name[]; |
| 28 | }; |
| 29 | |
Rob Landley | 8324b89 | 2006-11-19 02:49:22 -0500 | [diff] [blame] | 30 | // args.c |
| 31 | void get_optflags(void); |
| 32 | |
landley | cd9dfc3 | 2006-10-18 18:38:16 -0400 | [diff] [blame] | 33 | // functions.c |
landley | 09ea7ac | 2006-10-30 01:38:00 -0500 | [diff] [blame] | 34 | void verror_msg(char *msg, int err, va_list va); |
| 35 | void error_msg(char *msg, ...); |
| 36 | void perror_msg(char *msg, ...); |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 37 | void error_exit(char *msg, ...); |
landley | 09ea7ac | 2006-10-30 01:38:00 -0500 | [diff] [blame] | 38 | void perror_exit(char *msg, ...); |
Rob Landley | 055cfcb | 2007-01-14 20:20:06 -0500 | [diff] [blame] | 39 | void usage_exit(void); |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 40 | void strlcpy(char *dest, char *src, size_t size); |
| 41 | void *xmalloc(size_t size); |
landley | cd9dfc3 | 2006-10-18 18:38:16 -0400 | [diff] [blame] | 42 | void *xzalloc(size_t size); |
| 43 | void xrealloc(void **ptr, size_t size); |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 44 | void *xstrndup(char *s, size_t n); |
Rob Landley | fa98d01 | 2006-11-02 02:57:27 -0500 | [diff] [blame] | 45 | void *xstrdup(char *s); |
landley | 00f87f1 | 2006-10-25 18:38:37 -0400 | [diff] [blame] | 46 | char *xmsprintf(char *format, ...); |
Rob Landley | 24d1d45 | 2007-01-20 18:04:20 -0500 | [diff] [blame] | 47 | void xprintf(char *format, ...); |
| 48 | void xputc(char c); |
| 49 | void xflush(void); |
landley | 09ea7ac | 2006-10-30 01:38:00 -0500 | [diff] [blame] | 50 | void xexec(char **argv); |
Rob Landley | d3e9d64 | 2007-01-08 03:25:47 -0500 | [diff] [blame] | 51 | void xaccess(char *path, int flags); |
Rob Landley | 1322beb | 2007-01-07 22:51:12 -0500 | [diff] [blame] | 52 | int xcreate(char *path, int flags, int mode); |
| 53 | int xopen(char *path, int flags); |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 54 | FILE *xfopen(char *path, char *mode); |
Rob Landley | 9016377 | 2007-01-18 21:54:08 -0500 | [diff] [blame] | 55 | ssize_t readall(int fd, void *buf, size_t len); |
| 56 | ssize_t writeall(int fd, void *buf, size_t len); |
| 57 | size_t xread(int fd, void *buf, size_t len); |
| 58 | void xreadall(int fd, void *buf, size_t len); |
| 59 | void xwrite(int fd, void *buf, size_t len); |
landley | 00f87f1 | 2006-10-25 18:38:37 -0400 | [diff] [blame] | 60 | char *xgetcwd(void); |
Rob Landley | d25f7e4 | 2007-02-03 14:11:26 -0500 | [diff] [blame] | 61 | void xstat(char *path, struct stat *st); |
Rob Landley | fa98d01 | 2006-11-02 02:57:27 -0500 | [diff] [blame] | 62 | char *xabspath(char *path); |
Rob Landley | 0a04b3e | 2006-11-03 00:05:52 -0500 | [diff] [blame] | 63 | struct string_list *find_in_path(char *path, char *filename); |
landley | 09ea7ac | 2006-10-30 01:38:00 -0500 | [diff] [blame] | 64 | void utoa_to_buf(unsigned n, char *buf, unsigned buflen); |
| 65 | void itoa_to_buf(int n, char *buf, unsigned buflen); |
| 66 | char *utoa(unsigned n); |
| 67 | char *itoa(int n); |
Rob Landley | e2580db | 2007-01-23 13:20:38 -0500 | [diff] [blame] | 68 | off_t fdlength(int fd); |
Rob Landley | d25f7e4 | 2007-02-03 14:11:26 -0500 | [diff] [blame] | 69 | struct dirtree *read_dirtree_node(char *path); |
Rob Landley | 720fc26 | 2007-02-04 19:14:58 -0500 | [diff] [blame^] | 70 | struct dirtree *read_dirtree(char *path, struct dirtree *parent); |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 71 | |
landley | cd9dfc3 | 2006-10-18 18:38:16 -0400 | [diff] [blame] | 72 | // getmountlist.c |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 73 | struct mtab_list { |
| 74 | struct mtab_list *next; |
landley | 09ea7ac | 2006-10-30 01:38:00 -0500 | [diff] [blame] | 75 | struct stat stat; |
| 76 | struct statvfs statvfs; |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 77 | char *dir; |
| 78 | char *device; |
| 79 | char type[0]; |
| 80 | }; |
| 81 | |
| 82 | struct mtab_list *getmountlist(int die); |
| 83 | |
Rob Landley | 6000f13 | 2007-01-18 22:00:12 -0500 | [diff] [blame] | 84 | void bunzipStream(int src_fd, int dst_fd); |