aboutsummaryrefslogtreecommitdiff
path: root/tests/fcntl/src.c
blob: c60e578e798af0a4749910d57e4fbe21020842d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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) >= 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) == O_RDWR);
  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: %d\n", fcntl(f, F_GETFL) == (O_RDWR | O_APPEND));
  printf("errno: %d\n", errno);
  printf("\n");
  errno = 0;

  struct 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;
}