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 | |
| 24 | // args.c |
| 25 | void get_optflags(void); |
| 26 | |
landley | cd9dfc3 | 2006-10-18 18:38:16 -0400 | [diff] [blame] | 27 | // functions.c |
landley | 09ea7ac | 2006-10-30 01:38:00 -0500 | [diff] [blame] | 28 | void verror_msg(char *msg, int err, va_list va); |
| 29 | void error_msg(char *msg, ...); |
| 30 | void perror_msg(char *msg, ...); |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 31 | void error_exit(char *msg, ...); |
landley | 09ea7ac | 2006-10-30 01:38:00 -0500 | [diff] [blame] | 32 | void perror_exit(char *msg, ...); |
Rob Landley | 055cfcb | 2007-01-14 20:20:06 -0500 | [diff] [blame^] | 33 | void usage_exit(void); |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 34 | void strlcpy(char *dest, char *src, size_t size); |
| 35 | void *xmalloc(size_t size); |
landley | cd9dfc3 | 2006-10-18 18:38:16 -0400 | [diff] [blame] | 36 | void *xzalloc(size_t size); |
| 37 | void xrealloc(void **ptr, size_t size); |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 38 | void *xstrndup(char *s, size_t n); |
Rob Landley | fa98d01 | 2006-11-02 02:57:27 -0500 | [diff] [blame] | 39 | void *xstrdup(char *s); |
landley | 00f87f1 | 2006-10-25 18:38:37 -0400 | [diff] [blame] | 40 | char *xmsprintf(char *format, ...); |
landley | 09ea7ac | 2006-10-30 01:38:00 -0500 | [diff] [blame] | 41 | void xexec(char **argv); |
Rob Landley | d3e9d64 | 2007-01-08 03:25:47 -0500 | [diff] [blame] | 42 | void xaccess(char *path, int flags); |
Rob Landley | 1322beb | 2007-01-07 22:51:12 -0500 | [diff] [blame] | 43 | int xcreate(char *path, int flags, int mode); |
| 44 | int xopen(char *path, int flags); |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 45 | FILE *xfopen(char *path, char *mode); |
landley | 64b2e23 | 2006-10-30 10:01:19 -0500 | [diff] [blame] | 46 | ssize_t reread(int fd, void *buf, size_t count); |
Rob Landley | f3e452a | 2007-01-08 02:49:39 -0500 | [diff] [blame] | 47 | ssize_t rewrite(int fd, void *buf, size_t count); |
landley | 64b2e23 | 2006-10-30 10:01:19 -0500 | [diff] [blame] | 48 | ssize_t readall(int fd, void *buf, size_t count); |
Rob Landley | f3e452a | 2007-01-08 02:49:39 -0500 | [diff] [blame] | 49 | ssize_t writeall(int fd, void *buf, size_t count); |
Rob Landley | 055cfcb | 2007-01-14 20:20:06 -0500 | [diff] [blame^] | 50 | size_t xread(int fd, void *buf, size_t count); |
| 51 | void xreadall(int fd, void *buf, size_t count); |
Rob Landley | 3388f4c | 2007-01-08 04:26:01 -0500 | [diff] [blame] | 52 | void xwrite(int fd, void *buf, size_t count); |
landley | 00f87f1 | 2006-10-25 18:38:37 -0400 | [diff] [blame] | 53 | char *xgetcwd(void); |
Rob Landley | fa98d01 | 2006-11-02 02:57:27 -0500 | [diff] [blame] | 54 | char *xabspath(char *path); |
Rob Landley | 0a04b3e | 2006-11-03 00:05:52 -0500 | [diff] [blame] | 55 | struct string_list *find_in_path(char *path, char *filename); |
landley | 09ea7ac | 2006-10-30 01:38:00 -0500 | [diff] [blame] | 56 | void utoa_to_buf(unsigned n, char *buf, unsigned buflen); |
| 57 | void itoa_to_buf(int n, char *buf, unsigned buflen); |
| 58 | char *utoa(unsigned n); |
| 59 | char *itoa(int n); |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 60 | |
landley | cd9dfc3 | 2006-10-18 18:38:16 -0400 | [diff] [blame] | 61 | // getmountlist.c |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 62 | struct mtab_list { |
| 63 | struct mtab_list *next; |
landley | 09ea7ac | 2006-10-30 01:38:00 -0500 | [diff] [blame] | 64 | struct stat stat; |
| 65 | struct statvfs statvfs; |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 66 | char *dir; |
| 67 | char *device; |
| 68 | char type[0]; |
| 69 | }; |
| 70 | |
| 71 | struct mtab_list *getmountlist(int die); |
| 72 | |
Rob Landley | 1322beb | 2007-01-07 22:51:12 -0500 | [diff] [blame] | 73 | char *bunzipStream(int src_fd, int dst_fd); |