aboutsummaryrefslogtreecommitdiff
path: root/store/works/life/operating-system-course-design/read-file.c
diff options
context:
space:
mode:
Diffstat (limited to 'store/works/life/operating-system-course-design/read-file.c')
-rw-r--r--store/works/life/operating-system-course-design/read-file.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/store/works/life/operating-system-course-design/read-file.c b/store/works/life/operating-system-course-design/read-file.c
new file mode 100644
index 0000000..fe71f94
--- /dev/null
+++ b/store/works/life/operating-system-course-design/read-file.c
@@ -0,0 +1,25 @@
+#include <bits/types.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdio.h>
+
+int main() {
+ int fd = open("/mnt/fat-test/big", O_RDONLY);
+ if (fd < 0)
+ return 1;
+
+ __off_t size = lseek(fd, 0, SEEK_END);
+ if (size < 0)
+ return 2;
+
+ for (__off_t i = 512; i <= size; i += 512) {
+ if (lseek(fd, size - i, SEEK_SET) < 0)
+ return 3;
+ char buffer[512];
+ if (read(fd, buffer, 512) < 0)
+ return 4;
+ }
+
+ return 0;
+}