r11090 - in libprelude/trunk/libmissing: . m4 tests

[email protected]
Newsgroups gmane.comp.security.ids.prelude.cvs
Message-ID <[email protected]>
Author: yoann
Date: 2008-11-12 14:59:41 +0100 (Wed, 12 Nov 2008)
New Revision: 11090

Added:
   libprelude/trunk/libmissing/tests/test-select-fd.c
   libprelude/trunk/libmissing/tests/test-select-in.sh
   libprelude/trunk/libmissing/tests/test-select-out.sh
   libprelude/trunk/libmissing/tests/test-select-stdin.c
Modified:
   libprelude/trunk/libmissing/Makefile.am
   libprelude/trunk/libmissing/config.charset
   libprelude/trunk/libmissing/fseeko.c
   libprelude/trunk/libmissing/m4/getaddrinfo.m4
   libprelude/trunk/libmissing/m4/gnulib-comp.m4
   libprelude/trunk/libmissing/m4/netdb_h.m4
   libprelude/trunk/libmissing/m4/printf.m4
   libprelude/trunk/libmissing/m4/sys_ioctl_h.m4
   libprelude/trunk/libmissing/netdb.in.h
   libprelude/trunk/libmissing/sys_stat.in.h
   libprelude/trunk/libmissing/tests/Makefile.am
   libprelude/trunk/libmissing/tests/sockets.h
Log:
Update GnuLib code.


Modified: libprelude/trunk/libmissing/Makefile.am
===================================================================
--- libprelude/trunk/libmissing/Makefile.am	2008-11-12 13:59:37 UTC (rev 11089)
+++ libprelude/trunk/libmissing/Makefile.am	2008-11-12 13:59:41 UTC (rev 11090)
@@ -486,6 +486,11 @@
 	      -e 's|@''NEXT_NETDB_H''@|$(NEXT_NETDB_H)|g' \
 	      -e 's|@''HAVE_NETDB_H''@|$(HAVE_NETDB_H)|g' \
 	      -e 's|@''GNULIB_GETADDRINFO''@|$(GNULIB_GETADDRINFO)|g' \
+	      -e 's|@''HAVE_STRUCT_ADDRINFO''@|$(HAVE_STRUCT_ADDRINFO)|g' \
+	      -e 's|@''HAVE_DECL_FREEADDRINFO''@|$(HAVE_DECL_FREEADDRINFO)|g' \
+	      -e 's|@''HAVE_DECL_GAI_STRERROR''@|$(HAVE_DECL_GAI_STRERROR)|g' \
+	      -e 's|@''HAVE_DECL_GETADDRINFO''@|$(HAVE_DECL_GETADDRINFO)|g' \
+	      -e 's|@''HAVE_DECL_GETNAMEINFO''@|$(HAVE_DECL_GETNAMEINFO)|g' \
 	      < $(srcdir)/netdb.in.h; \
 	} > $@-t
 	mv $@-t $@

Modified: libprelude/trunk/libmissing/config.charset
===================================================================
--- libprelude/trunk/libmissing/config.charset	2008-11-12 13:59:37 UTC (rev 11089)
+++ libprelude/trunk/libmissing/config.charset	2008-11-12 13:59:41 UTC (rev 11090)
@@ -1,7 +1,7 @@
 #! /bin/sh
 # Output a system dependent table of character encoding aliases.
 #
-#   Copyright (C) 2000-2004, 2006-2007 Free Software Foundation, Inc.
+#   Copyright (C) 2000-2004, 2006-2008 Free Software Foundation, Inc.
 #
 #   This program is free software; you can redistribute it and/or modify
 #   it under the terms of the GNU Lesser General Public License as published by
@@ -478,8 +478,8 @@
 	# space nevertheless.
 	echo "* UTF-8"
 	;;
