struct stat orig_st;
struct stat new_st;
char *file_name;
/* initialize file_name */
int fd = open(file_name, O_WRONLY, S_IRWXU);
if (fd == -1) {
/* handle Error */
}
/*... write to file ...*/
if (fstat(fd, &orig_st) == -1) {
/* handle error */
}
close(fd);
fd = -1;
/* ... */
fd = open(file_name, O_RDONLY, S_IRWXU);
if (fd == -1) {
/* handle error */
}
if (fstat(fd, &new_st) == -1) {
/* handle error */
}
if ((orig_st.st_dev != new_st.st_dev) ||
(orig_st.st_ino != new_st.st_ino)) {
/* file was tampered with! */
}
/*... read from file ...*/
close(fd);
fd = -1;
|