dirseek

dirseek - /* * dirseek.c * * Tests seeking on directories...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: /* * dirseek.c * * Tests seeking on directories (both legally and illegally). * * Makes a test subdirectory in the current directory. * * Intended for the file system assignment. Should run (on SFS) * when that assignment is complete. * * Note: checks a few things that are not _strictly_ guaranteed * by the official semantics of getdirentry() but that are more * or less necessary in a sane implementation, like that the * current seek position returned after seeking is the same * position that was requested. If you believe your * implementation is legal and the the test is rejecting it * gratuitously, please contact the course staff. */ #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <string.h> #include <stdio.h> #include <stdlib.h> #include <err.h> #define TESTDIR "seektestdir" static struct { const char *name; int make_it; off_t pos; } testfiles = { { ".", 0, -1 }, { "..", 0, -1 }, { "ridcully", 1, -1 }, { "weatherwax", 1, -1 }, { "ogg", 1, -1 }, { "vorbis", 1, -1 }, { "verence", 1, -1 }, { "magrat", 1, -1 }, { "agnes", 1, -1 }, { "rincewind", 1, -1 }, { "angua", 1, -1 }, { "cherry", 1, -1 }, { "dorfl", 1, -1 }, { "nobby", 1, -1 }, { "carrot", 1, -1 }, { "vimes", 1, -1 }, { "detritus", 1, -1 }, { "twoflower", 1, -1 }, { "teatime", 1, -1 }, { "qu", 1, -1 }, { NULL, 0, 0 } }; /************************************************************/ /* Test code */ /************************************************************/ static int dirfd; static int findentry(const char *name) { int i; for (i=0; testfiles[i].name; i++) { if (!strcmp(testfiles[i].name, name)) { return i; } } return -1; } static void openit(void) { dirfd = open(".", O_RDONLY); if (dirfd < 0) { err(1, ".: open"); } } static void closeit(void) { if (close(dirfd)<0) { err(1, ".: close"); } dirfd = -1; } static void readit(void) { char buf[4096]; off_t pos; int len; int n, i, ix; for (i=0; testfiles[i].name; i++) { testfiles[i].pos = -1; } pos = lseek(dirfd, 0, SEEK_CUR); if (pos < 0) { errx(1, ".: lseek(0, SEEK_CUR)"); } n = 0; while ((len = getdirentry(dirfd, buf, sizeof(buf)-1)) > 0) { if ((unsigned)len >= sizeof(buf)-1) {...
View Full Document

This note was uploaded on 11/10/2009 for the course CS 536 taught by Professor Lums during the Spring '09 term at Indiana.

Page1 / 9

dirseek - /* * dirseek.c * * Tests seeking on directories...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online