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