]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Synchronize support/ infrastructure with master
authorFlorian Weimer <fweimer@redhat.com>
Tue, 16 Jan 2018 07:28:18 +0000 (08:28 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Tue, 16 Jan 2018 07:28:18 +0000 (08:28 +0100)
This commit updates the support/ subdirectory to
commit 1a51e46e4a87e1cd9528ac5e5656011636e4086b
on the master branch.

141 files changed:
scripts/backport-support.sh
support/Makefile
support/capture_subprocess.h
support/check.c
support/check.h
support/check_addrinfo.c
support/check_dns_packet.c
support/check_hostent.c
support/check_netent.c
support/check_nss.h
support/delayed_exit.c
support/format_nss.h
support/ignore_stderr.c
support/namespace.h
support/next_to_fault.c [new file with mode: 0644]
support/next_to_fault.h [new file with mode: 0644]
support/oom_error.c
support/resolv_test.c
support/resolv_test.h
support/run_diff.h
support/set_fortify_handler.c
support/support-xfstat.c [new file with mode: 0644]
support/support-xstat.c
support/support.h
support/support_become_root.c
support/support_can_chroot.c
support/support_capture_subprocess.c
support/support_capture_subprocess_check.c
support/support_chroot.c
support/support_enter_mount_namespace.c [new file with mode: 0644]
support/support_enter_network_namespace.c
support/support_format_address_family.c
support/support_format_addrinfo.c
support/support_format_dns_packet.c
support/support_format_herrno.c
support/support_format_hostent.c
support/support_format_netent.c
support/support_isolate_in_subprocess.c
support/support_record_failure.c
support/support_run_diff.c
support/support_shared_allocate.c
support/support_test_compare_failure.c [new file with mode: 0644]
support/support_test_main.c
support/support_test_verify_impl.c
support/support_write_file_string.c
support/temp_file-internal.h
support/temp_file.c
support/temp_file.h
support/test-driver.c
support/test-driver.h
support/tst-support-namespace.c
support/tst-support_capture_subprocess.c
support/tst-support_format_dns_packet.c
support/tst-support_record_failure-2.sh
support/tst-support_record_failure.c
support/tst-test_compare.c [new file with mode: 0644]
support/tst-xreadlink.c [new file with mode: 0644]
support/write_message.c
support/xaccept.c
support/xaccept4.c
support/xasprintf.c
support/xbind.c
support/xcalloc.c
support/xchroot.c
support/xclose.c
support/xconnect.c
support/xdlfcn.c
support/xdlfcn.h
support/xdup2.c
support/xfclose.c
support/xfopen.c
support/xfork.c
support/xftruncate.c [new file with mode: 0644]
support/xgetsockname.c
support/xlisten.c
support/xlseek.c [new file with mode: 0644]
support/xmalloc.c
support/xmemstream.c
support/xmemstream.h
support/xmkdir.c
support/xmmap.c
support/xmprotect.c
support/xmunmap.c
support/xopen.c
support/xpipe.c
support/xpoll.c
support/xpthread_attr_destroy.c
support/xpthread_attr_init.c
support/xpthread_attr_setdetachstate.c
support/xpthread_attr_setguardsize.c
support/xpthread_attr_setstacksize.c
support/xpthread_barrier_destroy.c
support/xpthread_barrier_init.c
support/xpthread_barrier_wait.c
support/xpthread_cancel.c
support/xpthread_check_return.c
support/xpthread_cond_wait.c
support/xpthread_create.c
support/xpthread_detach.c
support/xpthread_join.c
support/xpthread_mutex_consistent.c
support/xpthread_mutex_destroy.c
support/xpthread_mutex_init.c
support/xpthread_mutex_lock.c
support/xpthread_mutex_unlock.c
support/xpthread_mutexattr_destroy.c
support/xpthread_mutexattr_init.c
support/xpthread_mutexattr_setprotocol.c
support/xpthread_mutexattr_setpshared.c
support/xpthread_mutexattr_setrobust.c
support/xpthread_mutexattr_settype.c
support/xpthread_once.c
support/xpthread_rwlock_init.c
support/xpthread_rwlock_rdlock.c
support/xpthread_rwlock_unlock.c
support/xpthread_rwlock_wrlock.c
support/xpthread_rwlockattr_init.c
support/xpthread_rwlockattr_setkind_np.c
support/xpthread_sigmask.c
support/xpthread_spin_lock.c
support/xpthread_spin_unlock.c
support/xraise.c [new file with mode: 0644]
support/xreadlink.c [new file with mode: 0644]
support/xrealloc.c
support/xrecvfrom.c
support/xsendto.c
support/xsetsockopt.c
support/xsigaction.c [new file with mode: 0644]
support/xsignal.c [new file with mode: 0644]
support/xsignal.h
support/xsocket.c
support/xsocket.h
support/xstdio.h
support/xstrdup.c
support/xstrndup.c [new file with mode: 0644]
support/xsysconf.c [new file with mode: 0644]
support/xthread.h
support/xunistd.h
support/xunlink.c [new file with mode: 0644]
support/xwaitpid.c
support/xwrite.c

index 2ece7ce575e03a7591a3baf15b6568058fc3b4a7..4057e42d3c7370e4c4862d200083fc20052a18b4 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/bash
 # Create a patch which backports the support/ subdirectory.
-# Copyright (C) 2017 Free Software Foundation, Inc.
+# 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
index 027a663000e5bd206f8b0369de5d64e2b57f0505..1bda81e55e519a57cd8b8c6838277649c2045c69 100644 (file)
@@ -1,5 +1,5 @@
 # Makefile for support library, used only at build and test time
-# Copyright (C) 2016-2017 Free Software Foundation, Inc.
+# 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
@@ -32,15 +32,18 @@ libsupport-routines = \
   check_netent \
   delayed_exit \
   ignore_stderr \
+  next_to_fault \
   oom_error \
   resolv_test \
   set_fortify_handler \
+  support-xfstat \
   support-xstat \
   support_become_root \
   support_can_chroot \
   support_capture_subprocess \
   support_capture_subprocess_check \
   support_chroot \
+  support_enter_mount_namespace \
   support_enter_network_namespace \
   support_format_address_family \
   support_format_addrinfo \
@@ -52,6 +55,7 @@ libsupport-routines = \
   support_record_failure \
   support_run_diff \
   support_shared_allocate \
+  support_test_compare_failure \
   support_write_file_string \
   support_test_main \
   support_test_verify_impl \
@@ -70,8 +74,10 @@ libsupport-routines = \
   xfclose \
   xfopen \
   xfork \
+  xftruncate \
   xgetsockname \
   xlisten \
+  xlseek \
   xmalloc \
   xmemstream \
   xmkdir \
@@ -84,8 +90,8 @@ libsupport-routines = \
   xpthread_attr_destroy \
   xpthread_attr_init \
   xpthread_attr_setdetachstate \
-  xpthread_attr_setstacksize \
   xpthread_attr_setguardsize \
+  xpthread_attr_setstacksize \
   xpthread_barrier_destroy \
   xpthread_barrier_init \
   xpthread_barrier_wait \
@@ -109,19 +115,26 @@ libsupport-routines = \
   xpthread_once \
   xpthread_rwlock_init \
   xpthread_rwlock_rdlock \
-  xpthread_rwlock_wrlock \
   xpthread_rwlock_unlock \
+  xpthread_rwlock_wrlock \
   xpthread_rwlockattr_init \
   xpthread_rwlockattr_setkind_np \
   xpthread_sigmask \
   xpthread_spin_lock \
   xpthread_spin_unlock \
+  xraise \
+  xreadlink \
   xrealloc \
   xrecvfrom \
   xsendto \
   xsetsockopt \
+  xsigaction \
+  xsignal \
   xsocket \
   xstrdup \
+  xstrndup \
+  xsysconf \
+  xunlink \
   xwaitpid \
   xwrite \
 
@@ -138,6 +151,8 @@ tests = \
   tst-support_capture_subprocess \
   tst-support_format_dns_packet \
   tst-support_record_failure \
+  tst-test_compare \
+  tst-xreadlink \
 
 ifeq ($(run-built-tests),yes)
 tests-special = \
index 43caf9bce4675b66ee45e699aef458c6e1052123..b0886ba1d165263b2ebf84344de7c59b3e54d0e3 100644 (file)
@@ -1,5 +1,5 @@
 /* Capture output from a subprocess.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index 592f2bc856e301d9cb151df8aaca69ae801b70af..78f2b3cde14bc0bdfbd1f99ebe09aac58f48f48f 100644 (file)
@@ -1,5 +1,5 @@
 /* Support code for reporting test results.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
@@ -18,6 +18,7 @@
 
 #include <support/check.h>
 
+#include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 static void
 print_failure (const char *file, int line, const char *format, va_list ap)
 {
+  int saved_errno = errno;
   printf ("error: %s:%d: ", file, line);
   vprintf (format, ap);
   puts ("");
+  errno = saved_errno;
 }
 
 int
index bdcd12952af6c286cebc9ec0916abedff71b77ed..2192f38941af2515f814408db519228fbb6611e3 100644 (file)
@@ -1,5 +1,5 @@
 /* Functionality for reporting test results.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
@@ -86,6 +86,61 @@ void support_test_verify_exit_impl (int status, const char *file, int line,
    does not support reporting failures from a DSO.  */
 void support_record_failure (void);
 
+/* Static assertion, under a common name for both C++ and C11.  */
+#ifdef __cplusplus
+# define support_static_assert static_assert
+#else
+# define support_static_assert _Static_assert
+#endif
+
+/* Compare the two integers LEFT and RIGHT and report failure if they
+   are different.  */
+#define TEST_COMPARE(left, right)                                       \
+  ({                                                                    \
+    /* + applies the integer promotions, for bitfield support.   */     \
+    typedef __typeof__ (+ (left)) __left_type;                          \
+    typedef __typeof__ (+ (right)) __right_type;                        \
+    __left_type __left_value = (left);                                  \
+    __right_type __right_value = (right);                               \
+    int __left_is_positive = __left_value > 0;                          \
+    int __right_is_positive = __right_value > 0;                        \
+    /* Prevent use with floating-point types.  */                       \
+    support_static_assert ((__left_type) 1.0 == (__left_type) 1.5,      \
+                           "left value has floating-point type");       \
+    support_static_assert ((__right_type) 1.0 == (__right_type) 1.5,    \
+                           "right value has floating-point type");      \
+    /* Prevent accidental use with larger-than-long long types.  */     \
+    support_static_assert (sizeof (__left_value) <= sizeof (long long), \
+                           "left value fits into long long");           \
+    support_static_assert (sizeof (__right_value) <= sizeof (long long), \
+                    "right value fits into long long");                 \
+    /* Compare the value.  */                                           \
+    if (__left_value != __right_value                                   \
+        || __left_is_positive != __right_is_positive)                   \
+      /* Pass the sign for printing the correct value.  */              \
+      support_test_compare_failure                                      \
+        (__FILE__, __LINE__,                                            \
+         #left, __left_value, __left_is_positive, sizeof (__left_type), \
+         #right, __right_value, __right_is_positive, sizeof (__right_type)); \
+  })
+
+/* Internal implementation of TEST_COMPARE.  LEFT_POSITIVE and
+   RIGHT_POSITIVE are used to store the sign separately, so that both
+   unsigned long long and long long arguments fit into LEFT_VALUE and
+   RIGHT_VALUE, and the function can still print the original value.
+   LEFT_SIZE and RIGHT_SIZE specify the size of the argument in bytes,
+   for hexadecimal formatting.  */
+void support_test_compare_failure (const char *file, int line,
+                                   const char *left_expr,
+                                   long long left_value,
+                                   int left_positive,
+                                   int left_size,
+                                   const char *right_expr,
+                                   long long right_value,
+                                   int right_positive,
+                                   int right_size);
+
+
 /* Internal function called by the test driver.  */
 int support_report_failure (int status)
   __attribute__ ((weak, warn_unused_result));
index 55895ace3c7f83681d3b041fb28b1765d6cd8fcd..91ad7c56bdacf8a0d74848212fab1f9627fcd803 100644 (file)
@@ -1,5 +1,5 @@
 /* Compare struct addrinfo values against a formatted string.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
@@ -20,6 +20,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <support/check.h>
 #include <support/format_nss.h>
 #include <support/run_diff.h>
index d2a31bed7b4bc3d760a12226589574390bde0222..6c1277bd670da5bf94f24b1d54a733205e209377 100644 (file)
@@ -1,5 +1,5 @@
 /* Check that a DNS packet buffer has the expected contents.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
@@ -20,6 +20,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <support/check.h>
 #include <support/format_nss.h>
 #include <support/run_diff.h>
index 890d672d501af9e28c9ed3120013ed230bde1260..56384f9b03ca419abd6388532bd652ce6f530da7 100644 (file)
@@ -1,5 +1,5 @@
 /* Compare struct hostent values against a formatted string.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
@@ -20,6 +20,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <support/check.h>
 #include <support/format_nss.h>
 #include <support/run_diff.h>
index daa3083fd108724ee0bc3924eadb6e5428827d27..cbcbfb14e52314c90154a2c656bef5e577792bb6 100644 (file)
@@ -1,5 +1,5 @@
 /* Compare struct netent values against a formatted string.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
@@ -20,6 +20,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <support/check.h>
 #include <support/format_nss.h>
 #include <support/run_diff.h>
index 2893f2c2957eb94b2ba51ef4de5174851e709bf9..6aa28fa24e948c2fb87aba18e8a236dbaac42874 100644 (file)
@@ -1,5 +1,5 @@
 /* Test verification functions for NSS- and DNS-related data.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 67442f95df3f4e9b1849bec7f8f783a91e286401..2780d9a6fe61ac5e4b04547ad9c13e1259809cd1 100644 (file)
@@ -1,5 +1,5 @@
 /* Time-triggered process termination.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index fb4597c2384d70a1d5d4a1973133bcb46dc20130..e55354e788313587ee0d836d54482379e59d4222 100644 (file)
@@ -1,5 +1,5 @@
 /* String formatting functions for NSS- and DNS-related data.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 7b77a2cd56828f9f9b01891fdf5acb9de43b3db2..450333ad38a6223311875f4b1e17b8249434363a 100644 (file)
@@ -1,5 +1,5 @@
 /* Avoid all the buffer overflow messages on stderr.
-   Copyright (C) 2015-2017 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
index 9eddb1a0e904170d2b2f0128520e89267f496bed..3c3842a49bb2880cd0881675df9398676cae90b0 100644 (file)
@@ -1,5 +1,5 @@
 /* Entering namespaces for test case isolation.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
@@ -51,6 +51,11 @@ bool support_can_chroot (void);
    has sufficient privileges.  */
 bool support_enter_network_namespace (void);
 
+/* Enter a mount namespace and mark / as private (not shared).  If
+   this function returns true, mount operations in this process will
+   not affect the host system afterwards.  */
+bool support_enter_mount_namespace (void);
+
 /* Return true if support_enter_network_namespace managed to enter a
    UTS namespace.  */
 bool support_in_uts_namespace (void);
diff --git a/support/next_to_fault.c b/support/next_to_fault.c
new file mode 100644 (file)
index 0000000..1971bf7
--- /dev/null
@@ -0,0 +1,52 @@
+/* Memory allocation next to an unmapped page.
+   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 <support/check.h>
+#include <support/next_to_fault.h>
+#include <support/xunistd.h>
+#include <sys/mman.h>
+#include <sys/param.h>
+
+struct support_next_to_fault
+support_next_to_fault_allocate (size_t size)
+{
+  long page_size = sysconf (_SC_PAGE_SIZE);
+  TEST_VERIFY_EXIT (page_size > 0);
+  struct support_next_to_fault result;
+  result.region_size = roundup (size, page_size) + page_size;
+  if (size + page_size <= size || result.region_size <= size)
+    FAIL_EXIT1 ("support_next_to_fault_allocate (%zu): overflow", size);
+  result.region_start
+    = xmmap (NULL, result.region_size, PROT_READ | PROT_WRITE,
+             MAP_PRIVATE | MAP_ANONYMOUS, -1);
+  /* Unmap the page after the allocation.  */
+  xmprotect (result.region_start + (result.region_size - page_size),
+             page_size, PROT_NONE);
+  /* Align the allocation within the region so that it ends just
+     before the PROT_NONE page.  */
+  result.buffer = result.region_start + result.region_size - page_size - size;
+  result.length = size;
+  return result;
+}
+
+void
+support_next_to_fault_free (struct support_next_to_fault *ntf)
+{
+  xmunmap (ntf->region_start, ntf->region_size);
+  *ntf = (struct support_next_to_fault) { NULL, };
+}
diff --git a/support/next_to_fault.h b/support/next_to_fault.h
new file mode 100644 (file)
index 0000000..75759b5
--- /dev/null
@@ -0,0 +1,48 @@
+/* Memory allocation next to an unmapped page.
+   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/>.  */
+
+#ifndef SUPPORT_NEXT_TO_FAULT_H
+#define SUPPORT_NEXT_TO_FAULT_H
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+__BEGIN_DECLS
+
+/* The memory region created by next_to_fault_allocate.  */
+struct support_next_to_fault
+{
+  /* The user data.  */
+  char *buffer;
+  size_t length;
+
+  /* The entire allocated region.  */
+  void *region_start;
+  size_t region_size;
+};
+
+/* Allocate a buffer of SIZE bytes just before a page which is mapped
+   with PROT_NONE (so that overrunning the buffer will cause a
+   fault).  */
+struct support_next_to_fault support_next_to_fault_allocate (size_t size);
+
+/* Deallocate the memory region allocated by
+   next_to_fault_allocate.  */
+void support_next_to_fault_free (struct support_next_to_fault *);
+
+#endif /* SUPPORT_NEXT_TO_FAULT_H */
index 78169782736a76271c8be9c602d3cb049c209c3c..fd87fe23059ba61d474982c93df8f3606566c771 100644 (file)
@@ -1,5 +1,5 @@
 /* Reporting out-of-memory errors.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 1625dcf43a204434d395a6fbf8524d06c5f403fc..3f2a09f36f44587838abe05d3257feb8de353e08 100644 (file)
@@ -1,5 +1,5 @@
 /* DNS test framework and libresolv redirection.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
@@ -43,15 +43,99 @@ enum
     max_response_length = 65536
   };
 
-/* List of pointers to be freed.  The hash table implementation
-   (struct hsearch_data) does not provide a way to deallocate all
-   objects, so this approach is used to avoid memory leaks.  */
-struct to_be_freed
+/* Used for locating domain names containing for the purpose of
+   forming compression references.  */
+struct compressed_name
 {
-  struct to_be_freed *next;
-  void *ptr;
+  uint16_t offset;
+  unsigned char length;
+  unsigned char name[];         /* Without terminating NUL.  */
 };
 
+static struct compressed_name *
+allocate_compressed_name (const unsigned char *encoded, unsigned int offset)
+{
+  /* Compute the length of the domain name.  */
+  size_t length;
+  {
+    const unsigned char *p;
+    for (p = encoded; *p != '\0';)
+      {
+        /* No compression references are allowed.  */
+        TEST_VERIFY (*p <= 63);
+        /* Skip over the label.  */
+        p += 1 + *p;
+      }
+    length = p - encoded;
+    ++length;                   /* For the terminating NUL byte.  */
+  }
+  TEST_VERIFY_EXIT (length <= 255);
+
+  struct compressed_name *result
+    = xmalloc (offsetof (struct compressed_name, name) + length);
+  result->offset = offset;
+  result->length = length;
+  memcpy (result->name, encoded, length);
+  return result;
+}
+
+/* Convert CH to lower case.  Only change letters in the ASCII
+   range.  */
+static inline unsigned char
+ascii_tolower (unsigned char ch)
+{
+  if ('A' <= ch && ch <= 'Z')
+    return ch - 'A' + 'a';
+  else
+    return ch;
+}
+
+/* Compare both names, for use with tsearch.  The order is arbitrary,
+   but the comparison is case-insenstive.  */
+static int
+compare_compressed_name (const void *left, const void *right)
+{
+  const struct compressed_name *crleft = left;
+  const struct compressed_name *crright = right;
+
+  if (crleft->length != crright->length)
+    /* The operands are converted to int before the subtraction.  */
+    return crleft->length - crright->length;
+
+  const unsigned char *nameleft = crleft->name;
+  const unsigned char *nameright = crright->name;
+
+  while (true)
+    {
+      int lenleft = *nameleft++;
+      int lenright = *nameright++;
+
+      /* Labels must not e compression references.  */
+      TEST_VERIFY (lenleft <= 63);
+      TEST_VERIFY (lenright <= 63);
+
+      if (lenleft != lenright)
+        return left - right;
+      if (lenleft == 0)
+        /* End of name reached without spotting a difference.  */
+        return 0;
+      /* Compare the label in a case-insenstive manner.  */
+      const unsigned char *endnameleft = nameleft + lenleft;
+      while (nameleft < endnameleft)
+        {
+          int l = *nameleft++;
+          int r = *nameright++;
+          if (l != r)
+            {
+              l = ascii_tolower (l);
+              r = ascii_tolower (r);
+              if (l != r)
+                return l - r;
+            }
+        }
+    }
+}
+
 struct resolv_response_builder
 {
   const unsigned char *query_buffer;
@@ -67,11 +151,8 @@ struct resolv_response_builder
      written RDATA sub-structure.  0 if no RDATA is being written.  */
   size_t current_rdata_offset;
 
-  /* Hash table for locating targets for label compression.  */
-  struct hsearch_data compression_offsets;
-  /* List of pointers which need to be freed.  Used for domain names
-     involved in label compression.  */
-  struct to_be_freed *to_be_freed;
+  /* tsearch tree for locating targets for label compression.  */
+  void *compression_offsets;
 
   /* Must be last.  Not zeroed for performance reasons.  */
   unsigned char buffer[max_response_length];
@@ -79,18 +160,6 @@ struct resolv_response_builder
 
 /* Response builder. */
 
-/* Add a pointer to the list of pointers to be freed when B is
-   deallocated.  */
-static void
-response_push_pointer_to_free (struct resolv_response_builder *b, void *ptr)
-{
-  if (ptr == NULL)
-    return;
-  struct to_be_freed *e = xmalloc (sizeof (*e));
-  *e = (struct to_be_freed) {b->to_be_freed, ptr};
-  b->to_be_freed = e;
-}
-
 void
 resolv_response_init (struct resolv_response_builder *b,
                       struct resolv_response_flags flags)
@@ -194,120 +263,88 @@ void
 resolv_response_add_name (struct resolv_response_builder *b,
                           const char *const origname)
 {
-  /* Normalized name.  */
-  char *name;
-  /* Normalized name with case preserved.  */
-  char *name_case;
-  {
-    size_t namelen = strlen (origname);
-    /* Remove trailing dots.  FIXME: Handle trailing quoted dots.  */
-    while (namelen > 0 && origname[namelen - 1] == '.')
-      --namelen;
-    name = xmalloc (namelen + 1);
-    name_case = xmalloc (namelen + 1);
-    /* Copy and convert to lowercase.  FIXME: This needs to normalize
-       escaping as well.  */
-    for (size_t i = 0; i < namelen; ++i)
-      {
-        char ch = origname[i];
-        name_case[i] = ch;
-        if ('A' <= ch && ch <= 'Z')
-          ch = ch - 'A' + 'a';
-        name[i] = ch;
-      }
-    name[namelen] = 0;
-    name_case[namelen] = 0;
-  }
-  char *name_start = name;
-  char *name_case_start = name_case;
+  unsigned char encoded_name[NS_MAXDNAME];
+  if (ns_name_pton (origname, encoded_name, sizeof (encoded_name)) < 0)
+    FAIL_EXIT1 ("ns_name_pton (\"%s\"): %m", origname);
 
-  bool compression = false;
-  while (*name)
+  /* Copy the encoded name into the output buffer, apply compression
+     where possible.  */
+  for (const unsigned char *name = encoded_name; ;)
     {
-      /* Search for a previous name we can reference.  */
-      ENTRY new_entry =
+      if (*name == '\0')
         {
-          .key = name,
-          .data = (void *) (uintptr_t) b->offset,
-        };
+          /* We have reached the end of the name.  Add the terminating
+             NUL byte.  */
+          response_add_byte (b, '\0');
+          break;
+        }
 
-      /* If the label can be a compression target because it is at a
-         reachable offset, add it to the hash table.  */
-      ACTION action;
-      if (b->offset < (1 << 12))
-        action = ENTER;
-      else
-        action = FIND;
+      /* Set to the compression target if compression is possible.  */
+      struct compressed_name *crname_target;
 
-      /* Search for known compression offsets in the hash table.  */
-      ENTRY *e;
-      if (hsearch_r (new_entry, action, &e, &b->compression_offsets) == 0)
-        {
-          if (action == FIND && errno == ESRCH)
-            /* Fall through.  */
-            e = NULL;
-          else
-            FAIL_EXIT1 ("hsearch_r failure in name compression: %m");
-        }
+      /* Compression references can only reach the beginning of the
+         packet.  */
+      enum { compression_limit = 1 << 12 };
+
+      {
+        /* The trailing part of the name to be looked up in the tree
+           with the compression targets.  */
+        struct compressed_name *crname
+          = allocate_compressed_name (name, b->offset);
+
+        if (b->offset < compression_limit)
+          {
+            /* Add the name to the tree, for future compression
+               references.  */
+            void **ptr = tsearch (crname, &b->compression_offsets,
+                                  compare_compressed_name);
+            if (ptr == NULL)
+              FAIL_EXIT1 ("tsearch out of memory");
+            crname_target = *ptr;
+
+            if (crname_target != crname)
+              /* The new name was not actually added to the tree.
+                 Deallocate it.  */
+              free (crname);
+            else
+              /* Signal that the tree did not yet contain the name,
+                 but keep the allocation because it is now part of the
+                 tree.  */
+              crname_target = NULL;
+          }
+        else
+          {
+            /* This name cannot be reached by a compression reference.
+               No need to add it to the tree for future reference.  */
+            void **ptr = tfind (crname, &b->compression_offsets,
+                                compare_compressed_name);
+            if (ptr != NULL)
+              crname_target = *ptr;
+            else
+              crname_target = NULL;
+            TEST_VERIFY (crname_target != crname);
+            /* Not added to the tree.  */
+            free (crname);
+          }
+      }
 
-      /* The name is known.  Reference the previous location.  */
-      if (e != NULL && e->data != new_entry.data)
+      if (crname_target != NULL)
         {
-          size_t old_offset = (uintptr_t) e->data;
+          /* The name is known.  Reference the previous location.  */
+          unsigned int old_offset = crname_target->offset;
+          TEST_VERIFY_EXIT (old_offset < compression_limit);
           response_add_byte (b, 0xC0 | (old_offset >> 8));
           response_add_byte (b, old_offset);
-          compression = true;
           break;
         }
-
-      /* The name does not exist yet.  Write one label.  First, add
-         room for the label length.  */
-      size_t buffer_label_offset = b->offset;
-      response_add_byte (b, 0);
-
-      /* Copy the label.  */
-      while (true)
+      else
         {
-          char ch = *name_case;
-          if (ch == '\0')
-            break;
-          ++name;
-          ++name_case;
-          if (ch == '.')
-            break;
-          /* FIXME: Handle escaping.  */
-          response_add_byte (b, ch);
+          /* The name is new.  Add this label.  */
+          unsigned int len = 1 + *name;
+          resolv_response_add_data (b, name, len);
+          name += len;
         }
-
-      /* Patch in the label length.  */
-      size_t label_length = b->offset - buffer_label_offset - 1;
-      if (label_length == 0)
-        FAIL_EXIT1 ("empty label in name compression: %s", origname);
-      if (label_length > 63)
-        FAIL_EXIT1 ("label too long in name compression: %s", origname);
-      b->buffer[buffer_label_offset] = label_length;
-
-      /* Continue with the tail of the name and the next label.  */
-    }
-
-  if (compression)
-    {
-      /* If we found an immediate match for the name, we have not put
-         it into the hash table, and can free it immediately.  */
-      if (name == name_start)
-        free (name_start);
-      else
-        response_push_pointer_to_free (b, name_start);
-    }
-  else
-    {
-      /* Terminate the sequence of labels.  With compression, this is
-         implicit in the compression reference.  */
-      response_add_byte (b, 0);
-      response_push_pointer_to_free (b, name_start);
     }
-
-  free (name_case_start);
 }
 
 void
@@ -403,22 +440,13 @@ response_builder_allocate
   memset (b, 0, offsetof (struct resolv_response_builder, buffer));
   b->query_buffer = query_buffer;
   b->query_length = query_length;
-  TEST_VERIFY_EXIT (hcreate_r (10000, &b->compression_offsets) != 0);
   return b;
 }
 
 static void
 response_builder_free (struct resolv_response_builder *b)
 {
-  struct to_be_freed *current = b->to_be_freed;
-  while (current != NULL)
-    {
-      struct to_be_freed *next = current->next;
-      free (current->ptr);
-      free (current);
-      current = next;
-    }
-  hdestroy_r (&b->compression_offsets);
+  tdestroy (b->compression_offsets, free);
   free (b);
 }
 
