File: unlink.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 (81 lines) | stat: -rw-r--r-- 1,769 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
/* COVERAGE: unlink unlinkat */
#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

// To test for glibc support for unlinkat(), 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 fd1;

  fd1 = creat("foobar1",S_IREAD|S_IWRITE);
  close (fd1);
  
#if GLIBC_SUPPORT
  fd1 = creat("foobar2", S_IREAD|S_IWRITE);
  close (fd1);
#endif

  unlink("foobar1");
  //staptest// unlink ("foobar1") = 0

#if GLIBC_SUPPORT
  unlinkat(AT_FDCWD, "foobar2", 0);
  //staptest// unlinkat (AT_FDCWD, "foobar2", 0x0) = 0
#endif

  unlink("foobar1");
  //staptest// unlink ("foobar1") = -NNNN (ENOENT)

#if GLIBC_SUPPORT
  unlinkat(AT_FDCWD, "foobar1", 0);
  //staptest// unlinkat (AT_FDCWD, "foobar1", 0x0) = -NNNN (ENOENT)
#endif

  unlink("foobar2");
  //staptest// unlink ("foobar2") = -NNNN (ENOENT)

#if GLIBC_SUPPORT
  unlinkat(AT_FDCWD, "foobar2", 0);
  //staptest// unlinkat (AT_FDCWD, "foobar2", 0x0) = -NNNN (ENOENT)
#endif

  unlink(0);
  //staptest// unlink ( *(null)) = -NNNN (EFAULT)

#if GLIBC_SUPPORT
  unlinkat(AT_FDCWD, 0, 0);
  //staptest// unlinkat (AT_FDCWD, *(null), 0x0) = -NNNN (EFAULT)
#endif

  unlink("..");
  //staptest// unlink ("..") = -NNNN (EISDIR)

#if GLIBC_SUPPORT
  unlinkat(AT_FDCWD, "..", 0);
  //staptest// unlinkat (AT_FDCWD, "..", 0x0) = -NNNN (EISDIR)
#endif

  unlink("");
  //staptest// unlink ("") = -NNNN (ENOENT)

#if GLIBC_SUPPORT
  unlinkat(AT_FDCWD, "", 0);
  //staptest// unlinkat (AT_FDCWD, "", 0x0) = -NNNN (ENOENT)
#endif

  return 0;
}