1303 files changed, 32187 insertions, 57138 deletions
diff --git a/libbb/platform.c b/libbb/platform.c index 5fcd448..04ef246 100644 --- a/libbb/platform.c +++ b/libbb/platform.c @@ -17,6 +17,24 @@ char* FAST_FUNC strchrnul(const char *s, int c) } #endif +#ifndef HAVE_USLEEP +int FAST_FUNC usleep(unsigned usec) +{ + struct timespec ts; + ts.tv_sec = usec / 1000000u; + ts.tv_nsec = (usec % 1000000u) * 1000u; + /* + * If a signal has non-default handler, nanosleep returns early. + * Our version of usleep doesn't return early + * if interrupted by such signals: + * + */ + while (nanosleep(&ts, &ts) != 0) + continue; + return 0; +} +#endif + #ifndef HAVE_VASPRINTF int FAST_FUNC vasprintf(char **string_ptr, const char *format, va_list p) { @@ -179,3 +197,22 @@ ssize_t FAST_FUNC getline(char **lineptr, size_t *n, FILE *stream) return len; } #endif + +#ifndef HAVE_TTYNAME_R +int ttyname_r(int fd, char *buf, size_t buflen) +{ + int r; + char path[sizeof("/proc/self/fd/%d") + sizeof(int)*3]; + + if (!isatty(fd)) + return errno == EINVAL ? ENOTTY : errno; + sprintf(path, "/proc/self/fd/%d", fd); + r = readlink(path, buf, buflen); + if (r < 0) + return errno; + if (r >= buflen) + return ERANGE; + buf[r] = '\0'; + return 0; +} +#endif |