~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/fcntl-open/src.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-09-20 22:44:35 UTC
  • mfrom: (4.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20130920224435-apuwj4fsl3fqv1a6
Tags: 1.5.6~20130920~6010666-1
* New snapshot release
* Update the list of supported architectures to the same as libv8
  (Closes: #723129)
* emlibtool has been removed from upstream.
* Fix warning syntax-error-in-dep5-copyright
* Refresh of the patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <stdio.h>
 
1
#include <assert.h>
2
2
#include <errno.h>
3
 
#include <sys/stat.h>
4
3
#include <fcntl.h>
 
4
#include <signal.h>
 
5
#include <stdio.h>
 
6
#include <stdlib.h>
5
7
#include <string.h>
6
 
 
7
 
int main() {
 
8
#include <unistd.h>
 
9
#include <sys/stat.h>
 
10
 
 
11
char nonexistent_name[] = "noexist-##";
 
12
 
 
13
void create_file(const char *path, const char *buffer, int mode) {
 
14
  int fd = open(path, O_WRONLY | O_CREAT | O_EXCL, mode);
 
15
  assert(fd >= 0);
 
16
 
 
17
  int err = write(fd, buffer, sizeof(char) * strlen(buffer));
 
18
  assert(err ==  (sizeof(char) * strlen(buffer)));
 
19
 
 
20
  close(fd);
 
21
}
 
22
 
 
23
void setup() {
 
24
  create_file("test-file", "abcdef", 0777);
 
25
  mkdir("test-folder", 0777);
 
26
}
 
27
 
 
28
void cleanup() {
 
29
  unlink("test-file");
 
30
  rmdir("test-folder");
 
31
  for (int i = 0; i < 3; i++) {
 
32
    for (int j = 0; j < 16; j++) {
 
33
      nonexistent_name[8] = 'a' + i;
 
34
      nonexistent_name[9] = 'a' + j;
 
35
      unlink(nonexistent_name);
 
36
    }
 
37
  }
 
38
  unlink("creat-me");
 
39
}
 
40
 
 
41
void test() {
8
42
  struct stat s;
9
43
  int modes[] = {O_RDONLY, O_WRONLY, O_RDWR};
10
 
  char nonexistent_name[] = "/noexist-##";
11
44
 
12
45
  for (int i = 0; i < 3; i++) {
13
46
    for (int j = 0; j < 16; j++) {
18
51
      if (j & 0x8) flags |= O_APPEND;
19
52
 
20
53
      printf("EXISTING FILE %d,%d\n", i, j);
21
 
      printf("success: %d\n", open("/test-file", flags, 0777) != -1);
 
54
      printf("success: %d\n", open("test-file", flags, 0777) != -1);
22
55
      printf("errno: %d\n", errno);
23
 
      stat("/test-file", &s);
 
56
      stat("test-file", &s);
24
57
      printf("st_mode: 0%o\n", s.st_mode & 037777777000);
25
58
      memset(&s, 0, sizeof s);
26
59
      printf("\n");
27
60
      errno = 0;
28
61
 
29
62
      printf("EXISTING FOLDER %d,%d\n", i, j);
30
 
      printf("success: %d\n", open("/test-folder", flags, 0777) != -1);
 
63
      printf("success: %d\n", open("test-folder", flags, 0777) != -1);
31
64
      printf("errno: %d\n", errno);
32
 
      stat("/test-folder", &s);
 
65
      stat("test-folder", &s);
33
66
      printf("st_mode: 0%o\n", s.st_mode & 037777777000);
34
67
      memset(&s, 0, sizeof s);
35
68
      printf("\n");
36
69
      errno = 0;
37
70
 
38
 
      nonexistent_name[9] = 'a' + i;
39
 
      nonexistent_name[10] = 'a' + j;
 
71
      nonexistent_name[8] = 'a' + i;
 
72
      nonexistent_name[9] = 'a' + j;
40
73
      printf("NON-EXISTING %d,%d\n", i, j);
41
74
      printf("success: %d\n", open(nonexistent_name, flags, 0777) != -1);
42
75
      printf("errno: %d\n", errno);
49
82
  }
50
83
 
51
84
  printf("CREAT\n");
52
 
  printf("success: %d\n", creat("/creat-me", 0777) != -1);
 
85
  printf("success: %d\n", creat("creat-me", 0777) != -1);
53
86
  printf("errno: %d\n", errno);
 
87
}
54
88
 
55
 
  return 0;
 
89
int main() {
 
90
  atexit(cleanup);
 
91
  signal(SIGABRT, cleanup);
 
92
  setup();
 
93
  test();
 
94
  return EXIT_SUCCESS;
56
95
}