3
0

readahead.c 707 B

12345678910111213141516171819202122232425262728293031323334
  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 "busybox.h"
  13. int readahead_main(int argc, char **argv)
  14. {
  15. FILE *f;
  16. int retval = EXIT_SUCCESS;
  17. if (argc == 1) bb_show_usage();
  18. while (*++argv) {
  19. if ((f = fopen_or_warn(*argv, "r")) != NULL) {
  20. int r, fd=fileno(f);
  21. r = readahead(fd, 0, fdlength(fd));
  22. fclose(f);
  23. if (r >= 0) continue;
  24. }
  25. retval = EXIT_FAILURE;
  26. }
  27. return retval;
  28. }