OSDN Git Service

Remove itoa/utoa, let libc do this with sprintf.
[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 // Unfortunately, sizeof() doesn't work in a preprocessor test.  TODO.
7
8 //#if sizeof(double) <= sizeof(long)
9 //typedef double FLOAT;
10 //#else
11 typedef float FLOAT;
12 //#endif
13
14 // libc generally has this, but the headers are screwed up
15 ssize_t getline(char **lineptr, size_t *n, FILE *stream);
16
17 // llist.c
18
19 // All these list types can be handled by the same code because first element
20 // is always next pointer, so next = (mytype *)&struct. (The payloads are
21 // named differently to catch using the wrong type early.)
22
23 struct string_list {
24   struct string_list *next;
25   char str[0];
26 };
27
28 struct arg_list {
29   struct arg_list *next;
30   char *arg;
31 };
32
33 struct double_list {
34   struct double_list *next, *prev;
35   char *data;
36 };
37
38 void llist_traverse(void *list, void (*using)(void *data));
39 void *llist_pop(void *list);  // actually void **list, but the compiler's dumb
40 void dlist_add_nomalloc(struct double_list **list, struct double_list *new);
41 struct double_list *dlist_add(struct double_list **list, char *data);
42
43 // args.c
44 void get_optflags(void);
45
46 // dirtree.c
47
48 // Values returnable from callback function (bitfield, or them together)
49 // Default with no callback is 0
50
51 // Add this node to the tree
52 #define DIRTREE_SAVE         1
53 // Recurse into children
54 #define DIRTREE_RECURSE      2
55 // Call again after handling all children of this directory
56 // (Ignored for non-directories, sets linklen = -1 before second call.)
57 #define DIRTREE_COMEAGAIN    4
58 // Follow symlinks to directories
59 #define DIRTREE_SYMFOLLOW    8
60 // Don't look at any more files in this directory.
61 #define DIRTREE_ABORT      256
62
63 #define DIRTREE_ABORTVAL ((struct dirtree *)1)
64
65 struct dirtree {
66   struct dirtree *next, *parent, *child;
67   long extra; // place for user to store their stuff (can be pointer)
68   struct stat st;
69   char *symlink;
70   int data;  // dirfd for directory, linklen for symlink, -1 = comeagain
71   char name[];
72 };
73
74 struct dirtree *dirtree_add_node(struct dirtree *p, char *name, int symfollow);
75 char *dirtree_path(struct dirtree *node, int *plen);
76 int dirtree_notdotdot(struct dirtree *catch);
77 int dirtree_parentfd(struct dirtree *node);
78 struct dirtree *dirtree_handle_callback(struct dirtree *new,
79   int (*callback)(struct dirtree *node));
80 void dirtree_recurse(struct dirtree *node,
81   int (*callback)(struct dirtree *node), int symfollow);
82 struct dirtree *dirtree_read(char *path, int (*callback)(struct dirtree *node));
83
84 // help.c
85
86 void show_help(void);
87
88 // xwrap.c
89 void xstrncpy(char *dest, char *src, size_t size);
90 void xexit(void) noreturn;
91 void *xmalloc(size_t size);
92 void *xzalloc(size_t size);
93 void *xrealloc(void *ptr, size_t size);
94 char *xstrndup(char *s, size_t n);
95 char *xstrdup(char *s);
96 char *xmsprintf(char *format, ...);
97 void xprintf(char *format, ...);
98 void xputs(char *s);
99 void xputc(char c);
100 void xflush(void);
101 void xexec_optargs(int skip);
102 void xexec(char **argv);
103 void xaccess(char *path, int flags);
104 void xunlink(char *path);
105 int xcreate(char *path, int flags, int mode);
106 int xopen(char *path, int flags);
107 void xclose(int fd);
108 int xdup(int fd);
109 FILE *xfdopen(int fd, char *mode);
110 FILE *xfopen(char *path, char *mode);
111 size_t xread(int fd, void *buf, size_t len);
112 void xreadall(int fd, void *buf, size_t len);
113 void xwrite(int fd, void *buf, size_t len);
114 off_t xlseek(int fd, off_t offset, int whence);
115 char *xreadfile(char *name);
116 int xioctl(int fd, int request, void *data);
117 char *xgetcwd(void);
118 void xstat(char *path, struct stat *st);
119 char *xabspath(char *path, int exact);
120 char *xrealpath(char *path);
121 void xchdir(char *path);
122 void xmkpath(char *path, int mode);
123 void xsetuid(uid_t uid);
124 char *xreadlink(char *name);
125 long xparsetime(char *arg, long units, long *fraction);
126 void xpidfile(char *name);
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 struct string_list **splitpath(char *path, struct string_list **list);
138 char *readfile(char *name);
139 void msleep(long miliseconds);
140 int64_t peek(void *ptr, int size);
141 void poke(void *ptr, uint64_t val, int size);
142 struct string_list *find_in_path(char *path, char *filename);
143 long atolx(char *c);
144 int numlen(long l);
145 int stridx(char *haystack, char needle);
146 off_t fdlength(int fd);
147 void loopfiles_rw(char **argv, int flags, int permissions, int failok,
148   void (*function)(int fd, char *name));
149 void loopfiles(char **argv, void (*function)(int fd, char *name));
150 char *get_rawline(int fd, long *plen, char end);
151 char *get_line(int fd);
152 void xsendfile(int in, int out);
153 int wfchmodat(int rc, char *name, mode_t mode);
154 int copy_tempfile(int fdin, char *name, char **tempname);
155 void delete_tempfile(int fdin, int fdout, char **tempname);
156 void replace_tempfile(int fdin, int fdout, char **tempname);
157 void crc_init(unsigned int *crc_table, int little_endian);
158 void terminal_size(unsigned *x, unsigned *y);
159 int yesno(char *prompt, int def);
160 void for_each_pid_with_name_in(char **names, int (*callback)(pid_t pid, char *name));
161
162 // net.c
163 int xsocket(int domain, int type, int protocol);
164
165 // getmountlist.c
166 struct mtab_list {
167   struct mtab_list *next;
168   struct stat stat;
169   struct statvfs statvfs;
170   char *dir;
171   char *device;
172   char type[0];
173 };
174
175 struct mtab_list *xgetmountlist(char *path);
176
177 void bunzipStream(int src_fd, int dst_fd);
178
179 // signal
180
181 void sigatexit(void *handler);
182 int sig_to_num(char *pidstr);
183 char *num_to_sig(int sig);
184
185 mode_t string_to_mode(char *mode_str, mode_t base);
186 void mode_to_string(mode_t mode, char *buf);
187
188 // password helper functions
189 int read_password(char * buff, int buflen, char* mesg);
190 int update_password(char *filename, char* username, char* encrypted);
191
192 // cut helper functions
193 unsigned long get_int_value(const char *numstr, unsigned lowrange, unsigned highrange);
194
195 // grep helper functions
196 char  *astrcat (char *, char *);
197 char *xastrcat (char *, char *);
198
199 void daemonize(void);