aboutsummaryrefslogtreecommitdiff
path: root/tests/fcntl/src.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/fcntl/src.c')
-rw-r--r--tests/fcntl/src.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/fcntl/src.c b/tests/fcntl/src.c
new file mode 100644
index 00000000..1e9a1536
--- /dev/null
+++ b/tests/fcntl/src.c
@@ -0,0 +1,80 @@
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+
+int main() {
+ int f = open("/test", O_RDWR, 0777);
+
+ printf("F_DUPFD: %d\n", fcntl(f, F_DUPFD, 100));
+ printf("errno: %d\n", errno);
+ printf("\n");
+ errno = 0;
+
+ printf("F_DUPFD/error1: %d\n", fcntl(50, F_DUPFD, 200));
+ printf("errno: %d\n", errno);
+ printf("\n");
+ errno = 0;
+
+ printf("F_DUPFD/error2: %d\n", fcntl(f, F_DUPFD, -1));
+ printf("errno: %d\n", errno);
+ printf("\n");
+ errno = 0;
+
+ printf("F_GETFD: %d\n", fcntl(f, F_GETFD));
+ printf("errno: %d\n", errno);
+ printf("\n");
+ errno = 0;
+
+ printf("F_SETFD: %d\n", fcntl(f, F_SETFD));
+ printf("errno: %d\n", errno);
+ printf("\n");
+ errno = 0;
+
+ printf("F_GETFL: %d\n", fcntl(f, F_GETFL));
+ printf("errno: %d\n", errno);
+ printf("\n");
+ errno = 0;
+
+ printf("F_SETFL: %d\n", fcntl(f, F_SETFL, O_APPEND));
+ printf("errno: %d\n", errno);
+ printf("\n");
+ errno = 0;
+
+ printf("F_GETFL/2: %#x\n", fcntl(f, F_GETFL));
+ printf("errno: %d\n", errno);
+ printf("\n");
+ errno = 0;
+
+ flock lk;
+ lk.l_type = 42;
+ printf("F_GETLK: %d\n", fcntl(f, F_GETLK, &lk));
+ printf("errno: %d\n", errno);
+ printf("lk.l_type == F_UNLCK: %d\n", lk.l_type == F_UNLCK);
+ printf("\n");
+ errno = 0;
+
+ printf("F_SETLK: %d\n", fcntl(f, F_SETLK, &lk));
+ printf("errno: %d\n", errno);
+ printf("\n");
+ errno = 0;
+
+ printf("F_SETLKW: %d\n", fcntl(f, F_SETLK, &lk));
+ printf("errno: %d\n", errno);
+ printf("\n");
+ errno = 0;
+
+ printf("F_SETOWN: %d\n", fcntl(f, F_SETOWN, 123));
+ printf("errno: %d\n", errno);
+ printf("\n");
+ errno = 0;
+
+ printf("F_GETOWN: %d\n", fcntl(f, F_GETOWN));
+ printf("errno: %d\n", errno);
+ printf("\n");
+ errno = 0;
+
+ printf("INVALID: %d\n", fcntl(f, 123));
+ printf("errno: %d\n", errno);
+
+ return 0;
+}