readahead.c (877B)
1 /* see LICENSE file for copyright and license details */ 2 3 #if FEATURE_LINUX_READAHEAD 4 #ifndef _DEFAULT_SOURCE 5 #define _DEFAULT_SOURCE 6 #endif 7 #ifndef _GNU_SOURCE 8 #define _GNU_SOURCE 9 #endif 10 #endif 11 #include <fcntl.h> 12 #include <limits.h> 13 #include <stdio.h> 14 #include <stdlib.h> 15 16 #include "util.h" 17 18 static void 19 usage(void) 20 { 21 eprintf("usage: %s file...\n", argv0); 22 } 23 24 // ?man readahead: read files into page cache 25 // ?man arguments: file... 26 // ?man preload file contents into the page cache 27 int 28 main(int argc, char *argv[]) 29 { 30 FILE *fp; 31 32 ARGBEGIN 33 { 34 default: 35 usage(); 36 } 37 ARGEND; 38 39 if (argc == 0) 40 usage(); 41 42 for (; argc > 0; argc--, argv++) { 43 if (!(fp = fopen(argv[0], "r"))) { 44 weprintf("fopen %s:", argv[0]); 45 continue; 46 } 47 if (readahead(fileno(fp), 0, -1) < 0) 48 weprintf("readahead %s:", argv[0]); 49 fclose(fp); 50 } 51 return 0; 52 }