diff options
author | Rob Landley <rob@landley.net> | 2012-04-14 22:30:41 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2012-04-14 22:30:41 -0500 |
commit | eb7ea22c7505f10928e104a9df39edc70a8f7036 (patch) | |
tree | bc928711030e2378298c8e5012c7c76b9b606661 /lib/lib.c | |
parent | 43e9d331c8055dff7e243bd19d2d06df826d6f38 (diff) | |
download | toybox-eb7ea22c7505f10928e104a9df39edc70a8f7036.tar.gz |
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Diffstat (limited to 'lib/lib.c')
-rw-r--r-- | lib/lib.c | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -208,6 +208,13 @@ void xclose(int fd) if (close(fd)) perror_exit("xclose"); } +int xdup(int fd) +{ + fd = dup(fd); + if (fd == -1) perror_exit("xdup"); + return fd; +} + // Die unless we can open/create a file, returning FILE *. FILE *xfopen(char *path, char *mode) { @@ -497,6 +504,16 @@ long atolx(char *numstr) return val; } +int numlen(long l) +{ + int len = 0; + while (l) { + l /= 10; + len++; + } + return len; +} + // Return how long the file at fd is, if there's any way to determine it. off_t fdlength(int fd) { |