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(s.st_mode))) {
/* handle error */
}
/* due to a race condition here, we will verify with fstat later */
if(!(fildes = open(filename, O_WRONLY, 0600)) == -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 */
|