Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#ccccff
struct stat pre_s;
struct stat post_s;
int fildes;

if(!fgets(filename, sizeof(filename), stdin)) {
    /* handle error */
}

if((stat(filename, &pre_s) != 0) || (!S_ISREG(pre_s.st_mode))) {
    /* handle error */
}

/* due to a race condition here, we will verify with fstat later */

if((fildes = open(filename, O_WRONLY)) == -1) {
    /* handle error */
}

if(fstat(fildes, &post_s) != 0) {
    /* handle error */
}

if(!(pre_s.st_mode == post_s.st_mode &&
     pre_s.st_ino  == post_s.st_ino  &&
     pre_s.st_dev  == post_s.st_dev)) {
    /* handle error */
}

/* operate on file */

...