Whamcloud - gitweb
b=15967
[fs/lustre-release.git] / lustre / tests / o_directory.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  */
4
5 /* for O_DIRECTORY */
6 #ifndef _GNU_SOURCE
7 #define _GNU_SOURCE
8 #endif
9
10 #include <fcntl.h>
11 #include <unistd.h>
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include <errno.h>
15 #include <string.h>
16 #include <sys/types.h>
17 #include <sys/stat.h>
18
19 int main(int argc, char **argv)
20 {
21         int fd, rc;
22
23         if (argc != 2) {
24                 printf("Usage: %s <filename>\n", argv[0]);
25                 exit(1);
26         }
27
28         fd = open(argv[1], O_RDONLY | O_CREAT, 0600);
29         if (fd == -1) {
30                 printf("Error opening %s for create: %s\n", argv[1],
31                        strerror(errno));
32                 exit(1);
33         }
34         rc = close(fd);
35         if (rc < 0) {
36                 printf("Error closing %s: %s\n", argv[1], strerror(errno));
37                 exit(1);
38         }
39
40         fd = open(argv[1], O_DIRECTORY);
41         if (fd >= 0) {
42                 printf("opening %s as directory should have returned an "
43                        "error!\n", argv[1]);
44                 exit(1);
45         }
46         if (errno != ENOTDIR) {
47                 printf("opening %s as directory, expected -ENOTDIR and got "
48                        "%s\n", argv[1], strerror(errno));
49                 exit(1);
50         }
51
52         return 0;
53 }