summaryrefslogtreecommitdiffstats
path: root/src/examples/create.c
blob: 65be47d69fdd0f7eda3b4f9b8490ecf079ffe82e (plain) (blame)
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
#include <stdio.h>
#include <syscall.h>

int
main (int argc, char *argv[])
{
  if (create ("test", 1)) {
    printf ("created file\n");
  } else {
    printf ("couldn't create file\n");
  }
  int fd = open ("test"); // open 2
  printf ("opened file with fd %d\n", fd);
  int fd2 = open ("test"); // open 3
  printf ("opened file with fd %d\n", fd2);
  close(fd); // close 2
  int fd3 = open ("test"); // open 2
  printf ("opened file with fd %d\n", fd3);
  close(fd2); // close 3
  int fd4 = open ("test"); // open 3
  printf ("opened file with fd %d\n", fd4);
  close(fd4); // close 3, valid
  close(fd3); // close 2, valid
  close(fd); // close closed 2, invalid
  int fd5 = open ("test"); // open 2
  printf ("opened file with fd %d\n", fd5);

  halt ();
}