1#!/bin/sh
2# Exercise du on a file with a big timestamp.
3
4# Copyright (C) 2010-2023 Free Software Foundation, Inc.
5
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.
10
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.
15
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/>.
18
19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20print_ver_ du
21
22export LC_ALL=C
23export TZ=UTC0
24
25# 2**63 - 1
26bignum=9223372036854775807
27
28touch -d @$bignum future 2>/dev/null &&
29future_time=$(ls -l future) &&
30case "$future_time" in
31*" $bignum "*)
32  : ;;
33*' Dec  4  300627798676 '*)
34  skip_ "file system and localtime both handle big timestamps" ;;
35*)
36  skip_ "file system or localtime mishandles big timestamps:" \
37      "$future_time" ;;
38esac || skip_ "file system cannot represent big timestamps"
39
40printf "0\t$bignum\tfuture\n" > exp || framework_failure_
41printf "du: time '$bignum' is out of range\n" > err_ok || framework_failure_
42
43du --time future >out 2>err || fail=1
44
45# On some systems an empty file occupies 4 blocks.
46# Map the number of blocks to 0.
47sed 's/^[0-9][0-9]*/0/' out > k && mv k out
48
49compare exp out || fail=1
50compare err err_ok || fail=1
51
52Exit $fail
53