aboutsummaryrefslogtreecommitdiff
path: root/lib/lib.c
diff options
context:
space:
mode:
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)
{