summaryrefslogtreecommitdiff
path: root/pgm3/pgm3test.d
diff options
context:
space:
mode:
Diffstat (limited to 'pgm3/pgm3test.d')
-rw-r--r--pgm3/pgm3test.d/fileinfo.c30
-rw-r--r--pgm3/pgm3test.d/link.c30
-rw-r--r--pgm3/pgm3test.d/script24
-rw-r--r--pgm3/pgm3test.d/subdir/subfileinfo.c30
-rw-r--r--pgm3/pgm3test.d/subdir/subsubdir/file1bin0 -> 1023 bytes
-rw-r--r--pgm3/pgm3test.d/subdir/subsubdir/file2bin0 -> 1023 bytes
-rw-r--r--pgm3/pgm3test.d/subdir/subsubdir/file3bin0 -> 1023 bytes
-rw-r--r--pgm3/pgm3test.d/symlink.c30
8 files changed, 144 insertions, 0 deletions
diff --git a/pgm3/pgm3test.d/fileinfo.c b/pgm3/pgm3test.d/fileinfo.c
new file mode 100644
index 0000000..eed7902
--- /dev/null
+++ b/pgm3/pgm3test.d/fileinfo.c
@@ -0,0 +1,30 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/sysmacros.h>
+#include <sys/time.h>
+
+main(argc,argv)
+int argc; char *argv[];
+{
+
+ struct stat info;
+
+ if (argc != 2) {
+ fprintf(stderr, "fileinfo: usage fileinfo filename\n");
+ exit(1);
+ }
+
+ if (stat(argv[1], &info) != 0) {
+ fprintf(stderr,"fileinfo: cannot stat %s:", argv[1]);
+ perror(NULL);
+ }
+ printf("%s: ", argv[1]);
+ printf("(device,i_number)=(%d/%d,%ld)", major(info.st_dev), minor(info.st_dev), (long) info.st_ino);
+ printf(" last accessed %d seconds ago\n", time(NULL)-info.st_atime);
+ if (S_ISREG(info.st_mode))
+ printf("\tdesignated a regular file\n");
+ if (S_ISLNK(info.st_mode))
+ printf("\tdesignated a symlink\n");
+}
diff --git a/pgm3/pgm3test.d/link.c b/pgm3/pgm3test.d/link.c
new file mode 100644
index 0000000..eed7902
--- /dev/null
+++ b/pgm3/pgm3test.d/link.c
@@ -0,0 +1,30 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/sysmacros.h>
+#include <sys/time.h>
+
+main(argc,argv)
+int argc; char *argv[];
+{
+
+ struct stat info;
+
+ if (argc != 2) {
+ fprintf(stderr, "fileinfo: usage fileinfo filename\n");
+ exit(1);
+ }
+
+ if (stat(argv[1], &info) != 0) {
+ fprintf(stderr,"fileinfo: cannot stat %s:", argv[1]);
+ perror(NULL);
+ }
+ printf("%s: ", argv[1]);
+ printf("(device,i_number)=(%d/%d,%ld)", major(info.st_dev), minor(info.st_dev), (long) info.st_ino);
+ printf(" last accessed %d seconds ago\n", time(NULL)-info.st_atime);
+ if (S_ISREG(info.st_mode))
+ printf("\tdesignated a regular file\n");
+ if (S_ISLNK(info.st_mode))
+ printf("\tdesignated a symlink\n");
+}
diff --git a/pgm3/pgm3test.d/script b/pgm3/pgm3test.d/script
new file mode 100644
index 0000000..9bb8248
--- /dev/null
+++ b/pgm3/pgm3test.d/script
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+# after doing a
+# cp -a ~kearns/public/415/P3/pgm3test.d .
+# run ./script to set access times
+#
+# ./script should be run before every test to
+# reset access times to well-known values
+
+OLD='2005-01-01'
+NEW='yesterday'
+
+TOUCH=/usr/bin/touch
+
+#give a.out current access time
+$TOUCH --time=access ./a.out
+
+# give fileinfo.c access time of Jan 1, 2005
+$TOUCH --time=access --date=$OLD ./fileinfo.c
+
+# subdir/subsubdir files given staggered access times
+$TOUCH --time=access --date=$OLD ./subdir/subsubdir/file1
+$TOUCH --time=access --date=$NEW ./subdir/subsubdir/file2
+$TOUCH --time=access --date=$NEW ./subdir/subsubdir/file3
diff --git a/pgm3/pgm3test.d/subdir/subfileinfo.c b/pgm3/pgm3test.d/subdir/subfileinfo.c
new file mode 100644
index 0000000..eed7902
--- /dev/null
+++ b/pgm3/pgm3test.d/subdir/subfileinfo.c
@@ -0,0 +1,30 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/sysmacros.h>
+#include <sys/time.h>
+
+main(argc,argv)
+int argc; char *argv[];
+{
+
+ struct stat info;
+
+ if (argc != 2) {
+ fprintf(stderr, "fileinfo: usage fileinfo filename\n");
+ exit(1);
+ }
+
+ if (stat(argv[1], &info) != 0) {
+ fprintf(stderr,"fileinfo: cannot stat %s:", argv[1]);
+ perror(NULL);
+ }
+ printf("%s: ", argv[1]);
+ printf("(device,i_number)=(%d/%d,%ld)", major(info.st_dev), minor(info.st_dev), (long) info.st_ino);
+ printf(" last accessed %d seconds ago\n", time(NULL)-info.st_atime);
+ if (S_ISREG(info.st_mode))
+ printf("\tdesignated a regular file\n");
+ if (S_ISLNK(info.st_mode))
+ printf("\tdesignated a symlink\n");
+}
diff --git a/pgm3/pgm3test.d/subdir/subsubdir/file1 b/pgm3/pgm3test.d/subdir/subsubdir/file1
new file mode 100644
index 0000000..1bce2be
--- /dev/null
+++ b/pgm3/pgm3test.d/subdir/subsubdir/file1
Binary files differ
diff --git a/pgm3/pgm3test.d/subdir/subsubdir/file2 b/pgm3/pgm3test.d/subdir/subsubdir/file2
new file mode 100644
index 0000000..1bce2be
--- /dev/null
+++ b/pgm3/pgm3test.d/subdir/subsubdir/file2
Binary files differ
diff --git a/pgm3/pgm3test.d/subdir/subsubdir/file3 b/pgm3/pgm3test.d/subdir/subsubdir/file3
new file mode 100644
index 0000000..1bce2be
--- /dev/null
+++ b/pgm3/pgm3test.d/subdir/subsubdir/file3
Binary files differ
diff --git a/pgm3/pgm3test.d/symlink.c b/pgm3/pgm3test.d/symlink.c
new file mode 100644
index 0000000..eed7902
--- /dev/null
+++ b/pgm3/pgm3test.d/symlink.c
@@ -0,0 +1,30 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/sysmacros.h>
+#include <sys/time.h>
+
+main(argc,argv)
+int argc; char *argv[];
+{
+
+ struct stat info;
+
+ if (argc != 2) {
+ fprintf(stderr, "fileinfo: usage fileinfo filename\n");
+ exit(1);
+ }
+
+ if (stat(argv[1], &info) != 0) {
+ fprintf(stderr,"fileinfo: cannot stat %s:", argv[1]);
+ perror(NULL);
+ }
+ printf("%s: ", argv[1]);
+ printf("(device,i_number)=(%d/%d,%ld)", major(info.st_dev), minor(info.st_dev), (long) info.st_ino);
+ printf(" last accessed %d seconds ago\n", time(NULL)-info.st_atime);
+ if (S_ISREG(info.st_mode))
+ printf("\tdesignated a regular file\n");
+ if (S_ISLNK(info.st_mode))
+ printf("\tdesignated a symlink\n");
+}