2 # Ensure that touch -h works.
4 # Copyright (C) 2009-2024 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 .
"${srcdir=.}/tests/init.sh"; path_prepend_ .
/src
22 ln -s nowhere dangling || framework_failure_
23 touch file || framework_failure_
24 ln -s file link || framework_failure_
27 # These first tests should work on every platform.
28 # -h does not create files, but it warns. Use -c to silence warning.
29 returns_
1 touch -h no-file
2> err || fail
=1
30 compare
/dev
/null err
&& fail
=1
31 touch -h -c no-file
2> err || fail
=1
32 compare
/dev
/null err || fail
=1
34 # -h works on regular files
35 touch -h file || fail
=1
37 # -h coupled with -r uses timestamp of the symlink, not the referent.
38 touch -h -r dangling
file || fail
=1
39 test -f nowhere
&& fail
=1
41 # The remaining tests of -h require kernel support for changing symlink times.
42 grep '^#define HAVE_UTIMENSAT 1' "$CONFIG_HEADER" > /dev
/null ||
43 grep '^#define HAVE_LUTIMES 1' "$CONFIG_HEADER" > /dev
/null ||
44 skip_
'this system lacks the utimensat function'
46 # Changing time of dangling symlink is okay.
47 # Skip the test if this fails, but the error text corresponds to
48 # ENOSYS (possible with old kernel but new glibc).
49 touch -h dangling
2> err
51 0) test -f nowhere
&& fail
=1
52 compare
/dev
/null err || fail
=1;;
53 1) grep 'Function not implemented' err \
54 && skip_
'this system lacks the utimensat function'
59 # Change the mtime of a symlink.
60 touch -m -h -d 2009-10-10 link || fail
=1
61 case $
(stat
--format=%y link
) in
65 case $
(stat
--format=%y
file) in
69 # Test interactions with -.
70 touch -h - > file || fail
=1
72 # If >&- works, test "touch -ch -" etc.
73 # >&- apparently does not work in HP-UX 11.23.
74 # This test is ineffective unless /dev/stdout also works.
75 # If stdout is open, it is not a symlink.
76 if env
test -w /dev
/stdout
>/dev
/null
&&
77 env
test ! -w /dev
/stdout
>&-; then
78 returns_
1 touch -h - >&- || fail
=1
79 touch -h -c - >&- || fail
=1