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 174
|
/* COVERAGE: open openat close creat */
#define _GNU_SOURCE
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
// To test for glibc support for openat():
//
// 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, fd2;
fd2 = creat("foobar1",S_IREAD|S_IWRITE);
//staptest// [[[[[[[[open (!!!!openat (AT_FDCWD, ]]]]"foobar1", O_WRONLY|O_CREAT[[[[.O_LARGEFILE]]]]?|O_TRUNC!!!!creat ("foobar1"]]]], 0600) = NNNN
creat((char *)-1, S_IREAD|S_IWRITE);
#ifdef __s390__
//staptest// [[[[open (0x[7]?[f]+, O_WRONLY|O_CREAT[[[[.O_LARGEFILE]]]]?|O_TRUNC!!!!creat (0x[7]?[f]+]]]], 0600) = NNNN
#else
//staptest// [[[[[[[[open (!!!!openat (AT_FDCWD, ]]]]0x[f]+, O_WRONLY|O_CREAT[[[[.O_LARGEFILE]]]]?|O_TRUNC!!!!creat (0x[f]+]]]], 0600) = NNNN
#endif
creat("foobarX", -1);
//staptest// [[[[[[[[open (!!!!openat (AT_FDCWD, ]]]]"foobarX", O_WRONLY|O_CREAT[[[[.O_LARGEFILE]]]]?|O_TRUNC!!!!creat ("foobarX"]]]], 037777777777) =
fd1 = open("foobar2",O_WRONLY|O_CREAT, S_IRWXU);
//staptest// [[[[open (!!!!openat (AT_FDCWD, ]]]]"foobar2", O_WRONLY|O_CREAT[[[[.O_LARGEFILE]]]]?, 0700) = NNNN
close(fd1);
//staptest// close (NNNN) = 0
#if GLIBC_SUPPORT
fd1 = openat(AT_FDCWD, "foobar2", O_WRONLY|O_CREAT, S_IRWXU);
//staptest// openat (AT_FDCWD, "foobar2", O_WRONLY|O_CREAT[[[[.O_LARGEFILE]]]]?, 0700) = NNNN
close(fd1);
//staptest// close (NNNN) = 0
#endif
fd1 = open("foobar2",O_RDONLY);
//staptest// [[[[open (!!!!openat (AT_FDCWD, ]]]]"foobar2", O_RDONLY[[[[.O_LARGEFILE]]]]?) = NNNN
close(fd1);
//staptest// close (NNNN) = 0
#if GLIBC_SUPPORT
fd1 = openat(AT_FDCWD, "foobar2", O_RDONLY);
//staptest// openat (AT_FDCWD, "foobar2", O_RDONLY[[[[.O_LARGEFILE]]]]?) = NNNN
close(fd1);
//staptest// close (NNNN) = 0
#endif
fd1 = open("foobar2",O_RDWR);
//staptest// [[[[open (!!!!openat (AT_FDCWD, ]]]]"foobar2", O_RDWR[[[[.O_LARGEFILE]]]]?) = NNNN
close(fd1);
//staptest// close (NNNN) = 0
#if GLIBC_SUPPORT
fd1 = openat(AT_FDCWD, "foobar2", O_RDWR);
//staptest// openat (AT_FDCWD, "foobar2", O_RDWR[[[[.O_LARGEFILE]]]]?) = NNNN
close(fd1);
//staptest// close (NNNN) = 0
#endif
fd1 = open("foobar2",O_APPEND|O_WRONLY);
//staptest// [[[[open (!!!!openat (AT_FDCWD, ]]]]"foobar2", O_WRONLY|O_APPEND[[[[.O_LARGEFILE]]]]?) = NNNN
close(fd1);
//staptest// close (NNNN) = 0
#if GLIBC_SUPPORT
fd1 = openat(AT_FDCWD, "foobar2", O_APPEND|O_WRONLY);
//staptest// openat (AT_FDCWD, "foobar2", O_WRONLY|O_APPEND[[[[.O_LARGEFILE]]]]?) = NNNN
close(fd1);
//staptest// close (NNNN) = 0
#endif
fd1 = open("foobar2",O_DIRECT|O_RDWR);
//staptest// [[[[open (!!!!openat (AT_FDCWD, ]]]]"foobar2", O_RDWR|O_DIRECT[[[[.O_LARGEFILE]]]]?) = NNNN
close(fd1);
//staptest// close (NNNN) = 0
#if GLIBC_SUPPORT
fd1 = openat(AT_FDCWD, "foobar2", O_DIRECT|O_RDWR);
//staptest// openat (AT_FDCWD, "foobar2", O_RDWR|O_DIRECT[[[[.O_LARGEFILE]]]]?) = NNNN
close(fd1);
//staptest// close (NNNN) = 0
#endif
fd1 = open("foobar2",O_NOATIME|O_SYNC|O_RDWR);
//staptest// [[[[open (!!!!openat (AT_FDCWD, ]]]]"foobar2", O_RDWR[[[[.O_LARGEFILE]]]]?|O_SYNC|O_NOATIME) = NNNN
close(fd1);
//staptest// close (NNNN) = 0
#if GLIBC_SUPPORT
fd1 = openat(AT_FDCWD, "foobar2", O_NOATIME|O_SYNC|O_RDWR);
//staptest// openat (AT_FDCWD, "foobar2", O_RDWR[[[[.O_LARGEFILE]]]]?|O_SYNC|O_NOATIME) = NNNN
close(fd1);
//staptest// close (NNNN) = 0
#endif
/* Now test some bad opens */
fd1 = open("/",O_WRONLY);
//staptest// [[[[open (!!!!openat (AT_FDCWD, ]]]]"/", O_WRONLY[[[[.O_LARGEFILE]]]]?) = -NNNN (EISDIR)
close (fd1);
//staptest// close (NNNN) = -NNNN (EBADF)
#if GLIBC_SUPPORT
fd1 = openat(AT_FDCWD, "/", O_WRONLY);
//staptest// openat (AT_FDCWD, "/", O_WRONLY[[[[.O_LARGEFILE]]]]?) = -NNNN (EISDIR)
close (fd1);
//staptest// close (NNNN) = -NNNN (EBADF)
#endif
fd1 = open("foobar2",O_WRONLY|O_CREAT|O_EXCL, S_IRWXU);
//staptest// [[[[open (!!!!openat (AT_FDCWD, ]]]]"foobar2", O_WRONLY|O_CREAT|O_EXCL[[[[.O_LARGEFILE]]]]?, 0700) = -NNNN (EEXIST)
#if GLIBC_SUPPORT
fd1 = openat(AT_FDCWD, "foobar2",O_WRONLY|O_CREAT|O_EXCL, S_IRWXU);
//staptest// openat (AT_FDCWD, "foobar2", O_WRONLY|O_CREAT|O_EXCL[[[[.O_LARGEFILE]]]]?, 0700) = -NNNN (EEXIST)
#endif
open((char *)-1, O_WRONLY|O_CREAT|O_EXCL, S_IRWXU);
#ifdef __s390__
//staptest// [[[[open (!!!!openat (AT_FDCWD, ]]]]0x[7]?[f]+, O_WRONLY|O_CREAT|O_EXCL[[[[.O_LARGEFILE]]]]?, 0700) =
#else
//staptest// [[[[open (!!!!openat (AT_FDCWD, ]]]]0x[f]+, O_WRONLY|O_CREAT|O_EXCL[[[[.O_LARGEFILE]]]]?, 0700) =
#endif
#if GLIBC_SUPPORT
openat(-1, "foobarX", O_WRONLY|O_CREAT|O_EXCL, S_IRWXU);
//staptest// openat (-1, "foobarX", O_WRONLY|O_CREAT|O_EXCL[[[[.O_LARGEFILE]]]]?, 0700) =
openat(AT_FDCWD, (char *)-1, O_WRONLY|O_CREAT|O_EXCL, S_IRWXU);
#ifdef __s390__
//staptest// openat (AT_FDCWD, 0x[7]?[f]+, O_WRONLY|O_CREAT|O_EXCL[[[[.O_LARGEFILE]]]]?, 0700) =
#else
//staptest// openat (AT_FDCWD, 0x[f]+, O_WRONLY|O_CREAT|O_EXCL[[[[.O_LARGEFILE]]]]?, 0700) =
#endif
#endif
open("foobarX", -1, S_IRWXU);
//staptest// [[[[open (!!!!openat (AT_FDCWD, ]]]]"foobarX", O_[^ ]+|XXXX, 0700) =
fd1 = open("foobarY", O_WRONLY|O_CREAT, -1);
//staptest// [[[open (!!!!openat (AT_FDCWD, ]]]]"foobarY", O_WRONLY|O_CREAT[[[[|O_LARGEFILE]]]]?, 037777777777) = NNNN
close(fd1);
//staptest// close (NNNN) = 0
#if GLIBC_SUPPORT
openat(AT_FDCWD, "foobarX", -1, S_IRWXU);
//staptest// openat (AT_FDCWD, "foobarX", O_[^ ]+|XXXX, 0700) =
fd1 = openat(AT_FDCWD, "foobarZ", O_WRONLY|O_CREAT, -1);
//staptest// openat (AT_FDCWD, "foobarZ", O_WRONLY|O_CREAT[[[[|O_LARGEFILE]]]]?, 037777777777) = NNNN
close(fd1);
//staptest// close (NNNN) = 0
#endif
close(-1);
//staptest// close (-1) = -NNNN (EBADF)
return 0;
}
|