Mercurial > hg > octave-shane > gnulib-hg
annotate tests/test-symlinkat.c @ 17530:8981b79e1271
error: make the module depend on vfprintf-posix
* modules/error (Depends-on): Add vfprintf-posix, since error
calls vfprintf unconditionally, via error_tail.
author | Jim Meyering <meyering@fb.com> |
---|---|
date | Sat, 12 Oct 2013 19:28:40 -0700 |
parents | 3a09cc104f4c |
children | 344018b6e5d7 |
rev | line source |
---|---|
13539
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
12842
diff
changeset
|
1 /* Tests of symlinkat. |
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
16201
diff
changeset
|
2 Copyright (C) 2009-2013 Free Software Foundation, Inc. |
11956 | 3 |
4 This program is free software: you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 3 of the License, or | |
7 (at your option) any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
16 | |
17 /* Written by Eric Blake <ebb9@byu.net>, 2009. */ | |
18 | |
19 #include <config.h> | |
20 | |
21 #include <unistd.h> | |
22 | |
12489 | 23 #include "signature.h" |
24 SIGNATURE_CHECK (symlinkat, int, (char const *, int, char const *)); | |
25 | |
11956 | 26 #include <fcntl.h> |
27 #include <errno.h> | |
12061 | 28 #include <stdbool.h> |
11956 | 29 #include <stdio.h> |
30 #include <stdlib.h> | |
31 #include <string.h> | |
32 #include <sys/stat.h> | |
33 | |
12842
b2bf8684a2db
tests: silence warning about system return
Eric Blake <ebb9@byu.net>
parents:
12559
diff
changeset
|
34 #include "ignore-value.h" |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12489
diff
changeset
|
35 #include "macros.h" |
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12489
diff
changeset
|
36 |
11956 | 37 #ifndef HAVE_SYMLINK |
38 # define HAVE_SYMLINK 0 | |
39 #endif | |
40 | |
12061 | 41 #define BASE "test-symlinkat.t" |
42 | |
43 #include "test-symlink.h" | |
44 | |
45 static int dfd = AT_FDCWD; | |
46 | |
47 static int | |
48 do_symlink (char const *contents, char const *name) | |
49 { | |
50 return symlinkat (contents, dfd, name); | |
51 } | |
52 | |
11956 | 53 int |
12197
e45d9bb2233e
tests: avoid several compiler warnings
Eric Blake <ebb9@byu.net>
parents:
12146
diff
changeset
|
54 main (void) |
11956 | 55 { |
12061 | 56 int result; |
11956 | 57 |
12061 | 58 /* Remove any leftovers from a previous partial run. */ |
12842
b2bf8684a2db
tests: silence warning about system return
Eric Blake <ebb9@byu.net>
parents:
12559
diff
changeset
|
59 ignore_value (system ("rm -rf " BASE "*")); |
11956 | 60 |
15704
17eaeb48cbef
symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
61 /* Test behaviour for invalid file descriptors. */ |
17eaeb48cbef
symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
62 { |
17eaeb48cbef
symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
63 errno = 0; |
17eaeb48cbef
symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
64 ASSERT (symlinkat ("foo", -1, "bar") == -1); |
17eaeb48cbef
symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
65 ASSERT (errno == EBADF |
17eaeb48cbef
symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
66 || errno == ENOSYS /* seen on mingw */ |
17eaeb48cbef
symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
67 ); |
17eaeb48cbef
symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
68 } |
17eaeb48cbef
symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
69 { |
17295
3a09cc104f4c
tests: don't assume fd 99 is closed
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
70 close (99); |
15704
17eaeb48cbef
symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
71 errno = 0; |
17eaeb48cbef
symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
72 ASSERT (symlinkat ("foo", 99, "bar") == -1); |
17eaeb48cbef
symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
73 ASSERT (errno == EBADF |
17eaeb48cbef
symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
74 || errno == ENOSYS /* seen on mingw */ |
17eaeb48cbef
symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
75 ); |
17eaeb48cbef
symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
76 } |
17eaeb48cbef
symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
77 |
12061 | 78 /* Perform same checks as counterpart functions. */ |
13539
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
12842
diff
changeset
|
79 result = test_symlink (do_symlink, false); |
12061 | 80 dfd = openat (AT_FDCWD, ".", O_RDONLY); |
81 ASSERT (0 <= dfd); | |
82 ASSERT (test_symlink (do_symlink, false) == result); | |
11956 | 83 |
84 ASSERT (close (dfd) == 0); | |
12061 | 85 if (result == 77) |
12146
e076a06bae48
maint: prefer 'file system' over 'filesystem'
Eric Blake <ebb9@byu.net>
parents:
12061
diff
changeset
|
86 fputs ("skipping test: symlinks not supported on this file system\n", |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12197
diff
changeset
|
87 stderr); |
12061 | 88 return result; |
11956 | 89 } |