OSDN Git Service

Cleanup pass on mkpasswd.c
[android-x86/external-toybox.git] / lib / lib.h
1 /* lib.h - header file for lib directory
2  *
3  * Copyright 2006 Rob Landley <rob@landley.net>
4  */
5
6 // llist.c
7
8 // All these list types can be handled by the same code because first element
9 // is always next pointer, so next = (mytype *)&struct. (The payloads are
10 // named differently to catch using the wrong type early.)
11
12 struct string_list {
13   struct string_list *next;
14   char str[0];
15 };
16
17 struct arg_list {
18   struct arg_list *next;
19   char *arg;
20 };
21
22 struct double_list {
23   struct double_list *next, *prev;
24   char *data;
25 };
26
27 void llist_free_arg(void *node);
28 void llist_free_double(void *node);
29 void llist_traverse(void *list, void (*using)(void *node));
30 void *llist_pop(void *list);  // actually void **list
31 void *dlist_pop(void *list);  // actually struct double_list **list
32 void dlist_add_nomalloc(struct double_list **list, struct double_list *new);
33 struct double_list *dlist_add(struct double_list **list, char *data);
34 void *dlist_terminate(void *list);
35
36 // args.c
37 void get_optflags(void);
38
39 // dirtree.c
40
41 // Values returnable from callback function (bitfield, or them together)
42 // Default with no callback is 0
43
44 // Add this node to the tree
45 #define DIRTREE_SAVE         1
46 // Recurse into children
47 #define DIRTREE_RECURSE      2
48 // Call again after handling all children of this directory
49 // (Ignored for non-directories, sets linklen = -1 before second call.)
50 #define DIRTREE_COMEAGAIN    4
51 // Follow symlinks to directories
52 #define DIRTREE_SYMFOLLOW    8
53 // Don't look at any more files in this directory.
54 #define DIRTREE_ABORT      256
55
56 #define DIRTREE_ABORTVAL ((struct dirtree *)1)
57
58 struct dirtree {
59   struct dirtree *next, *parent, *child;
60   long extra; // place for user to store their stuff (can be pointer)
61   struct stat st;
62   char *symlink;
63   int data;  // dirfd for directory, linklen for symlink, -1 = comeagain
64   char name[];
65 };
66
67 struct dirtree *dirtree_add_node(struct dirtree *p, char *name, int symfollow);
68 char *dirtree_path(struct dirtree *node, int *plen);
69 int dirtree_notdotdot(struct dirtree *catch);
70 int dirtree_parentfd(struct dirtree *node);
71 struct dirtree *dirtree_handle_callback(struct dirtree *new,
72   int (*callback)(struct dirtree *node));
73 void dirtree_recurse(struct dirtree *node,
74   int (*callback)(struct dirtree *node), int symfollow);
75 struct dirtree *dirtree_read(char *path, int (*callback)(struct dirtree *node));
76
77 // help.c
78
79 void show_help(void);
80
81 // xwrap.c
82 void xstrncpy(char *dest, char *src, size_t size);
83 void xexit(void) noreturn;
84 void *xmalloc(size_t size);
85 void *xzalloc(size_t size);
86 void *xrealloc(void *ptr, size_t size);
87 char *xstrndup(char *s, size_t n);
88 char *xstrdup(char *s);
89 char *xmprintf(char *format, ...);
90 void xprintf(char *format, ...);
91 void xputs(char *s);
92 void xputc(char c);
93 void xflush(void);
94 pid_t xfork(void);
95 void xexec_optargs(int skip);
96 void xexec(char **argv);
97 pid_t xpopen(char **argv, int *pipes);
98 int xpclose(pid_t pid, int *pipes);
99 void xaccess(char *path, int flags);
100 void xunlink(char *path);
101 int xcreate(char *path, int flags, int mode);
102 int xopen(char *path, int flags);
103 void xclose(int fd);
104 int xdup(int fd);
105 FILE *xfdopen(int fd, char *mode);
106 FILE *xfopen(char *path, char *mode);
107 size_t xread(int fd, void *buf, size_t len);
108 void xreadall(int fd, void *buf, size_t len);
109 void xwrite(int fd, void *buf, size_t len);
110 off_t xlseek(int fd, off_t offset, int whence);
111 char *xreadfile(char *name, char *buf, off_t len);
112 int xioctl(int fd, int request, void *data);
113 char *xgetcwd(void);
114 void xstat(char *path, struct stat *st);
115 char *xabspath(char *path, int exact);
116 char *xrealpath(char *path);
117 void xchdir(char *path);
118 void xchroot(char *path);
119 struct passwd *xgetpwuid(uid_t uid);
120 struct group *xgetgrgid(gid_t gid);
121 struct passwd *xgetpwnam(char *name);
122 void xsetuser(struct passwd *pwd);
123 char *xreadlink(char *name);
124 long xparsetime(char *arg, long units, long *fraction);
125 void xpidfile(char *name);
126 void xregcomp(regex_t *preg, char *rexec, int cflags);
127
128 // lib.c
129 void verror_msg(char *msg, int err, va_list va);
130 void error_msg(char *msg, ...);
131 void perror_msg(char *msg, ...);
132 void error_exit(char *msg, ...) noreturn;
133 void perror_exit(char *msg, ...) noreturn;
134 ssize_t readall(int fd, void *buf, size_t len);
135 ssize_t writeall(int fd, void *buf, size_t len);
136 off_t lskip(int fd, off_t offset);
137 int mkpathat(int atfd, char *dir, mode_t lastmode, int flags);
138 struct string_list **splitpath(char *path, struct string_list **list);
139 char *readfile(char *name, char *buf, off_t len);
140 void msleep(long miliseconds);
141 int64_t peek(void *ptr, int size);
142 void poke(void *ptr, uint64_t val, int size);
143 struct string_list *find_in_path(char *path, char *filename);
144 long atolx(char *c);
145 long atolx_range(char *numstr, long low, long high);
146 int numlen(long l);
147 int stridx(char *haystack, char needle);
148 int strstart(char **a, char *b);
149 off_t fdlength(int fd);
150 void loopfiles_rw(char **argv, int flags, int permissions, int failok,
151   void (*function)(int fd, char *name));
152 void loopfiles(char **argv, void (*function)(int fd, char *name));
153 char *get_rawline(int fd, long *plen, char end);
154 char *get_line(int fd);
155 void xsendfile(int in, int out);
156 int wfchmodat(int rc, char *name, mode_t mode);
157 int copy_tempfile(int fdin, char *name, char **tempname);
158 void delete_tempfile(int fdin, int fdout, char **tempname);
159 void replace_tempfile(int fdin, int fdout, char **tempname);
160 void crc_init(unsigned int *crc_table, int little_endian);
161 int terminal_size(unsigned *x, unsigned *y);
162 int yesno(char *prompt, int def);
163 int human_readable(char *buf, unsigned long long num);
164
165 // net.c
166 int xsocket(int domain, int type, int protocol);
167
168 // password.c
169 int get_salt(char *salt, char * algo);
170
171 // getmountlist.c
172 struct mtab_list {
173   struct mtab_list *next, *prev;
174   struct stat stat;
175   struct statvfs statvfs;
176   char *dir;
177   char *device;
178   char *opts;
179   char type[0];
180 };
181
182 struct mtab_list *xgetmountlist(char *path);
183
184 // signal
185
186 void generic_signal(int signal);
187 void sigatexit(void *handler);
188 int sig_to_num(char *pidstr);
189 char *num_to_sig(int sig);
190
191 mode_t string_to_mode(char *mode_str, mode_t base);
192 void mode_to_string(mode_t mode, char *buf);
193 void names_to_pid(char **names, int (*callback)(pid_t pid, char *name));
194
195 // Functions in need of further review/cleanup
196 #include "lib/pending.h"