summaryrefslogtreecommitdiff
path: root/io
diff options
context:
space:
mode:
Diffstat (limited to 'io')
-rw-r--r--io/Makefile76
-rw-r--r--io/Versions13
-rw-r--r--io/access.c9
-rw-r--r--io/bits/fcntl2.h2
-rw-r--r--io/bits/poll2.h2
-rw-r--r--io/bits/statx.h91
-rw-r--r--io/bug-ftw1.c2
-rw-r--r--io/bug-ftw2.c2
-rw-r--r--io/bug-ftw4.c2
-rw-r--r--io/chdir.c2
-rw-r--r--io/chmod.c3
-rw-r--r--io/chown.c2
-rw-r--r--io/close.c2
-rw-r--r--io/copy_file_range-compat.c160
-rw-r--r--io/copy_file_range.c (renamed from io/have_o_cloexec.c)11
-rw-r--r--io/creat.c2
-rw-r--r--io/creat64.c2
-rw-r--r--io/dup.c2
-rw-r--r--io/dup2.c2
-rw-r--r--io/dup3.c2
-rw-r--r--io/euidaccess.c2
-rw-r--r--io/faccessat.c2
-rw-r--r--io/fchdir.c2
-rw-r--r--io/fchmod.c2
-rw-r--r--io/fchmodat.c2
-rw-r--r--io/fchown.c2
-rw-r--r--io/fchownat.c2
-rw-r--r--io/fcntl.c2
-rw-r--r--io/fcntl.h24
-rw-r--r--io/fcntl64.c38
-rw-r--r--io/flock.c2
-rw-r--r--io/fstat.c2
-rw-r--r--io/fstat64.c2
-rw-r--r--io/fstatat.c2
-rw-r--r--io/fstatat64.c2
-rw-r--r--io/fstatfs.c2
-rw-r--r--io/fstatfs64.c2
-rw-r--r--io/fstatvfs.c2
-rw-r--r--io/fstatvfs64.c2
-rw-r--r--io/fts.c33
-rw-r--r--io/fts.h24
-rw-r--r--io/fts64.c2
-rw-r--r--io/ftw.c23
-rw-r--r--io/ftw.h2
-rw-r--r--io/ftw64.c2
-rw-r--r--io/ftwtest-sh2
-rw-r--r--io/futimens.c4
-rw-r--r--io/fxstat.c2
-rw-r--r--io/fxstat64.c2
-rw-r--r--io/fxstatat.c2
-rw-r--r--io/fxstatat64.c2
-rw-r--r--io/getcwd.c2
-rw-r--r--io/getdirname.c2
-rw-r--r--io/getwd.c2
-rw-r--r--io/isatty.c2
-rw-r--r--io/lchmod.c2
-rw-r--r--io/lchown.c2
-rw-r--r--io/link.c2
-rw-r--r--io/linkat.c2
-rw-r--r--io/lockf.c2
-rw-r--r--io/lockf64.c2
-rw-r--r--io/lseek.c2
-rw-r--r--io/lseek64.c2
-rw-r--r--io/lstat.c2
-rw-r--r--io/lstat64.c2
-rw-r--r--io/lxstat.c2
-rw-r--r--io/lxstat64.c2
-rw-r--r--io/mkdir.c3
-rw-r--r--io/mkdirat.c2
-rw-r--r--io/mkfifo.c2
-rw-r--r--io/mkfifoat.c2
-rw-r--r--io/mknod.c2
-rw-r--r--io/mknodat.c2
-rw-r--r--io/open.c2
-rw-r--r--io/open64.c2
-rw-r--r--io/open64_2.c2
-rw-r--r--io/open_2.c2
-rw-r--r--io/openat.c3
-rw-r--r--io/openat64.c3
-rw-r--r--io/openat64_2.c2
-rw-r--r--io/openat_2.c2
-rw-r--r--io/pipe.c2
-rw-r--r--io/pipe2.c2
-rw-r--r--io/poll.c2
-rw-r--r--io/posix_fadvise.c2
-rw-r--r--io/posix_fadvise64.c2
-rw-r--r--io/posix_fallocate.c2
-rw-r--r--io/posix_fallocate64.c2
-rw-r--r--io/ppoll.c2
-rw-r--r--io/pwd.c2
-rw-r--r--io/read.c3
-rw-r--r--io/readlink.c2
-rw-r--r--io/readlinkat.c2
-rw-r--r--io/rmdir.c2
-rw-r--r--io/sendfile.c2
-rw-r--r--io/sendfile64.c2
-rw-r--r--io/stat.c2
-rw-r--r--io/stat64.c2
-rw-r--r--io/statfs.c2
-rw-r--r--io/statfs64.c2
-rw-r--r--io/statvfs.c2
-rw-r--r--io/statvfs64.c2
-rw-r--r--io/statx.c29
-rw-r--r--io/statx_generic.c81
-rw-r--r--io/symlink.c2
-rw-r--r--io/symlinkat.c2
-rw-r--r--io/sys/poll.h9
-rw-r--r--io/sys/sendfile.h2
-rw-r--r--io/sys/stat.h25
-rw-r--r--io/sys/statfs.h2
-rw-r--r--io/sys/statvfs.h2
-rw-r--r--io/test-lfs.c25
-rw-r--r--io/test-stat.c2
-rw-r--r--io/test-stat2.c2
-rw-r--r--io/test-utime.c15
-rw-r--r--io/tst-copy_file_range-compat.c30
-rw-r--r--io/tst-copy_file_range.c835
-rw-r--r--io/tst-faccessat.c1
-rw-r--r--io/tst-fchmodat.c1
-rw-r--r--io/tst-fchownat.c1
-rw-r--r--io/tst-fcntl.c4
-rw-r--r--io/tst-fstatat.c1
-rw-r--r--io/tst-fts.c2
-rw-r--r--io/tst-futimesat.c1
-rw-r--r--io/tst-getcwd-abspath.c66
-rw-r--r--io/tst-getcwd.c2
-rw-r--r--io/tst-linkat.c1
-rw-r--r--io/tst-mkdirat.c4
-rw-r--r--io/tst-mkfifoat.c4
-rw-r--r--io/tst-mknodat.c4
-rw-r--r--io/tst-open-tmpfile.c318
-rw-r--r--io/tst-openat.c1
-rw-r--r--io/tst-posix_fallocate-common.c85
-rw-r--r--io/tst-posix_fallocate.c107
-rw-r--r--io/tst-posix_fallocate64.c44
-rw-r--r--io/tst-readlinkat.c1
-rw-r--r--io/tst-renameat.c1
-rw-r--r--io/tst-statx.c157
-rw-r--r--io/tst-symlinkat.c1
-rw-r--r--io/tst-unlinkat.c1
-rw-r--r--io/ttyname.c2
-rw-r--r--io/ttyname_r.c2
-rw-r--r--io/umask.c2
-rw-r--r--io/unlink.c2
-rw-r--r--io/unlinkat.c2
-rw-r--r--io/utime.c3
-rw-r--r--io/utime.h5
-rw-r--r--io/utimensat.c2
-rw-r--r--io/write.c3
-rw-r--r--io/xmknod.c2
-rw-r--r--io/xmknodat.c2
-rw-r--r--io/xstat.c2
-rw-r--r--io/xstat64.c2
153 files changed, 2260 insertions, 333 deletions
diff --git a/io/Makefile b/io/Makefile
index deb6100156..ec5c6d7a2f 100644
--- a/io/Makefile
+++ b/io/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1992-2016 Free Software Foundation, Inc.
+# Copyright (C) 1992-2018 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
@@ -25,13 +25,13 @@ include ../Makeconfig
headers := sys/stat.h bits/stat.h sys/statfs.h bits/statfs.h sys/vfs.h \
sys/statvfs.h bits/statvfs.h fcntl.h sys/fcntl.h bits/fcntl.h \
poll.h sys/poll.h bits/poll.h bits/fcntl2.h bits/poll2.h \
- utime.h ftw.h fts.h sys/sendfile.h
+ bits/statx.h utime.h ftw.h fts.h sys/sendfile.h
routines := \
utime \
mkfifo mkfifoat \
stat fstat lstat stat64 fstat64 lstat64 fstatat fstatat64 \
- xstat fxstat lxstat xstat64 fxstat64 lxstat64 \
+ xstat fxstat lxstat xstat64 fxstat64 lxstat64 statx \
mknod mknodat xmknod xmknodat \
fxstatat fxstatat64 \
statfs fstatfs statfs64 fstatfs64 \
@@ -40,7 +40,7 @@ routines := \
mkdir mkdirat \
open open_2 open64 open64_2 openat openat_2 openat64 openat64_2 \
read write lseek lseek64 access euidaccess faccessat \
- fcntl flock lockf lockf64 \
+ fcntl fcntl64 flock lockf lockf64 \
close dup dup2 dup3 pipe pipe2 \
creat creat64 \
chdir fchdir \
@@ -52,11 +52,9 @@ routines := \
ftw ftw64 fts fts64 poll ppoll \
posix_fadvise posix_fadvise64 \
posix_fallocate posix_fallocate64 \
- sendfile sendfile64 \
+ sendfile sendfile64 copy_file_range \
utimensat futimens
-aux := have_o_cloexec
-
# These routines will be omitted from the libc shared object.
# Instead the static object files will be included in a special archive
# linked against when the shared library will be used.
@@ -71,7 +69,17 @@ tests := test-utime test-stat test-stat2 test-lfs tst-getcwd \
tst-renameat tst-fchownat tst-fchmodat tst-faccessat \
tst-symlinkat tst-linkat tst-readlinkat tst-mkdirat \
tst-mknodat tst-mkfifoat tst-ttyname_r bug-ftw5 \
- tst-posix_fallocate tst-fts tst-fts-lfs
+ tst-posix_fallocate tst-posix_fallocate64 \
+ tst-fts tst-fts-lfs tst-open-tmpfile \
+ tst-copy_file_range tst-getcwd-abspath \
+
+# This test includes the compat implementation of copy_file_range,
+# which uses internal, unexported libc functions.
+tests-static += tst-copy_file_range-compat
+tests-internal += tst-copy_file_range-compat
+
+# Likewise for statx, but we do not need static linking here.
+tests-internal += tst-statx
ifeq ($(run-built-tests),yes)
tests-special += $(objpfx)ftwtest.out
@@ -79,34 +87,40 @@ endif
include ../Rules
-CFLAGS-open.c = -fexceptions -fasynchronous-unwind-tables
-CFLAGS-open64.c = -fexceptions -fasynchronous-unwind-tables
-CFLAGS-fcntl.c = -fexceptions -fasynchronous-unwind-tables
-CFLAGS-poll.c = -fexceptions -fasynchronous-unwind-tables
-CFLAGS-ppoll.c = -fexceptions -fasynchronous-unwind-tables
-CFLAGS-lockf.c = -fexceptions
-CFLAGS-statfs.c = -fexceptions
-CFLAGS-fstatfs.c = -fexceptions
-CFLAGS-statvfs.c = -fexceptions
-CFLAGS-fstatvfs.c = -fexceptions
-CFLAGS-fts.c = -Wno-uninitialized $(uses-callbacks) -fexceptions
-CFLAGS-fts64.c = -Wno-uninitialized $(uses-callbacks) -fexceptions
-CFLAGS-ftw.c = $(uses-callbacks) -fexceptions
-CFLAGS-ftw64.c = $(uses-callbacks) -fexceptions
-CFLAGS-lockf.c = -fexceptions
-CFLAGS-posix_fallocate.c = -fexceptions
-CFLAGS-posix_fallocate64.c = -fexceptions
-CFLAGS-fallocate.c = -fexceptions
-CFLAGS-fallocate64.c = -fexceptions
-CFLAGS-sync_file_range.c = -fexceptions
-
-CFLAGS-test-stat.c = -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
-CFLAGS-test-lfs.c = -D_LARGEFILE64_SOURCE
+CFLAGS-open.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-open64.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-creat.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-creat64.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-fcntl.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-fcntl64.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-poll.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-ppoll.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-lockf.c += -fexceptions
+CFLAGS-statfs.c += -fexceptions
+CFLAGS-fstatfs.c += -fexceptions
+CFLAGS-statvfs.c += -fexceptions
+CFLAGS-fstatvfs.c += -fexceptions
+CFLAGS-fts.c += -Wno-uninitialized $(uses-callbacks) -fexceptions
+CFLAGS-fts64.c += -Wno-uninitialized $(uses-callbacks) -fexceptions
+CFLAGS-ftw.c += $(uses-callbacks) -fexceptions
+CFLAGS-ftw64.c += $(uses-callbacks) -fexceptions
+CFLAGS-lockf.c += -fexceptions
+CFLAGS-posix_fallocate.c += -fexceptions
+CFLAGS-posix_fallocate64.c += -fexceptions
+CFLAGS-fallocate.c += -fexceptions
+CFLAGS-fallocate64.c += -fexceptions
+CFLAGS-read.c += -fexceptions
+CFLAGS-write.c += -fexceptions
+
+CFLAGS-test-stat.c += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
+CFLAGS-test-lfs.c += -D_LARGEFILE64_SOURCE
test-stat2-ARGS = Makefile . $(objpfx)test-stat2
tst-statvfs-ARGS = $(objpfx)tst-statvfs tst-statvfs.c /tmp
+tst-open-tmpfile-ARGS = --test-dir=$(objpfx)
+
ifeq ($(run-built-tests),yes)
$(objpfx)ftwtest.out: ftwtest-sh $(objpfx)ftwtest
$(SHELL) $< $(common-objpfx) '$(test-program-cmd)' > $@; \
diff --git a/io/Versions b/io/Versions
index 64316cd025..f7e5dbe49e 100644
--- a/io/Versions
+++ b/io/Versions
@@ -125,4 +125,17 @@ libc {
GLIBC_2.23 {
fts64_children; fts64_close; fts64_open; fts64_read; fts64_set;
}
+ GLIBC_2.27 {
+ copy_file_range;
+ }
+ GLIBC_2.28 {
+ fcntl64;
+ statx;
+ }
+ GLIBC_PRIVATE {
+ __libc_fcntl64;
+ __fcntl_nocancel;
+ __open64_nocancel;
+ __write_nocancel;
+ }
}
diff --git a/io/access.c b/io/access.c
index 45347048af..7130264ed7 100644
--- a/io/access.c
+++ b/io/access.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
@@ -19,6 +19,13 @@
#include <stddef.h>
#include <unistd.h>
+/* Test for access to FILE without setting errno. */
+int
+__access_noerrno (const char *file, int type)
+{
+ return -1;
+}
+
/* Test for access to FILE. */
int
__access (const char *file, int type)
diff --git a/io/bits/fcntl2.h b/io/bits/fcntl2.h
index c3f267e422..38a18b27a1 100644
--- a/io/bits/fcntl2.h
+++ b/io/bits/fcntl2.h
@@ -1,5 +1,5 @@
/* Checking macros for fcntl functions.
- Copyright (C) 2007-2016 Free Software Foundation, Inc.
+ Copyright (C) 2007-2018 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
diff --git a/io/bits/poll2.h b/io/bits/poll2.h
index 137bfaf65f..7e8406b87d 100644
--- a/io/bits/poll2.h
+++ b/io/bits/poll2.h
@@ -1,5 +1,5 @@
/* Checking macros for poll functions.
- Copyright (C) 2012-2016 Free Software Foundation, Inc.
+ Copyright (C) 2012-2018 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
diff --git a/io/bits/statx.h b/io/bits/statx.h
new file mode 100644
index 0000000000..e31254e361
--- /dev/null
+++ b/io/bits/statx.h
@@ -0,0 +1,91 @@
+/* statx-related definitions and declarations.
+ Copyright (C) 2018 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
+ <http://www.gnu.org/licenses/>. */
+
+/* This interface is based on <linux/stat.h> in Linux. */
+
+#ifndef _SYS_STAT_H
+# error Never include <bits/stat.x.h> directly, include <sys/stat.h> instead.
+#endif
+
+struct statx_timestamp
+{
+ __int64_t tv_sec;
+ __uint32_t tv_nsec;
+ __int32_t __statx_timestamp_pad1[1];
+};
+
+/* Warning: The kernel may add additional fields to this struct in the
+ future. Only use this struct for calling the statx function, not
+ for storing data. (Expansion will be controlled by the mask
+ argument of the statx function.) */
+struct statx
+{
+ __uint32_t stx_mask;
+ __uint32_t stx_blksize;
+ __uint64_t stx_attributes;
+ __uint32_t stx_nlink;
+ __uint32_t stx_uid;
+ __uint32_t stx_gid;
+ __uint16_t stx_mode;
+ __uint16_t __statx_pad1[1];
+ __uint64_t stx_ino;
+ __uint64_t stx_size;
+ __uint64_t stx_blocks;
+ __uint64_t stx_attributes_mask;
+ struct statx_timestamp stx_atime;
+ struct statx_timestamp stx_btime;
+ struct statx_timestamp stx_ctime;
+ struct statx_timestamp stx_mtime;
+ __uint32_t stx_rdev_major;
+ __uint32_t stx_rdev_minor;
+ __uint32_t stx_dev_major;
+ __uint32_t stx_dev_minor;
+ __uint64_t __statx_pad2[14];
+};
+
+#define STATX_TYPE 0x0001U
+#define STATX_MODE 0x0002U
+#define STATX_NLINK 0x0004U
+#define STATX_UID 0x0008U
+#define STATX_GID 0x0010U
+#define STATX_ATIME 0x0020U
+#define STATX_MTIME 0x0040U
+#define STATX_CTIME 0x0080U
+#define STATX_INO 0x0100U
+#define STATX_SIZE 0x0200U
+#define STATX_BLOCKS 0x0400U
+#define STATX_BASIC_STATS 0x07ffU
+#define STATX_ALL 0x0fffU
+#define STATX_BTIME 0x0800U
+#define STATX__RESERVED 0x80000000U
+
+#define STATX_ATTR_COMPRESSED 0x0004
+#define STATX_ATTR_IMMUTABLE 0x0010
+#define STATX_ATTR_APPEND 0x0020
+#define STATX_ATTR_NODUMP 0x0040
+#define STATX_ATTR_ENCRYPTED 0x0800
+#define STATX_ATTR_AUTOMOUNT 0x1000
+
+__BEGIN_DECLS
+
+/* Fill *BUF with information about PATH in DIRFD. */
+int statx (int __dirfd, const char *__restrict __path, int __flags,
+ unsigned int __mask, struct statx *__restrict __buf)
+ __THROW __nonnull ((2, 5));
+
+__END_DECLS
diff --git a/io/bug-ftw1.c b/io/bug-ftw1.c
index 6efc4e7123..30a2b6bfc7 100644
--- a/io/bug-ftw1.c
+++ b/io/bug-ftw1.c
@@ -1,5 +1,5 @@
/* Test for ftw function searching in root directory.
- Copyright (C) 2001-2016 Free Software Foundation, Inc.
+ Copyright (C) 2001-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 2001.
diff --git a/io/bug-ftw2.c b/io/bug-ftw2.c
index 139b8ff214..f0911e914f 100644
--- a/io/bug-ftw2.c
+++ b/io/bug-ftw2.c
@@ -1,5 +1,5 @@
/* Test for ftw function searching in current directory.
- Copyright (C) 2001-2016 Free Software Foundation, Inc.
+ Copyright (C) 2001-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 2001.
diff --git a/io/bug-ftw4.c b/io/bug-ftw4.c
index c4b72acdd3..db8d1ecd3d 100644
--- a/io/bug-ftw4.c
+++ b/io/bug-ftw4.c
@@ -1,5 +1,5 @@
/* Test if ftw function doesn't leak fds.
- Copyright (C) 2003-2016 Free Software Foundation, Inc.
+ Copyright (C) 2003-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
diff --git a/io/chdir.c b/io/chdir.c
index 16784cbabe..d30499207d 100644
--- a/io/chdir.c
+++ b/io/chdir.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/chmod.c b/io/chmod.c
index cbb3c674e9..407a80c219 100644
--- a/io/chmod.c
+++ b/io/chmod.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
@@ -35,4 +35,5 @@ __chmod (const char *file, mode_t mode)
}
stub_warning (chmod)
+libc_hidden_def (__chmod)
weak_alias (__chmod, chmod)
diff --git a/io/chown.c b/io/chown.c
index 06124c4fbd..655d7eaced 100644
--- a/io/chown.c
+++ b/io/chown.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/close.c b/io/close.c
index ccbe862e49..3f9dbdb9c3 100644
--- a/io/close.c
+++ b/io/close.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/copy_file_range-compat.c b/io/copy_file_range-compat.c
new file mode 100644
index 0000000000..4ab22cad19
--- /dev/null
+++ b/io/copy_file_range-compat.c
@@ -0,0 +1,160 @@
+/* Emulation of copy_file_range.
+ Copyright (C) 2017-2018 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
+ <http://www.gnu.org/licenses/>. */
+
+/* The following macros should be defined before including this
+ file:
+
+ COPY_FILE_RANGE_DECL Declaration specifiers for the function below.
+ COPY_FILE_RANGE Name of the function to define. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+COPY_FILE_RANGE_DECL
+ssize_t
+COPY_FILE_RANGE (int infd, __off64_t *pinoff,
+ int outfd, __off64_t *poutoff,
+ size_t length, unsigned int flags)
+{
+ if (flags != 0)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ {
+ struct stat64 instat;
+ struct stat64 outstat;
+ if (fstat64 (infd, &instat) != 0 || fstat64 (outfd, &outstat) != 0)
+ return -1;
+ if (S_ISDIR (instat.st_mode) || S_ISDIR (outstat.st_mode))
+ {
+ __set_errno (EISDIR);
+ return -1;
+ }
+ if (!S_ISREG (instat.st_mode) || !S_ISREG (outstat.st_mode))
+ {
+ /* We need a regular input file so that the we can seek
+ backwards in case of a write failure. */
+ __set_errno (EINVAL);
+ return -1;
+ }
+ if (instat.st_dev != outstat.st_dev)
+ {
+ /* Cross-device copies are not supported. */
+ __set_errno (EXDEV);
+ return -1;
+ }
+ }
+
+ /* The output descriptor must not have O_APPEND set. */
+ {
+ int flags = __fcntl (outfd, F_GETFL);
+ if (flags & O_APPEND)
+ {
+ __set_errno (EBADF);
+ return -1;
+ }
+ }
+
+ /* Avoid an overflow in the result. */
+ if (length > SSIZE_MAX)
+ length = SSIZE_MAX;
+
+ /* Main copying loop. The buffer size is arbitrary and is a
+ trade-off between stack size consumption, cache usage, and
+ amortization of system call overhead. */
+ size_t copied = 0;
+ char buf[8192];
+ while (length > 0)
+ {
+ size_t to_read = length;
+ if (to_read > sizeof (buf))
+ to_read = sizeof (buf);
+
+ /* Fill the buffer. */
+ ssize_t read_count;
+ if (pinoff == NULL)
+ read_count = read (infd, buf, to_read);
+ else
+ read_count = __libc_pread64 (infd, buf, to_read, *pinoff);
+ if (read_count == 0)
+ /* End of file reached prematurely. */
+ return copied;
+ if (read_count < 0)
+ {
+ if (copied > 0)
+ /* Report the number of bytes copied so far. */
+ return copied;
+ return -1;
+ }
+ if (pinoff != NULL)
+ *pinoff += read_count;
+
+ /* Write the buffer part which was read to the destination. */
+ char *end = buf + read_count;
+ for (char *p = buf; p < end; )
+ {
+ ssize_t write_count;
+ if (poutoff == NULL)
+ write_count = write (outfd, p, end - p);
+ else
+ write_count = __libc_pwrite64 (outfd, p, end - p, *poutoff);
+ if (write_count < 0)
+ {
+ /* Adjust the input read position to match what we have
+ written, so that the caller can pick up after the
+ error. */
+ size_t written = p - buf;
+ /* NB: This needs to be signed so that we can form the
+ negative value below. */
+ ssize_t overread = read_count - written;
+ if (pinoff == NULL)
+ {
+ if (overread > 0)
+ {
+ /* We are on an error recovery path, so we
+ cannot deal with failure here. */
+ int save_errno = errno;
+ (void) __libc_lseek64 (infd, -overread, SEEK_CUR);
+ __set_errno (save_errno);
+ }
+ }
+ else /* pinoff != NULL */
+ *pinoff -= overread;
+
+ if (copied + written > 0)
+ /* Report the number of bytes copied so far. */
+ return copied + written;
+ return -1;
+ }
+ p += write_count;
+ if (poutoff != NULL)
+ *poutoff += write_count;
+ } /* Write loop. */
+
+ copied += read_count;
+ length -= read_count;
+ }
+ return copied;
+}
diff --git a/io/have_o_cloexec.c b/io/copy_file_range.c
index 30f79ac40c..98bff8bd26 100644
--- a/io/have_o_cloexec.c
+++ b/io/copy_file_range.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 2007-2016 Free Software Foundation, Inc.
+/* Generic implementation of copy_file_range.
+ Copyright (C) 2017-2018 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
@@ -15,9 +16,7 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
-#include <fcntl.h>
-#include <kernel-features.h>
+#define COPY_FILE_RANGE_DECL
+#define COPY_FILE_RANGE copy_file_range
-#if defined O_CLOEXEC && !defined __ASSUME_O_CLOEXEC
-int __have_o_cloexec;
-#endif
+#include <io/copy_file_range-compat.c>
diff --git a/io/creat.c b/io/creat.c
index caacb69a9b..21ee56ebc9 100644
--- a/io/creat.c
+++ b/io/creat.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/creat64.c b/io/creat64.c
index 7be7903b95..f515b654ae 100644
--- a/io/creat64.c
+++ b/io/creat64.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/dup.c b/io/dup.c
index 02969c0568..77f40b0256 100644
--- a/io/dup.c
+++ b/io/dup.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/dup2.c b/io/dup2.c
index d16ba54ce5..a3a99e7dcf 100644
--- a/io/dup2.c
+++ b/io/dup2.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/dup3.c b/io/dup3.c
index 6b733a8bed..590ec0150d 100644
--- a/io/dup3.c
+++ b/io/dup3.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2008-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2008-2018 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
diff --git a/io/euidaccess.c b/io/euidaccess.c
index c8d25e78be..7138b22575 100644
--- a/io/euidaccess.c
+++ b/io/euidaccess.c
@@ -1,5 +1,5 @@
/* Test for access to FILE using effective UID and GID. Stub version.
- Copyright (C) 1991-2016 Free Software Foundation, Inc.
+ Copyright (C) 1991-2018 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
diff --git a/io/faccessat.c b/io/faccessat.c
index e4c2e84eb7..e307b1360f 100644
--- a/io/faccessat.c
+++ b/io/faccessat.c
@@ -1,5 +1,5 @@
/* Test for access to file, relative to open directory. Stub version.
- Copyright (C) 2006-2016 Free Software Foundation, Inc.
+ Copyright (C) 2006-2018 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
diff --git a/io/fchdir.c b/io/fchdir.c
index 31d9ae72ab..4726e1b154 100644
--- a/io/fchdir.c
+++ b/io/fchdir.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/fchmod.c b/io/fchmod.c
index c00d83fbc4..75bf5b7b97 100644
--- a/io/fchmod.c
+++ b/io/fchmod.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/fchmodat.c b/io/fchmodat.c
index 1b90899403..271d415409 100644
--- a/io/fchmodat.c
+++ b/io/fchmodat.c
@@ -1,5 +1,5 @@
/* Change the protections of file relative to open directory. Stub version.
- Copyright (C) 2006-2016 Free Software Foundation, Inc.
+ Copyright (C) 2006-2018 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
diff --git a/io/fchown.c b/io/fchown.c
index 6d326ad246..f6ae6d0123 100644
--- a/io/fchown.c
+++ b/io/fchown.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/fchownat.c b/io/fchownat.c
index 1d49dcaf55..4cd03b813b 100644
--- a/io/fchownat.c
+++ b/io/fchownat.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2005-2018 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
diff --git a/io/fcntl.c b/io/fcntl.c
index e540942c69..d8a01a7d52 100644
--- a/io/fcntl.c
+++ b/io/fcntl.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/fcntl.h b/io/fcntl.h
index 1a92a8d738..6b0e9fa1fa 100644
--- a/io/fcntl.h
+++ b/io/fcntl.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
@@ -71,9 +71,10 @@ typedef __pid_t pid_t;
#endif
/* For XPG all symbols from <sys/stat.h> should also be available. */
+#ifdef __USE_XOPEN2K8
+# include <bits/types/struct_timespec.h>
+#endif
#if defined __USE_XOPEN || defined __USE_XOPEN2K8
-# define __need_timespec
-# include <time.h>
# include <bits/stat.h>
# define S_IFMT __S_IFMT
@@ -138,7 +139,7 @@ typedef __pid_t pid_t;
# define SEEK_END 2 /* Seek from end of file. */
#endif /* XPG */
-/* The constants AT_REMOVEDIR and AT_EACCESS have the same value. AT_EASSESS
+/* The constants AT_REMOVEDIR and AT_EACCESS have the same value. AT_EACCESS
is meaningful only to faccessat, while AT_REMOVEDIR is meaningful only to
unlinkat. The two functions do completely different things and therefore,
the flags can be allowed to overlap. For example, passing AT_REMOVEDIR to
@@ -156,6 +157,10 @@ typedef __pid_t pid_t;
# define AT_NO_AUTOMOUNT 0x800 /* Suppress terminal automount
traversal. */
# define AT_EMPTY_PATH 0x1000 /* Allow empty relative pathname. */
+# define AT_STATX_SYNC_TYPE 0x6000
+# define AT_STATX_SYNC_AS_STAT 0x0000
+# define AT_STATX_FORCE_SYNC 0x2000
+# define AT_STATX_DONT_SYNC 0x4000
# endif
# define AT_EACCESS 0x200 /* Test access permitted for
effective IDs, not real IDs. */
@@ -166,7 +171,18 @@ typedef __pid_t pid_t;
This function is a cancellation point and therefore not marked with
__THROW. */
+#ifndef __USE_FILE_OFFSET64
extern int fcntl (int __fd, int __cmd, ...);
+#else
+# ifdef __REDIRECT
+extern int __REDIRECT (fcntl, (int __fd, int __cmd, ...), fcntl64);
+# else
+# define fcntl fcntl64
+# endif
+#endif
+#ifdef __USE_LARGEFILE64
+extern int fcntl64 (int __fd, int __cmd, ...);
+#endif
/* Open FILE and return a new file descriptor for it, or -1 on error.
OFLAG determines the type of access used. If O_CREAT or O_TMPFILE is set
diff --git a/io/fcntl64.c b/io/fcntl64.c
new file mode 100644
index 0000000000..f4e6809abc
--- /dev/null
+++ b/io/fcntl64.c
@@ -0,0 +1,38 @@
+/* Manipulate file descriptor. Stub LFS version.
+ Copyright (C) 2018 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <fcntl.h>
+
+/* Perform file control operations on FD. */
+int
+__fcntl64 (int fd, int cmd, ...)
+{
+ if (fd < 0)
+ {
+ __set_errno (EBADF);
+ return -1;
+ }
+
+ __set_errno (ENOSYS);
+ return -1;
+}
+libc_hidden_def (__fcntl64)
+stub_warning (fcntl64)
+
+weak_alias (__fcntl64, fcntl64)
diff --git a/io/flock.c b/io/flock.c
index 0f6d8e04be..8e578d54ab 100644
--- a/io/flock.c
+++ b/io/flock.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1992-2018 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
diff --git a/io/fstat.c b/io/fstat.c
index 50f2a4fbfc..1cb59f3a59 100644
--- a/io/fstat.c
+++ b/io/fstat.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2018 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
diff --git a/io/fstat64.c b/io/fstat64.c
index 4ede2540ec..0f4de02cee 100644
--- a/io/fstat64.c
+++ b/io/fstat64.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2018 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
diff --git a/io/fstatat.c b/io/fstatat.c
index 9d8b370169..3a7ba20076 100644
--- a/io/fstatat.c
+++ b/io/fstatat.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2005-2018 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
diff --git a/io/fstatat64.c b/io/fstatat64.c
index dcdccf87af..f4f46a9574 100644
--- a/io/fstatat64.c
+++ b/io/fstatat64.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2005-2018 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
diff --git a/io/fstatfs.c b/io/fstatfs.c
index efd1fb2321..a1c7c5a0d1 100644
--- a/io/fstatfs.c
+++ b/io/fstatfs.c
@@ -1,5 +1,5 @@
/* Return information about the filesystem on which FD resides.
- Copyright (C) 1996-2016 Free Software Foundation, Inc.
+ Copyright (C) 1996-2018 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
diff --git a/io/fstatfs64.c b/io/fstatfs64.c
index e00b992da2..3f4d889368 100644
--- a/io/fstatfs64.c
+++ b/io/fstatfs64.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1998-2018 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
diff --git a/io/fstatvfs.c b/io/fstatvfs.c
index 4e7333d96c..26b4a5086e 100644
--- a/io/fstatvfs.c
+++ b/io/fstatvfs.c
@@ -1,5 +1,5 @@
/* Return information about the filesystem on which FD resides.
- Copyright (C) 1996-2016 Free Software Foundation, Inc.
+ Copyright (C) 1996-2018 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
diff --git a/io/fstatvfs64.c b/io/fstatvfs64.c
index db947292cb..f44f18a615 100644
--- a/io/fstatvfs64.c
+++ b/io/fstatvfs64.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1998-2018 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
diff --git a/io/fts.c b/io/fts.c
index 0c5abfcdd6..ad9d333f45 100644
--- a/io/fts.c
+++ b/io/fts.c
@@ -1,5 +1,5 @@
/* File tree traversal functions.
- Copyright (C) 1994-2016 Free Software Foundation, Inc.
+ Copyright (C) 1994-2018 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
@@ -85,17 +85,16 @@ static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94";
# define LSTAT lstat
#endif
-static FTSENTRY *fts_alloc (FTSOBJ *, const char *, size_t) internal_function;
-static FTSENTRY *fts_build (FTSOBJ *, int) internal_function;
-static void fts_lfree (FTSENTRY *) internal_function;
-static void fts_load (FTSOBJ *, FTSENTRY *) internal_function;
-static size_t fts_maxarglen (char * const *) internal_function;
-static void fts_padjust (FTSOBJ *, FTSENTRY *) internal_function;
-static int fts_palloc (FTSOBJ *, size_t) internal_function;
-static FTSENTRY *fts_sort (FTSOBJ *, FTSENTRY *, int) internal_function;
-static u_short fts_stat (FTSOBJ *, FTSENTRY *, int) internal_function;
-static int fts_safe_changedir (FTSOBJ *, FTSENTRY *, int, const char *)
- internal_function;
+static FTSENTRY *fts_alloc (FTSOBJ *, const char *, size_t);
+static FTSENTRY *fts_build (FTSOBJ *, int);
+static void fts_lfree (FTSENTRY *);
+static void fts_load (FTSOBJ *, FTSENTRY *);
+static size_t fts_maxarglen (char * const *);
+static void fts_padjust (FTSOBJ *, FTSENTRY *);
+static int fts_palloc (FTSOBJ *, size_t);
+static FTSENTRY *fts_sort (FTSOBJ *, FTSENTRY *, int);
+static u_short fts_stat (FTSOBJ *, FTSENTRY *, int);
+static int fts_safe_changedir (FTSOBJ *, FTSENTRY *, int, const char *);
#ifndef MAX
#define MAX(a, b) ({ __typeof__ (a) _a = (a); \
@@ -231,7 +230,6 @@ mem1: free(sp);
}
static void
-internal_function
fts_load (FTSOBJ *sp, FTSENTRY *p)
{
int len;
@@ -607,7 +605,6 @@ dirent_not_directory(const struct dirent *dp)
* been found, cutting the stat calls by about 2/3.
*/
static FTSENTRY *
-internal_function
fts_build (FTSOBJ *sp, int type)
{
struct dirent *dp;
@@ -870,7 +867,6 @@ mem1: saved_errno = errno;
}
static u_short
-internal_function
fts_stat (FTSOBJ *sp, FTSENTRY *p, int follow)
{
FTSENTRY *t;
@@ -951,7 +947,6 @@ err: memset(sbp, 0, sizeof(struct STAT));
}
static FTSENTRY *
-internal_function
fts_sort (FTSOBJ *sp, FTSENTRY *head, int nitems)
{
FTSENTRY **ap, *p;
@@ -986,7 +981,6 @@ fts_sort (FTSOBJ *sp, FTSENTRY *head, int nitems)
}
static FTSENTRY *
-internal_function
fts_alloc (FTSOBJ *sp, const char *name, size_t namelen)
{
FTSENTRY *p;
@@ -1023,7 +1017,6 @@ fts_alloc (FTSOBJ *sp, const char *name, size_t namelen)
}
static void
-internal_function
fts_lfree (FTSENTRY *head)
{
FTSENTRY *p;
@@ -1042,7 +1035,6 @@ fts_lfree (FTSENTRY *head)
* plus 256 bytes so don't realloc the path 2 bytes at a time.
*/
static int
-internal_function
fts_palloc (FTSOBJ *sp, size_t more)
{
char *p;
@@ -1074,7 +1066,6 @@ fts_palloc (FTSOBJ *sp, size_t more)
* already returned.
*/
static void
-internal_function
fts_padjust (FTSOBJ *sp, FTSENTRY *head)
{
FTSENTRY *p;
@@ -1099,7 +1090,6 @@ fts_padjust (FTSOBJ *sp, FTSENTRY *head)
}
static size_t
-internal_function
fts_maxarglen (char * const *argv)
{
size_t len, max;
@@ -1116,7 +1106,6 @@ fts_maxarglen (char * const *argv)
* Assumes p->fts_dev and p->fts_ino are filled in.
*/
static int
-internal_function
fts_safe_changedir (FTSOBJ *sp, FTSENTRY *p, int fd, const char *path)
{
int ret, oerrno, newfd;
diff --git a/io/fts.h b/io/fts.h
index 127a0d2721..71dc53958b 100644
--- a/io/fts.h
+++ b/io/fts.h
@@ -1,5 +1,5 @@
/* File tree traversal functions declarations.
- Copyright (C) 1994-2016 Free Software Foundation, Inc.
+ Copyright (C) 1994-2018 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
@@ -105,8 +105,8 @@ typedef struct _ftsent {
char *fts_path; /* root path */
int fts_errno; /* errno for this node */
int fts_symfd; /* fd for symlink */
- u_short fts_pathlen; /* strlen(fts_path) */
- u_short fts_namelen; /* strlen(fts_name) */
+ unsigned short fts_pathlen; /* strlen(fts_path) */
+ unsigned short fts_namelen; /* strlen(fts_name) */
ino_t fts_ino; /* inode */
dev_t fts_dev; /* device */
@@ -130,17 +130,17 @@ typedef struct _ftsent {
#define FTS_SL 12 /* symbolic link */
#define FTS_SLNONE 13 /* symbolic link without target */
#define FTS_W 14 /* whiteout object */
- u_short fts_info; /* user flags for FTSENT structure */
+ unsigned short fts_info; /* user flags for FTSENT structure */
#define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */
#define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */
- u_short fts_flags; /* private flags for FTSENT structure */
+ unsigned short fts_flags; /* private flags for FTSENT structure */
#define FTS_AGAIN 1 /* read node again */
#define FTS_FOLLOW 2 /* follow symbolic link */
#define FTS_NOINSTR 3 /* no instructions */
#define FTS_SKIP 4 /* discard node */
- u_short fts_instr; /* fts_set() instructions */
+ unsigned short fts_instr; /* fts_set() instructions */
struct stat *fts_statp; /* stat(2) information */
char fts_name[1]; /* file name */
@@ -157,8 +157,8 @@ typedef struct _ftsent64 {
char *fts_path; /* root path */
int fts_errno; /* errno for this node */
int fts_symfd; /* fd for symlink */
- u_short fts_pathlen; /* strlen(fts_path) */
- u_short fts_namelen; /* strlen(fts_name) */
+ unsigned short fts_pathlen; /* strlen(fts_path) */
+ unsigned short fts_namelen; /* strlen(fts_name) */
ino64_t fts_ino; /* inode */
dev_t fts_dev; /* device */
@@ -166,11 +166,11 @@ typedef struct _ftsent64 {
short fts_level; /* depth (-1 to N) */
- u_short fts_info; /* user flags for FTSENT structure */
+ unsigned short fts_info; /* user flags for FTSENT structure */
- u_short fts_flags; /* private flags for FTSENT structure */
+ unsigned short fts_flags; /* private flags for FTSENT structure */
- u_short fts_instr; /* fts_set() instructions */
+ unsigned short fts_instr; /* fts_set() instructions */
struct stat64 *fts_statp; /* stat(2) information */
char fts_name[1]; /* file name */
@@ -193,7 +193,7 @@ FTS *__REDIRECT (fts_open, (char * const *, int,
int (*)(const FTSENT **, const FTSENT **)),
fts64_open);
FTSENT *__REDIRECT (fts_read, (FTS *), fts64_read);
-int __REDIRECT (fts_set, (FTS *, FTSENT *, int), fts64_set) __THROW;
+int __REDIRECT_NTH (fts_set, (FTS *, FTSENT *, int), fts64_set);
# else
# define fts_children fts64_children
# define fts_close fts64_close
diff --git a/io/fts64.c b/io/fts64.c
index 2ff19778aa..539110c1a0 100644
--- a/io/fts64.c
+++ b/io/fts64.c
@@ -1,5 +1,5 @@
/* File tree traversal functions LFS version.
- Copyright (C) 2015-2016 Free Software Foundation, Inc.
+ Copyright (C) 2015-2018 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
diff --git a/io/ftw.c b/io/ftw.c
index f2bd0a955e..f6ecbe7d90 100644
--- a/io/ftw.c
+++ b/io/ftw.c
@@ -1,5 +1,5 @@
/* File tree walker functions.
- Copyright (C) 1996-2016 Free Software Foundation, Inc.
+ Copyright (C) 1996-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
@@ -109,8 +109,6 @@ extern char *xgetcwd (void);
# define __tfind tfind
# undef __tsearch
# define __tsearch tsearch
-# undef internal_function
-# define internal_function /* empty */
# undef dirent64
# define dirent64 dirent
# undef MAX
@@ -222,7 +220,7 @@ static const int ftw_arr[] =
/* Forward declarations of local functions. */
static int ftw_dir (struct ftw_data *data, struct STAT *st,
- struct dir_data *old_dir) internal_function;
+ struct dir_data *old_dir);
static int
@@ -337,11 +335,11 @@ open_dir_stream (int *dfdp, struct ftw_data *data, struct dir_data *dirp)
if (dfdp != NULL && *dfdp != -1)
{
- int fd = openat64_not_cancel_3 (*dfdp, data->dirbuf + data->ftw.base,
- O_RDONLY | O_DIRECTORY | O_NDELAY);
+ int fd = __openat64_nocancel (*dfdp, data->dirbuf + data->ftw.base,
+ O_RDONLY | O_DIRECTORY | O_NDELAY);
dirp->stream = NULL;
if (fd != -1 && (dirp->stream = __fdopendir (fd)) == NULL)
- close_not_cancel_no_status (fd);
+ __close_nocancel_nostatus (fd);
}
else
{
@@ -363,7 +361,7 @@ open_dir_stream (int *dfdp, struct ftw_data *data, struct dir_data *dirp)
result = -1;
else
{
- dirp->streamfd = dirfd (dirp->stream);
+ dirp->streamfd = __dirfd (dirp->stream);
dirp->content = NULL;
data->dirstreams[data->actdir] = dirp;
@@ -377,7 +375,6 @@ open_dir_stream (int *dfdp, struct ftw_data *data, struct dir_data *dirp)
static int
-internal_function
process_entry (struct ftw_data *data, struct dir_data *dir, const char *name,
size_t namlen, int d_type)
{
@@ -477,7 +474,6 @@ process_entry (struct ftw_data *data, struct dir_data *dir, const char *name,
static int
__attribute ((noinline))
-internal_function
ftw_dir (struct ftw_data *data, struct STAT *st, struct dir_data *old_dir)
{
struct dir_data dir;
@@ -522,7 +518,7 @@ fail:
/* If necessary, change to this directory. */
if (data->flags & FTW_CHDIR)
{
- if (__fchdir (dirfd (dir.stream)) < 0)
+ if (__fchdir (__dirfd (dir.stream)) < 0)
{
result = -1;
goto fail;
@@ -606,7 +602,7 @@ fail:
/* Change back to the parent directory. */
int done = 0;
if (old_dir->stream != NULL)
- if (__fchdir (dirfd (old_dir->stream)) == 0)
+ if (__fchdir (__dirfd (old_dir->stream)) == 0)
done = 1;
if (!done)
@@ -628,7 +624,6 @@ fail:
static int
__attribute ((noinline))
-internal_function
ftw_startup (const char *dir, int is_nftw, void *func, int descriptors,
int flags)
{
@@ -791,7 +786,7 @@ ftw_startup (const char *dir, int is_nftw, void *func, int descriptors,
{
int save_err = errno;
__fchdir (cwdfd);
- close_not_cancel_no_status (cwdfd);
+ __close_nocancel_nostatus (cwdfd);
__set_errno (save_err);
}
else if (cwd != NULL)
diff --git a/io/ftw.h b/io/ftw.h
index fd4bc3664a..9679acb9bd 100644
--- a/io/ftw.h
+++ b/io/ftw.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1992-2018 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
diff --git a/io/ftw64.c b/io/ftw64.c
index 016c25862b..1f6bcdfff7 100644
--- a/io/ftw64.c
+++ b/io/ftw64.c
@@ -1,5 +1,5 @@
/* File tree walker functions. LFS version.
- Copyright (C) 1996-2016 Free Software Foundation, Inc.
+ Copyright (C) 1996-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
diff --git a/io/ftwtest-sh b/io/ftwtest-sh
index db8435ab5a..822d4903f6 100644
--- a/io/ftwtest-sh
+++ b/io/ftwtest-sh
@@ -1,6 +1,6 @@
#!/bin/sh
# Test for nftw(3).
-# Copyright (C) 1997-2016 Free Software Foundation, Inc.
+# Copyright (C) 1997-2018 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
diff --git a/io/futimens.c b/io/futimens.c
index 80465ac2df..fb170ffc3c 100644
--- a/io/futimens.c
+++ b/io/futimens.c
@@ -1,5 +1,5 @@
-/* Change access and modification times of open file. Linux version.
- Copyright (C) 2007-2016 Free Software Foundation, Inc.
+/* Change access and modification times of open file. Stub version.
+ Copyright (C) 2007-2018 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
diff --git a/io/fxstat.c b/io/fxstat.c
index 0e07d48a12..f7cb8f9dd2 100644
--- a/io/fxstat.c
+++ b/io/fxstat.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/fxstat64.c b/io/fxstat64.c
index 5e1632ced2..4d899a6990 100644
--- a/io/fxstat64.c
+++ b/io/fxstat64.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/fxstatat.c b/io/fxstatat.c
index 3d71896d81..7f793e1453 100644
--- a/io/fxstatat.c
+++ b/io/fxstatat.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2005-2018 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
diff --git a/io/fxstatat64.c b/io/fxstatat64.c
index ce36159195..41104a8ee0 100644
--- a/io/fxstatat64.c
+++ b/io/fxstatat64.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2005-2018 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
diff --git a/io/getcwd.c b/io/getcwd.c
index c402ca7484..e6b8b6e6e5 100644
--- a/io/getcwd.c
+++ b/io/getcwd.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/getdirname.c b/io/getdirname.c
index 2152623c1e..8456b3e085 100644
--- a/io/getdirname.c
+++ b/io/getdirname.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1992-2018 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
diff --git a/io/getwd.c b/io/getwd.c
index 090bda4362..e5c4dd32c6 100644
--- a/io/getwd.c
+++ b/io/getwd.c
@@ -1,5 +1,5 @@
/* Obsolete function to get current working directory.
- Copyright (C) 1991-2016 Free Software Foundation, Inc.
+ Copyright (C) 1991-2018 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
diff --git a/io/isatty.c b/io/isatty.c
index 3f8e3fd5cc..3d28276a1d 100644
--- a/io/isatty.c
+++ b/io/isatty.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/lchmod.c b/io/lchmod.c
index ea34e8a3c9..bdf3232b37 100644
--- a/io/lchmod.c
+++ b/io/lchmod.c
@@ -1,5 +1,5 @@
/* lchmod -- Change the protections of a file or symbolic link. Stub version.
- Copyright (C) 2002-2016 Free Software Foundation, Inc.
+ Copyright (C) 2002-2018 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
diff --git a/io/lchown.c b/io/lchown.c
index 3594900c3f..0b564702f7 100644
--- a/io/lchown.c
+++ b/io/lchown.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2018 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
diff --git a/io/link.c b/io/link.c
index b902d5cb72..82e2048cfb 100644
--- a/io/link.c
+++ b/io/link.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/linkat.c b/io/linkat.c
index 8db993d431..8d7b1267dd 100644
--- a/io/linkat.c
+++ b/io/linkat.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2005-2018 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
diff --git a/io/lockf.c b/io/lockf.c
index 0d3d19d020..68a799d54c 100644
--- a/io/lockf.c
+++ b/io/lockf.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1994-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1994-2018 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
diff --git a/io/lockf64.c b/io/lockf64.c
index 229e2619c0..334b8d3180 100644
--- a/io/lockf64.c
+++ b/io/lockf64.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1994-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1994-2018 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
diff --git a/io/lseek.c b/io/lseek.c
index 21948ecfbe..cb702c3e87 100644
--- a/io/lseek.c
+++ b/io/lseek.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/lseek64.c b/io/lseek64.c
index 1152bd0302..2c756ef36e 100644
--- a/io/lseek64.c
+++ b/io/lseek64.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/lstat.c b/io/lstat.c
index cfd94db512..c26688f48f 100644
--- a/io/lstat.c
+++ b/io/lstat.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2018 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
diff --git a/io/lstat64.c b/io/lstat64.c
index 64df63b86e..c3eb7a76f5 100644
--- a/io/lstat64.c
+++ b/io/lstat64.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2018 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
diff --git a/io/lxstat.c b/io/lxstat.c
index e08ba3cf6f..69f976c33e 100644
--- a/io/lxstat.c
+++ b/io/lxstat.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/lxstat64.c b/io/lxstat64.c
index cecf658c34..3298806e2e 100644
--- a/io/lxstat64.c
+++ b/io/lxstat64.c
@@ -1,5 +1,5 @@
/* lxstat64 -- get file metadata, not following symlinks. Stub version.
- Copyright (C) 1991-2016 Free Software Foundation, Inc.
+ Copyright (C) 1991-2018 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
diff --git a/io/mkdir.c b/io/mkdir.c
index b6f84f1ac2..2b43cab26a 100644
--- a/io/mkdir.c
+++ b/io/mkdir.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
@@ -36,4 +36,5 @@ __mkdir (const char *path, mode_t mode)
}
stub_warning (mkdir)
+libc_hidden_def (__mkdir)
weak_alias (__mkdir, mkdir)
diff --git a/io/mkdirat.c b/io/mkdirat.c
index 3d74b7e2c7..bfee3e9a63 100644
--- a/io/mkdirat.c
+++ b/io/mkdirat.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/mkfifo.c b/io/mkfifo.c
index 1d439e7529..c2796ab2fa 100644
--- a/io/mkfifo.c
+++ b/io/mkfifo.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/mkfifoat.c b/io/mkfifoat.c
index 5ef500ee4f..3bfff5b402 100644
--- a/io/mkfifoat.c
+++ b/io/mkfifoat.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/mknod.c b/io/mknod.c
index 574366d242..fcbfd919fb 100644
--- a/io/mknod.c
+++ b/io/mknod.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1995-2018 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
diff --git a/io/mknodat.c b/io/mknodat.c
index 9839d70a6b..2707972b7f 100644
--- a/io/mknodat.c
+++ b/io/mknodat.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1995-2018 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
diff --git a/io/open.c b/io/open.c
index f82ca497a3..bcdd650f27 100644
--- a/io/open.c
+++ b/io/open.c
@@ -1,5 +1,5 @@
/* Open a file by name. Stub version.
- Copyright (C) 1991-2016 Free Software Foundation, Inc.
+ Copyright (C) 1991-2018 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
diff --git a/io/open64.c b/io/open64.c
index 438ba47c1c..0d14f0c6a7 100644
--- a/io/open64.c
+++ b/io/open64.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/open64_2.c b/io/open64_2.c
index 957fd8c6d9..3f1e9c29da 100644
--- a/io/open64_2.c
+++ b/io/open64_2.c
@@ -1,5 +1,5 @@
/* _FORTIFY_SOURCE wrapper for open64.
- Copyright (C) 2013-2016 Free Software Foundation, Inc.
+ Copyright (C) 2013-2018 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
diff --git a/io/open_2.c b/io/open_2.c
index 4168c117f4..7513132977 100644
--- a/io/open_2.c
+++ b/io/open_2.c
@@ -1,5 +1,5 @@
/* _FORTIFY_SOURCE wrapper for open.
- Copyright (C) 2013-2016 Free Software Foundation, Inc.
+ Copyright (C) 2013-2018 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
diff --git a/io/openat.c b/io/openat.c
index c7714a99f4..c4571f7d7d 100644
--- a/io/openat.c
+++ b/io/openat.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2005-2018 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
@@ -22,7 +22,6 @@
#include <stdio.h>
#include <sys/stat.h>
#include <kernel-features.h>
-#include <libc-internal.h>
/* Some mostly-generic code (e.g. sysdeps/posix/getcwd.c) uses this variable
if __ASSUME_ATFCTS is not defined. */
diff --git a/io/openat64.c b/io/openat64.c
index 1557818170..81dd615ce4 100644
--- a/io/openat64.c
+++ b/io/openat64.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2005-2018 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
@@ -21,7 +21,6 @@
#include <stddef.h>
#include <stdio.h>
#include <sys/stat.h>
-#include <libc-internal.h>
/* Open FILE with access OFLAG. Interpret relative paths relative to
the directory associated with FD. If O_CREAT or O_TMPFILE is in OFLAG, a
diff --git a/io/openat64_2.c b/io/openat64_2.c
index 533391fc0c..4a62963e33 100644
--- a/io/openat64_2.c
+++ b/io/openat64_2.c
@@ -1,5 +1,5 @@
/* _FORTIFY_SOURCE wrapper for openat64.
- Copyright (C) 2013-2016 Free Software Foundation, Inc.
+ Copyright (C) 2013-2018 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
diff --git a/io/openat_2.c b/io/openat_2.c
index c4f2f755a4..41883df80b 100644
--- a/io/openat_2.c
+++ b/io/openat_2.c
@@ -1,5 +1,5 @@
/* _FORTIFY_SOURCE wrapper for openat.
- Copyright (C) 2013-2016 Free Software Foundation, Inc.
+ Copyright (C) 2013-2018 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
diff --git a/io/pipe.c b/io/pipe.c
index 305293f488..8694934053 100644
--- a/io/pipe.c
+++ b/io/pipe.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/pipe2.c b/io/pipe2.c
index 5949ef5c89..0eee916481 100644
--- a/io/pipe2.c
+++ b/io/pipe2.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/poll.c b/io/poll.c
index 808303bcb2..dfdce0f783 100644
--- a/io/poll.c
+++ b/io/poll.c
@@ -1,5 +1,5 @@
/* Poll (or wait) for file descriptor I/O availability. Stub version.
- Copyright (C) 1994-2016 Free Software Foundation, Inc.
+ Copyright (C) 1994-2018 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
diff --git a/io/posix_fadvise.c b/io/posix_fadvise.c
index caec5f960c..f7b6ea01f3 100644
--- a/io/posix_fadvise.c
+++ b/io/posix_fadvise.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2000-2018 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
diff --git a/io/posix_fadvise64.c b/io/posix_fadvise64.c
index 76bdab450d..842cdf4e83 100644
--- a/io/posix_fadvise64.c
+++ b/io/posix_fadvise64.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2000-2018 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
diff --git a/io/posix_fallocate.c b/io/posix_fallocate.c
index 317ebc0b43..da858f8030 100644
--- a/io/posix_fallocate.c
+++ b/io/posix_fallocate.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2000-2018 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
diff --git a/io/posix_fallocate64.c b/io/posix_fallocate64.c
index e99f9014e0..da24c2ca3f 100644
--- a/io/posix_fallocate64.c
+++ b/io/posix_fallocate64.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2000-2018 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
diff --git a/io/ppoll.c b/io/ppoll.c
index 3e8ad612ae..ec26b99fee 100644
--- a/io/ppoll.c
+++ b/io/ppoll.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2006-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2006-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2006.
diff --git a/io/pwd.c b/io/pwd.c
index cd19b84498..2e06dec03e 100644
--- a/io/pwd.c
+++ b/io/pwd.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/read.c b/io/read.c
index 7498d3c119..6b8876952c 100644
--- a/io/read.c
+++ b/io/read.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
@@ -45,3 +45,4 @@ stub_warning (read)
weak_alias (__libc_read, __read)
libc_hidden_weak (__read)
weak_alias (__libc_read, read)
+libc_hidden_weak (read)
diff --git a/io/readlink.c b/io/readlink.c
index 48590acb40..c390405841 100644
--- a/io/readlink.c
+++ b/io/readlink.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/readlinkat.c b/io/readlinkat.c
index c955aba604..9f9cd227cf 100644
--- a/io/readlinkat.c
+++ b/io/readlinkat.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2005-2018 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
diff --git a/io/rmdir.c b/io/rmdir.c
index c73dd702a4..b5db6bee9a 100644
--- a/io/rmdir.c
+++ b/io/rmdir.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/sendfile.c b/io/sendfile.c
index 29ff4a2b30..97b579d484 100644
--- a/io/sendfile.c
+++ b/io/sendfile.c
@@ -1,5 +1,5 @@
/* sendfile -- copy data directly from one file descriptor to another
- Copyright (C) 2002-2016 Free Software Foundation, Inc.
+ Copyright (C) 2002-2018 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
diff --git a/io/sendfile64.c b/io/sendfile64.c
index 31e0e4b060..d3fff65dd6 100644
--- a/io/sendfile64.c
+++ b/io/sendfile64.c
@@ -1,5 +1,5 @@
/* sendfile -- copy data directly from one file descriptor to another
- Copyright (C) 2002-2016 Free Software Foundation, Inc.
+ Copyright (C) 2002-2018 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
diff --git a/io/stat.c b/io/stat.c
index a4ed79a878..ec53868b63 100644
--- a/io/stat.c
+++ b/io/stat.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2018 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
diff --git a/io/stat64.c b/io/stat64.c
index 59ad8ee481..5020551c0f 100644
--- a/io/stat64.c
+++ b/io/stat64.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2018 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
diff --git a/io/statfs.c b/io/statfs.c
index 040cee8b8b..c1996180fc 100644
--- a/io/statfs.c
+++ b/io/statfs.c
@@ -1,5 +1,5 @@
/* statfs -- Return information about the filesystem on which FILE resides.
- Copyright (C) 1996-2016 Free Software Foundation, Inc.
+ Copyright (C) 1996-2018 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
diff --git a/io/statfs64.c b/io/statfs64.c
index 1beda66436..17121aea65 100644
--- a/io/statfs64.c
+++ b/io/statfs64.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1998-2018 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
diff --git a/io/statvfs.c b/io/statvfs.c
index b55bac5636..1b6b7bf6fd 100644
--- a/io/statvfs.c
+++ b/io/statvfs.c
@@ -1,5 +1,5 @@
/* Return information about the filesystem on which FILE resides.
- Copyright (C) 1998-2016 Free Software Foundation, Inc.
+ Copyright (C) 1998-2018 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
diff --git a/io/statvfs64.c b/io/statvfs64.c
index 671ad0e44c..bba8de658f 100644
--- a/io/statvfs64.c
+++ b/io/statvfs64.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1998-2018 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
diff --git a/io/statx.c b/io/statx.c
new file mode 100644
index 0000000000..0b90cd00d1
--- /dev/null
+++ b/io/statx.c
@@ -0,0 +1,29 @@
+/* Generic statx implementation.
+ Copyright (C) 2018 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <sys/stat.h>
+
+#include "statx_generic.c"
+
+int
+statx (int fd, const char *path, int flags,
+ unsigned int mask, struct statx *buf)
+{
+ return statx_generic (fd, path, flags, mask, buf);
+}
diff --git a/io/statx_generic.c b/io/statx_generic.c
new file mode 100644
index 0000000000..df327f8c52
--- /dev/null
+++ b/io/statx_generic.c
@@ -0,0 +1,81 @@
+/* Generic implementation of statx based on fstatat64.
+ Copyright (C) 2018 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
+
+static inline struct statx_timestamp
+statx_convert_timestamp (struct timespec tv)
+{
+ return (struct statx_timestamp) { tv.tv_sec, tv.tv_nsec };
+}
+
+/* Approximate emulation of statx. This will always fill in
+ POSIX-mandated attributes even if the underlying file system does
+ not actually support it (for example, GID and UID on file systems
+ without UNIX-style permissions). */
+static __attribute__ ((unused)) int
+statx_generic (int fd, const char *path, int flags,
+ unsigned int mask, struct statx *buf)
+{
+ /* Flags which need to be cleared before passing them to
+ fstatat64. */
+ static const int clear_flags = AT_STATX_SYNC_AS_STAT;
+
+ /* Flags supported by our emulation. */
+ static const int supported_flags
+ = AT_EMPTY_PATH | AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW | clear_flags;
+
+ if (__glibc_unlikely ((flags & ~supported_flags) != 0))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ struct stat64 st;
+ int ret = __fstatat64 (fd, path, &st, flags & ~clear_flags);
+ if (ret != 0)
+ return ret;
+
+ /* The interface is defined in such a way that unused (padding)
+ fields have to be cleared. STATX_BASIC_STATS corresponds to the
+ data which is available via fstatat64. */
+ *buf = (struct statx)
+ {
+ .stx_mask = STATX_BASIC_STATS,
+ .stx_blksize = st.st_blksize,
+ .stx_nlink = st.st_nlink,
+ .stx_uid = st.st_uid,
+ .stx_gid = st.st_gid,
+ .stx_mode = st.st_mode,
+ .stx_ino = st.st_ino,
+ .stx_size = st.st_size,
+ .stx_blocks = st.st_blocks,
+ .stx_atime = statx_convert_timestamp (st.st_atim),
+ .stx_ctime = statx_convert_timestamp (st.st_ctim),
+ .stx_mtime = statx_convert_timestamp (st.st_mtim),
+ .stx_rdev_major = major (st.st_rdev),
+ .stx_rdev_minor = minor (st.st_rdev),
+ .stx_dev_major = major (st.st_dev),
+ .stx_dev_minor = minor (st.st_dev),
+ };
+
+ return 0;
+}
diff --git a/io/symlink.c b/io/symlink.c
index f3134914de..f15a92a51a 100644
--- a/io/symlink.c
+++ b/io/symlink.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/symlinkat.c b/io/symlinkat.c
index 240c9fcc43..4a149292b9 100644
--- a/io/symlinkat.c
+++ b/io/symlinkat.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2005-2018 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
diff --git a/io/sys/poll.h b/io/sys/poll.h
index e751860acd..68f68ca412 100644
--- a/io/sys/poll.h
+++ b/io/sys/poll.h
@@ -1,5 +1,5 @@
/* Compatibility definitions for System V `poll' interface.
- Copyright (C) 1994-2016 Free Software Foundation, Inc.
+ Copyright (C) 1994-2018 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
@@ -24,11 +24,8 @@
/* Get the platform dependent bits of `poll'. */
#include <bits/poll.h>
#ifdef __USE_GNU
-/* Get the __sigset_t definition. */
-# include <bits/sigset.h>
-/* Get the timespec definition. */
-# define __need_timespec
-# include <time.h>
+# include <bits/types/__sigset_t.h>
+# include <bits/types/struct_timespec.h>
#endif
diff --git a/io/sys/sendfile.h b/io/sys/sendfile.h
index d4c14bacde..75b9d3238b 100644
--- a/io/sys/sendfile.h
+++ b/io/sys/sendfile.h
@@ -1,5 +1,5 @@
/* sendfile -- copy data directly from one file descriptor to another
- Copyright (C) 1998-2016 Free Software Foundation, Inc.
+ Copyright (C) 1998-2018 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
diff --git a/io/sys/stat.h b/io/sys/stat.h
index bf63882c7e..762c8538ba 100644
--- a/io/sys/stat.h
+++ b/io/sys/stat.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
@@ -26,19 +26,16 @@
#include <bits/types.h> /* For __mode_t and __dev_t. */
-#if defined __USE_XOPEN || defined __USE_XOPEN2K || defined __USE_ATFILE
-# if defined __USE_XOPEN || defined __USE_XOPEN2K
-# define __need_time_t
-# endif
-# ifdef __USE_ATFILE
-# define __need_timespec
-# endif
-# include <time.h> /* For time_t resp. timespec. */
+#ifdef __USE_XOPEN2K8
+# include <bits/types/struct_timespec.h>
#endif
#if defined __USE_XOPEN || defined __USE_XOPEN2K
/* The Single Unix specification says that some more types are
available here. */
+
+# include <bits/types/time_t.h>
+
# ifndef __dev_t_defined
typedef __dev_t dev_t;
# define __dev_t_defined
@@ -115,7 +112,7 @@ __BEGIN_DECLS
# ifdef __S_IFLNK
# define S_IFLNK __S_IFLNK
# endif
-# if (defined __USE_MISC || defined __USE_UNIX98) \
+# if (defined __USE_MISC || defined __USE_XOPEN_EXTENDED) \
&& defined __S_IFSOCK
# define S_IFSOCK __S_IFSOCK
# endif
@@ -140,7 +137,7 @@ __BEGIN_DECLS
# define S_ISLNK(mode) 0
#endif
-#if (defined __USE_UNIX98 || defined __USE_XOPEN2K) \
+#if (defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K) \
&& defined __S_IFSOCK
# define S_ISSOCK(mode) __S_ISTYPE((mode), __S_IFSOCK)
#elif defined __USE_XOPEN2K
@@ -292,7 +289,7 @@ extern int lchmod (const char *__file, __mode_t __mode)
#endif
/* Set file access permissions of the file FD is open on to MODE. */
-#ifdef __USE_POSIX
+#if defined __USE_POSIX199309 || defined __USE_XOPEN_EXTENDED
extern int fchmod (int __fd, __mode_t __mode) __THROW;
#endif
@@ -445,6 +442,10 @@ extern int __xmknodat (int __ver, int __fd, const char *__path,
__mode_t __mode, __dev_t *__dev)
__THROW __nonnull ((3, 5));
+#ifdef __USE_GNU
+# include <bits/statx.h>
+#endif
+
#ifdef __USE_EXTERN_INLINES
/* Inlined versions of the real stat and mknod functions. */
diff --git a/io/sys/statfs.h b/io/sys/statfs.h
index 69a228d0fb..1bd0513bc6 100644
--- a/io/sys/statfs.h
+++ b/io/sys/statfs.h
@@ -1,5 +1,5 @@
/* Definitions for getting information about a filesystem.
- Copyright (C) 1996-2016 Free Software Foundation, Inc.
+ Copyright (C) 1996-2018 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
diff --git a/io/sys/statvfs.h b/io/sys/statvfs.h
index 5d96652ac1..b33bdab898 100644
--- a/io/sys/statvfs.h
+++ b/io/sys/statvfs.h
@@ -1,5 +1,5 @@
/* Definitions for getting information about a filesystem.
- Copyright (C) 1998-2016 Free Software Foundation, Inc.
+ Copyright (C) 1998-2018 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
diff --git a/io/test-lfs.c b/io/test-lfs.c
index 3088a21fd8..f7721a5995 100644
--- a/io/test-lfs.c
+++ b/io/test-lfs.c
@@ -1,5 +1,5 @@
/* Some basic tests for LFS.
- Copyright (C) 2000-2016 Free Software Foundation, Inc.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Andreas Jaeger <aj@suse.de>, 2000.
@@ -53,7 +53,7 @@ do_prepare (int argc, char *argv[])
struct rlimit64 rlim;
name_len = strlen (test_dir);
- name = malloc (name_len + sizeof ("/lfsXXXXXX"));
+ name = xmalloc (name_len + sizeof ("/lfsXXXXXX"));
mempcpy (mempcpy (name, test_dir, name_len),
"/lfsXXXXXX", sizeof ("/lfsXXXXXX"));
@@ -163,6 +163,27 @@ do_test (int argc, char *argv[])
error (0, errno, "lseek64 failed with error");
exit (EXIT_FAILURE);
}
+ off64_t offset64 = lseek64 (fd, 0, SEEK_CUR);
+ if (offset64 != TWO_GB + 100)
+ {
+ error (0, 0, "lseek64 did not return expected offset");
+ exit (EXIT_FAILURE);
+ }
+ off_t offset = lseek (fd, 0, SEEK_CUR);
+ if (sizeof (off_t) < sizeof (off64_t))
+ {
+ if (offset != -1 || errno != EOVERFLOW)
+ {
+ error (0, 0, "lseek did not fail with EOVERFLOW");
+ exit (EXIT_FAILURE);
+ }
+ }
+ else
+ if (offset != TWO_GB + 100)
+ {
+ error (0, 0, "lseek did not return expected offset");
+ exit (EXIT_FAILURE);
+ }
ret = write (fd, "Hello", 5);
if (ret == -1 && errno == EFBIG)
diff --git a/io/test-stat.c b/io/test-stat.c
index 9d8e6b63ba..841759c17a 100644
--- a/io/test-stat.c
+++ b/io/test-stat.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2000-2018 Free Software Foundation, Inc.
Contributed by Maciej W. Rozycki <macro@ds2.pg.gda.pl>, 2000.
This file is part of the GNU C Library.
diff --git a/io/test-stat2.c b/io/test-stat2.c
index f62f5c1ee0..35550ab201 100644
--- a/io/test-stat2.c
+++ b/io/test-stat2.c
@@ -1,5 +1,5 @@
/* Test consistence of results of stat and stat64.
- Copyright (C) 2000-2016 Free Software Foundation, Inc.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2000.
diff --git a/io/test-utime.c b/io/test-utime.c
index d8d2390757..0ab778e374 100644
--- a/io/test-utime.c
+++ b/io/test-utime.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1994-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1994-2018 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
@@ -16,6 +16,7 @@
<http://www.gnu.org/licenses/>. */
#include <fcntl.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
@@ -26,23 +27,17 @@
int
main (int argc, char *argv[])
{
- char file[L_tmpnam];
+ char file[] = "/tmp/test-utime.XXXXXX";
struct utimbuf ut;
struct stat st;
struct stat stnow;
time_t now1, now2;
int fd;
- if (tmpnam (file) == 0)
- {
- perror ("tmpnam");
- return 1;
- }
-
- fd = creat (file, 0666);
+ fd = mkstemp (file);
if (fd < 0)
{
- perror ("creat");
+ perror ("mkstemp");
return 1;
}
close (fd);
diff --git a/io/tst-copy_file_range-compat.c b/io/tst-copy_file_range-compat.c
new file mode 100644
index 0000000000..00c109a74d
--- /dev/null
+++ b/io/tst-copy_file_range-compat.c
@@ -0,0 +1,30 @@
+/* Test the fallback implementation of copy_file_range.
+ Copyright (C) 2017-2018 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
+ <http://www.gnu.org/licenses/>. */
+
+/* Get the declaration of the official copy_of_range function. */
+#include <unistd.h>
+
+/* Compile a local version of copy_file_range. */
+#define COPY_FILE_RANGE_DECL static
+#define COPY_FILE_RANGE copy_file_range_compat
+#include <io/copy_file_range-compat.c>
+
+/* Re-use the test, but run it against copy_file_range_compat defined
+ above. */
+#define copy_file_range copy_file_range_compat
+#include "tst-copy_file_range.c"
diff --git a/io/tst-copy_file_range.c b/io/tst-copy_file_range.c
new file mode 100644
index 0000000000..3d531a1937
--- /dev/null
+++ b/io/tst-copy_file_range.c
@@ -0,0 +1,835 @@
+/* Tests for copy_file_range.
+ Copyright (C) 2017-2018 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <array_length.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <libgen.h>
+#include <poll.h>
+#include <sched.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <support/check.h>
+#include <support/namespace.h>
+#include <support/support.h>
+#include <support/temp_file.h>
+#include <support/test-driver.h>
+#include <support/xunistd.h>
+#ifdef CLONE_NEWNS
+# include <sys/mount.h>
+#endif
+
+/* Boolean flags which indicate whether to use pointers with explicit
+ output flags. */
+static int do_inoff;
+static int do_outoff;
+
+/* Name and descriptors of the input files. Files are truncated and
+ reopened (with O_RDWR) between tests. */
+static char *infile;
+static int infd;
+static char *outfile;
+static int outfd;
+
+/* Like the above, but on a different file system. xdevfile can be
+ NULL if no suitable file system has been found. */
+static char *xdevfile;
+
+/* Input and output offsets. Set according to do_inoff and do_outoff
+ before the test. The offsets themselves are always set to
+ zero. */
+static off64_t inoff;
+static off64_t *pinoff;
+static off64_t outoff;
+static off64_t *poutoff;
+
+/* These are a collection of copy sizes used in tests. The selection
+ takes into account that the fallback implementation uses an
+ internal buffer of 8192 bytes. */
+enum { maximum_size = 99999 };
+static const int typical_sizes[] =
+ { 0, 1, 2, 3, 1024, 2048, 4096, 8191, 8192, 8193, 16383, 16384, 16385,
+ maximum_size };
+
+/* The random contents of this array can be used as a pattern to check
+ for correct write operations. */
+static unsigned char random_data[maximum_size];
+
+/* The size chosen by the test harness. */
+static int current_size;
+
+/* Maximum writable file offset. Updated by find_maximum_offset
+ below. */
+static off64_t maximum_offset;
+
+/* Error code when crossing the offset. */
+static int maximum_offset_errno;
+
+/* If true: Writes which cross the limit will fail. If false: Writes
+ which cross the limit will result in a partial write. */
+static bool maximum_offset_hard_limit;
+
+/* Fills maximum_offset etc. above. Truncates outfd as a side
+ effect. */
+static void
+find_maximum_offset (void)
+{
+ xftruncate (outfd, 0);
+ if (maximum_offset != 0)
+ return;
+
+ uint64_t upper = -1;
+ upper >>= 1; /* Maximum of off64_t. */
+ TEST_VERIFY ((off64_t) upper > 0);
+ TEST_VERIFY ((off64_t) (upper + 1) < 0);
+ if (lseek64 (outfd, upper, SEEK_SET) >= 0)
+ {
+ if (write (outfd, "", 1) == 1)
+ FAIL_EXIT1 ("created a file larger than the off64_t range");
+ }
+
+ uint64_t lower = 1024 * 1024; /* A reasonable minimum file size. */
+ /* Loop invariant: writing at lower succeeds, writing at upper fails. */
+ while (lower + 1 < upper)
+ {
+ uint64_t middle = (lower + upper) / 2;
+ if (test_verbose > 0)
+ printf ("info: %s: remaining test range %" PRIu64 " .. %" PRIu64
+ ", probe at %" PRIu64 "\n", __func__, lower, upper, middle);
+ xftruncate (outfd, 0);
+ if (lseek64 (outfd, middle, SEEK_SET) >= 0
+ && write (outfd, "", 1) == 1)
+ lower = middle;
+ else
+ upper = middle;
+ }
+ TEST_VERIFY (lower + 1 == upper);
+ maximum_offset = lower;
+ printf ("info: maximum writable file offset: %" PRIu64 " (%" PRIx64 ")\n",
+ lower, lower);
+
+ /* Check that writing at the valid offset actually works. */
+ xftruncate (outfd, 0);
+ xlseek (outfd, lower, SEEK_SET);
+ TEST_COMPARE (write (outfd, "", 1), 1);
+
+ /* Cross the boundary with a two-byte write. This can either result
+ in a short write, or a failure. */
+ xlseek (outfd, lower, SEEK_SET);
+ ssize_t ret = write (outfd, " ", 2);
+ if (ret < 0)
+ {
+ maximum_offset_errno = errno;
+ maximum_offset_hard_limit = true;
+ }
+ else
+ maximum_offset_hard_limit = false;
+
+ /* Check that writing at the next offset actually fails. This also
+ obtains the expected errno value. */
+ xftruncate (outfd, 0);
+ const char *action;
+ if (lseek64 (outfd, lower + 1, SEEK_SET) != 0)
+ {
+ if (write (outfd, "", 1) != -1)
+ FAIL_EXIT1 ("write to impossible offset %" PRIu64 " succeeded",
+ lower + 1);
+ action = "writing";
+ int errno_copy = errno;
+ if (maximum_offset_hard_limit)
+ TEST_COMPARE (errno_copy, maximum_offset_errno);
+ else
+ maximum_offset_errno = errno_copy;
+ }
+ else
+ {
+ action = "seeking";
+ maximum_offset_errno = errno;
+ }
+ printf ("info: %s out of range fails with %m (%d)\n",
+ action, maximum_offset_errno);
+
+ xftruncate (outfd, 0);
+ xlseek (outfd, 0, SEEK_SET);
+}
+
+/* Perform a copy of a file. */
+static void
+simple_file_copy (void)
+{
+ xwrite (infd, random_data, current_size);
+
+ int length;
+ int in_skipped; /* Expected skipped bytes in input. */
+ if (do_inoff)
+ {
+ xlseek (infd, 1, SEEK_SET);
+ inoff = 2;
+ length = current_size - 3;
+ in_skipped = 2;
+ }
+ else
+ {
+ xlseek (infd, 3, SEEK_SET);
+ length = current_size - 5;
+ in_skipped = 3;
+ }
+ int out_skipped; /* Expected skipped bytes before the written data. */
+ if (do_outoff)
+ {
+ xlseek (outfd, 4, SEEK_SET);
+ outoff = 5;
+ out_skipped = 5;
+ }
+ else
+ {
+ xlseek (outfd, 6, SEEK_SET);
+ length = current_size - 6;
+ out_skipped = 6;
+ }
+ if (length < 0)
+ length = 0;
+
+ TEST_COMPARE (copy_file_range (infd, pinoff, outfd, poutoff,
+ length, 0), length);
+ if (do_inoff)
+ {
+ TEST_COMPARE (inoff, 2 + length);
+ TEST_COMPARE (xlseek (infd, 0, SEEK_CUR), 1);
+ }
+ else
+ TEST_COMPARE (xlseek (infd, 0, SEEK_CUR), 3 + length);
+ if (do_outoff)
+ {
+ TEST_COMPARE (outoff, 5 + length);
+ TEST_COMPARE (xlseek (outfd, 0, SEEK_CUR), 4);
+ }
+ else
+ TEST_COMPARE (xlseek (outfd, 0, SEEK_CUR), 6 + length);
+
+ struct stat64 st;
+ xfstat (outfd, &st);
+ if (length > 0)
+ TEST_COMPARE (st.st_size, out_skipped + length);
+ else
+ {
+ /* If we did not write anything, we also did not add any
+ padding. */
+ TEST_COMPARE (st.st_size, 0);
+ return;
+ }
+
+ xlseek (outfd, 0, SEEK_SET);
+ char *bytes = xmalloc (st.st_size);
+ TEST_COMPARE (read (outfd, bytes, st.st_size), st.st_size);
+ for (int i = 0; i < out_skipped; ++i)
+ TEST_COMPARE (bytes[i], 0);
+ TEST_VERIFY (memcmp (bytes + out_skipped, random_data + in_skipped,
+ length) == 0);
+ free (bytes);
+}
+
+/* Test that reading from a pipe willfails. */
+static void
+pipe_as_source (void)
+{
+ int pipefds[2];
+ xpipe (pipefds);
+
+ for (int length = 0; length < 2; ++length)
+ {
+ if (test_verbose > 0)
+ printf ("info: %s: length=%d\n", __func__, length);
+
+ /* Make sure that there is something to copy in the pipe. */
+ xwrite (pipefds[1], "@", 1);
+
+ TEST_COMPARE (copy_file_range (pipefds[0], pinoff, outfd, poutoff,
+ length, 0), -1);
+ /* Linux 4.10 and later return EINVAL. Older kernels return
+ EXDEV. */
+ TEST_VERIFY (errno == EINVAL || errno == EXDEV);
+ TEST_COMPARE (inoff, 0);
+ TEST_COMPARE (outoff, 0);
+ TEST_COMPARE (xlseek (outfd, 0, SEEK_CUR), 0);
+
+ /* Make sure that nothing was read. */
+ char buf = 'A';
+ TEST_COMPARE (read (pipefds[0], &buf, 1), 1);
+ TEST_COMPARE (buf, '@');
+ }
+
+ xclose (pipefds[0]);
+ xclose (pipefds[1]);
+}
+
+/* Test that writing to a pipe fails. */
+static void
+pipe_as_destination (void)
+{
+ /* Make sure that there is something to read in the input file. */
+ xwrite (infd, "abc", 3);
+ xlseek (infd, 0, SEEK_SET);
+
+ int pipefds[2];
+ xpipe (pipefds);
+
+ for (int length = 0; length < 2; ++length)
+ {
+ if (test_verbose > 0)
+ printf ("info: %s: length=%d\n", __func__, length);
+
+ TEST_COMPARE (copy_file_range (infd, pinoff, pipefds[1], poutoff,
+ length, 0), -1);
+ /* Linux 4.10 and later return EINVAL. Older kernels return
+ EXDEV. */
+ TEST_VERIFY (errno == EINVAL || errno == EXDEV);
+ TEST_COMPARE (inoff, 0);
+ TEST_COMPARE (outoff, 0);
+ TEST_COMPARE (xlseek (infd, 0, SEEK_CUR), 0);
+
+ /* Make sure that nothing was written. */
+ struct pollfd pollfd = { .fd = pipefds[0], .events = POLLIN, };
+ TEST_COMPARE (poll (&pollfd, 1, 0), 0);
+ }
+
+ xclose (pipefds[0]);
+ xclose (pipefds[1]);
+}
+
+/* Test a write failure after (potentially) writing some bytes.
+ Failure occurs near the start of the buffer. */
+static void
+delayed_write_failure_beginning (void)
+{
+ /* We need to write something to provoke the error. */
+ if (current_size == 0)
+ return;
+ xwrite (infd, random_data, sizeof (random_data));
+ xlseek (infd, 0, SEEK_SET);
+
+ /* Write failure near the start. The actual error code varies among
+ file systems. */
+ find_maximum_offset ();
+ off64_t where = maximum_offset;
+
+ if (current_size == 1)
+ ++where;
+ outoff = where;
+ if (do_outoff)
+ xlseek (outfd, 1, SEEK_SET);
+ else
+ xlseek (outfd, where, SEEK_SET);
+ if (maximum_offset_hard_limit || where > maximum_offset)
+ {
+ TEST_COMPARE (copy_file_range (infd, pinoff, outfd, poutoff,
+ sizeof (random_data), 0), -1);
+ TEST_COMPARE (errno, maximum_offset_errno);
+ TEST_COMPARE (xlseek (infd, 0, SEEK_CUR), 0);
+ TEST_COMPARE (inoff, 0);
+ if (do_outoff)
+ TEST_COMPARE (xlseek (outfd, 0, SEEK_CUR), 1);
+ else
+ TEST_COMPARE (xlseek (outfd, 0, SEEK_CUR), where);
+ TEST_COMPARE (outoff, where);
+ struct stat64 st;
+ xfstat (outfd, &st);
+ TEST_COMPARE (st.st_size, 0);
+ }
+ else
+ {
+ /* The offset is not a hard limit. This means we write one
+ byte. */
+ TEST_COMPARE (copy_file_range (infd, pinoff, outfd, poutoff,
+ sizeof (random_data), 0), 1);
+ if (do_inoff)
+ {
+ TEST_COMPARE (inoff, 1);
+ TEST_COMPARE (xlseek (infd, 0, SEEK_CUR), 0);
+ }
+ else
+ {
+ TEST_COMPARE (xlseek (infd, 0, SEEK_CUR), 1);
+ TEST_COMPARE (inoff, 0);
+ }
+ if (do_outoff)
+ {
+ TEST_COMPARE (xlseek (outfd, 0, SEEK_CUR), 1);
+ TEST_COMPARE (outoff, where + 1);
+ }
+ else
+ {
+ TEST_COMPARE (xlseek (outfd, 0, SEEK_CUR), where + 1);
+ TEST_COMPARE (outoff, where);
+ }
+ struct stat64 st;
+ xfstat (outfd, &st);
+ TEST_COMPARE (st.st_size, where + 1);
+ }
+}
+
+/* Test a write failure after (potentially) writing some bytes.
+ Failure occurs near the end of the buffer. */
+static void
+delayed_write_failure_end (void)
+{
+ if (current_size <= 1)
+ /* This would be same as the first test because there is not
+ enough data to write to make a difference. */
+ return;
+ xwrite (infd, random_data, sizeof (random_data));
+ xlseek (infd, 0, SEEK_SET);
+
+ find_maximum_offset ();
+ off64_t where = maximum_offset - current_size + 1;
+ if (current_size == sizeof (random_data))
+ /* Otherwise we do not reach the non-writable byte. */
+ ++where;
+ outoff = where;
+ if (do_outoff)
+ xlseek (outfd, 1, SEEK_SET);
+ else
+ xlseek (outfd, where, SEEK_SET);
+ ssize_t ret = copy_file_range (infd, pinoff, outfd, poutoff,
+ sizeof (random_data), 0);
+ if (ret < 0)
+ {
+ TEST_COMPARE (ret, -1);
+ TEST_COMPARE (errno, maximum_offset_errno);
+ struct stat64 st;
+ xfstat (outfd, &st);
+ TEST_COMPARE (st.st_size, 0);
+ }
+ else
+ {
+ /* The first copy succeeded. This happens in the emulation
+ because the internal buffer of limited size does not
+ necessarily cross the off64_t boundary on the first write
+ operation. */
+ if (test_verbose > 0)
+ printf ("info: copy_file_range (%zu) returned %zd\n",
+ sizeof (random_data), ret);
+ TEST_VERIFY (ret > 0);
+ TEST_VERIFY (ret < maximum_size);
+ struct stat64 st;
+ xfstat (outfd, &st);
+ TEST_COMPARE (st.st_size, where + ret);
+ if (do_inoff)
+ {
+ TEST_COMPARE (inoff, ret);
+ TEST_COMPARE (xlseek (infd, 0, SEEK_CUR), 0);
+ }
+ else
+ TEST_COMPARE (xlseek (infd, 0, SEEK_CUR), ret);
+
+ char *buffer = xmalloc (ret);
+ TEST_COMPARE (pread64 (outfd, buffer, ret, where), ret);
+ TEST_VERIFY (memcmp (buffer, random_data, ret) == 0);
+ free (buffer);
+
+ /* The second copy fails. */
+ TEST_COMPARE (copy_file_range (infd, pinoff, outfd, poutoff,
+ sizeof (random_data), 0), -1);
+ TEST_COMPARE (errno, maximum_offset_errno);
+ }
+}
+
+/* Test a write failure across devices. */
+static void
+cross_device_failure (void)
+{
+ if (xdevfile == NULL)
+ /* Subtest not supported due to missing cross-device file. */
+ return;
+
+ /* We need something to write. */
+ xwrite (infd, random_data, sizeof (random_data));
+ xlseek (infd, 0, SEEK_SET);
+
+ int xdevfd = xopen (xdevfile, O_RDWR | O_LARGEFILE, 0);
+ TEST_COMPARE (copy_file_range (infd, pinoff, xdevfd, poutoff,
+ current_size, 0), -1);
+ TEST_COMPARE (errno, EXDEV);
+ TEST_COMPARE (xlseek (infd, 0, SEEK_CUR), 0);
+ struct stat64 st;
+ xfstat (xdevfd, &st);
+ TEST_COMPARE (st.st_size, 0);
+
+ xclose (xdevfd);
+}
+
+/* Try to exercise ENOSPC behavior with a tempfs file system (so that
+ we do not have to fill up a regular file system to get the error).
+ This function runs in a subprocess, so that we do not change the
+ mount namespace of the actual test process. */
+static void
+enospc_failure_1 (void *closure)
+{
+#ifdef CLONE_NEWNS
+ support_become_root ();
+
+ /* Make sure that we do not alter the file system mounts of the
+ parents. */
+ if (! support_enter_mount_namespace ())
+ {
+ printf ("warning: ENOSPC test skipped\n");
+ return;
+ }
+
+ char *mountpoint = closure;
+ if (mount ("none", mountpoint, "tmpfs", MS_NODEV | MS_NOEXEC,
+ "size=500k") != 0)
+ {
+ printf ("warning: could not mount tmpfs at %s: %m\n", mountpoint);
+ return;
+ }
+
+ /* The source file must reside on the same file system. */
+ char *intmpfsfile = xasprintf ("%s/%s", mountpoint, "in");
+ int intmpfsfd = xopen (intmpfsfile, O_RDWR | O_CREAT | O_LARGEFILE, 0600);
+ xwrite (intmpfsfd, random_data, sizeof (random_data));
+ xlseek (intmpfsfd, 1, SEEK_SET);
+ inoff = 1;
+
+ char *outtmpfsfile = xasprintf ("%s/%s", mountpoint, "out");
+ int outtmpfsfd = xopen (outtmpfsfile, O_RDWR | O_CREAT | O_LARGEFILE, 0600);
+
+ /* Fill the file with data until ENOSPC is reached. */
+ while (true)
+ {
+ ssize_t ret = write (outtmpfsfd, random_data, sizeof (random_data));
+ if (ret < 0 && errno != ENOSPC)
+ FAIL_EXIT1 ("write to %s: %m", outtmpfsfile);
+ if (ret < sizeof (random_data))
+ break;
+ }
+ TEST_COMPARE (write (outtmpfsfd, "", 1), -1);
+ TEST_COMPARE (errno, ENOSPC);
+ off64_t maxsize = xlseek (outtmpfsfd, 0, SEEK_CUR);
+ TEST_VERIFY_EXIT (maxsize > sizeof (random_data));
+
+ /* Constructed the expected file contents. */
+ char *expected = xmalloc (maxsize);
+ TEST_COMPARE (pread64 (outtmpfsfd, expected, maxsize, 0), maxsize);
+ /* Go back a little, so some bytes can be written. */
+ enum { offset = 20000 };
+ TEST_VERIFY_EXIT (offset < maxsize);
+ TEST_VERIFY_EXIT (offset < sizeof (random_data));
+ memcpy (expected + maxsize - offset, random_data + 1, offset);
+
+ if (do_outoff)
+ {
+ outoff = maxsize - offset;
+ xlseek (outtmpfsfd, 2, SEEK_SET);
+ }
+ else
+ xlseek (outtmpfsfd, -offset, SEEK_CUR);
+
+ /* First call is expected to succeed because we made room for some
+ bytes. */
+ TEST_COMPARE (copy_file_range (intmpfsfd, pinoff, outtmpfsfd, poutoff,
+ maximum_size, 0), offset);
+ if (do_inoff)
+ {
+ TEST_COMPARE (inoff, 1 + offset);
+ TEST_COMPARE (xlseek (intmpfsfd, 0, SEEK_CUR), 1);
+ }
+ else
+ TEST_COMPARE (xlseek (intmpfsfd, 0, SEEK_CUR), 1 + offset);
+ if (do_outoff)
+ {
+ TEST_COMPARE (outoff, maxsize);
+ TEST_COMPARE (xlseek (outtmpfsfd, 0, SEEK_CUR), 2);
+ }
+ else
+ TEST_COMPARE (xlseek (outtmpfsfd, 0, SEEK_CUR), maxsize);
+ struct stat64 st;
+ xfstat (outtmpfsfd, &st);
+ TEST_COMPARE (st.st_size, maxsize);
+ char *actual = xmalloc (st.st_size);
+ TEST_COMPARE (pread64 (outtmpfsfd, actual, st.st_size, 0), st.st_size);
+ TEST_VERIFY (memcmp (expected, actual, maxsize) == 0);
+
+ /* Second call should fail with ENOSPC. */
+ TEST_COMPARE (copy_file_range (intmpfsfd, pinoff, outtmpfsfd, poutoff,
+ maximum_size, 0), -1);
+ TEST_COMPARE (errno, ENOSPC);
+
+ /* Offsets should be unchanged. */
+ if (do_inoff)
+ {
+ TEST_COMPARE (inoff, 1 + offset);
+ TEST_COMPARE (xlseek (intmpfsfd, 0, SEEK_CUR), 1);
+ }
+ else
+ TEST_COMPARE (xlseek (intmpfsfd, 0, SEEK_CUR), 1 + offset);
+ if (do_outoff)
+ {
+ TEST_COMPARE (outoff, maxsize);
+ TEST_COMPARE (xlseek (outtmpfsfd, 0, SEEK_CUR), 2);
+ }
+ else
+ TEST_COMPARE (xlseek (outtmpfsfd, 0, SEEK_CUR), maxsize);
+ TEST_COMPARE (xlseek (outtmpfsfd, 0, SEEK_END), maxsize);
+ TEST_COMPARE (pread64 (outtmpfsfd, actual, maxsize, 0), maxsize);
+ TEST_VERIFY (memcmp (expected, actual, maxsize) == 0);
+
+ free (actual);
+ free (expected);
+
+ xclose (intmpfsfd);
+ xclose (outtmpfsfd);
+ free (intmpfsfile);
+ free (outtmpfsfile);
+
+#else /* !CLONE_NEWNS */
+ puts ("warning: ENOSPC test skipped (no mount namespaces)");
+#endif
+}
+
+/* Call enospc_failure_1 in a subprocess. */
+static void
+enospc_failure (void)
+{
+ char *mountpoint
+ = support_create_temp_directory ("tst-copy_file_range-enospc-");
+ support_isolate_in_subprocess (enospc_failure_1, mountpoint);
+ free (mountpoint);
+}
+
+/* The target file descriptor must have O_APPEND enabled. */
+static void
+oappend_failure (void)
+{
+ /* Add data, to make sure we do not fail because there is
+ insufficient input data. */
+ xwrite (infd, random_data, current_size);
+ xlseek (infd, 0, SEEK_SET);
+
+ xclose (outfd);
+ outfd = xopen (outfile, O_RDWR | O_APPEND, 0);
+ TEST_COMPARE (copy_file_range (infd, pinoff, outfd, poutoff,
+ current_size, 0), -1);
+ TEST_COMPARE (errno, EBADF);
+}
+
+/* Test that a short input file results in a shortened copy. */
+static void
+short_copy (void)
+{
+ if (current_size == 0)
+ /* Nothing to shorten. */
+ return;
+
+ /* Two subtests, one with offset 0 and current_size - 1 bytes, and
+ another one with current_size bytes, but offset 1. */
+ for (int shift = 0; shift < 2; ++shift)
+ {
+ if (test_verbose > 0)
+ printf ("info: shift=%d\n", shift);
+ xftruncate (infd, 0);
+ xlseek (infd, 0, SEEK_SET);
+ xwrite (infd, random_data, current_size - !shift);
+
+ if (do_inoff)
+ {
+ inoff = shift;
+ xlseek (infd, 2, SEEK_SET);
+ }
+ else
+ {
+ inoff = 3;
+ xlseek (infd, shift, SEEK_SET);
+ }
+ ftruncate (outfd, 0);
+ xlseek (outfd, 0, SEEK_SET);
+ outoff = 0;
+
+ /* First call copies current_size - 1 bytes. */
+ TEST_COMPARE (copy_file_range (infd, pinoff, outfd, poutoff,
+ current_size, 0), current_size - 1);
+ char *buffer = xmalloc (current_size);
+ TEST_COMPARE (pread64 (outfd, buffer, current_size, 0),
+ current_size - 1);
+ TEST_VERIFY (memcmp (buffer, random_data + shift, current_size - 1)
+ == 0);
+ free (buffer);
+
+ if (do_inoff)
+ {
+ TEST_COMPARE (inoff, current_size - 1 + shift);
+ TEST_COMPARE (xlseek (infd, 0, SEEK_CUR), 2);
+ }
+ else
+ TEST_COMPARE (xlseek (infd, 0, SEEK_CUR), current_size - 1 + shift);
+ if (do_outoff)
+ {
+ TEST_COMPARE (outoff, current_size - 1);
+ TEST_COMPARE (xlseek (outfd, 0, SEEK_CUR), 0);
+ }
+ else
+ TEST_COMPARE (xlseek (outfd, 0, SEEK_CUR), current_size - 1);
+
+ /* First call copies zero bytes. */
+ TEST_COMPARE (copy_file_range (infd, pinoff, outfd, poutoff,
+ current_size, 0), 0);
+ /* And the offsets are unchanged. */
+ if (do_inoff)
+ {
+ TEST_COMPARE (inoff, current_size - 1 + shift);
+ TEST_COMPARE (xlseek (infd, 0, SEEK_CUR), 2);
+ }
+ else
+ TEST_COMPARE (xlseek (infd, 0, SEEK_CUR), current_size - 1 + shift);
+ if (do_outoff)
+ {
+ TEST_COMPARE (outoff, current_size - 1);
+ TEST_COMPARE (xlseek (outfd, 0, SEEK_CUR), 0);
+ }
+ else
+ TEST_COMPARE (xlseek (outfd, 0, SEEK_CUR), current_size - 1);
+ }
+}
+
+/* A named test function. */
+struct test_case
+{
+ const char *name;
+ void (*func) (void);
+ bool sizes; /* If true, call the test with different current_size values. */
+};
+
+/* The available test cases. */
+static struct test_case tests[] =
+ {
+ { "simple_file_copy", simple_file_copy, .sizes = true },
+ { "pipe_as_source", pipe_as_source, },
+ { "pipe_as_destination", pipe_as_destination, },
+ { "delayed_write_failure_beginning", delayed_write_failure_beginning,
+ .sizes = true },
+ { "delayed_write_failure_end", delayed_write_failure_end, .sizes = true },
+ { "cross_device_failure", cross_device_failure, .sizes = true },
+ { "enospc_failure", enospc_failure, },
+ { "oappend_failure", oappend_failure, .sizes = true },
+ { "short_copy", short_copy, .sizes = true },
+ };
+
+static int
+do_test (void)
+{
+ for (unsigned char *p = random_data; p < array_end (random_data); ++p)
+ *p = rand () >> 24;
+
+ infd = create_temp_file ("tst-copy_file_range-in-", &infile);
+ xclose (create_temp_file ("tst-copy_file_range-out-", &outfile));
+
+ /* Try to find a different directory from the default input/output
+ file. */
+ {
+ struct stat64 instat;
+ xfstat (infd, &instat);
+ static const char *const candidates[] =
+ { NULL, "/var/tmp", "/dev/shm" };
+ for (const char *const *c = candidates; c < array_end (candidates); ++c)
+ {
+ const char *path = *c;
+ char *to_free = NULL;
+ if (path == NULL)
+ {
+ to_free = xreadlink ("/proc/self/exe");
+ path = dirname (to_free);
+ }
+
+ struct stat64 cstat;
+ xstat (path, &cstat);
+ if (cstat.st_dev == instat.st_dev)
+ {
+ free (to_free);
+ continue;
+ }
+
+ printf ("info: using alternate temporary files directory: %s\n", path);
+ xdevfile = xasprintf ("%s/tst-copy_file_range-xdev-XXXXXX", path);
+ free (to_free);
+ break;
+ }
+ if (xdevfile != NULL)
+ {
+ int xdevfd = mkstemp (xdevfile);
+ if (xdevfd < 0)
+ FAIL_EXIT1 ("mkstemp (\"%s\"): %m", xdevfile);
+ struct stat64 xdevst;
+ xfstat (xdevfd, &xdevst);
+ TEST_VERIFY (xdevst.st_dev != instat.st_dev);
+ add_temp_file (xdevfile);
+ xclose (xdevfd);
+ }
+ else
+ puts ("warning: no alternate directory on different file system found");
+ }
+ xclose (infd);
+
+ for (do_inoff = 0; do_inoff < 2; ++do_inoff)
+ for (do_outoff = 0; do_outoff < 2; ++do_outoff)
+ for (struct test_case *test = tests; test < array_end (tests); ++test)
+ for (const int *size = typical_sizes;
+ size < array_end (typical_sizes); ++size)
+ {
+ current_size = *size;
+ if (test_verbose > 0)
+ printf ("info: %s do_inoff=%d do_outoff=%d current_size=%d\n",
+ test->name, do_inoff, do_outoff, current_size);
+
+ inoff = 0;
+ if (do_inoff)
+ pinoff = &inoff;
+ else
+ pinoff = NULL;
+ outoff = 0;
+ if (do_outoff)
+ poutoff = &outoff;
+ else
+ poutoff = NULL;
+
+ infd = xopen (infile, O_RDWR | O_LARGEFILE, 0);
+ xftruncate (infd, 0);
+ outfd = xopen (outfile, O_RDWR | O_LARGEFILE, 0);
+ xftruncate (outfd, 0);
+
+ test->func ();
+
+ xclose (infd);
+ xclose (outfd);
+
+ if (!test->sizes)
+ /* Skip the other sizes unless they have been
+ requested. */
+ break;
+ }
+
+ free (infile);
+ free (outfile);
+ free (xdevfile);
+
+ return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/io/tst-faccessat.c b/io/tst-faccessat.c
index 48532070a7..7bdeed008c 100644
--- a/io/tst-faccessat.c
+++ b/io/tst-faccessat.c
@@ -6,6 +6,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <sys/stat.h>
static void prepare (void);
diff --git a/io/tst-fchmodat.c b/io/tst-fchmodat.c
index bfb75d62e5..7d4a8717ff 100644
--- a/io/tst-fchmodat.c
+++ b/io/tst-fchmodat.c
@@ -6,6 +6,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <sys/stat.h>
static void prepare (void);
diff --git a/io/tst-fchownat.c b/io/tst-fchownat.c
index da8fd3b023..e8adf6229f 100644
--- a/io/tst-fchownat.c
+++ b/io/tst-fchownat.c
@@ -4,6 +4,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <sys/stat.h>
static void prepare (void);
diff --git a/io/tst-fcntl.c b/io/tst-fcntl.c
index 98a642e5fc..272f4a2c2d 100644
--- a/io/tst-fcntl.c
+++ b/io/tst-fcntl.c
@@ -1,5 +1,5 @@
/* Tests for fcntl.
- Copyright (C) 2000-2016 Free Software Foundation, Inc.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 2000.
@@ -47,7 +47,7 @@ do_prepare (int argc, char *argv[])
size_t name_len;
name_len = strlen (test_dir);
- name = malloc (name_len + sizeof ("/fcntlXXXXXX"));
+ name = xmalloc (name_len + sizeof ("/fcntlXXXXXX"));
mempcpy (mempcpy (name, test_dir, name_len),
"/fcntlXXXXXX", sizeof ("/fcntlXXXXXX"));
/* Create the temporary file. */
diff --git a/io/tst-fstatat.c b/io/tst-fstatat.c
index 5493102167..4766bb2e71 100644
--- a/io/tst-fstatat.c
+++ b/io/tst-fstatat.c
@@ -4,6 +4,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <sys/stat.h>
static void prepare (void);
diff --git a/io/tst-fts.c b/io/tst-fts.c
index b7d77143f4..7848da9a1a 100644
--- a/io/tst-fts.c
+++ b/io/tst-fts.c
@@ -1,5 +1,5 @@
/* Simple test for some fts functions.
- Copyright (C) 2015-2016 Free Software Foundation, Inc.
+ Copyright (C) 2015-2018 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
diff --git a/io/tst-futimesat.c b/io/tst-futimesat.c
index c1e8d93f41..af58ad06dd 100644
--- a/io/tst-futimesat.c
+++ b/io/tst-futimesat.c
@@ -4,6 +4,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <sys/stat.h>
#include <sys/time.h>
diff --git a/io/tst-getcwd-abspath.c b/io/tst-getcwd-abspath.c
new file mode 100644
index 0000000000..3a3636f2ed
--- /dev/null
+++ b/io/tst-getcwd-abspath.c
@@ -0,0 +1,66 @@
+/* BZ #22679 getcwd(3) should not succeed without returning an absolute path.
+
+ Copyright (C) 2018 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 <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <support/check.h>
+#include <support/namespace.h>
+#include <support/support.h>
+#include <support/temp_file.h>
+#include <support/test-driver.h>
+#include <support/xunistd.h>
+#include <unistd.h>
+
+static char *chroot_dir;
+
+/* The actual test. Run it in a subprocess, so that the test harness
+ can remove the temporary directory in --direct mode. */
+static void
+getcwd_callback (void *closure)
+{
+ xchroot (chroot_dir);
+
+ errno = 0;
+ char *cwd = getcwd (NULL, 0);
+ TEST_COMPARE (errno, ENOENT);
+ TEST_VERIFY (cwd == NULL);
+
+ errno = 0;
+ cwd = realpath (".", NULL);
+ TEST_COMPARE (errno, ENOENT);
+ TEST_VERIFY (cwd == NULL);
+
+ _exit (0);
+}
+
+static int
+do_test (void)
+{
+ support_become_root ();
+ if (!support_can_chroot ())
+ return EXIT_UNSUPPORTED;
+
+ chroot_dir = support_create_temp_directory ("tst-getcwd-abspath-");
+ support_isolate_in_subprocess (getcwd_callback, NULL);
+
+ return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/io/tst-getcwd.c b/io/tst-getcwd.c
index ab15b2b0bc..8e7a11eb0d 100644
--- a/io/tst-getcwd.c
+++ b/io/tst-getcwd.c
@@ -1,5 +1,5 @@
/* Test of getcwd function.
- Copyright (C) 2000-2016 Free Software Foundation, Inc.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 2000.
diff --git a/io/tst-linkat.c b/io/tst-linkat.c
index d63c982751..97445b7954 100644
--- a/io/tst-linkat.c
+++ b/io/tst-linkat.c
@@ -4,6 +4,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <sys/stat.h>
static void prepare (void);
diff --git a/io/tst-mkdirat.c b/io/tst-mkdirat.c
index 3efa4622ef..605e51ef1e 100644
--- a/io/tst-mkdirat.c
+++ b/io/tst-mkdirat.c
@@ -1,9 +1,11 @@
#include <dirent.h>
#include <fcntl.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <sys/stat.h>
static void prepare (void);
@@ -129,13 +131,11 @@ do_test (void)
if (strcmp (d->d_name, "some-dir") == 0)
{
has_some_dir = true;
-#ifdef _DIRENT_HAVE_D_TYPE
if (d->d_type != DT_UNKNOWN && d->d_type != DT_DIR)
{
puts ("d_type for some-dir wrong");
return 1;
}
-#endif
}
else if (strcmp (d->d_name, ".") != 0 && strcmp (d->d_name, "..") != 0)
{
diff --git a/io/tst-mkfifoat.c b/io/tst-mkfifoat.c
index 2bf29f63af..c9239dcde8 100644
--- a/io/tst-mkfifoat.c
+++ b/io/tst-mkfifoat.c
@@ -1,9 +1,11 @@
#include <dirent.h>
#include <fcntl.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <sys/stat.h>
static void prepare (void);
@@ -129,13 +131,11 @@ do_test (void)
if (strcmp (d->d_name, "some-fifo") == 0)
{
has_some_fifo = true;
-#ifdef _DIRENT_HAVE_D_TYPE
if (d->d_type != DT_UNKNOWN && d->d_type != DT_FIFO)
{
puts ("d_type for some-fifo wrong");
return 1;
}
-#endif
}
else if (strcmp (d->d_name, ".") != 0 && strcmp (d->d_name, "..") != 0)
{
diff --git a/io/tst-mknodat.c b/io/tst-mknodat.c
index cba4dffadf..88a98cab79 100644
--- a/io/tst-mknodat.c
+++ b/io/tst-mknodat.c
@@ -1,9 +1,11 @@
#include <dirent.h>
#include <fcntl.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <sys/stat.h>
static void prepare (void);
@@ -129,13 +131,11 @@ do_test (void)
if (strcmp (d->d_name, "some-fifo") == 0)
{
has_some_fifo = true;
-#ifdef _DIRENT_HAVE_D_TYPE
if (d->d_type != DT_UNKNOWN && d->d_type != DT_FIFO)
{
puts ("d_type for some-fifo wrong");
return 1;
}
-#endif
}
else if (strcmp (d->d_name, ".") != 0 && strcmp (d->d_name, "..") != 0)
{
diff --git a/io/tst-open-tmpfile.c b/io/tst-open-tmpfile.c
new file mode 100644
index 0000000000..592b5a020b
--- /dev/null
+++ b/io/tst-open-tmpfile.c
@@ -0,0 +1,318 @@
+/* Test open and openat with O_TMPFILE.
+ Copyright (C) 2016-2018 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
+ <http://www.gnu.org/licenses/>. */
+
+/* This test verifies that open and openat work as expected, i.e. they
+ create a deleted file with the requested file mode. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <support/support.h>
+
+#ifdef O_TMPFILE
+typedef int (*wrapper_func) (const char *, int, mode_t);
+
+/* Error-checking wrapper for the open function, compatible with the
+ wrapper_func type. */
+static int
+wrap_open (const char *path, int flags, mode_t mode)
+{
+ int ret = open (path, flags, mode);
+ if (ret < 0)
+ {
+ printf ("error: open (\"%s\", 0x%x, 0%03o): %m\n", path, flags, mode);
+ exit (1);
+ }
+ return ret;
+}
+
+/* Error-checking wrapper for the openat function, compatible with the
+ wrapper_func type. */
+static int
+wrap_openat (const char *path, int flags, mode_t mode)
+{
+ int ret = openat (AT_FDCWD, path, flags, mode);
+ if (ret < 0)
+ {
+ printf ("error: openat (\"%s\", 0x%x, 0%03o): %m\n", path, flags, mode);
+ exit (1);
+ }
+ return ret;
+}
+
+/* Error-checking wrapper for the open64 function, compatible with the
+ wrapper_func type. */
+static int
+wrap_open64 (const char *path, int flags, mode_t mode)
+{
+ int ret = open64 (path, flags, mode);
+ if (ret < 0)
+ {
+ printf ("error: open64 (\"%s\", 0x%x, 0%03o): %m\n", path, flags, mode);
+ exit (1);
+ }
+ return ret;
+}
+
+/* Error-checking wrapper for the openat64 function, compatible with the
+ wrapper_func type. */
+static int
+wrap_openat64 (const char *path, int flags, mode_t mode)
+{
+ int ret = openat64 (AT_FDCWD, path, flags, mode);
+ if (ret < 0)
+ {
+ printf ("error: openat64 (\"%s\", 0x%x, 0%03o): %m\n", path, flags, mode);
+ exit (1);
+ }
+ return ret;
+}
+
+/* Return true if FD is flagged as deleted in /proc/self/fd, false if
+ not. */
+static bool
+is_file_deteted (int fd)
+{
+ char *proc_fd_path = xasprintf ("/proc/self/fd/%d", fd);
+ char file_path[4096];
+ ssize_t file_path_length
+ = readlink (proc_fd_path, file_path, sizeof (file_path));
+ if (file_path_length < 0)
+ {
+ printf ("error: readlink (\"%s\"): %m", proc_fd_path);
+ free (proc_fd_path);
+ exit (1);
+ }
+ free (proc_fd_path);
+ if (file_path_length == sizeof (file_path))
+ {
+ printf ("error: path in /proc resolves to overlong file name: %.*s\n",
+ (int) file_path_length, file_path);
+ exit (1);
+ }
+ const char *deleted = " (deleted)";
+ if (file_path_length < strlen (deleted))
+ {
+ printf ("error: path in /proc is too short: %.*s\n",
+ (int) file_path_length, file_path);
+ exit (1);
+ }
+ return memcmp (file_path + file_path_length - strlen (deleted),
+ deleted, strlen (deleted)) == 0;
+}
+
+/* Obtain a file name which is difficult to guess. */
+static char *
+get_random_name (void)
+{
+ unsigned long long bytes[2];
+ int random_device = open ("/dev/urandom", O_RDONLY);
+ if (random_device < 0)
+ {
+ printf ("error: open (\"/dev/urandom\"): %m\n");
+ exit (1);
+ }
+ ssize_t ret = read (random_device, bytes, sizeof (bytes));
+ if (ret < 0)
+ {
+ printf ("error: read (\"/dev/urandom\"): %m\n");
+ exit (1);
+ }
+ if (ret != sizeof (bytes))
+ {
+ printf ("error: short read from /dev/urandom: %zd\n", ret);
+ exit (1);
+ }
+ close (random_device);
+ return xasprintf ("tst-open-tmpfile-%08llx%08llx.tmp", bytes[0], bytes[1]);
+}
+
+/* Check open/openat (as specified by OP and WRAPPER) with a specific
+ PATH/FLAGS/MODE combination. */
+static void
+check_wrapper_flags_mode (const char *op, wrapper_func wrapper,
+ const char *path, int flags, mode_t mode)
+{
+ int fd = wrapper (path, flags | O_TMPFILE, mode);
+ struct stat64 st;
+ if (fstat64 (fd, &st) != 0)
+ {
+ printf ("error: fstat64: %m\n");
+ exit (1);
+ }
+
+ /* Verify that the mode was correctly processed. */
+ int actual_mode = st.st_mode & 0777;
+ if (actual_mode != mode)
+ {
+ printf ("error: unexpected mode; expected 0%03o, actual 0%03o\n",
+ mode, actual_mode);
+ exit (1);
+ }
+
+ /* Check that the file is marked as deleted in /proc. */
+ if (!is_file_deteted (fd))
+ {
+ printf ("error: path in /proc is not marked as deleted\n");
+ exit (1);
+ }
+
+ /* Check that the file can be turned into a regular file with
+ linkat. Open a file descriptor for the directory at PATH. Use
+ AT_FDCWD if PATH is ".", to exercise that functionality as
+ well. */
+ int path_fd;
+ if (strcmp (path, ".") == 0)
+ path_fd = AT_FDCWD;
+ else
+ {
+ path_fd = open (path, O_RDONLY | O_DIRECTORY);
+ if (path_fd < 0)
+ {
+ printf ("error: open (\"%s\"): %m\n", path);
+ exit (1);
+ }
+ }
+
+ /* Use a hard-to-guess name for the new directory entry. */
+ char *new_name = get_random_name ();
+
+ /* linkat does not require privileges if the path in /proc/self/fd
+ is used. */
+ char *proc_fd_path = xasprintf ("/proc/self/fd/%d", fd);
+ if (linkat (AT_FDCWD, proc_fd_path, path_fd, new_name,
+ AT_SYMLINK_FOLLOW) == 0)
+ {
+ if (unlinkat (path_fd, new_name, 0) != 0 && errno != ENOENT)
+ {
+ printf ("error: unlinkat (\"%s/%s\"): %m\n", path, new_name);
+ exit (1);
+ }
+ }
+ else
+ {
+ /* linkat failed. This is expected if O_EXCL was specified. */
+ if ((flags & O_EXCL) == 0)
+ {
+ printf ("error: linkat failed after %s (\"%s\", 0x%x, 0%03o): %m\n",
+ op, path, flags, mode);
+ exit (1);
+ }
+ }
+
+ free (proc_fd_path);
+ free (new_name);
+ if (path_fd != AT_FDCWD)
+ close (path_fd);
+ close (fd);
+}
+
+/* Check OP/WRAPPER with various flags at a specific PATH and
+ MODE. */
+static void
+check_wrapper_mode (const char *op, wrapper_func wrapper,
+ const char *path, mode_t mode)
+{
+ check_wrapper_flags_mode (op, wrapper, path, O_WRONLY, mode);
+ check_wrapper_flags_mode (op, wrapper, path, O_WRONLY | O_EXCL, mode);
+ check_wrapper_flags_mode (op, wrapper, path, O_RDWR, mode);
+ check_wrapper_flags_mode (op, wrapper, path, O_RDWR | O_EXCL, mode);
+}
+
+/* Check open/openat with varying permissions. */
+static void
+check_wrapper (const char *op, wrapper_func wrapper,
+ const char *path)
+{
+ printf ("info: testing %s at: %s\n", op, path);
+ check_wrapper_mode (op, wrapper, path, 0);
+ check_wrapper_mode (op, wrapper, path, 0640);
+ check_wrapper_mode (op, wrapper, path, 0600);
+ check_wrapper_mode (op, wrapper, path, 0755);
+ check_wrapper_mode (op, wrapper, path, 0750);
+}
+
+/* Verify that the directory at PATH supports O_TMPFILE. Exit with
+ status 77 (unsupported) if the kernel does not support O_TMPFILE.
+ Even with kernel support, not all file systems O_TMPFILE, so return
+ true if the directory supports O_TMPFILE, false if not. */
+static bool
+probe_path (const char *path)
+{
+ int fd = openat (AT_FDCWD, path, O_TMPFILE | O_RDWR, 0);
+ if (fd < 0)
+ {
+ if (errno == EISDIR)
+ /* The system does not support O_TMPFILE. */
+ {
+ printf ("info: kernel does not support O_TMPFILE\n");
+ exit (77);
+ }
+ if (errno == EOPNOTSUPP)
+ {
+ printf ("info: path does not support O_TMPFILE: %s\n", path);
+ return false;
+ }
+ printf ("error: openat (\"%s\", O_TMPFILE | O_RDWR): %m\n", path);
+ exit (1);
+ }
+ close (fd);
+ return true;
+}
+
+static int
+do_test (void)
+{
+ umask (0);
+ const char *paths[] = { ".", "/dev/shm", "/tmp",
+ getenv ("TEST_TMPFILE_PATH"),
+ NULL };
+ bool supported = false;
+ for (int i = 0; paths[i] != NULL; ++i)
+ if (probe_path (paths[i]))
+ {
+ supported = true;
+ check_wrapper ("open", wrap_open, paths[i]);
+ check_wrapper ("openat", wrap_openat, paths[i]);
+ check_wrapper ("open64", wrap_open64, paths[i]);
+ check_wrapper ("openat64", wrap_openat64, paths[i]);
+ }
+
+ if (!supported)
+ return 77;
+
+ return 0;
+}
+
+#else /* !O_TMPFILE */
+
+static int
+do_test (void)
+{
+ return 77;
+}
+
+#endif /* O_TMPFILE */
+
+#include <support/test-driver.c>
diff --git a/io/tst-openat.c b/io/tst-openat.c
index 0ceb745880..741b8d0ad2 100644
--- a/io/tst-openat.c
+++ b/io/tst-openat.c
@@ -1,5 +1,6 @@
#include <dirent.h>
#include <fcntl.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/io/tst-posix_fallocate-common.c b/io/tst-posix_fallocate-common.c
new file mode 100644
index 0000000000..43ed9442d4
--- /dev/null
+++ b/io/tst-posix_fallocate-common.c
@@ -0,0 +1,85 @@
+/* Common posix_fallocate tests definitions.
+ Copyright (C) 2016-2018 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <fcntl.h>
+#include <limits.h>
+#include <stdint.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <support/support.h>
+#include <support/check.h>
+#include <support/temp_file.h>
+
+static char *temp_filename;
+static int temp_fd;
+
+static void
+do_prepare (int argc, char **argv)
+{
+ temp_fd = create_temp_file ("tst-posix_fallocate.", &temp_filename);
+ if (temp_fd == -1)
+ FAIL_EXIT1 ("cannot create temporary file: %m\n");
+}
+#define PREPARE do_prepare
+
+static int
+do_test_with_offset (off_t offset)
+{
+ struct stat st;
+
+ if (posix_fallocate (temp_fd, offset, 768) != 0)
+ FAIL_EXIT1 ("1st posix_fallocate call failed");
+
+ if (fstat (temp_fd, &st) != 0)
+ FAIL_EXIT1 ("2nd fstat failed");
+
+ if (st.st_size != (offset + 768))
+ FAIL_EXIT1 ("file size after first posix_fallocate call is %lu, "
+ "expected %lu",
+ (unsigned long int) st.st_size, 512lu + 768lu);
+
+ if (posix_fallocate (temp_fd, 0, 1024) != 0)
+ FAIL_EXIT1 ("2nd posix_fallocate call failed");
+
+ if (fstat (temp_fd, &st) != 0)
+ FAIL_EXIT1 ("3rd fstat failed");
+
+ if (st.st_size != (offset) + 768)
+ FAIL_EXIT1 ("file size changed in second posix_fallocate");
+
+ offset += 2048;
+ if (posix_fallocate (temp_fd, offset, 64) != 0)
+ FAIL_EXIT1 ("3rd posix_fallocate call failed");
+
+ if (fstat (temp_fd, &st) != 0)
+ FAIL_EXIT1 ("4th fstat failed");
+
+ if (st.st_size != (offset + 64))
+ FAIL_EXIT1 ("file size after first posix_fallocate call is %llu, "
+ "expected %u",
+ (unsigned long long int) st.st_size, 2048u + 64u);
+
+ return 0;
+}
+
+/* This function is defined by the individual tests. */
+static int do_test (void);
+
+#include <support/test-driver.c>
diff --git a/io/tst-posix_fallocate.c b/io/tst-posix_fallocate.c
index 53f0704c34..1497ae23c1 100644
--- a/io/tst-posix_fallocate.c
+++ b/io/tst-posix_fallocate.c
@@ -1,100 +1,33 @@
-#include <fcntl.h>
-#include <sys/stat.h>
+/* Basic posix_fallocate tests.
+ Copyright (C) 2016-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
-static void do_prepare (void);
-#define PREPARE(argc, argv) do_prepare ()
-static int do_test (void);
-#define TEST_FUNCTION do_test ()
-#include <test-skeleton.c>
+ 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.
-static int fd;
+ 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.
-static void
-do_prepare (void)
-{
- fd = create_temp_file ("tst-posix_fallocate.", NULL);
- if (fd == -1)
- {
- printf ("cannot create temporary file: %m\n");
- exit (1);
- }
-}
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+#include "tst-posix_fallocate-common.c"
static int
do_test (void)
{
- struct stat64 st;
+ struct stat st;
- if (fstat64 (fd, &st) != 0)
- {
- puts ("1st fstat failed");
- return 1;
- }
+ if (fstat (temp_fd, &st) != 0)
+ FAIL_EXIT1 ("1st fstat failed");
if (st.st_size != 0)
- {
- puts ("file not created with size 0");
- return 1;
- }
-
- if (posix_fallocate (fd, 512, 768) != 0)
- {
- puts ("1st posix_fallocate call failed");
- return 1;
- }
-
- if (fstat64 (fd, &st) != 0)
- {
- puts ("2nd fstat failed");
- return 1;
- }
-
- if (st.st_size != 512 + 768)
- {
- printf ("file size after first posix_fallocate call is %llu, expected %u\n",
- (unsigned long long int) st.st_size, 512u + 768u);
- return 1;
- }
-
- if (posix_fallocate (fd, 0, 1024) != 0)
- {
- puts ("2nd posix_fallocate call failed");
- return 1;
- }
-
- if (fstat64 (fd, &st) != 0)
- {
- puts ("3rd fstat failed");
- return 1;
- }
-
- if (st.st_size != 512 + 768)
- {
- puts ("file size changed in second posix_fallocate");
- return 1;
- }
-
- if (posix_fallocate (fd, 2048, 64) != 0)
- {
- puts ("3rd posix_fallocate call failed");
- return 1;
- }
-
- if (fstat64 (fd, &st) != 0)
- {
- puts ("4th fstat failed");
- return 1;
- }
-
- if (st.st_size != 2048 + 64)
- {
- printf ("file size after first posix_fallocate call is %llu, expected %u\n",
- (unsigned long long int) st.st_size, 2048u + 64u);
- return 1;
- }
-
- close (fd);
+ FAIL_EXIT1 ("file not created with size 0");
- return 0;
+ return do_test_with_offset (512);
}
diff --git a/io/tst-posix_fallocate64.c b/io/tst-posix_fallocate64.c
new file mode 100644
index 0000000000..f88e335d8f
--- /dev/null
+++ b/io/tst-posix_fallocate64.c
@@ -0,0 +1,44 @@
+/* Basic posix_fallocate tests (with _FILE_OFFSET_BITS).
+ Copyright (C) 2016-2018 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
+ <http://www.gnu.org/licenses/>. */
+
+#define _FILE_OFFSET_BITS 64
+#include "tst-posix_fallocate-common.c"
+
+static int
+do_test (void)
+{
+ struct stat st;
+ int ret;
+
+ if (fstat (temp_fd, &st) != 0)
+ FAIL_EXIT1 ("1st fstat failed");
+
+ if (st.st_size != 0)
+ FAIL_EXIT1 ("file not created with size 0");
+
+ ret = do_test_with_offset (512);
+ if (ret == 1)
+ return 1;
+
+ off_t base_offset = UINT32_MAX + 512LL;
+ ret = do_test_with_offset (base_offset);
+ if (ret == 1)
+ return 1;
+
+ return 0;
+}
diff --git a/io/tst-readlinkat.c b/io/tst-readlinkat.c
index 891b6e6817..51fafc92d3 100644
--- a/io/tst-readlinkat.c
+++ b/io/tst-readlinkat.c
@@ -4,6 +4,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <sys/stat.h>
static void prepare (void);
diff --git a/io/tst-renameat.c b/io/tst-renameat.c
index a7c0ec16c4..435302b52b 100644
--- a/io/tst-renameat.c
+++ b/io/tst-renameat.c
@@ -4,6 +4,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <sys/stat.h>
static void prepare (void);
diff --git a/io/tst-statx.c b/io/tst-statx.c
new file mode 100644
index 0000000000..61bf31d177
--- /dev/null
+++ b/io/tst-statx.c
@@ -0,0 +1,157 @@
+/* Basic test of statx system call.
+ Copyright (C) 2018 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <support/check.h>
+#include <support/support.h>
+#include <support/temp_file.h>
+#include <support/xunistd.h>
+#include <sys/stat.h>
+#include <sys/syscall.h>
+#include <sys/sysmacros.h>
+#include <unistd.h>
+
+/* Ensure that the types have the kernel-expected layout. */
+_Static_assert (sizeof (struct statx_timestamp) == 16, "statx_timestamp size");
+_Static_assert (sizeof (struct statx) == 256, "statx size");
+_Static_assert (offsetof (struct statx, stx_nlink) == 16, "statx nlink");
+_Static_assert (offsetof (struct statx, stx_ino) == 32, "statx ino");
+_Static_assert (offsetof (struct statx, stx_atime) == 64, "statx atime");
+_Static_assert (offsetof (struct statx, stx_rdev_major) == 128, "statx rdev");
+_Static_assert (offsetof (struct statx, __statx_pad2) == 144, "statx pad2");
+
+#include "statx_generic.c"
+
+typedef int (*statx_function) (int, const char *, int, unsigned int,
+ struct statx *);
+
+/* Return true if we have a real implementation of statx. */
+static bool
+kernel_supports_statx (void)
+{
+#ifdef __NR_statx
+ struct statx buf;
+ return syscall (__NR_statx, 0, "", AT_EMPTY_PATH, 0, &buf) == 0
+ || errno != ENOSYS;
+#else
+ return false;
+#endif
+}
+
+/* Tests which apply to both implementations. */
+static void
+both_implementations_tests (statx_function impl, const char *path, int fd)
+{
+ uint64_t ino;
+ {
+ struct statx buf = { 0, };
+ TEST_COMPARE (statx (fd, "", AT_EMPTY_PATH, STATX_BASIC_STATS, &buf), 0);
+ TEST_COMPARE (buf.stx_size, 3);
+ ino = buf.stx_ino;
+ }
+ {
+ struct statx buf = { 0, };
+ TEST_COMPARE (statx (AT_FDCWD, path, 0, STATX_BASIC_STATS, &buf), 0);
+ TEST_COMPARE (buf.stx_size, 3);
+ TEST_COMPARE (buf.stx_ino, ino);
+ }
+ {
+ struct statx stx = { 0, };
+ TEST_COMPARE (statx (fd, "", AT_EMPTY_PATH, STATX_BASIC_STATS, &stx), 0);
+ struct stat64 st;
+ xfstat (fd, &st);
+ TEST_COMPARE (stx.stx_mode, st.st_mode);
+ TEST_COMPARE (stx.stx_dev_major, major (st.st_dev));
+ TEST_COMPARE (stx.stx_dev_minor, minor (st.st_dev));
+ }
+ {
+ struct statx stx = { 0, };
+ TEST_COMPARE (statx (AT_FDCWD, "/dev/null", 0, STATX_BASIC_STATS, &stx),
+ 0);
+ struct stat64 st;
+ xstat ("/dev/null", &st);
+ TEST_COMPARE (stx.stx_mode, st.st_mode);
+ TEST_COMPARE (stx.stx_dev_major, major (st.st_dev));
+ TEST_COMPARE (stx.stx_dev_minor, minor (st.st_dev));
+ TEST_COMPARE (stx.stx_rdev_major, major (st.st_rdev));
+ TEST_COMPARE (stx.stx_rdev_minor, minor (st.st_rdev));
+ }
+}
+
+/* Tests which apply only to the non-kernel (generic)
+ implementation. */
+static void
+non_kernel_tests (statx_function impl, int fd)
+{
+ /* The non-kernel implementation must always fail for explicit sync
+ flags. */
+ struct statx buf;
+ errno = 0;
+ TEST_COMPARE (impl (fd, "", AT_EMPTY_PATH | AT_STATX_FORCE_SYNC,
+ STATX_BASIC_STATS, &buf), -1);
+ TEST_COMPARE (errno, EINVAL);
+ errno = 0;
+ TEST_COMPARE (impl (fd, "", AT_EMPTY_PATH | AT_STATX_DONT_SYNC,
+ STATX_BASIC_STATS, &buf), -1);
+ TEST_COMPARE (errno, EINVAL);
+}
+
+static int
+do_test (void)
+{
+ char *path;
+ int fd = create_temp_file ("tst-statx-", &path);
+ TEST_VERIFY_EXIT (fd >= 0);
+ support_write_file_string (path, "abc");
+
+ both_implementations_tests (&statx, path, fd);
+ both_implementations_tests (&statx_generic, path, fd);
+
+ if (kernel_supports_statx ())
+ {
+ puts ("info: kernel supports statx");
+ struct statx buf;
+ buf.stx_size = 0;
+ TEST_COMPARE (statx (fd, "", AT_EMPTY_PATH | AT_STATX_FORCE_SYNC,
+ STATX_BASIC_STATS, &buf),
+ 0);
+ TEST_COMPARE (buf.stx_size, 3);
+ buf.stx_size = 0;
+ TEST_COMPARE (statx (fd, "", AT_EMPTY_PATH | AT_STATX_DONT_SYNC,
+ STATX_BASIC_STATS, &buf),
+ 0);
+ TEST_COMPARE (buf.stx_size, 3);
+ }
+ else
+ {
+ puts ("info: kernel does not support statx");
+ non_kernel_tests (&statx, fd);
+ }
+ non_kernel_tests (&statx_generic, fd);
+
+ xclose (fd);
+ free (path);
+
+ return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/io/tst-symlinkat.c b/io/tst-symlinkat.c
index 1e98588fc8..214a8e348e 100644
--- a/io/tst-symlinkat.c
+++ b/io/tst-symlinkat.c
@@ -4,6 +4,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <sys/stat.h>
static void prepare (void);
diff --git a/io/tst-unlinkat.c b/io/tst-unlinkat.c
index c25443c27f..e21d56f9f7 100644
--- a/io/tst-unlinkat.c
+++ b/io/tst-unlinkat.c
@@ -1,5 +1,6 @@
#include <dirent.h>
#include <fcntl.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/io/ttyname.c b/io/ttyname.c
index cc7adda415..7ba359ead8 100644
--- a/io/ttyname.c
+++ b/io/ttyname.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/ttyname_r.c b/io/ttyname_r.c
index 6462b1ff87..709174656a 100644
--- a/io/ttyname_r.c
+++ b/io/ttyname_r.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/umask.c b/io/umask.c
index 9cf0514b94..824e7a52a5 100644
--- a/io/umask.c
+++ b/io/umask.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/unlink.c b/io/unlink.c
index 5dbcf92874..b7104efa4d 100644
--- a/io/unlink.c
+++ b/io/unlink.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/unlinkat.c b/io/unlinkat.c
index a5ecc0dce1..5a192bed39 100644
--- a/io/unlinkat.c
+++ b/io/unlinkat.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2005-2018 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
diff --git a/io/utime.c b/io/utime.c
index c7b7cfeae8..3f3c03c92d 100644
--- a/io/utime.c
+++ b/io/utime.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* utime -- change access and modification times of file. Stub version.
+ Copyright (C) 1991-2018 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
diff --git a/io/utime.h b/io/utime.h
index 3cc0d5e99d..8409ba4ddc 100644
--- a/io/utime.h
+++ b/io/utime.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
@@ -29,8 +29,7 @@ __BEGIN_DECLS
#include <bits/types.h>
#if defined __USE_XOPEN || defined __USE_XOPEN2K
-# define __need_time_t
-# include <time.h>
+# include <bits/types/time_t.h>
#endif
/* Structure describing file times. */
diff --git a/io/utimensat.c b/io/utimensat.c
index bc7341f84e..6b67a52e9e 100644
--- a/io/utimensat.c
+++ b/io/utimensat.c
@@ -1,5 +1,5 @@
/* Change access and modification times of open file. Stub version.
- Copyright (C) 2007-2016 Free Software Foundation, Inc.
+ Copyright (C) 2007-2018 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
diff --git a/io/write.c b/io/write.c
index 0e1c109064..aec88765dc 100644
--- a/io/write.c
+++ b/io/write.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
@@ -46,3 +46,4 @@ stub_warning (write)
weak_alias (__libc_write, __write)
libc_hidden_weak (__write)
weak_alias (__libc_write, write)
+libc_hidden_weak (write)
diff --git a/io/xmknod.c b/io/xmknod.c
index 9f82c0b089..fb6f70ace0 100644
--- a/io/xmknod.c
+++ b/io/xmknod.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/xmknodat.c b/io/xmknodat.c
index 3c2e04ddb1..8f4fc7241e 100644
--- a/io/xmknodat.c
+++ b/io/xmknodat.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2005-2018 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
diff --git a/io/xstat.c b/io/xstat.c
index 80ed0b87f7..07245a3850 100644
--- a/io/xstat.c
+++ b/io/xstat.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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
diff --git a/io/xstat64.c b/io/xstat64.c
index 4e09392461..99003ea090 100644
--- a/io/xstat64.c
+++ b/io/xstat64.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 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