readahead.c 748 B

1234567891011121314151617181920212223242526272829303132333435
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * readahead implementation for busybox
  4. *
  5. * Preloads the given files in RAM, to reduce access time.
  6. * Does this by calling the readahead(2) system call.
  7. *
  8. * Copyright (C) 2006 Michael Opdenacker <michael@free-electrons.com>
  9. *
  10. * Licensed under GPLv2 or later, see file License in this tarball for details.
  11. */
  12. #include "libbb.h"
  13. int readahead_main(int argc, char **argv);
  14. int readahead_main(int argc, char **argv)
  15. {
  16. FILE *f;
  17. int retval = EXIT_SUCCESS;
  18. if (argc == 1) bb_show_usage();
  19. while (*++argv) {
  20. if ((f = fopen_or_warn(*argv, "r")) != NULL) {
  21. int r, fd=fileno(f);
  22. r = readahead(fd, 0, fdlength(fd));
  23. fclose(f);
  24. if (r >= 0) continue;
  25. }
  26. retval = EXIT_FAILURE;
  27. }
  28. return retval;
  29. }