ubase

suckless linux base utils
git clone git://git.2f30.org/ubase
Log | Files | Refs | README | LICENSE

readahead.c (579B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include <fcntl.h>
      3 #include <limits.h>
      4 #include <stdio.h>
      5 #include <stdlib.h>
      6 
      7 #include "util.h"
      8 
      9 static void
     10 usage(void)
     11 {
     12 	eprintf("usage: %s file...\n", argv0);
     13 }
     14 
     15 int
     16 main(int argc, char *argv[])
     17 {
     18 	FILE *fp;
     19 
     20 	ARGBEGIN {
     21 	default:
     22 		usage();
     23 	} ARGEND;
     24 
     25 	if (argc == 0)
     26 		usage();
     27 
     28 	for (; argc > 0; argc--, argv++) {
     29 		if (!(fp = fopen(argv[0], "r"))) {
     30 			weprintf("fopen %s:", argv[0]);
     31 			continue;
     32 		}
     33 		if (readahead(fileno(fp), 0, -1) < 0)
     34 			weprintf("readahead %s:", argv[0]);
     35 		fclose(fp);
     36 	}
     37 	return 0;
     38 }