-    beos*)
-	# BeOS has a single locale, and it has UTF-8 encoding.
+    beos* | haiku*)
+	# BeOS and Haiku have a single locale, and it has UTF-8 encoding.
 	echo "* UTF-8"
 	;;
     msdosdjgpp*)

Modified: libprelude/trunk/libmissing/fseeko.c
===================================================================
--- libprelude/trunk/libmissing/fseeko.c	2008-11-12 13:59:37 UTC (rev 11089)
+++ libprelude/trunk/libmissing/fseeko.c	2008-11-12 13:59:41 UTC (rev 11090)
@@ -41,7 +41,7 @@
 #endif
 
   /* These tests are based on fpurge.c.  */
-#if defined _IO_ferror_unlocked || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Linux libc5 */
+#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
   if (fp->_IO_read_end == fp->_IO_read_ptr
       && fp->_IO_write_ptr == fp->_IO_write_base
       && fp->_IO_save_base == NULL)

Modified: libprelude/trunk/libmissing/m4/getaddrinfo.m4
===================================================================
--- libprelude/trunk/libmissing/m4/getaddrinfo.m4	2008-11-12 13:59:37 UTC (rev 11089)
+++ libprelude/trunk/libmissing/m4/getaddrinfo.m4	2008-11-12 13:59:41 UTC (rev 11090)
@@ -1,4 +1,4 @@
-# getaddrinfo.m4 serial 16
+# getaddrinfo.m4 serial 17
 dnl Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -71,8 +71,9 @@
   gl_PREREQ_GETADDRINFO
 ])
 
