{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

dirseek - dirseek.c Tests seeking on directories(both...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * 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 */
Image of page 1

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

View Full Document Right Arrow Icon
/************************************************************/ 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) {
Image of page 2
if ((unsigned)len >= sizeof(buf)-1) { errx(1, ".: entry %d: getdirentry returned "
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern