From 6c9b79537f03115c5e2d4883fd407a6ac870bffd Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Tue, 11 Jan 2022 10:18:56 -0600 Subject: Resume and rearrange Signed-off-by: Matt Strapp --- OLD/csci5271/hw1/hw1p2b.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 OLD/csci5271/hw1/hw1p2b.c (limited to 'OLD/csci5271/hw1/hw1p2b.c') diff --git a/OLD/csci5271/hw1/hw1p2b.c b/OLD/csci5271/hw1/hw1p2b.c new file mode 100644 index 0000000..df5ac73 --- /dev/null +++ b/OLD/csci5271/hw1/hw1p2b.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include +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 -- cgit v1.2.3