Tomato 1.28
[tomato.git] / release / src / router / busybox / miscutils / readahead.c
blobfb71ce85f010b3f3097b265e09e8f7ba383b58ee
1 /* vi: set sw=4 ts=4: */
2 /*
3 * readahead implementation for busybox
5 * Preloads the given files in RAM, to reduce access time.
6 * Does this by calling the readahead(2) system call.
8 * Copyright (C) 2006 Michael Opdenacker <michael@free-electrons.com>
10 * Licensed under GPLv2 or later, see file License in this tarball for details.
13 #include "libbb.h"
15 int readahead_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
16 int readahead_main(int argc, char **argv)
18 int retval = EXIT_SUCCESS;
20 if (argc == 1) bb_show_usage();
22 while (*++argv) {
23 int fd = open_or_warn(*argv, O_RDONLY);
24 if (fd >= 0) {
25 off_t len;
26 int r;
28 /* fdlength was reported to be unreliable - use seek */
29 len = xlseek(fd, 0, SEEK_END);
30 xlseek(fd, 0, SEEK_SET);
31 r = readahead(fd, 0, len);
32 close(fd);
33 if (r >= 0)
34 continue;
36 retval = EXIT_FAILURE;
39 return retval;