index b953dc12000742465b75a2092f95c92718318ab5..4c2e6c1b417f5fcd7d3b5113f66c633e9105afc3 100644 (file)
@@ -1,5 +1,5 @@
 /* DNS test framework and libresolv redirection.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index f65b5dd22cf33327d26b8285b5d37f4461099a9c..6e949226fa4fed75bd8095715d3f0fb24053c83b 100644 (file)
@@ -1,5 +1,5 @@
 /* Invoke the system diff tool to compare two strings.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index f434a8082a2b1149a8ac136ac99701c4d04de9e7..c2dacbb179fb96beb1bfb47cdf9af06382aaf0be 100644 (file)
@@ -1,5 +1,5 @@
 /* Set signal handler for use in fortify tests.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
diff --git a/support/support-xfstat.c b/support/support-xfstat.c
new file mode 100644 (file)
index 0000000..f69253a
--- /dev/null
@@ -0,0 +1,28 @@
+/* fstat64 with error checking.
+   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 <support/check.h>
+#include <support/xunistd.h>
+#include <sys/stat.h>
+
+void
+xfstat (int fd, struct stat64 *result)
+{
+  if (fstat64 (fd, result) != 0)
+    FAIL_EXIT1 ("fstat64 (%d): %m", fd);
+}
index 86a81ec60153ae32e38523a86998755b996bec1d..fc10c6dcb781e6f11cd641835d71f603aa4ed3bd 100644 (file)
@@ -1,5 +1,5 @@
 /* stat64 with error checking.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index 4b5f04c2ccc2c419d5f77d685c5a6a24dc30c674..bc5827ed87d0d96c0a16d64fed1e90f319ea4f77 100644 (file)
@@ -1,5 +1,5 @@
 /* Common extra functions.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
@@ -68,6 +68,7 @@ void *xrealloc (void *p, size_t n);
 char *xasprintf (const char *format, ...)
   __attribute__ ((format (printf, 1, 2), malloc));
 char *xstrdup (const char *);
+char *xstrndup (const char *, size_t);
 
 __END_DECLS
 
index 3fa0bd4ac05036950c15ffcfa64da45b0981714f..6947dbaa8077913cb24df872df260b9b07ac61e2 100644 (file)
@@ -1,5 +1,5 @@
 /* Acquire root privileges.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
 
 #include <support/namespace.h>
 
+#include <errno.h>
+#include <fcntl.h>
 #include <sched.h>
 #include <stdio.h>
+#include <string.h>
+#include <support/check.h>
+#include <support/xunistd.h>
 #include <unistd.h>
 
+#ifdef CLONE_NEWUSER
+/* The necessary steps to allow file creation in user namespaces.  */
+static void
+setup_uid_gid_mapping (uid_t original_uid, gid_t original_gid)
+{
+  int fd = open64 ("/proc/self/uid_map", O_WRONLY);
+  if (fd < 0)
+    {
+      printf ("warning: could not open /proc/self/uid_map: %m\n"
+              "warning: file creation may not be possible\n");
+      return;
+    }
+
+  /* We map our original UID to the same UID in the container so we
+     own our own files normally.  Without that, file creation could
+     fail with EOVERFLOW (sic!).  */
+  char buf[100];
+  int ret = snprintf (buf, sizeof (buf), "%llu %llu 1\n",
+                      (unsigned long long) original_uid,
+                      (unsigned long long) original_uid);
+  TEST_VERIFY_EXIT (ret < sizeof (buf));
+  xwrite (fd, buf, ret);
+  xclose (fd);
+
+  /* Linux 3.19 introduced the setgroups file.  We need write "deny" to this
+     file otherwise writing to gid_map will fail with EPERM.  */
+  fd = open64 ("/proc/self/setgroups", O_WRONLY, 0);
+  if (fd < 0)
+    {
+      if (errno != ENOENT)
+        FAIL_EXIT1 ("open64 (\"/proc/self/setgroups\", 0x%x, 0%o): %m",
+                    O_WRONLY, 0);
+      /* This kernel doesn't expose the setgroups file so simply move on.  */
+    }
+  else
+    {
+      xwrite (fd, "deny\n", strlen ("deny\n"));
+      xclose (fd);
+    }
+
+  /* Now map our own GID, like we did for the user ID.  */
+  fd = xopen ("/proc/self/gid_map", O_WRONLY, 0);
+  ret = snprintf (buf, sizeof (buf), "%llu %llu 1\n",
+                  (unsigned long long) original_gid,
+                  (unsigned long long) original_gid);
+  TEST_VERIFY_EXIT (ret < sizeof (buf));
+  xwrite (fd, buf, ret);
+  xclose (fd);
+}
+#endif /* CLONE_NEWUSER */
+
 bool
 support_become_root (void)
 {
 #ifdef CLONE_NEWUSER
+  uid_t original_uid = getuid ();
+  gid_t original_gid = getgid ();
+
   if (unshare (CLONE_NEWUSER | CLONE_NEWNS) == 0)
-    /* Even if we do not have UID zero, we have extended privileges at
-       this point.  */
-    return true;
+    {
+      setup_uid_gid_mapping (original_uid, original_gid);
+      /* Even if we do not have UID zero, we have extended privileges at
+         this point.  */
+      return true;
+    }
 #endif
   if (setuid (0) != 0)
     {
index 0dfd2deb543176e2e4725f7c65558c7a2dd60941..8922576d19a2781395021641cf7580b6427ffcab 100644 (file)
@@ -1,5 +1,5 @@
 /* Return true if the process can perform a chroot operation.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
@@ -21,9 +21,9 @@
 #include <support/check.h>
 #include <support/namespace.h>
 #include <support/support.h>
+#include <support/xunistd.h>
 #include <sys/stat.h>
 #include <unistd.h>
-#include <xunistd.h>
 
 static void
 callback (void *closure)
index 030f12425260833a3e54f3ecb16cd1e19ecb1cba..6d2029e13bd6ae73dd3ef55592e7246446a7a102 100644 (file)
@@ -1,5 +1,5 @@
 /* Capture output from a subprocess.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index e1cf73b6a578156d8eec2fdddf1c685dd10bd8ec..ff5ee89fb02599ae5206f21745046dd8f888ed42 100644 (file)
@@ -1,5 +1,5 @@
 /* Verify capture output from a subprocess.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index f3ef551b053cba2c8f88ba4e07d1bc7f4cb9b772..6356b1af6cf410e4e324b247924c61f1e94d6553 100644 (file)
@@ -1,5 +1,5 @@
 /* Setup a chroot environment for use within tests.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
@@ -45,11 +45,7 @@ struct support_chroot *
 support_chroot_create (struct support_chroot_configuration conf)
 {
   struct support_chroot *chroot = xmalloc (sizeof (*chroot));
-
-  chroot->path_chroot = xasprintf ("%s/tst-resolv-res_init-XXXXXX", test_dir);
-  if (mkdtemp (chroot->path_chroot) == NULL)
-    FAIL_EXIT1 ("mkdtemp (\"%s\"): %m", chroot->path_chroot);
-  add_temp_file (chroot->path_chroot);
+  chroot->path_chroot = support_create_temp_directory ("tst-resolv-res_init-");
 
   /* Create the /etc directory in the chroot environment.  */
   char *path_etc = xasprintf ("%s/etc", chroot->path_chroot);
diff --git a/support/support_enter_mount_namespace.c b/support/support_enter_mount_namespace.c
new file mode 100644 (file)
index 0000000..ba68e99
--- /dev/null
@@ -0,0 +1,47 @@
+/* Enter a mount namespace.
+   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 <support/namespace.h>
+
+#include <sched.h>
+#include <stdio.h>
+#ifdef CLONE_NEWNS
+# include <sys/mount.h>
+#endif /* CLONE_NEWNS */
+
+bool
+support_enter_mount_namespace (void)
+{
+#ifdef CLONE_NEWNS
+  if (unshare (CLONE_NEWNS) == 0)
+    {
+      /* On some systems, / is marked as MS_SHARED, which means that
+         mounts within the namespace leak to the rest of the system,
+         which is not what we want.  */
+      if (mount ("none", "/", NULL, MS_REC | MS_PRIVATE, NULL) != 0)
+        {
+          printf ("warning: making the mount namespace private failed: %m\n");
+          return false;
+        }
+      return true;
+    }
+  else
+    printf ("warning: unshare (CLONE_NEWNS) failed: %m\n");
+#endif /* CLONE_NEWNS */
+  return false;
+}
index 28b0ee29cffe00e44ba09ff57f65f2f3ed253c78..1d874df8854eca4cf757e3bb2ea71583fcea8cb4 100644 (file)
@@ -1,5 +1,5 @@
 /* Enter a network namespace.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 5d42c42a4537782099309ed0304b08264189cc34..2acb9afffd4016e13327eb7515b0aeeacc4a47d2 100644 (file)
@@ -1,5 +1,5 @@
 /* Convert an address family to a string.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index eedb0305911a46afbe5183fc7f82e83987e2fb2a..c5e00e516a8279f7a9a4656d0be91ed41bc029fe 100644 (file)
@@ -1,5 +1,5 @@
 /* Convert struct addrinfo values to a string.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
@@ -21,6 +21,7 @@
 #include <arpa/inet.h>
 #include <errno.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <support/support.h>
 #include <support/xmemstream.h>
 
index 2992c579717e19da3ce24055b6d5de131c10e3c0..1170eafb0f008fee85a823850839e9a05fd5165a 100644 (file)
@@ -1,5 +1,5 @@
 /* Convert a DNS packet to a human-readable representation.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
@@ -20,6 +20,7 @@
 
 #include <arpa/inet.h>
 #include <resolv.h>
+#include <stdbool.h>
 #include <support/check.h>
 #include <support/support.h>
 #include <support/xmemstream.h>
index 493d6ae962be1a5575fdf7dd60d4321a2e25981f..3d2dc8b27a59540eb5c99763dc5d25adff8b3f49 100644 (file)
@@ -1,5 +1,5 @@
 /* Convert a h_errno error code to a string.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 88c85ec1f1f31e450528f5644d49cdfa43c9b027..a4a62afe0a23c02c5b6b4d0e5e99bf820b75e9af 100644 (file)
@@ -1,5 +1,5 @@
 /* Convert a struct hostent object to a string.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
@@ -21,6 +21,7 @@
 #include <arpa/inet.h>
 #include <errno.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <support/support.h>
 #include <support/xmemstream.h>
 
index 020f5720d92b052dc649a9e80e5e2622be7170b4..0d15e784401005a1bd734c16d1a71f9735c27b67 100644 (file)
@@ -1,5 +1,5 @@
 /* Convert a struct netent object to a string.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
@@ -20,6 +20,7 @@
 
 #include <arpa/inet.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <support/support.h>
 #include <support/xmemstream.h>
 
index cf4861438303454e73576561931b2300cfa1b4ac..25edc003852d16591240df5ec4739ec6b4841588 100644 (file)
@@ -1,5 +1,5 @@
 /* Run a function in a subprocess.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index 684055c7467dc7b03e5b331cc3b4570ce1053607..356798f55608ca7116be84aa6c76ff62d0b1732b 100644 (file)
@@ -1,5 +1,5 @@
 /* Global test failure counter.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index f5155de72749cacd89e780ab0c654a37f5dffa6a..f24f6c328110f8051f33a7356ea8487f00338fd2 100644 (file)
@@ -1,5 +1,5 @@
 /* Invoke the system diff tool to compare two strings.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 61d088e8cf5171be06a5eb6f8d5394cdfa20943a..8ab43c4b380f59e8bbdcc14b5453b1a41f09c57a 100644 (file)
@@ -1,5 +1,5 @@
 /* Allocate a memory region shared across processes.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
diff --git a/support/support_test_compare_failure.c b/support/support_test_compare_failure.c
new file mode 100644 (file)
index 0000000..8eb51c4
--- /dev/null
@@ -0,0 +1,58 @@
+/* Reporting a numeric comparison failure.
+   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 <errno.h>
+#include <stdio.h>
+#include <support/check.h>
+
+static void
+report (const char *which, const char *expr, long long value, int positive,
+        int size)
+{
+  printf ("  %s: ", which);
+  if (positive)
+    printf ("%llu", (unsigned long long) value);
+  else
+    printf ("%lld", value);
+  unsigned long long mask
+    = (~0ULL) >> (8 * (sizeof (unsigned long long) - size));
+  printf (" (0x%llx); from: %s\n", (unsigned long long) value & mask, expr);
+}
+
+void
+support_test_compare_failure (const char *file, int line,
+                              const char *left_expr,
+                              long long left_value,
+                              int left_positive,
+                              int left_size,
+                              const char *right_expr,
+                              long long right_value,
+                              int right_positive,
+                              int right_size)
+{
+  int saved_errno = errno;
+  support_record_failure ();
+  if (left_size != right_size)
+    printf ("%s:%d: numeric comparison failure (widths %d and %d)\n",
+            file, line, left_size * 8, right_size * 8);
+  else
+    printf ("%s:%d: numeric comparison failure\n", file, line);
+  report (" left", left_expr, left_value, left_positive, left_size);
+  report ("right", right_expr, right_value, right_positive, right_size);
+  errno = saved_errno;
+}
index 3c411a467b04f4dec279ddb84841d1d2f6d56e70..396385729b6809adf4d06a2e26e5a76b33508e03 100644 (file)
@@ -1,5 +1,5 @@
 /* Main worker function for the test driver.
-   Copyright (C) 1998-2017 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
index 55ab2111b3d0d7dcb032f8483d18cb1d45b12513..5ff5555a6a6cce32380913ccb50c907eb2ac0f51 100644 (file)
@@ -1,5 +1,5 @@
 /* Implementation of the TEST_VERIFY and TEST_VERIFY_EXIT macros.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
 
 #include <support/check.h>
 
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 
 void
 support_test_verify_impl (const char *file, int line, const char *expr)
 {
+  int saved_errno = errno;
   support_record_failure ();
   printf ("error: %s:%d: not true: %s\n", file, line, expr);
+  errno = saved_errno;
 }
 
 void
index 48e89597f39f8aefaaa440213d236220360161e7..7505679401ed8c07ac4600db5e3b8594bd14ecfd 100644 (file)
@@ -1,5 +1,5 @@
 /* Write a string to a file.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
@@ -19,7 +19,7 @@
 #include <fcntl.h>
 #include <string.h>
 #include <support/check.h>
-#include <xunistd.h>
+#include <support/xunistd.h>
 
 void
 support_write_file_string (const char *path, const char *contents)
index fb6cceb0658b10a691448ee1cc75e9bb399db35a..4cee3c0c35458aa2ab342bc6c31a5ac2ca3056af 100644 (file)
@@ -1,5 +1,5 @@
 /* Internal weak declarations for temporary file handling.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index fdb2477ab9e7dd3fe8851a2968a36ea75ec96c75..0bbc7f997264f75813ecfa2e7e3e4ac33487a8fd 100644 (file)
@@ -1,5 +1,5 @@
 /* Temporary file handling for tests.
-   Copyright (C) 1998-2017 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
@@ -86,6 +86,19 @@ create_temp_file (const char *base, char **filename)
   return fd;
 }
 
+char *
+support_create_temp_directory (const char *base)
+{
+  char *path = xasprintf ("%s/%sXXXXXX", test_dir, base);
+  if (mkdtemp (path) == NULL)
+    {
+      printf ("error: mkdtemp (\"%s\"): %m", path);
+      exit (1);
+    }
+  add_temp_file (path);
+  return path;
+}
+
 /* Helper functions called by the test skeleton follow.  */
 
 void
index 6fed8df1ea51b85287d7b17b1b9d035b0cb9ac2c..c7795cc577ca22a95bf44a3e193dbe496b5aaa8c 100644 (file)
@@ -1,5 +1,5 @@
 /* Declarations for temporary file handling.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
@@ -32,6 +32,11 @@ void add_temp_file (const char *name);
    *FILENAME.  */
 int create_temp_file (const char *base, char **filename);
 
+/* Create a temporary directory and schedule it for deletion.  BASE is
+   used as a prefix for the unique directory name, which the function
+   returns.  The caller should free this string.  */
+char *support_create_temp_directory (const char *base);
+
 __END_DECLS
 
 #endif /* SUPPORT_TEMP_FILE_H */
index 47c387c2b485bc8415a17b1ce56fb6f49769a58d..09c8783e4f54d8094d6827aba704a55a23c8fb7e 100644 (file)
@@ -1,5 +1,5 @@
 /* Main function for test programs.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index a8fe9c3565cddbe3b4fe054202742acafbc43179..1708d68d608ee4a497bcfcf95ef8ca3518ec53e3 100644 (file)
@@ -1,5 +1,5 @@
 /* Interfaces for the test driver.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index dbe7cc07c8f8aaa4eb4701362468c5754cffaa7a..e20423c4a30cb8b1d1f4bebfbb410ae644f4133c 100644 (file)
@@ -1,5 +1,5 @@
 /* Test entering namespaces.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 5672fba0f7f4d94c2eebe05d659dc1f25b6b55c0..a68525609147676858c139a57f03783c74963646 100644 (file)
@@ -1,5 +1,5 @@
 /* Test capturing output from a subprocess.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index 9c8589c09c1949154b5e1da0cc3ca5d77c3bc953..b1135eebc6c02d55210fa4bfa859d173d32cb4b9 100644 (file)
@@ -1,5 +1,5 @@
 /* Tests for the support_format_dns_packet function.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 2c9372cc2916220e963baba0cc3e09105648e2c6..09cd96290a014b7e03e13e9ec9a23978233675a9 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/sh
 # Test failure recording (with and without --direct).
-# Copyright (C) 2016-2017 Free Software Foundation, Inc.
+# 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
index e739e739c399cb94449449bd14a465f23b4becc3..8757f2da029d5abeaf59c4a0982ce440dd9b2cb4 100644 (file)
@@ -1,5 +1,5 @@
 /* Test support_record_failure state sharing.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
diff --git a/support/tst-test_compare.c b/support/tst-test_compare.c
new file mode 100644 (file)
index 0000000..123ba1b
--- /dev/null
@@ -0,0 +1,116 @@
+/* Basic test for the TEST_COMPARE macro.
+   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 <string.h>
+#include <support/check.h>
+#include <support/capture_subprocess.h>
+
+static void
+subprocess (void *closure)
+{
+  char ch = 1;
+  /* These tests should fail.  */
+  TEST_COMPARE (ch, -1);         /* Line 28.  */
+  TEST_COMPARE (2LL, -2LL);      /* Line 29.  */
+  TEST_COMPARE (3LL, (short) -3); /* Line 30.  */
+}
+
+struct bitfield
+{
+  int i2 : 2;
+  int i3 : 3;
+  unsigned int u2 : 2;
+  unsigned int u3 : 3;
+  int i31 : 31;
+  unsigned int u31 : 31 ;
+  long long int i63 : 63;
+  unsigned long long int u63 : 63;
+};
+
+/* Functions which return signed sizes are common, so test that these
+   results can readily checked using TEST_COMPARE.  */
+
+static int
+return_ssize_t (void)
+{
+  return 4;
+}
+
+static int
+return_int (void)
+{
+  return 4;
+}
+
+
+static int
+do_test (void)
+{
+  /* This should succeed.  */
+  TEST_COMPARE (1, 1);
+  TEST_COMPARE (2LL, 2U);
+  {
+    char i8 = 3;
+    unsigned short u16 = 3;
+    TEST_COMPARE (i8, u16);
+  }
+  TEST_COMPARE (return_ssize_t (), sizeof (char[4]));
+  TEST_COMPARE (return_int (), sizeof (char[4]));
+
+  struct bitfield bitfield = { 0 };
+  TEST_COMPARE (bitfield.i2, bitfield.i3);
+  TEST_COMPARE (bitfield.u2, bitfield.u3);
+  TEST_COMPARE (bitfield.u2, bitfield.i3);
+  TEST_COMPARE (bitfield.u3, bitfield.i3);
+  TEST_COMPARE (bitfield.i2, bitfield.u3);
+  TEST_COMPARE (bitfield.i3, bitfield.u2);
+  TEST_COMPARE (bitfield.i63, bitfield.i63);
+  TEST_COMPARE (bitfield.u63, bitfield.u63);
+  TEST_COMPARE (bitfield.i31, bitfield.i63);
+  TEST_COMPARE (bitfield.i63, bitfield.i31);
+
+  struct support_capture_subprocess proc = support_capture_subprocess
+    (&subprocess, NULL);
+
+  /* Discard the reported error.  */
+  support_record_failure_reset ();
+
+  puts ("info: *** subprocess output starts ***");
+  fputs (proc.out.buffer, stdout);
+  puts ("info: *** subprocess output ends ***");
+
+  TEST_VERIFY
+    (strcmp (proc.out.buffer,
+             "tst-test_compare.c:28: numeric comparison failure\n"
+             "   left: 1 (0x1); from: ch\n"
+             "  right: -1 (0xffffffff); from: -1\n"
+             "tst-test_compare.c:29: numeric comparison failure\n"
+             "   left: 2 (0x2); from: 2LL\n"
+             "  right: -2 (0xfffffffffffffffe); from: -2LL\n"
+             "tst-test_compare.c:30: numeric comparison failure"
+             " (widths 64 and 32)\n"
+             "   left: 3 (0x3); from: 3LL\n"
+             "  right: -3 (0xfffffffd); from: (short) -3\n") == 0);
+
+  /* Check that there is no output on standard error.  */
+  support_capture_subprocess_check (&proc, "TEST_COMPARE", 0, sc_allow_stdout);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/support/tst-xreadlink.c b/support/tst-xreadlink.c
new file mode 100644 (file)
index 0000000..b142207
--- /dev/null
@@ -0,0 +1,72 @@
+/* Test the xreadlink function.
+   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 <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <support/check.h>
+#include <support/support.h>
+#include <support/temp_file.h>
+#include <support/xunistd.h>
+
+static int
+do_test (void)
+{
+  char *dir = support_create_temp_directory ("tst-xreadlink-");
+  char *symlink_name = xasprintf ("%s/symlink", dir);
+  add_temp_file (symlink_name);
+
+  /* The limit 10000 is arbitrary and simply there to prevent an
+     attempt to exhaust all available disk space.  */
+  for (int size = 1; size < 10000; ++size)
+    {
+      char *contents = xmalloc (size + 1);
+      for (int i = 0; i < size; ++i)
+        contents[i] = 'a' + (rand () % 26);
+      contents[size] = '\0';
+      if (symlink (contents, symlink_name) != 0)
+        {
+          if (errno == ENAMETOOLONG)
+            {
+              printf ("info: ENAMETOOLONG failure at %d bytes\n", size);
+              free (contents);
+              break;
+            }
+          FAIL_EXIT1 ("symlink (%d bytes): %m", size);
+        }
+
+      char *readlink_result = xreadlink (symlink_name);
+      TEST_VERIFY (strcmp (readlink_result, contents) == 0);
+      free (readlink_result);
+      xunlink (symlink_name);
+      free (contents);
+    }
+
+  /* Create an empty file to suppress the temporary file deletion
+     warning.  */
+  xclose (xopen (symlink_name, O_WRONLY | O_CREAT, 0));
+
+  free (symlink_name);
+  free (dir);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
index f03ed931d6b0fdef192de057e40df6a06d468b9b..a3e2f90535aa87cfbcf344f81672a712b08ba0b9 100644 (file)
@@ -1,5 +1,5 @@
 /* Write a message to standard output.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
 
 #include <support/support.h>
 
+#include <errno.h>
 #include <string.h>
 #include <unistd.h>
 
 void
 write_message (const char *message)
 {
+  int saved_errno = errno;
   ssize_t unused __attribute__ ((unused));
   unused = write (STDOUT_FILENO, message, strlen (message));
+  errno = saved_errno;
 }
index 7b25af3b053206e47ca802fea8a75e72a551fced..fd65fc6c3af27e9f80785a7e40cade56d7e6882f 100644 (file)
@@ -1,5 +1,5 @@
 /* accept with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 67dd95e9fbbb3e1e0bd32350add0495bf1ca3fa3..ada3c92267e8bb19defec5ccfe99dc7f73e79dea 100644 (file)
@@ -1,5 +1,5 @@
 /* accept4 with error checking.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index 5157680fa25036f293a2ac36dfd5834de04ed432..e593ec5e82b7ec1411686e916d8d502dd271cad3 100644 (file)
@@ -1,5 +1,5 @@
 /* Error-checking wrapper for asprintf.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index cfc6dd8fa86fe8001d8c77416705e3108fa34686..938e7c07d6de3e29e46b3efeafb66d2b377c728c 100644 (file)
@@ -1,5 +1,5 @@
 /* bind with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 135f42dab2dabc4a1036795e735348733ae13e56..403569041f662243ea0f1f74c54622c4d9189547 100644 (file)
@@ -1,5 +1,5 @@
 /* Error-checking wrapper for calloc.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index abcc299e003b397f792946c92fb8b715d33c243e..d4759a1bd1f58d47c3ec9b0d6d6b4b7679a1364b 100644 (file)
@@ -1,5 +1,5 @@
 /* chroot with error checking.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index c931e084216c906dbb14ba03f5326c5baeceb5a6..702bef6c6eba1c75433d17812fcaada6bba8472a 100644 (file)
@@ -1,5 +1,5 @@
 /* close with error checking.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index 0266dbc643c827cff2711f9d43ef1394640b01ef..341805d80d802da682fd47dd446a06bafaba2732 100644 (file)
@@ -1,5 +1,5 @@
 /* connect with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 6e3979983d8cf3cd38a18e9cc1beda9bdf0bd99b..f34bb059c00f27f71bd9a160f965620c196dda6d 100644 (file)
@@ -1,5 +1,5 @@
 /* Support functionality for using dlopen/dlclose/dlsym.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
@@ -16,6 +16,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include <stddef.h>
 #include <support/check.h>
 #include <support/xdlfcn.h>
 
index 9bdcb38d3e230393ad0251b871e8777571581fc6..5ab7494e70924f52e6aa25979bb910100f024397 100644 (file)
@@ -1,5 +1,5 @@
 /* Support functionality for using dlopen/dlclose/dlsym.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index dc08c945182008ffe33bec6d09bdf9800479b8bf..b8c4c223fb7d532351be6f75cb931f4c820ad8b2 100644 (file)
@@ -1,5 +1,5 @@
 /* dup2 with error checking.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index 2737f0504495a7d80ff89240c88801d5c5097bb9..39d46f042a71791e86057e29316968f6a5b30a3f 100644 (file)
@@ -1,5 +1,5 @@
 /* fclose with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 14532a09f3c12332207b0e2dd0811de71dbc18ff..fb931cf22b45fe39f540de029a11dea648b6e179 100644 (file)
@@ -1,5 +1,5 @@
 /* fopen with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index aa52ba62c52cf80401492a11574705796b7f5147..dffa2a13d068656ebbc0871e1817667e69b0e515 100644 (file)
@@ -1,5 +1,5 @@
 /* fork with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
diff --git a/support/xftruncate.c b/support/xftruncate.c
new file mode 100644 (file)
index 0000000..27c7e12
--- /dev/null
@@ -0,0 +1,27 @@
+/* ftruncate with error checking.
+   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 <support/check.h>
+#include <support/xunistd.h>
+
+void
+xftruncate (int fd, long long length)
+{
+  if (ftruncate64 (fd, length) != 0)
+    FAIL_EXIT1 ("ftruncate64 (%d, %lld): %m", fd, length);
+}
index c3bd884f8dbeb685862e080a57311439441f5ce8..797194f79d813b4c0f077ad321f1b02f17285f5f 100644 (file)
@@ -1,5 +1,5 @@
 /* getsockname with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 1953e5900a930c16e127245d595bff712cf0d295..aa70091adb6a54069a592101c42c5b96c25b85cc 100644 (file)
@@ -1,5 +1,5 @@
 /* listen with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
diff --git a/support/xlseek.c b/support/xlseek.c
new file mode 100644 (file)
index 0000000..2422939
--- /dev/null
@@ -0,0 +1,29 @@
+/* lseek with error checking.
+   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 <support/check.h>
+#include <support/xunistd.h>
+
+long long
+xlseek (int fd, long long offset, int whence)
+{
+  long long result = lseek64 (fd, offset, whence);
+  if (result < 0)
+    FAIL_EXIT1 ("lseek64 (%d, %lld, %d): %m", fd, offset, whence);
+  return result;
+}
index 450f6997893eecb1ebf09a64d351d9f8256c953e..78317e2b127cd3d550187dafb2c17dbd5bc85976 100644 (file)
@@ -1,5 +1,5 @@
 /* Error-checking wrapper for malloc.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index bce6dc917002e5d98f5156197bc19c54be00f52d..df5fbc489a2d9b7411865b9fd0517c80db5a2322 100644 (file)
@@ -1,5 +1,5 @@
 /* Error-checking wrappers for memstream functions.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index e5ba231e4d59aaed87f2d628d2ec7d007874e11e..2d4a577f292232925b4dcd3b0633229058ff9346 100644 (file)
@@ -1,5 +1,5 @@
 /* Error-checking wrappers for memstream functions.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index ea17d49391866d3dc37bf74a9d11d7ff9a9210bc..7e67f783de6d3090dcec41fda31136a9e19060fa 100644 (file)
@@ -1,5 +1,5 @@
 /* mkdir with error checking.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index 435b1eb73334dea85e4eda6fd6135d5abea6edb3..d580c070138878ec8b5c6eeec63b9149a2e76156 100644 (file)
@@ -1,5 +1,5 @@
 /* mmap with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 9410251c3227a11b90bc7cddee09aba56454da1c..e6870988e0aa5add872a00f24991595ba7c896c2 100644 (file)
@@ -1,5 +1,5 @@
 /* mprotect with error checking.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index 6ef5a4a46823a7d63f40a2f3fefa122895f56046..e8e5bc2d598b3c94daf5ea90881195e7ee464c1f 100644 (file)
@@ -1,5 +1,5 @@
 /* munmap with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 7f033a03a7aad1791e1bb80fed6494cdff3f41cc..3d888e8862a91b6992062dd7aa98e8107653018b 100644 (file)
@@ -1,5 +1,5 @@
 /* open64 with error checking.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index 89a64a55c1ec96ef24fc7a0e14b6b037e9ca25a1..b8529df62085513b3118ffd5b8b5619aa96c9628 100644 (file)
@@ -1,5 +1,5 @@
 /* pipe with error checking.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index bec2521ffc44ca14d28f6ec4f5ed8c2e9c5a8c69..b24bf32fc5544136ba0dcce7780970f6be7dd7f3 100644 (file)
@@ -1,5 +1,5 @@
 /* poll with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 664c809e9fc2ff4b6b115682d27b30a6141c1a12..52aa2602fe07cee49e7a7fcc9cfae8b70449e90d 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_attr_destroy with error checking.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index 2e30ade9abd59596a00588c03e946bce9c7b220f..c7aa903db2cb1605bb15ed2d3e912d0b698907ca 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_attr_init with error checking.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index b544dbaa429628c073eb1c0d27119494a3887a77..6e845acc97d4a63923abf0051a5ea445e45671b8 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_attr_setdetachstate with error checking.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index 35fed5d9ec62421d49599e3896f1423254d4b369..964ec058c9f5832040da5d8caf8d33b7c4ce61b2 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_attr_setguardsize with error checking.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index 02d06310a9cc86c67db6766d89488cc8ce354201..c5517c0c6646f3290e56330fbe957dee9bf7c80d 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_attr_setstacksize with error checking.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index efc0719a6397ec4e366704aeec1868ca14b6c957..1dae148b465bf31440977369828547bebfcae828 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_barrier_destroy with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index b32dad1315e62d339f6b7f8b37481290d839043a..4a2975ad1247b8a0369e6dc927ef9abb8fa77899 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_barrier_init with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 7cee44d0a328806563f94a0f31b663027600d53e..61690c5e7c90e2654037401acbe0a56441e9bf41 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_barrier_wait with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 3af16f9b5433d5489cff5fe1ed72d249295dc8f2..26e864ea3e8c4241f1c3d1ecfa8bec7d18098db9 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_cancel with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 3094d82e9cbbc9dc507887f21ae4b67e13799d3b..1658db4b62a18039142c699ff32cc468bd556762 100644 (file)
@@ -1,5 +1,5 @@
 /* Return value checking for pthread functions, exit variant.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index b0e9b2a2327366b013f7646f3998c292c85c2fe2..08ec683b6600767f6039531a7ff2326629286892 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_cond_wait with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 98c63e54c369e10bd8c1c680c2002d36ef245dce..24b8456db9f45f8e946ef0010408b7f4cab98ab2 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_create with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 2088af2f575de637ecc76f7681f573913bc05580..c65f2d7db11dc44fba81abae98e9e6aba64a38bb 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_detach with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index f23bb9a5aea9e1a8e37b9ce8caff889a57ee80e4..29acbd283a17f9d6b5bedb561eabf4d1180eed79 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_join with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 52364be365da41afbef4fd14ef4911bb4f8ffeb0..d337163609aa877a91bc1e17ec112aa607bbccd1 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_mutex_consistent with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index f11f8f0acd00f2d3ef0d7c62bf3e5ea6bf979c42..d03f016629eb2e652641d2ee67b4c8b12a8da51c 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_mutex_destroy with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 2d16d1b9d9429c0fde19c0178c1619921809bbee..40855954a8e38336536ecb29ba0ba9f6fd1f8841 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_mutex_init with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index af727b45f354299aad2649ddb0f087074b698bce..4257960aaaf279ce6acfeeaf25c2525e311f7e5e 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_mutex_lock with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 161b41edf6def0801af20f9e446542e864844a82..5c385c69340e9c5eee12ef23d761c6754635692e 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_mutex_unlock with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index c699e32b410724edab603cacc849021fe64fdb6c..f352a7ad933365bc141c12f4771ad0b377585f91 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_mutexattr_destroy with error checking.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index fa93fab178eb17cb31b5ccfc13bd029a6231d08f..fe231581e300cdee8d2c507adcb74da495d48a7e 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_mutexattr_init with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 353f75e3d778ee8e5e219f910514487c47ffe9ca..e2f544d38ccf56286327fbb4889931cd7ad353cd 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_mutexattr_setprotocol with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 242da1aeca8e9a476aec7bd79427bbb8cb7a3734..2380560d796f272ffe1e3289e60a3e1632dad34d 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_mutexattr_setpshared with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index d7d6fa86301ab9d06f0c48571417f5acd5a095e1..7886c72a77b4b41bcdeb5e8b3180f24d9af72a48 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_mutexattr_setrobust with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index cf22170b56e2cbda4acc353fa8873469d731d5cc..91f790c9e52e71d48679ce0454fdf9c08f5bda34 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_mutexattr_settype with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 70d58dbab2ac60e4d253cc03ffaf4e6fa682fff5..b22c1ce3dd87f24a9a19f14aaee9f70909beff01 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_once with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 824288c90eb64f2fe74111e5df3c59fccc9804c3..e6c38115d872f02a18b78ed00ca4cde1194a9189 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_rwlock_init with error checking.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index 96330a5637df2103c39c89bcb6c0f373bbb9dde7..a88068fc86f9e2a37ba504230b2760f845c2f640 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_rwlock_rdlock with error checking.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index eaa136b3ec13e8315bfbb8d642c6310efc0c72b9..7eb282fd182e2a1124282b05e0621ed854f9abf9 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_rwlock_unlock with error checking.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index 8d25d5b818aea5bb6d809a39725b588d4330617b..0de37146c393cf371bb4ef81a7cfc4bf1635b486 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_rwlock_wrlock with error checking.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index 48baf247f3e6922251c355ee24ffecfd2e0e40de..96ac47d777aedf1846a5ba56b25aa61e26d05b35 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_rwlockattr_init with error checking.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index 958aace9f68d49d50793e062dcf16fde41532c18..34aa3df0a952903cf9dbf91e3c6fb2f9de2771f7 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_rwlockattr_setkind_np with error checking.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   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
index 0ba9ca02dc6aab53fb4d6b3320ea40d8125bd7f7..1fb91dcc209b35b4f51ad27aad1991411070849f 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_sigmask with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 6975215b171f82584b8a3af506d7b179454332cc..4cadbf70f9f4149828732eff0f08fc5efe1e5119 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_spin_lock with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 4f19a44c48bdfd0ebcf05692ba05a2da4593a48b..194613993af454322f9eadb0abf90ac386d7735f 100644 (file)
@@ -1,5 +1,5 @@
 /* pthread_spin_unlock with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
diff --git a/support/xraise.c b/support/xraise.c
new file mode 100644 (file)
index 0000000..1901e74
--- /dev/null
@@ -0,0 +1,27 @@
+/* Error-checking wrapper for raise.
+   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 <support/check.h>
+#include <support/xsignal.h>
+
+void
+xraise (int sig)
+{
+  if (raise (sig) != 0)
+    FAIL_EXIT1 ("raise (%d): %m" , sig);
+}
diff --git a/support/xreadlink.c b/support/xreadlink.c
new file mode 100644 (file)
index 0000000..c638649
--- /dev/null
@@ -0,0 +1,44 @@
+/* Error-checking, allocating wrapper for readlink.
+   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 <scratch_buffer.h>
+#include <support/check.h>
+#include <support/support.h>
+#include <xunistd.h>
+
+char *
+xreadlink (const char *path)
+{
+  struct scratch_buffer buf;
+  scratch_buffer_init (&buf);
+
+  while (true)
+    {
+      ssize_t count = readlink (path, buf.data, buf.length);
+      if (count < 0)
+        FAIL_EXIT1 ("readlink (\"%s\"): %m", path);
+      if (count < buf.length)
+        {
+          char *result = xstrndup (buf.data, count);
+          scratch_buffer_free (&buf);
+          return result;
+        }
+      if (!scratch_buffer_grow (&buf))
+        FAIL_EXIT1 ("scratch_buffer_grow in xreadlink");
+    }
+}
index 00c313880c1ba08cd32e57c2b25705eaa3d46fc8..4d9987c9bb50952de13b964aafb35feeed5dd636 100644 (file)
@@ -1,5 +1,5 @@
 /* Error-checking wrapper for realloc.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 17809c4dd2c64113252ee43acbce269e1a33fb81..a1011a5062819f8fc5fc696821a735adfcc4169e 100644 (file)
@@ -1,5 +1,5 @@
 /* recvfrom with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 20bddf696511ab879e31688f85debcc5402bc884..f51530793ec2e2b25eedfb078b2289f9ecff1eb1 100644 (file)
@@ -1,5 +1,5 @@
 /* sendto with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 9931882e759343273d01562de5ebacd271f9e64e..b7c07f21f99f407a003c00b4832d7cccafc4d57d 100644 (file)
@@ -1,5 +1,5 @@
 /* setsockopt with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
diff --git a/support/xsigaction.c b/support/xsigaction.c
new file mode 100644 (file)
index 0000000..51657de
--- /dev/null
@@ -0,0 +1,27 @@
+/* Error-checking wrapper for sigaction.
+   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 <support/check.h>
+#include <support/xsignal.h>
+
+void
+xsigaction (int sig, const struct sigaction *newact, struct sigaction *oldact)
+{
+  if (sigaction (sig, newact, oldact))
+    FAIL_EXIT1 ("sigaction (%d): %m" , sig);
+}
diff --git a/support/xsignal.c b/support/xsignal.c
new file mode 100644 (file)
index 0000000..e7369f0
--- /dev/null
@@ -0,0 +1,29 @@
+/* Error-checking wrapper for signal.
+   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 <support/check.h>
+#include <support/xsignal.h>
+
+sighandler_t
+xsignal (int sig, sighandler_t handler)
+{
+  sighandler_t result = signal (sig, handler);
+  if (result == SIG_ERR)
+    FAIL_EXIT1 ("signal (%d, %p): %m", sig, handler);
+  return result;
+}
index 3dc0d9d5ce68975a18b864e6fb232755381e9f1d..9ab8d1bfddf6c59831bf59e479d2f80bac86a580 100644 (file)
@@ -1,5 +1,5 @@
 /* Support functionality for using signals.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
 
 __BEGIN_DECLS
 
+/* The following functions call the corresponding libc functions and
+   terminate the process on error.  */
+
+void xraise (int sig);
+sighandler_t xsignal (int sig, sighandler_t handler);
+void xsigaction (int sig, const struct sigaction *newact,
+                 struct sigaction *oldact);
+
 /* The following functions call the corresponding libpthread functions
    and terminate the process on error.  */
 
index c1deaee9248fb2c4e248f900e5da36022bbcab8c..20282fb810085139dcd0921f8db2c1c8d460c9b2 100644 (file)
@@ -1,5 +1,5 @@
 /* socket with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index d6724948d8a1f58a4c61c95162bc005d744ee722..9673abdf54bb57762771d4e15bf4a0080afb13da 100644 (file)
@@ -1,5 +1,5 @@
 /* Error-checking wrappers for socket functions.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index bcc2e863bfc397ca697e1be9fcd54ff4d705dd4d..e7d0274474706380bbb027e814cbdef39b175f5d 100644 (file)
@@ -1,5 +1,5 @@
 /* Error-checking wrappers for stdio functions.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index d6a8c04baf04bcd005a9939206abac6764d385b6..89eee8584e989208ba4f9c33862b97c1557c3832 100644 (file)
@@ -1,5 +1,5 @@
 /* strdup with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
diff --git a/support/xstrndup.c b/support/xstrndup.c
new file mode 100644 (file)
index 0000000..e85fddd
--- /dev/null
@@ -0,0 +1,30 @@
+/* strndup with error checking.
+   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 <support/support.h>
+
+#include <string.h>
+
+char *
+xstrndup (const char *s, size_t length)
+{
+  char *p = strndup (s, length);
+  if (p == NULL)
+    oom_error ("strndup", length);
+  return p;
+}
diff --git a/support/xsysconf.c b/support/xsysconf.c
new file mode 100644 (file)
index 0000000..afefc2d
--- /dev/null
@@ -0,0 +1,36 @@
+/* Error-checking wrapper for sysconf.
+   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 <errno.h>
+#include <support/check.h>
+#include <support/xunistd.h>
+
+long
+xsysconf (int name)
+{
+  /* Detect errors by a changed errno value, in case -1 is a valid
+     value.  Make sure that the caller does not see the zero value for
+     errno.  */
+  int old_errno = errno;
+  errno = 0;
+  long result = sysconf (name);
+  if (errno != 0)
+    FAIL_EXIT1 ("sysconf (%d): %m", name);
+  errno = old_errno;
+  return result;
+}
index 472763ebe86cfef5e60738b24b915a0188ca4337..79358e7c99c946c4eda620e705b82974d0fd8bc7 100644 (file)
@@ -1,5 +1,5 @@
 /* Support functionality for using threads.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index c947bfd8fb8f443a49cac37945b29789db4ec539..5fe5dae818def4ec66a91e8c02d6cd8ed5c2aecd 100644 (file)
@@ -1,5 +1,5 @@
 /* POSIX-specific extra functions.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
@@ -36,8 +36,17 @@ void xpipe (int[2]);
 void xdup2 (int, int);
 int xopen (const char *path, int flags, mode_t);
 void xstat (const char *path, struct stat64 *);
+void xfstat (int fd, struct stat64 *);
 void xmkdir (const char *path, mode_t);
 void xchroot (const char *path);
+void xunlink (const char *path);
+long xsysconf (int name);
+long long xlseek (int fd, long long offset, int whence);
+void xftruncate (int fd, long long length);
+
+/* Read the link at PATH.  The caller should free the returned string
+   with free.  */
+char *xreadlink (const char *path);
 
 /* Close the file descriptor.  Ignore EINTR errors, but terminate the
    process on other errors.  */
diff --git a/support/xunlink.c b/support/xunlink.c
new file mode 100644 (file)
index 0000000..2ff9296
--- /dev/null
@@ -0,0 +1,27 @@
+/* Error-checking wrapper for unlink.
+   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 <support/check.h>
+#include <support/xunistd.h>
+
+void
+xunlink (const char *path)
+{
+  if (unlink (path) != 0)
+    FAIL_EXIT1 ("unlink (\"%s\"): %m", path);
+}
index 204795e4c0d86088c3201d31b3fa48bbc9255f49..1cb039ca177bc81d8317aa9049828170b874181b 100644 (file)
@@ -1,5 +1,5 @@
 /* waitpid with error checking.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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
index 134e8ee4c11563558a2cb458c597eb4ed53b45d1..bbaae9130a3f0229481d95f717972b24d4bb89f4 100644 (file)
@@ -1,5 +1,5 @@
 /* write with error checking and retries.
-   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   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