diff options
Diffstat (limited to 'lib')
-rwxr-xr-x[-rw-r--r--] | lib/lib.c | 43 | ||||
-rwxr-xr-x[-rw-r--r--] | lib/lib.h | 7 | ||||
-rwxr-xr-x[-rw-r--r--] | lib/net.c | 30 | ||||
-rwxr-xr-x[-rw-r--r--] | lib/portability.c | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | lib/xwrap.c | 9 |
5 files changed, 8 insertions, 81 deletions
diff --git a/lib/lib.c b/lib/lib.c index c16cffe..05e377f 100644..100755 --- a/lib/lib.c +++ b/lib/lib.c @@ -291,41 +291,6 @@ int stridx(char *haystack, char needle) return off-haystack; } -char *strlower(char *s) -{ - char *try, *new; - - if (!CFG_TOYBOX_I18N) { - try = new = xstrdup(s); - for (; *s; s++) *(new++) = tolower(*s); - } else { - // I can't guarantee the string _won't_ expand during reencoding, so...? - try = new = xmalloc(strlen(s)*2+1); - - while (*s) { - wchar_t c; - int len = mbrtowc(&c, s, MB_CUR_MAX, 0); - - if (len < 1) *(new++) = *(s++); - else { - s += len; - // squash title case too - c = towlower(c); - - // if we had a valid utf8 sequence, convert it to lower case, and can't - // encode back to utf8, something is wrong with your libc. But just - // in case somebody finds an exploit... - len = wcrtomb(new, c, 0); - if (len < 1) error_exit("bad utf8 %x", (int)c); - new += len; - } - } - *new = 0; - } - - return try; -} - int unescape(char c) { char *from = "\\abefnrtv", *to = "\\\a\b\033\f\n\r\t\v"; @@ -575,7 +540,7 @@ void delete_tempfile(int fdin, int fdout, char **tempname) { close(fdin); close(fdout); - if (*tempname) unlink(*tempname); + unlink(*tempname); tempfile2zap = (char *)1; free(*tempname); *tempname = NULL; @@ -868,7 +833,7 @@ void names_to_pid(char **names, int (*callback)(pid_t pid, char *name)) // display first few digits of number with power of two units, except we're // actually just counting decimal digits and showing mil/bil/trillions. -int human_readable(char *buf, unsigned long long num, int style) +int human_readable(char *buf, unsigned long long num) { int end, len; @@ -881,9 +846,9 @@ int human_readable(char *buf, unsigned long long num, int style) buf[1] = '.'; end = 3; } - if (style & HR_SPACE) buf[end++] = ' '; + buf[end++] = ' '; if (len) buf[end++] = " KMGTPE"[len]; - if (style & HR_B) buf[end++] = 'B'; + buf[end++] = 'B'; buf[end++] = 0; return end; diff --git a/lib/lib.h b/lib/lib.h index 17a4a97..3183f32 100644..100755 --- a/lib/lib.h +++ b/lib/lib.h @@ -160,7 +160,6 @@ long xstrtol(char *str, char **end, int base); long atolx(char *c); long atolx_range(char *numstr, long low, long high); int stridx(char *haystack, char needle); -char *strlower(char *s); int unescape(char c); int strstart(char **a, char *b); off_t fdlength(int fd); @@ -177,9 +176,7 @@ 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 yesno(char *prompt, int def); -#define HR_SPACE 1 -#define HR_B 2 -int human_readable(char *buf, unsigned long long num, int style); +int human_readable(char *buf, unsigned long long num); int qstrcmp(const void *a, const void *b); int xpoll(struct pollfd *fds, int nfds, int timeout); @@ -207,8 +204,6 @@ void tty_sigreset(int i); // 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); diff --git a/lib/net.c b/lib/net.c index 48d0a5f..5d3ea4a 100644..100755 --- a/lib/net.c +++ b/lib/net.c @@ -12,33 +12,3 @@ void xsetsockopt(int fd, int level, int opt, void *val, socklen_t len) { if (-1 == setsockopt(fd, level, opt, val, len)) perror_exit("setsockopt"); } - -int xconnect(char *host, char *port, int family, int socktype, int protocol, - int flags) -{ - struct addrinfo info, *ai, *ai2; - int fd; - - memset(&info, 0, sizeof(struct addrinfo)); - info.ai_family = family; - info.ai_socktype = socktype; - info.ai_protocol = protocol; - info.ai_flags = flags; - - fd = getaddrinfo(host, port, &info, &ai); - if (fd || !ai) - error_exit("Connect '%s%s%s': %s", host, port ? ":" : "", port ? port : "", - fd ? gai_strerror(fd) : "not found"); - - // Try all the returned addresses. Report errors if last entry can't connect. - for (ai2 = ai; ai; ai = ai->ai_next) { - fd = (ai->ai_next ? socket : xsocket)(ai->ai_family, ai->ai_socktype, - ai->ai_protocol); - if (!connect(fd, ai->ai_addr, ai->ai_addrlen)) break; - else if (!ai2->ai_next) perror_exit("connect"); - close(fd); - } - freeaddrinfo(ai2); - - return fd; -} diff --git a/lib/portability.c b/lib/portability.c index 78e500b..78e500b 100644..100755 --- a/lib/portability.c +++ b/lib/portability.c diff --git a/lib/xwrap.c b/lib/xwrap.c index 8086282..54f2cbb 100644..100755 --- a/lib/xwrap.c +++ b/lib/xwrap.c @@ -30,10 +30,10 @@ void xstrncat(char *dest, char *src, size_t size) void xexit(void) { - if (toys.rebound) longjmp(*toys.rebound, 1); if (fflush(NULL) || ferror(stdout)) if (!toys.exitval) perror_msg("write"); - exit(toys.exitval); + if (toys.rebound) longjmp(*toys.rebound, 1); + else exit(toys.exitval); } // Die unless we can allocate memory. @@ -136,10 +136,7 @@ void xexec(char **argv) if (CFG_TOYBOX && !CFG_TOYBOX_NORECURSE) toy_exec(argv); execvp(argv[0], argv); - perror_msg("exec %s", argv[0]); - toys.exitval = 127; - if (!CFG_TOYBOX_FORK) _exit(toys.exitval); - xexit(); + perror_exit("exec %s", argv[0]); } // Spawn child process, capturing stdin/stdout. |