{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

filetest - rv = write(fd writebuf 40 if(rv<0...

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

View Full Document Right Arrow Icon
/* * filetest.c * * Tests the filesystem by opening, writing to and reading from a * user specified file. * * This should run (on SFS) even before the file system assignment is started. * It should also continue to work once said assignment is complete. * It will not run fully on emufs, because emufs does not support remove(). */ #include <stdio.h> #include <string.h> #include <unistd.h> #include <err.h> int main(int argc, char *argv[]) { static char writebuf[40] = "Twiddle dee dee, Twiddle dum dum ....... \n"; static char readbuf[41]; int fd, rv; if (argc!=2) { errx(1, "Usage: filetest <filename>"); } fd = open(argv[1], O_WRONLY|O_CREAT|O_TRUNC, 0664); if (fd<0) { err(1, "%s: open for write", argv[1]);
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
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } rv = write(fd, writebuf, 40); if (rv<0) { err(1, "%s: write", argv[1]); } rv = close(fd); if (rv<0) { err(1, "%s: close (1st time)", argv[1]); } fd = open(argv[1], O_RDONLY); if (fd<0) { err(1, "%s: open for read", argv[1]); } rv = read(fd, readbuf, 40); if (rv<0) { err(1, "%s: read", argv[1]); } rv = close(fd); if (rv<0) { err(1, "%s: close (2nd time)", argv[1]); } /* ensure null termination */ readbuf[40] = 0; if (strcmp(readbuf, writebuf)) { errx(1, "Buffer data mismatch!"); } rv = remove(argv[1]); if (rv<0) { err(1, "%s: remove", argv[1]); } printf("Passed filetest.\n"); return 0; }...
View Full 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