File: link.c

package info (click to toggle)
systemtap 2.6-0.2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 21,220 kB
  • ctags: 10,944
  • sloc: cpp: 53,239; ansic: 50,615; exp: 33,694; sh: 9,906; xml: 7,665; perl: 2,089; python: 1,534; tcl: 1,236; makefile: 797; java: 148; lisp: 104; awk: 94; asm: 91; sed: 16
file content (173 lines) | stat: -rw-r--r-- 5,102 bytes parent folder | download
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* COVERAGE: link linkat symlink symlinkat readlink readlinkat */
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

// To test for glibc support for linkat(), symlinkat(), readlinkat():
//
// Since glibc 2.10:
//	_XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L
// Before glibc 2.10:
//	_ATFILE_SOURCE

#define GLIBC_SUPPORT \
  (_XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L \
   || defined(_ATFILE_SOURCE))

int main()
{
  int fd;
  char buf[128];

  fd = open("foobar",O_WRONLY|O_CREAT, S_IRWXU);
  close(fd);

  link("foobar", "foobar2");
  //staptest// link ("foobar", "foobar2") = 0

#if GLIBC_SUPPORT
  linkat(AT_FDCWD, "foobar", AT_FDCWD, "foobar3", 0);
  //staptest// linkat (AT_FDCWD, "foobar", AT_FDCWD, "foobar3", 0x0) = 0
#endif

  link("foobar", "foobar");
  //staptest// link ("foobar", "foobar") = -NNNN (EEXIST)

#if GLIBC_SUPPORT
  linkat(AT_FDCWD, "foobar", AT_FDCWD, "foobar", 0);
  //staptest// linkat (AT_FDCWD, "foobar", AT_FDCWD, "foobar", 0x0) = -NNNN (EEXIST)
#endif

  link("nonexist", "foo");
  //staptest// link ("nonexist", "foo") = -NNNN (ENOENT)

  link((char *)-1, "foo");
#ifdef __s390__
  //staptest// link ([7]?[f]+, "foo") = -NNNN (EFAULT)
#else
  //staptest// link ([f]+, "foo") = -NNNN (EFAULT)
#endif

  link("nonexist", (char *)-1);
#ifdef __s390__
  //staptest// link ("nonexist", [7]?[f]+) = -NNNN
#else
  //staptest// link ("nonexist", [f]+) = -NNNN
#endif

#if GLIBC_SUPPORT
  linkat(AT_FDCWD, "nonexist", AT_FDCWD, "foo", 0);
  //staptest// linkat (AT_FDCWD, "nonexist", AT_FDCWD, "foo", 0x0) = -NNNN (ENOENT)

  linkat(-1, "nonexist", AT_FDCWD, "foo", 0);
  //staptest// linkat (-1, "nonexist", AT_FDCWD, "foo", 0x0) = -NNNN (EBADF)

  linkat(AT_FDCWD, (char *)-1, AT_FDCWD, "foo", 0);
#ifdef __s390__
  //staptest// linkat (AT_FDCWD, [7]?[f]+, AT_FDCWD, "foo", 0x0) = -NNNN (EFAULT)
#else
  //staptest// linkat (AT_FDCWD, [f]+, AT_FDCWD, "foo", 0x0) = -NNNN (EFAULT)
#endif

  linkat(AT_FDCWD, "nonexist", -1, "foo", 0);
  //staptest// linkat (AT_FDCWD, "nonexist", -1, "foo", 0x0) = -NNNN (ENOENT)

  linkat(AT_FDCWD, "nonexist", AT_FDCWD, (char *)-1, 0);
#ifdef __s390__
  //staptest// linkat (AT_FDCWD, "nonexist", AT_FDCWD, [7]?[f]+, 0x0) = -NNNN
#else
  //staptest// linkat (AT_FDCWD, "nonexist", AT_FDCWD, [f]+, 0x0) = -NNNN
#endif

  linkat(AT_FDCWD, "nonexist", AT_FDCWD, "foo", -1);
  //staptest// linkat (AT_FDCWD, "nonexist", AT_FDCWD, "foo", AT_[^ ]+|XXXX) = -NNNN (EINVAL)
#endif

  symlink("foobar", "Sfoobar");
  //staptest// symlink ("foobar", "Sfoobar") = 0

  symlink((char *)-1, "Sfoobar");
#ifdef __s390__
  //staptest// symlink ([7]?[f]+, "Sfoobar") = -NNNN (EFAULT)
#else
  //staptest// symlink ([f]+, "Sfoobar") = -NNNN (EFAULT)
#endif

  symlink("foobar", (char *)-1);
#ifdef __s390__
  //staptest// symlink ("foobar", [7]?[f]+) = -NNNN (EFAULT)
#else
  //staptest// symlink ("foobar", [f]+) = -NNNN (EFAULT)
#endif

#if GLIBC_SUPPORT
  symlinkat("foobar", AT_FDCWD, "Sfoobar2");
  //staptest// symlinkat ("foobar", AT_FDCWD, "Sfoobar2") = 0

  symlinkat((char *)-1, AT_FDCWD, "Sfoobar2");
#ifdef __s390__
  //staptest// symlinkat ([7]?[f]+, AT_FDCWD, "Sfoobar2") = -NNNN (EFAULT)
#else
  //staptest// symlinkat ([f]+, AT_FDCWD, "Sfoobar2") = -NNNN (EFAULT)
#endif

  symlinkat("foobar", -1, "Sfoobar2");
  //staptest// symlinkat ("foobar", -1, "Sfoobar2") = -NNNN (EBADF)

  symlinkat("foobar", AT_FDCWD, (char *)-1);
#ifdef __s390__
  //staptest// symlinkat ("foobar", AT_FDCWD, [7]?[f]+) = -NNNN (EFAULT)
#else
  //staptest// symlinkat ("foobar", AT_FDCWD, [f]+) = -NNNN (EFAULT)
#endif
#endif

  readlink("Sfoobar", buf, sizeof(buf));
  //staptest// readlink ("Sfoobar", XXXX, 128) = 6

  readlink((char *)-1, buf, sizeof(buf));
#ifdef __s390__
  //staptest// readlink ([7]?[f]+, XXXX, 128) = -NNNN (EFAULT)
#else
  //staptest// readlink ([f]+, XXXX, 128) = -NNNN (EFAULT)
#endif

  readlink("Sfoobar", (char *)-1, sizeof(buf));
#ifdef __s390__
  //staptest// readlink ("Sfoobar", 0x[7]?[f]+, 128) = -NNNN (EFAULT)
#else
  //staptest// readlink ("Sfoobar", 0x[f]+, 128) = -NNNN (EFAULT)
#endif

  readlink("Sfoobar", buf, -1);
  //staptest// readlink ("Sfoobar", XXXX, -1) = -NNNN (EINVAL)

#if GLIBC_SUPPORT
  readlinkat(AT_FDCWD, "Sfoobar", buf, sizeof(buf));
  //staptest// readlinkat (AT_FDCWD, "Sfoobar", XXXX, 128) = 6

  readlinkat(-1, "Sfoobar", buf, sizeof(buf));
  //staptest// readlinkat (-1, "Sfoobar", XXXX, 128) = -NNNN (EBADF)

  readlinkat(AT_FDCWD, (char *)-1, buf, sizeof(buf));
#ifdef __s390__
  //staptest// readlinkat (AT_FDCWD, [7]?[f]+, XXXX, 128) = -NNNN (EFAULT)
#else
  //staptest// readlinkat (AT_FDCWD, [f]+, XXXX, 128) = -NNNN (EFAULT)
#endif

  readlinkat(AT_FDCWD, "Sfoobar", (char *)-1, sizeof(buf));
#ifdef __s390__
  //staptest// readlinkat (AT_FDCWD, "Sfoobar", 0x[7]?[f]+, 128) = -NNNN (EFAULT)
#else
  //staptest// readlinkat (AT_FDCWD, "Sfoobar", 0x[f]+, 128) = -NNNN (EFAULT)
#endif

  readlinkat(AT_FDCWD, "Sfoobar", buf, -1);
  //staptest// readlinkat (AT_FDCWD, "Sfoobar", XXXX, -1) = -NNNN (EINVAL)
#endif

  return 0;
}