mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-25 04:01:10 +00:00
088d3291ef
It is enabled through a new rule, tests-y2038, which is built only when the ABI supports the comapt 64-bit time_t (defined by the header time64-compat.h, which also enables the creation of the symbol Version for Linux). It means the tests are not built for ABI which already provide default 64-bit time_t. The new rule already adds the required LFS and 64-bit time_t compiler flags. The current coverage is: * libc: - adjtime tst-adjtime-time64 - adjtimex tst-adjtimex-time64 - clock_adjtime tst-clock_adjtime-time64 - clock_getres tst-clock-time64, tst-cpuclock1-time64 - clock_gettime tst-clock-time64, tst-clock2-time64, tst-cpuclock1-time64 - clock_nanosleep tst-clock_nanosleep-time64, tst-cpuclock1-time64 - clock_settime tst-clock2-time64 - cnd_timedwait tst-cnd-timedwait-time64 - ctime tst-ctime-time64 - ctime_r tst-ctime-time64 - difftime tst-difftime-time64 - fstat tst-stat-time64 - fstatat tst-stat-time64 - futimens tst-futimens-time64 - futimes tst-futimes-time64 - futimesat tst-futimesat-time64 - fts_* tst-fts-time64 - getitimer tst-itimer-timer64 - getrusage - gettimeofday tst-clock_nanosleep-time64 - glob / globfree tst-gnuglob64-time64 - gmtime tst-gmtime-time64 - gmtime_r tst-gmtime-time64 - lstat tst-stat-time64 - localtime tst-y2039-time64 - localtime_t tst-y2039-time64 - lutimes tst-lutimes-time64 - mktime tst-mktime4-time64 - mq_timedreceive tst-mqueue{1248}-time64 - mq_timedsend tst-mqueue{1248}-time64 - msgctl test-sysvmsg-time64 - mtx_timedlock tst-mtx-timedlock-time64 - nanosleep tst-cpuclock{12}-time64, tst-mqueue8-time64, tst-clock-time64 - nftw / ftw ftwtest-time64 - ntp_adjtime tst-ntp_adjtime-time64 - ntp_gettime tst-ntp_gettime-time64 - ntp_gettimex tst-ntp_gettimex-time64 - ppoll tst-ppoll-time64 - pselect tst-pselect-time64 - pthread_clockjoin_np tst-join14-time64 - pthread_cond_clockwait tst-cond11-time64 - pthread_cond_timedwait tst-abstime-time64 - pthread_mutex_clocklock tst-abstime-time64 - pthread_mutex_timedlock tst-abstime-time64 - pthread_rwlock_clockrdlock tst-abstime-time64, tst-rwlock14-time64 - pthread_rwlock_clockwrlock tst-abstime-time64, tst-rwlock14-time64 - pthread_rwlock_timedrdlock tst-abstime-time64, tst-rwlock14-time64 - pthread_rwlock_timedwrlock tst-abstime-time64, tst-rwlock14-time64 - pthread_timedjoin_np tst-join14-time64 - recvmmsg tst-cancel4_2-time64 - sched_rr_get_interval tst-sched_rr_get_interval-time64 - select tst-select-time64 - sem_clockwait tst-sem5-time64 - sem_timedwait tst-sem5-time64 - semctl test-sysvsem-time64 - semtimedop test-sysvsem-time64 - setitimer tst-mqueue2-time64, tst-itimer-timer64 - settimeofday tst-settimeofday-time64 - shmctl test-sysvshm-time64 - sigtimedwait tst-sigtimedwait-time64 - stat tst-stat-time64 - thrd_sleep tst-thrd-sleep-time64 - time tst-mqueue{1248}-time64 - timegm tst-timegm-time64 - timer_gettime tst-timer4-time64 - timer_settime tst-timer4-time64 - timerfd_gettime tst-timerfd-time64 - timerfd_settime tst-timerfd-time64 - timespec_get tst-timespec_get-time64 - timespec_getres tst-timespec_getres-time64 - utime tst-utime-time64 - utimensat tst-utimensat-time64 - utimes tst-utimes-time64 - wait3 tst-wait3-time64 - wait4 tst-wait4-time64 * librt: - aio_suspend tst-aio6-time64 - mq_timedreceive tst-mqueue{1248}-time64 - mq_timedsend tst-mqueue{1248}-time64 - timer_gettime tst-timer4-time64 - timer_settime tst-timer4-time64 * libanl: - gai_suspend Reviewed-by: Lukasz Majewski <lukma@denx.de> Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
170 lines
3.7 KiB
C
170 lines
3.7 KiB
C
/* futimesat basic tests.
|
|
Copyright (C) 2021 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with the GNU C Library; if not, see
|
|
<https://www.gnu.org/licenses/>. */
|
|
|
|
#include <dirent.h>
|
|
#include <errno.h>
|
|
#include <fcntl.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/time.h>
|
|
|
|
#include <support/test-driver.h>
|
|
#include <support/temp_file.h>
|
|
|
|
#ifndef struct_stat
|
|
# define struct_stat struct stat64
|
|
# define fstat fstat64
|
|
# define fstatat fstatat64
|
|
#endif
|
|
|
|
static int dir_fd;
|
|
|
|
static void
|
|
prepare (int argc, char *argv[])
|
|
{
|
|
size_t test_dir_len = strlen (test_dir);
|
|
static const char dir_name[] = "/tst-futimesat.XXXXXX";
|
|
|
|
size_t dirbuflen = test_dir_len + sizeof (dir_name);
|
|
char *dirbuf = malloc (dirbuflen);
|
|
if (dirbuf == NULL)
|
|
{
|
|
puts ("out of memory");
|
|
exit (1);
|
|
}
|
|
|
|
snprintf (dirbuf, dirbuflen, "%s%s", test_dir, dir_name);
|
|
if (mkdtemp (dirbuf) == NULL)
|
|
{
|
|
puts ("cannot create temporary directory");
|
|
exit (1);
|
|
}
|
|
|
|
add_temp_file (dirbuf);
|
|
|
|
dir_fd = open (dirbuf, O_RDONLY | O_DIRECTORY);
|
|
if (dir_fd == -1)
|
|
{
|
|
puts ("cannot open directory");
|
|
exit (1);
|
|
}
|
|
}
|
|
#define PREPARE prepare
|
|
|
|
static int
|
|
do_test (void)
|
|
{
|
|
/* fdopendir takes over the descriptor, make a copy. */
|
|
int dupfd = dup (dir_fd);
|
|
if (dupfd == -1)
|
|
{
|
|
puts ("dup failed");
|
|
return 1;
|
|
}
|
|
if (lseek (dupfd, 0, SEEK_SET) != 0)
|
|
{
|
|
puts ("1st lseek failed");
|
|
return 1;
|
|
}
|
|
|
|
/* The directory should be empty safe the . and .. files. */
|
|
DIR *dir = fdopendir (dupfd);
|
|
if (dir == NULL)
|
|
{
|
|
puts ("fdopendir failed");
|
|
return 1;
|
|
}
|
|
struct dirent64 *d;
|
|
while ((d = readdir64 (dir)) != NULL)
|
|
if (strcmp (d->d_name, ".") != 0 && strcmp (d->d_name, "..") != 0)
|
|
{
|
|
printf ("temp directory contains file \"%s\"\n", d->d_name);
|
|
return 1;
|
|
}
|
|
closedir (dir);
|
|
|
|
/* Try to create a file. */
|
|
int fd = openat (dir_fd, "some-file", O_CREAT|O_RDWR|O_EXCL, 0666);
|
|
if (fd == -1)
|
|
{
|
|
if (errno == ENOSYS)
|
|
{
|
|
puts ("*at functions not supported");
|
|
return 0;
|
|
}
|
|
|
|
puts ("file creation failed");
|
|
return 1;
|
|
}
|
|
write (fd, "hello", 5);
|
|
puts ("file created");
|
|
|
|
struct_stat st1;
|
|
if (fstat (fd, &st1) != 0)
|
|
{
|
|
puts ("fstat64 failed");
|
|
return 1;
|
|
}
|
|
|
|
close (fd);
|
|
|
|
struct timeval tv[2];
|
|
tv[0].tv_sec = st1.st_atime + 1;
|
|
tv[0].tv_usec = 0;
|
|
tv[1].tv_sec = st1.st_mtime + 1;
|
|
tv[1].tv_usec = 0;
|
|
if (futimesat (dir_fd, "some-file", tv) != 0)
|
|
{
|
|
puts ("futimesat failed");
|
|
return 1;
|
|
}
|
|
|
|
struct_stat st2;
|
|
if (fstatat (dir_fd, "some-file", &st2, 0) != 0)
|
|
{
|
|
puts ("fstatat64 failed");
|
|
return 1;
|
|
}
|
|
|
|
if (st2.st_mtime != tv[1].tv_sec
|
|
#ifdef _STATBUF_ST_NSEC
|
|
|| st2.st_mtim.tv_nsec != 0
|
|
#endif
|
|
)
|
|
{
|
|
puts ("stat shows different mtime");
|
|
return 1;
|
|
}
|
|
|
|
|
|
if (unlinkat (dir_fd, "some-file", 0) != 0)
|
|
{
|
|
puts ("unlinkat failed");
|
|
return 1;
|
|
}
|
|
|
|
close (dir_fd);
|
|
|
|
return 0;
|
|
}
|
|
|
|
#include <support/test-driver.c>
|