summaryrefslogtreecommitdiff
path: root/contrib/getdents-debug/getdents_c/getdents.c
diff options
context:
space:
mode:
authorJakob Unterwurzacher2020-05-24 23:46:41 +0200
committerJakob Unterwurzacher2020-05-24 23:46:41 +0200
commit6019598fdb9d223beec7da5848cf950ca90e85e7 (patch)
treebf2a6ee2241b4dd1b5331d0514cafd455d9a1b4a /contrib/getdents-debug/getdents_c/getdents.c
parent71c0481f0e42c6bf1749dde8a30d9a6b728e83a0 (diff)
contrib: collect getdents stuff in getdents-debug folder
Diffstat (limited to 'contrib/getdents-debug/getdents_c/getdents.c')
-rw-r--r--contrib/getdents-debug/getdents_c/getdents.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/contrib/getdents-debug/getdents_c/getdents.c b/contrib/getdents-debug/getdents_c/getdents.c
new file mode 100644
index 0000000..98c2346
--- /dev/null
+++ b/contrib/getdents-debug/getdents_c/getdents.c
@@ -0,0 +1,39 @@
+// See ../getdents/getdents.go for some info on why
+// this exists.
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <sys/stat.h>
+#include <sys/syscall.h>
+#include <errno.h>
+
+int main(int argc, char *argv[])
+{
+ if(argc < 2) {
+ printf("Usage: %s PATH\n", argv[0]);
+ printf("Run getdents(2) on PATH\n");
+ exit(1);
+ }
+
+ const char *path = argv[1];
+ int fd = open(path, O_RDONLY);
+ if (fd == -1) {
+ perror("open");
+ exit(1);
+ }
+
+ char tmp[10000];
+ int sum = 0;
+ for ( ; ; ) {
+ int n = syscall(SYS_getdents64, fd, tmp, sizeof(tmp));
+ printf("getdents64 fd%d: n=%d, errno=%d\n", fd, n, errno);
+ if (n <= 0) {
+ printf("total %d bytes\n", sum);
+ break;
+ }
+ sum += n;
+ }
+}