diff options
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) { |