diff options
author | Rob Landley <rob@landley.net> | 2015-04-03 11:49:31 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2015-04-03 11:49:31 -0500 |
commit | e10483fdc9ef8b69b2a420e8d991b865e05b85b9 (patch) | |
tree | 72069bd30eb5c716254b695e99d26ec819b49e7b /lib/lib.c | |
parent | 97c536c40eb4cc732b8a11688e0196281e90d81b (diff) | |
download | toybox-e10483fdc9ef8b69b2a420e8d991b865e05b85b9.tar.gz |
Add readfileat() to lib
Diffstat (limited to 'lib/lib.c')
-rw-r--r-- | lib/lib.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -362,14 +362,12 @@ off_t fdlength(int fd) // Read contents of file as a single nul-terminated string. // malloc new one if buf=len=0 -char *readfile(char *name, char *ibuf, off_t len) +char *readfileat(int dirfd, char *name, char *ibuf, off_t len) { int fd; char *buf; - fd = open(name, O_RDONLY); - if (fd == -1) return 0; - + if (-1 == (fd = openat(dirfd, name, O_RDONLY))) return 0; if (len<1) { len = fdlength(fd); // proc files don't report a length, so try 1 page minimum. @@ -388,6 +386,11 @@ char *readfile(char *name, char *ibuf, off_t len) return buf; } +char *readfile(char *name, char *ibuf, off_t len) +{ + return readfileat(AT_FDCWD, name, ibuf, len); +} + // Sleep for this many thousandths of a second void msleep(long miliseconds) { |