ps: conditionally enable -T on non-DESKTOP build too
[oweals/busybox.git] / miscutils / readahead.c
index 7b375cffff7c31f7df5b7b8f52f7f674420b77c5..fb71ce85f010b3f3097b265e09e8f7ba383b58ee 100644 (file)
@@ -22,9 +22,16 @@ int readahead_main(int argc, char **argv)
        while (*++argv) {
                int fd = open_or_warn(*argv, O_RDONLY);
                if (fd >= 0) {
-                       int r = readahead(fd, 0, fdlength(fd));
+                       off_t len;
+                       int r;
+
+                       /* fdlength was reported to be unreliable - use seek */
+                       len = xlseek(fd, 0, SEEK_END);
+                       xlseek(fd, 0, SEEK_SET);
+                       r = readahead(fd, 0, len);
                        close(fd);
-                       if (r >= 0) continue;
+                       if (r >= 0)
+                               continue;
                }
                retval = EXIT_FAILURE;
        }