-# Prerequisites of lib/getaddrinfo.c.
+# Prerequisites of lib/netdb.in.h and lib/getaddrinfo.c.
 AC_DEFUN([gl_PREREQ_GETADDRINFO], [
+  AC_REQUIRE([gl_NETDB_H_DEFAULTS])
   AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
   AC_SEARCH_LIBS(gethostbyname, [inet nsl])
   AC_SEARCH_LIBS(getservbyname, [inet nsl socket xnet])
@@ -104,6 +105,7 @@
   AC_CHECK_MEMBERS([struct sockaddr.sa_len], , , [#include <sys/socket.h>])
 
   AC_CHECK_HEADERS_ONCE(netinet/in.h)
+
   AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, gai_strerror, getnameinfo],,,[
   /* sys/types.h is not needed according to POSIX, but the
      sys/socket.h in i386-unknown-freebsd4.10 and
@@ -119,6 +121,19 @@
 #include <ws2tcpip.h>
 #endif
 ])
+  if test $ac_cv_have_decl_getaddrinfo = no; then
+    HAVE_DECL_GETADDRINFO=0
+  fi
+  if test $ac_cv_have_decl_freeaddrinfo = no; then
+    HAVE_DECL_FREEADDRINFO=0
+  fi
+  if test $ac_cv_have_decl_gai_strerror = no; then
+    HAVE_DECL_GAI_STRERROR=0
+  fi
+  if test $ac_cv_have_decl_getnameinfo = no; then
+    HAVE_DECL_GETNAMEINFO=0
+  fi
+
   AC_CHECK_TYPES([struct addrinfo],,,[
 #include <sys/types.h>
 #ifdef HAVE_SYS_SOCKET_H
@@ -131,4 +146,7 @@
 #include <ws2tcpip.h>
 #endif
 ])
+  if test $ac_cv_type_struct_addrinfo = no; then
+    HAVE_STRUCT_ADDRINFO=0
+  fi
 ])

Modified: libprelude/trunk/libmissing/m4/gnulib-comp.m4
===================================================================
--- libprelude/trunk/libmissing/m4/gnulib-comp.m4	2008-11-12 13:59:37 UTC (rev 11089)
+++ libprelude/trunk/libmissing/m4/gnulib-comp.m4	2008-11-12 13:59:41 UTC (rev 11090)
@@ -252,6 +252,7 @@
   gl_SYS_SOCKET_MODULE_INDICATOR([listen])
   AC_CHECK_DECLS_ONCE([alarm])
   AC_CHECK_HEADERS_ONCE([unistd.h sys/wait.h])
+  AC_CHECK_HEADERS_ONCE([unistd.h sys/wait.h])
   gl_SOCKETS
   gt_TYPE_WCHAR_T
   gt_TYPE_WINT_T
@@ -578,6 +579,10 @@
   tests/test-perror.c
   tests/test-perror.sh
   tests/test-poll.c
+  tests/test-select-fd.c
+  tests/test-select-in.sh
+  tests/test-select-out.sh
+  tests/test-select-stdin.c
   tests/test-select.c
   tests/test-sleep.c
   tests/test-snprintf.c

Modified: libprelude/trunk/libmissing/m4/netdb_h.m4
===================================================================
--- libprelude/trunk/libmissing/m4/netdb_h.m4	2008-11-12 13:59:37 UTC (rev 11089)
+++ libprelude/trunk/libmissing/m4/netdb_h.m4	2008-11-12 13:59:41 UTC (rev 11090)
@@ -1,4 +1,4 @@
-# netdb_h.m4 serial 3
+# netdb_h.m4 serial 4
 dnl Copyright (C) 2008 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -30,4 +30,10 @@
 AC_DEFUN([gl_NETDB_H_DEFAULTS],
 [
   GNULIB_GETADDRINFO=0; AC_SUBST([GNULIB_GETADDRINFO])
+  dnl Assume proper GNU behavior unless another module says otherwise.
+  HAVE_STRUCT_ADDRINFO=1;   AC_SUBST([HAVE_STRUCT_ADDRINFO])
+  HAVE_DECL_FREEADDRINFO=1; AC_SUBST([HAVE_DECL_FREEADDRINFO])
+  HAVE_DECL_GAI_STRERROR=1; AC_SUBST([HAVE_DECL_GAI_STRERROR])
+  HAVE_DECL_GETADDRINFO=1;  AC_SUBST([HAVE_DECL_GETADDRINFO])
+  HAVE_DECL_GETNAMEINFO=1;  AC_SUBST([HAVE_DECL_GETNAMEINFO])
 ])

Modified: libprelude/trunk/libmissing/m4/printf.m4
===================================================================
--- libprelude/trunk/libmissing/m4/printf.m4	2008-11-12 13:59:37 UTC (rev 11089)
+++ libprelude/trunk/libmissing/m4/printf.m4	2008-11-12 13:59:41 UTC (rev 11090)
@@ -1,4 +1,4 @@
-# printf.m4 serial 23
+# printf.m4 serial 24
 dnl Copyright (C) 2003, 2007-2008 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -815,6 +815,7 @@
   AC_CACHE_CHECK([whether printf survives out-of-memory conditions],
     [gl_cv_func_printf_enomem],
     [
+      gl_cv_func_printf_enomem="guessing no"
       if test "$cross_compiling" = no; then
         AC_LANG_CONFTEST([AC_LANG_SOURCE([
 ]GL_NOCRASH[
@@ -880,7 +881,8 @@
           gl_cv_func_printf_enomem="guessing no"
         fi
         rm -fr conftest*
-      else
+      fi
+      if test "$gl_cv_func_printf_enomem" = "guessing no"; then
 changequote(,)dnl
         case "$host_os" in
                     # Guess yes on glibc systems.
@@ -901,6 +903,8 @@
           osf*)     gl_cv_func_printf_enomem="guessing yes";;
                     # Guess yes on BeOS.
           beos*)    gl_cv_func_printf_enomem="guessing yes";;
+                    # Guess yes on Haiku.
+          haiku*)   gl_cv_func_printf_enomem="guessing yes";;
                     # If we don't know, assume the worst.
           *)        gl_cv_func_printf_enomem="guessing no";;
         esac
@@ -1305,5 +1309,6 @@
 dnl   OSF/1 4.0d                     #  .  #  #  #  #  .  .  .  .  #  .  .  #  #  #  #  #  #
 dnl   NetBSD 4.0                     .  ?  ?  ?  ?  ?  .  .  ?  ?  ?  ?  ?  .  .  .  ?  ?  ?
 dnl   NetBSD 3.0                     .  .  .  .  #  #  .  #  #  ?  #  .  #  .  .  .  .  .  .
+dnl   Haiku                          .  .  .  #  #  #  .  .  .  .  .  .  ?  .  .  .  .  .  .
 dnl   BeOS                           #  #  .  #  #  #  .  #  .  ?  .  #  ?  .  .  .  .  .  .
 dnl   mingw                          #  #  #  #  #  #  .  #  #  .  #  #  ?  .  #  #  #  .  .

Modified: libprelude/trunk/libmissing/m4/sys_ioctl_h.m4
===================================================================
--- libprelude/trunk/libmissing/m4/sys_ioctl_h.m4	2008-11-12 13:59:37 UTC (rev 11089)
+++ libprelude/trunk/libmissing/m4/sys_ioctl_h.m4	2008-11-12 13:59:41 UTC (rev 11090)
@@ -1,4 +1,4 @@
-# sys_ioctl_h.m4 serial 1
+# sys_ioctl_h.m4 serial 2
 dnl Copyright (C) 2008 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -19,10 +19,13 @@
     dnl header file, such as <unistd.h> or <stropts.h>, is needed for that.
     AC_CACHE_CHECK([whether <sys/ioctl.h> declares ioctl],
       [gl_cv_decl_ioctl_in_sys_ioctl_h],
-      [AC_CHECK_DECL([ioctl],
+      [dnl We cannot use AC_CHECK_DECL because it produces its own messages.
+       AC_COMPILE_IFELSE(
+         [AC_LANG_PROGRAM(
+            [AC_INCLUDES_DEFAULT([#include <sys/ioctl.h>])],
+            [(void) ioctl;])],
          [gl_cv_decl_ioctl_in_sys_ioctl_h=yes],
-         [gl_cv_decl_ioctl_in_sys_ioctl_h=no],
-         [#include <sys/ioctl.h>])
+         [gl_cv_decl_ioctl_in_sys_ioctl_h=no])
       ])
     if test $gl_cv_decl_ioctl_in_sys_ioctl_h != yes; then
       SYS_IOCTL_H='sys/ioctl.h'

Modified: libprelude/trunk/libmissing/netdb.in.h
===================================================================
--- libprelude/trunk/libmissing/netdb.in.h	2008-11-12 13:59:37 UTC (rev 11089)
+++ libprelude/trunk/libmissing/netdb.in.h	2008-11-12 13:59:41 UTC (rev 11090)
@@ -36,7 +36,7 @@
 #ifndef _GL_NETDB_H
 #define _GL_NETDB_H
 
-#if @HAVE_NETDB_H@ && HAVE_STRUCT_ADDRINFO
+#if @HAVE_NETDB_H@ && @HAVE_STRUCT_ADDRINFO@
 
 /* Declarations for a platform that has <netdb.h>.  */
 
@@ -50,7 +50,7 @@
 
 #if @GNULIB_GETADDRINFO@
 
-# ifndef HAVE_STRUCT_ADDRINFO
+# if !@HAVE_STRUCT_ADDRINFO@
 
 /* Structure to contain information about address of a service provider.  */
 struct addrinfo
@@ -139,7 +139,7 @@
 #  endif
 # endif
 
-# if !HAVE_DECL_GETADDRINFO
+# if !@HAVE_DECL_GETADDRINFO@
 /* Translate name of a service location and/or a service name to set of
    socket addresses.
    For more details, see the POSIX:2001 specification
@@ -150,21 +150,21 @@
 			struct addrinfo **restrict res);
 # endif
 
-# if !HAVE_DECL_FREEADDRINFO
+# if !@HAVE_DECL_FREEADDRINFO@
 /* Free `addrinfo' structure AI including associated storage.
    For more details, see the POSIX:2001 specification
    <http://www.opengroup.org/susv3xsh/getaddrinfo.html>.  */
 extern void freeaddrinfo (struct addrinfo *ai);
 # endif
 
-# if !HAVE_DECL_GAI_STRERROR
+# if !@HAVE_DECL_GAI_STRERROR@
 /* Convert error return from getaddrinfo() to a string.
    For more details, see the POSIX:2001 specification
    <http://www.opengroup.org/susv3xsh/gai_strerror.html>.  */
 extern const char *gai_strerror (int ecode);
 # endif
 
-# if !HAVE_DECL_GETNAMEINFO
+# if !@HAVE_DECL_GETNAMEINFO@
 /* Convert socket address to printable node and service names.
    For more details, see the POSIX:2001 specification
    <http://www.opengroup.org/susv3xsh/getnameinfo.html>.  */

Modified: libprelude/trunk/libmissing/sys_stat.in.h
===================================================================
--- libprelude/trunk/libmissing/sys_stat.in.h	2008-11-12 13:59:37 UTC (rev 11089)
+++ libprelude/trunk/libmissing/sys_stat.in.h	2008-11-12 13:59:41 UTC (rev 11090)
@@ -275,6 +275,12 @@
 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
 #endif
 
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
 #if @GNULIB_LSTAT@
 # if ! @HAVE_LSTAT@
 /* mingw does not support symlinks, therefore it does not have lstat.  But
@@ -341,6 +347,12 @@
      lchmod (f, m))
 #endif
 
+
+#ifdef __cplusplus
+}
+#endif
+
+
 #endif /* _GL_SYS_STAT_H */
 #endif /* _GL_SYS_STAT_H */
 #endif

Modified: libprelude/trunk/libmissing/tests/Makefile.am
===================================================================
--- libprelude/trunk/libmissing/tests/Makefile.am	2008-11-12 13:59:37 UTC (rev 11089)
+++ libprelude/trunk/libmissing/tests/Makefile.am	2008-11-12 13:59:41 UTC (rev 11090)
@@ -90,7 +90,7 @@
 ## begin gnulib module close
 
 
-EXTRA_DIST += close.c
+EXTRA_DIST += close.c w32sock.h
 
 EXTRA_libtests_a_SOURCES += close.c
 
@@ -261,11 +261,15 @@
 
 ## begin gnulib module select-tests
 
-TESTS += test-select
-check_PROGRAMS += test-select
+TESTS += test-select test-select-in.sh test-select-out.sh
+# test-select-stdin has to be run by hand.
+TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@'
+check_PROGRAMS += test-select test-select-fd test-select-stdin
 test_select_LDADD = $(LDADD) @LIBSOCKET@
+test_select_fd_LDADD = $(LDADD) @LIBSOCKET@
+test_select_stdin_LDADD = $(LDADD) @LIBSOCKET@
 
-EXTRA_DIST += test-select.c
+EXTRA_DIST += test-select.c test-select-fd.c test-select-in.sh test-select-out.sh test-select-stdin.c
 
 ## end   gnulib module select-tests
 

Modified: libprelude/trunk/libmissing/tests/sockets.h
===================================================================
--- libprelude/trunk/libmissing/tests/sockets.h	2008-11-12 13:59:37 UTC (rev 11089)
+++ libprelude/trunk/libmissing/tests/sockets.h	2008-11-12 13:59:41 UTC (rev 11090)
@@ -20,9 +20,9 @@
 #ifndef SOCKETS_H
 # define SOCKETS_H 1
 
-#define SOCKETS_1_0 0x100
+#define SOCKETS_1_0 0x100  /* don't use - does not work on Windows XP */
 #define SOCKETS_1_1 0x101
-#define SOCKETS_2_0 0x200
+#define SOCKETS_2_0 0x200  /* don't use - does not work on Windows XP */
 #define SOCKETS_2_1 0x201
 #define SOCKETS_2_2 0x202
 

Added: libprelude/trunk/libmissing/tests/test-select-fd.c
===================================================================
--- libprelude/trunk/libmissing/tests/test-select-fd.c	                        (rev 0)
+++ libprelude/trunk/libmissing/tests/test-select-fd.c	2008-11-12 13:59:41 UTC (rev 11090)
@@ -0,0 +1,72 @@
+/* Test of select() substitute, reading or writing from a given file descriptor.
+   Copyright (C) 2008 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <[email protected]>, 2008.  */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/select.h>
+
+int
+main (int argc, char *argv[])
+{
+  if (argc == 4)
+    {
+      char mode = argv[1][0];
+
+      if (mode == 'r' || mode == 'w')
+	{
+	  int fd = atoi (argv[2]);
+
+	  if (fd >= 0)
+	    {
+	      const char *result_file_name = argv[3];
+	      FILE *result_file = fopen (result_file_name, "wb");
+
+	      if (result_file != NULL)
+		{
+		  fd_set fds;
+		  struct timeval timeout;
+		  int ret;
+
+		  FD_ZERO (&fds);
+		  FD_SET (fd, &fds);
+		  timeout.tv_sec = 0;
+		  timeout.tv_usec = 10000;
+		  ret = (mode == 'r'
+			 ? select (fd + 1, &fds, NULL, NULL, &timeout)
+			 : select (fd + 1, NULL, &fds, NULL, &timeout));
+		  if (ret < 0)
+		    {
+		      perror ("select failed");
+		      exit (1);
+		    }
+		  if ((ret == 0) != ! FD_ISSET (fd, &fds))
+		    {
+		      fprintf (stderr, "incorrect return value\n");
+		      exit (1);
+		    }
+		  fprintf (result_file, "%d\n", ret);
+		  exit (0);
+		}
+	    }
+	}
+    }
+  fprintf (stderr, "Usage: test-select-fd mode fd result-file-name\n");
+  exit (1);
+}

Added: libprelude/trunk/libmissing/tests/test-select-in.sh
===================================================================
--- libprelude/trunk/libmissing/tests/test-select-in.sh	                        (rev 0)
+++ libprelude/trunk/libmissing/tests/test-select-in.sh	2008-11-12 13:59:41 UTC (rev 11090)
@@ -0,0 +1,33 @@
+#!/bin/sh
+# Test select() on file descriptors opened for reading.
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+tmpfiles="$tmpfiles t-select-in.tmp"
+
+# Regular files.
+
+rm -f t-select-in.tmp
+./test-select-fd${EXEEXT} r 0 t-select-in.tmp < ./test-select-fd${EXEEXT}
+test `cat t-select-in.tmp` = "1" || exit 1
+
+# Pipes.
+
+rm -f t-select-in.tmp
+{ sleep 1; echo abc; } | ./test-select-fd${EXEEXT} r 0 t-select-in.tmp
+test `cat t-select-in.tmp` = "0" || exit 1
+
+rm -f t-select-in.tmp
+echo abc | { sleep 1; ./test-select-fd${EXEEXT} r 0 t-select-in.tmp; }
+test `cat t-select-in.tmp` = "1" || exit 1
+
+# Special files.
+
+rm -f t-select-in.tmp
+./test-select-fd${EXEEXT} r 0 t-select-in.tmp < /dev/null
+test `cat t-select-in.tmp` = "1" || exit 1
+
+rm -fr $tmpfiles
+
+exit 0


Property changes on: libprelude/trunk/libmissing/tests/test-select-in.sh
___________________________________________________________________
Name: svn:executable
   + *

Added: libprelude/trunk/libmissing/tests/test-select-out.sh
===================================================================
--- libprelude/trunk/libmissing/tests/test-select-out.sh	                        (rev 0)
+++ libprelude/trunk/libmissing/tests/test-select-out.sh	2008-11-12 13:59:41 UTC (rev 11090)
@@ -0,0 +1,33 @@
+#!/bin/sh
+# Test select() on file descriptors opened for writing.
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+tmpfiles="$tmpfiles t-select-out.out t-select-out.tmp"
+
+# Regular files.
+
+rm -f t-select-out.tmp
+./test-select-fd${EXEEXT} w 1 t-select-out.tmp > t-select-out.out
+test `cat t-select-out.tmp` = "1" || exit 1
+
+# Pipes.
+
+rm -f t-select-out.tmp
+( { echo abc; ./test-select-fd${EXEEXT} w 1 t-select-out.tmp; } | { sleep 1; cat; } ) > /dev/null
+test `cat t-select-out.tmp` = "0" || exit 1
+
+rm -f t-select-out.tmp
+( { sleep 1; echo abc; ./test-select-fd${EXEEXT} w 1 t-select-out.tmp; } | cat) > /dev/null
+test `cat t-select-out.tmp` = "1" || exit 1
+
+# Special files.
+
+rm -f t-select-out.tmp
+./test-select-fd${EXEEXT} w 1 t-select-out.tmp > /dev/null
+test `cat t-select-out.tmp` = "1" || exit 1
+
+rm -fr $tmpfiles
+
+exit 0


Property changes on: libprelude/trunk/libmissing/tests/test-select-out.sh
___________________________________________________________________
Name: svn:executable
   + *

Added: libprelude/trunk/libmissing/tests/test-select-stdin.c
===================================================================
--- libprelude/trunk/libmissing/tests/test-select-stdin.c	                        (rev 0)
+++ libprelude/trunk/libmissing/tests/test-select-stdin.c	2008-11-12 13:59:41 UTC (rev 11090)
@@ -0,0 +1,80 @@
+/* Test of select() substitute, reading from stdin.
+   Copyright (C) 2008 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <[email protected]>, 2008.  */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/select.h>
+#include <sys/time.h>
+#include <unistd.h>
+
+int
+main ()
+{
+  printf ("Applying select() from standard input. Press Ctrl-C to abort.\n");
+  for (;;)
+    {
+      struct timeval before;
+      struct timeval after;
+      unsigned long spent_usec;
+      fd_set readfds;
+      struct timeval timeout;
+      int ret;
+
+      gettimeofday (&before, NULL);
+
+      FD_ZERO (&readfds);
+      FD_SET (0, &readfds);
+      timeout.tv_sec = 0;
+      timeout.tv_usec = 500000;
+      ret = select (1, &readfds, NULL, NULL, &timeout);
+
+      gettimeofday (&after, NULL);
+      spent_usec = (after.tv_sec - before.tv_sec) * 1000000
+		   + after.tv_usec - before.tv_usec;
+
+      if (ret < 0)
+	{
+	  perror ("select failed");
+	  exit (1);
+	}
+      if ((ret == 0) != ! FD_ISSET (0, &readfds))
+	{
+	  fprintf (stderr, "incorrect return value\n");
+	  exit (1);
+	}
+      if (ret == 0)
+	{
+	  if (spent_usec < 250000)
+	    {
+	      fprintf (stderr, "returned too early\n");
+	      exit (1);
+	    }
+	  /* Timeout */
+	  printf ("."); fflush (stdout);
+	}
+      else
+	{
+	  char c;
+
+	  printf ("Input available! Trying to read 1 byte...\n");
+	  read (0, &c, 1);
+	}
+    }
+}

_______________________________________________
Prelude-cvslog site list
[email protected]
http://lists.prelude-ids.org/mailman/listinfo/prelude-cvslog
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.