summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Makefile5
-rw-r--r--src/readahead.c56
2 files changed, 60 insertions, 1 deletions
diff --git a/src/Makefile b/src/Makefile
index bf012f1..3ef21f5 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -4,7 +4,7 @@ LD = gcc
#BIN_TARGETS = splashbard
#SBIN_TARGETS = runscript start-stop-daemon
-SBIN_TARGETS = runscript
+SBIN_TARGETS = runscript readahead
TARGET = $(BIN_TARGETS) $(SBIN_TARGETS)
.PHONY: all clean
@@ -13,6 +13,9 @@ all: $(TARGET)
tsplashd: splashbard.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
+readahead: readahead.c
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
+
runscript: runscript.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
diff --git a/src/readahead.c b/src/readahead.c
new file mode 100644
index 0000000..9d44788
--- /dev/null
+++ b/src/readahead.c
@@ -0,0 +1,56 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sysexits.h>
+
+static const char *program = "readahead";
+
+void usage(void) {
+ printf("usage: %s [-hv] FILE [...]\n", program);
+ exit(EX_USAGE);
+}
+
+int main( int argc, char *argv[]) {
+ int c, verbose=0;
+
+ /* parse options */
+ while ( (c = getopt(argc, argv, "hv")) >= 0 ) {
+ switch (c) {
+ case 'v': verbose++;
+ break;
+ case 'h':
+ default: usage();
+ break;
+ }
+ }
+
+ /* check that at least one file is specified */
+ if (optind == argc)
+ usage();
+
+ /* parse files */
+ c = EX_OK;
+ while (optind < argc) {
+ struct stat st;
+ FILE *f = fopen(argv[optind], "r");
+
+
+ /* check that file exists */
+ if (f == NULL) {
+ perror(argv[optind]);
+ c = EX_NOINPUT;
+ } else {
+ stat(argv[optind], &st);
+ readahead( fileno(f), 0, (size_t)st.st_size );
+ if (verbose)
+ printf("%s\n", argv[optind]);
+ fclose(f);
+ }
+ optind++;
+ }
+ return (c);
+}
+