aboutsummaryrefslogtreecommitdiff
path: root/lib/lib.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-04-14 22:30:41 -0500
committerRob Landley <rob@landley.net>2012-04-14 22:30:41 -0500
commiteb7ea22c7505f10928e104a9df39edc70a8f7036 (patch)
treebc928711030e2378298c8e5012c7c76b9b606661 /lib/lib.c
parent43e9d331c8055dff7e243bd19d2d06df826d6f38 (diff)
downloadtoybox-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.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 4190b065..a7eb65a6 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -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)
{