aboutsummaryrefslogtreecommitdiff
path: root/lib/lib.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-07-15 16:56:20 -0500
committerRob Landley <rob@landley.net>2012-07-15 16:56:20 -0500
commit2037b8396427ab82edd1912357e9177a2800b01a (patch)
treeb6eaae82fbd0db5b3e36a786d1a8b45d8b0a889a /lib/lib.c
parentf96fe64b1ed0ffa7bd7c954de3e1b14104d5bac6 (diff)
downloadtoybox-2037b8396427ab82edd1912357e9177a2800b01a.tar.gz
New infrastructure for od (oops).
Diffstat (limited to 'lib/lib.c')
-rw-r--r--lib/lib.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 6cb82e24..2b321099 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -286,6 +286,27 @@ off_t xlseek(int fd, off_t offset, int whence)
return offset;
}
+off_t lskip(int fd, off_t offset)
+{
+ off_t and = lseek(fd, offset, SEEK_CUR);
+
+ if (and != -1 && offset >= lseek(fd, offset, SEEK_END)
+ && offset+and == lseek(fd, offset+and, SEEK_SET)) return 0;
+ else {
+ char buf[4096];
+ while (offset>0) {
+ int try = offset>sizeof(buf) ? sizeof(buf) : offset, or;
+
+ or = readall(fd, buf, try);
+ if (or < 0) perror_msg("lskip to %lld", (long long)offset);
+ else offset -= try;
+ if (or < try) break;
+ }
+
+ return offset;
+ }
+}
+
char *xgetcwd(void)
{
char *buf = getcwd(NULL, 0);
@@ -503,8 +524,7 @@ long atolx(char *numstr)
long val = strtol(numstr, &c, 0);
if (*c) {
- end = strchr(suffixes, tolower(*c));
- if (end) {
+ if (c != numstr && (end = strchr(suffixes, tolower(*c)))) {
int shift = end-suffixes;
if (shift--) val *= 1024L<<(shift*10);
} else {
@@ -526,6 +546,17 @@ int numlen(long l)
return len;
}
+int stridx(char *haystack, char needle)
+{
+ char *off;
+
+ if (!needle) return -1;
+ off = strchr(haystack, needle);
+ if (!off) return -1;
+
+ return off-haystack;
+}
+
// Return how long the file at fd is, if there's any way to determine it.
off_t fdlength(int fd)
{