diff options
author | Matt Strapp <matt@mattstrapp.net> | 2021-09-25 16:18:39 -0500 |
---|---|---|
committer | Matt Strapp <matt@mattstrapp.net> | 2021-09-25 16:18:39 -0500 |
commit | 604ae9bc9e9c7fbda3b192f5a925c70a970d6962 (patch) | |
tree | 89269f8f68a428050a176d064aa742425e0c928d /csci5271/hw1/hw1p2b.c | |
parent | run formatter (diff) | |
parent | Start hw1 (diff) | |
download | homework-604ae9bc9e9c7fbda3b192f5a925c70a970d6962.tar homework-604ae9bc9e9c7fbda3b192f5a925c70a970d6962.tar.gz homework-604ae9bc9e9c7fbda3b192f5a925c70a970d6962.tar.bz2 homework-604ae9bc9e9c7fbda3b192f5a925c70a970d6962.tar.lz homework-604ae9bc9e9c7fbda3b192f5a925c70a970d6962.tar.xz homework-604ae9bc9e9c7fbda3b192f5a925c70a970d6962.tar.zst homework-604ae9bc9e9c7fbda3b192f5a925c70a970d6962.zip |
Merge branch 'master' of git.mattstrapp.net:RossTheRoss/Homework
Diffstat (limited to '')
-rw-r--r-- | csci5271/hw1/hw1p2b.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/csci5271/hw1/hw1p2b.c b/csci5271/hw1/hw1p2b.c new file mode 100644 index 0000000..df5ac73 --- /dev/null +++ b/csci5271/hw1/hw1p2b.c @@ -0,0 +1,28 @@ +#include <fcntl.h> +#include <stdlib.h> +#include <sys/stat.h> +#include <unistd.h> +void silly_function(char *pathname) { + struct stat f, we; + int rfd, wfd; + char *buf; + stat(pathname, &f); + stat("./critical", &we); + if (f.st_dev == we.st_dev && f.st_ino == we.st_ino) { + return; + } + rfd = open(pathname, O_RDONLY); + buf = malloc(f.st_size - 1); + read(rfd, buf, f.st_size - 1); + close(rfd); + stat(pathname, &f); + if (f.st_dev == we.st_dev && f.st_ino == we.st_ino) { + return; + } + wfd = open(pathname, O_WRONLY | O_TRUNC); + write(wfd, buf, f.st_size - 1); + close(wfd); + free(buf); +} + +int main() { silly_function("./not"); }
\ No newline at end of file |