aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c10
-rw-r--r--lib/lib.h1
2 files changed, 11 insertions, 0 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 89c8781b..a5bf4755 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -266,6 +266,16 @@ void xwrite(int fd, void *buf, size_t len)
if (len != writeall(fd, buf, len)) perror_exit("xwrite");
}
+// Die if lseek fails, probably due to being called on a pipe.
+
+off_t xlseek(int fd, off_t offset, int whence)
+{
+ offset = lseek(fd, offset, whence);
+ if (offset<0) perror_exit("lseek");
+
+ return offset;
+}
+
char *xgetcwd(void)
{
char *buf = getcwd(NULL, 0);
diff --git a/lib/lib.h b/lib/lib.h
index a473b546..61e80cf9 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -73,6 +73,7 @@ ssize_t writeall(int fd, void *buf, size_t len);
size_t xread(int fd, void *buf, size_t len);
void xreadall(int fd, void *buf, size_t len);
void xwrite(int fd, void *buf, size_t len);
+off_t xlseek(int fd, off_t offset, int whence);
char *readfile(char *name);
char *xreadfile(char *name);
char *xgetcwd(void);