OSDN Git Service

Merge branch 'master' of https://android.googlesource.com/platform/external/toybox...
[android-x86/external-toybox.git] / lib / lib.h
index 3cda7d9..faf0249 100644 (file)
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -24,6 +24,11 @@ struct double_list {
   char *data;
 };
 
+struct ptr_len {
+  void *ptr;
+  long len;
+};
+
 void llist_free_arg(void *node);
 void llist_free_double(void *node);
 void llist_traverse(void *list, void (*using)(void *node));
@@ -50,6 +55,8 @@ void get_optflags(void);
 #define DIRTREE_COMEAGAIN    4
 // Follow symlinks to directories
 #define DIRTREE_SYMFOLLOW    8
+// Don't warn about failure to stat
+#define DIRTREE_SHUTUP      16
 // Don't look at any more files in this directory.
 #define DIRTREE_ABORT      256
 
@@ -60,12 +67,13 @@ struct dirtree {
   long extra; // place for user to store their stuff (can be pointer)
   struct stat st;
   char *symlink;
-  int data;  // dirfd for directory, linklen for symlink
+  int dirfd;
   char again;
   char name[];
 };
 
-struct dirtree *dirtree_add_node(struct dirtree *p, char *name, int symfollow);
+struct dirtree *dirtree_start(char *name, int symfollow);
+struct dirtree *dirtree_add_node(struct dirtree *p, char *name, int flags);
 char *dirtree_path(struct dirtree *node, int *plen);
 int dirtree_notdotdot(struct dirtree *catch);
 int dirtree_parentfd(struct dirtree *node);
@@ -77,7 +85,7 @@ struct dirtree *dirtree_read(char *path, int (*callback)(struct dirtree *node));
 
 // help.c
 
-void show_help(void);
+void show_help(FILE *out);
 
 // xwrap.c
 void xstrncpy(char *dest, char *src, size_t size);
@@ -95,6 +103,7 @@ void xputc(char c);
 void xflush(void);
 void xexec(char **argv);
 pid_t xpopen_both(char **argv, int *pipes);
+int xwaitpid(pid_t pid);
 int xpclose_both(pid_t pid, int *pipes);
 pid_t xpopen(char **argv, int *pipe, int stdout);
 pid_t xpclose(pid_t pid, int pipe);
@@ -138,13 +147,14 @@ void verror_msg(char *msg, int err, va_list va);
 void error_msg(char *msg, ...) printf_format;
 void perror_msg(char *msg, ...) printf_format;
 void error_exit(char *msg, ...) printf_format noreturn;
+void help_exit(char *msg, ...) printf_format noreturn;
 void perror_exit(char *msg, ...) printf_format noreturn;
 ssize_t readall(int fd, void *buf, size_t len);
 ssize_t writeall(int fd, void *buf, size_t len);
 off_t lskip(int fd, off_t offset);
 int mkpathat(int atfd, char *dir, mode_t lastmode, int flags);
 struct string_list **splitpath(char *path, struct string_list **list);
-char *readfileat(int dirfd, char *name, char *buf, off_t len);
+char *readfileat(int dirfd, char *name, char *buf, off_t *len);
 char *readfile(char *name, char *buf, off_t len);
 void msleep(long miliseconds);
 int64_t peek_le(void *ptr, unsigned size);
@@ -156,8 +166,9 @@ long estrtol(char *str, char **end, int base);
 long xstrtol(char *str, char **end, int base);
 long atolx(char *c);
 long atolx_range(char *numstr, long low, long high);
-int numlen(long l);
 int stridx(char *haystack, char needle);
+char *strlower(char *s);
+char *chomp(char *s);
 int unescape(char c);
 int strstart(char **a, char *b);
 off_t fdlength(int fd);
@@ -173,13 +184,41 @@ void delete_tempfile(int fdin, int fdout, char **tempname);
 void replace_tempfile(int fdin, int fdout, char **tempname);
 void crc_init(unsigned int *crc_table, int little_endian);
 void base64_init(char *p);
-int terminal_size(unsigned *x, unsigned *y);
-int yesno(char *prompt, int def);
-int human_readable(char *buf, unsigned long long num);
+int yesno(int def);
+int qstrcmp(const void *a, const void *b);
+int xpoll(struct pollfd *fds, int nfds, int timeout);
+
+#define HR_SPACE 1 // Space between number and units
+#define HR_B     2 // Use "B" for single byte units
+#define HR_1000  4 // Use decimal instead of binary units
+int human_readable(char *buf, unsigned long long num, int style);
+
+// interestingtimes.c
+int xgettty(void);
+int terminal_size(unsigned *xx, unsigned *yy);
+int set_terminal(int fd, int raw, struct termios *old);
+int scan_key(char *scratch, int block);
+void tty_esc(char *s);
+void tty_jump(int x, int y);
+void tty_reset(void);
+void tty_sigreset(int i);
+
+// Results from scan_key()
+#define KEY_UP 256
+#define KEY_DOWN 257
+#define KEY_RIGHT 258
+#define KEY_LEFT 259
+#define KEY_PGUP 260
+#define KEY_PGDN 261
+#define KEY_HOME 262
+#define KEY_END  263
+#define KEY_INSERT 264
 
 // net.c
 int xsocket(int domain, int type, int protocol);
 void xsetsockopt(int fd, int level, int opt, void *val, socklen_t len);
+int xconnect(char *host, char *port, int family, int socktype, int protocol,
+  int flags);
 
 // password.c
 int get_salt(char *salt, char * algo);
@@ -211,7 +250,29 @@ char *num_to_sig(int sig);
 
 mode_t string_to_mode(char *mode_str, mode_t base);
 void mode_to_string(mode_t mode, char *buf);
+static inline char *basename_r(char *name)
+{
+  char *s = strrchr(name, '/');
+
+  if (s) return s+1;
+  return name;
+}
+
 void names_to_pid(char **names, int (*callback)(pid_t pid, char *name));
 
+pid_t xvforkwrap(pid_t pid);
+#define XVFORK() xvforkwrap(vfork())
+
+#define WOULD_EXIT(y, x) do { jmp_buf _noexit; \
+  int _noexit_res; \
+  toys.rebound = &_noexit; \
+  _noexit_res = setjmp(_noexit); \
+  if (!_noexit_res) do {x;} while(0); \
+  toys.rebound = 0; \
+  y = _noexit_res; \
+} while(0);
+
+#define NOEXIT(x) WOULD_EXIT(_noexit_res, x)
+
 // Functions in need of further review/cleanup
 #include "lib/pending.h"