aboutsummaryrefslogtreecommitdiffstats
path: root/csci5271/hw1/hw1p2b.c
diff options
context:
space:
mode:
authorMatt Strapp <matt@mattstrapp.net>2021-09-25 16:00:51 -0500
committerMatt Strapp <matt@mattstrapp.net>2021-09-25 16:00:51 -0500
commit3aafb02dc4ab079fc58b555a6808f302539c7a49 (patch)
tree3477f834297df7e7a3b705fd8ddca0c4dab3348a /csci5271/hw1/hw1p2b.c
parentEdit resume links (diff)
downloadhomework-3aafb02dc4ab079fc58b555a6808f302539c7a49.tar
homework-3aafb02dc4ab079fc58b555a6808f302539c7a49.tar.gz
homework-3aafb02dc4ab079fc58b555a6808f302539c7a49.tar.bz2
homework-3aafb02dc4ab079fc58b555a6808f302539c7a49.tar.lz
homework-3aafb02dc4ab079fc58b555a6808f302539c7a49.tar.xz
homework-3aafb02dc4ab079fc58b555a6808f302539c7a49.tar.zst
homework-3aafb02dc4ab079fc58b555a6808f302539c7a49.zip
Start hw1
Diffstat (limited to 'csci5271/hw1/hw1p2b.c')
-rw-r--r--csci5271/hw1/hw1p2b.c28
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