#include #include #include #include #include #include "syscalls.h" /* The C Programming Language: 2nd Edition * * Exercise 8-4: The standard library function * * int fseek(FILE *fp, long offset, int origin) * * is identical to `lseek` except that `fp` is a file pointer instead of a file * descriptor and the return value is an `int` status, not a position. Write * `fseek`. Make sure that your `fseek` coordinates properly with the buffering * done for the other functions of the library. * * Notes: Page 174 covers lseek, where it describes fseek's return value as 0 * for success and non-zero for errors. */ int main() { FILE *fp = fopen("8-04_fseek.c", "r"); if (fp == NULL) { exit(1); } fseek(fp, -34L, 2); puts(fp->base); fflush(stdout); fclose(fp); return 0; } /* If you see this, 8-4 works! */