summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2011-09-24 18:08:50 +0200
committerBruno Haible <bruno@clisp.org>2011-09-24 18:08:50 +0200
commit09001dfb3ec39d237f8e248ff347cf1be3e6f0c1 (patch)
tree6b4a6b865cc1cd2201918fa77bd182abfd424fa9
parenteab930966c2c1f42916fd775f4466a29192bbaa3 (diff)
downloadgnulib-09001dfb3ec39d237f8e248ff347cf1be3e6f0c1.tar.gz
fdopen: Support for MSVC 9.
* m4/fdopen.m4 (gl_FUNC_FDOPEN): Set REPLACE_FDOPEN also if HAVE_MSVC_INVALID_PARAMETER_HANDLER is 1. * lib/fdopen.c: Include msvc-inval.h. (fdopen_nothrow): New function. (rpl_fdopen): Use it. * modules/fdopen (Depends-on): Add msvc-inval. * modules/fclose-tests (Depends-on): Add fdopen. * modules/fflush-tests (Depends-on): Likewise. * modules/fgetc-tests (Depends-on): Likewise. * modules/fputc-tests (Depends-on): Likewise. * modules/fread-tests (Depends-on): Likewise. * modules/freopen-tests (Depends-on): Likewise. * modules/fseeko-tests (Depends-on): Likewise. * modules/ftello-tests (Depends-on): Likewise. * modules/fwrite-tests (Depends-on): Likewise. * doc/posix-functions/fdopen.texi: Mention the problem on MSVC.
-rw-r--r--ChangeLog20
-rw-r--r--doc/posix-functions/fdopen.texi3
-rw-r--r--lib/fdopen.c28
-rw-r--r--m4/fdopen.m440
-rw-r--r--modules/fclose-tests1
-rw-r--r--modules/fdopen1
-rw-r--r--modules/fflush-tests1
-rw-r--r--modules/fgetc-tests1
-rw-r--r--modules/fputc-tests1
-rw-r--r--modules/fread-tests1
-rw-r--r--modules/freopen-tests1
-rw-r--r--modules/fseeko-tests1
-rw-r--r--modules/ftello-tests1
-rw-r--r--modules/fwrite-tests1
14 files changed, 82 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index ceca562617..9def2635ec 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,25 @@
2011-09-24 Bruno Haible <bruno@clisp.org>
+ fdopen: Support for MSVC 9.
+ * m4/fdopen.m4 (gl_FUNC_FDOPEN): Set REPLACE_FDOPEN also if
+ HAVE_MSVC_INVALID_PARAMETER_HANDLER is 1.
+ * lib/fdopen.c: Include msvc-inval.h.
+ (fdopen_nothrow): New function.
+ (rpl_fdopen): Use it.
+ * modules/fdopen (Depends-on): Add msvc-inval.
+ * modules/fclose-tests (Depends-on): Add fdopen.
+ * modules/fflush-tests (Depends-on): Likewise.
+ * modules/fgetc-tests (Depends-on): Likewise.
+ * modules/fputc-tests (Depends-on): Likewise.
+ * modules/fread-tests (Depends-on): Likewise.
+ * modules/freopen-tests (Depends-on): Likewise.
+ * modules/fseeko-tests (Depends-on): Likewise.
+ * modules/ftello-tests (Depends-on): Likewise.
+ * modules/fwrite-tests (Depends-on): Likewise.
+ * doc/posix-functions/fdopen.texi: Mention the problem on MSVC.
+
+2011-09-24 Bruno Haible <bruno@clisp.org>
+
fgetc, fputc, fread, fwrite tests: Avoid compilation error on MSVC.
* modules/fgetc-tests (Depends-on): Add unistd.
* modules/fputc-tests (Depends-on): Likewise.
diff --git a/doc/posix-functions/fdopen.texi b/doc/posix-functions/fdopen.texi
index 49c006719c..58e582f873 100644
--- a/doc/posix-functions/fdopen.texi
+++ b/doc/posix-functions/fdopen.texi
@@ -9,6 +9,9 @@ Gnulib module: fdopen
Portability problems fixed by Gnulib:
@itemize
@item
+This function crashes when invoked with invalid arguments on some platforms:
+MSVC 9.
+@item
On Windows platforms (excluding Cygwin), this function does not set @code{errno}
upon failure.
@end itemize
diff --git a/lib/fdopen.c b/lib/fdopen.c
index c443ab6602..50c889b17a 100644
--- a/lib/fdopen.c
+++ b/lib/fdopen.c
@@ -21,8 +21,34 @@
#include <errno.h>
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+# include "msvc-inval.h"
+#endif
+
#undef fdopen
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+static FILE *
+fdopen_nothrow (int fd, const char *mode)
+{
+ FILE *result;
+
+ TRY_MSVC_INVAL
+ {
+ result = fdopen (fd, mode);
+ }
+ CATCH_MSVC_INVAL
+ {
+ result = NULL;
+ }
+ DONE_MSVC_INVAL;
+
+ return result;
+}
+#else
+# define fdopen_nothrow fdopen
+#endif
+
FILE *
rpl_fdopen (int fd, const char *mode)
{
@@ -30,7 +56,7 @@ rpl_fdopen (int fd, const char *mode)
FILE *fp;
errno = 0;
- fp = fdopen (fd, mode);
+ fp = fdopen_nothrow (fd, mode);
if (fp == NULL)
{
if (errno == 0)
diff --git a/m4/fdopen.m4 b/m4/fdopen.m4
index dd2cf264d6..8cae2fc273 100644
--- a/m4/fdopen.m4
+++ b/m4/fdopen.m4
@@ -1,4 +1,4 @@
-# fdopen.m4 serial 1
+# fdopen.m4 serial 2
dnl Copyright (C) 2011 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -8,12 +8,15 @@ AC_DEFUN([gl_FUNC_FDOPEN],
[
AC_REQUIRE([gl_STDIO_H_DEFAULTS])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
-
- dnl Test whether fdopen() sets errno when it fails due to a bad fd argument.
- AC_CACHE_CHECK([whether fdopen sets errno], [gl_cv_func_fdopen_works],
- [
- AC_RUN_IFELSE(
- [AC_LANG_SOURCE([[
+ AC_REQUIRE([gl_MSVC_INVAL])
+ if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
+ REPLACE_FDOPEN=1
+ else
+ dnl Test whether fdopen() sets errno when it fails due to a bad fd argument.
+ AC_CACHE_CHECK([whether fdopen sets errno], [gl_cv_func_fdopen_works],
+ [
+ AC_RUN_IFELSE(
+ [AC_LANG_SOURCE([[
#include <stdio.h>
#include <errno.h>
int
@@ -28,17 +31,18 @@ main (void)
return 2;
return 0;
}]])],
- [gl_cv_func_fdopen_works=yes],
- [gl_cv_func_fdopen_works=no],
- [case "$host_os" in
- mingw*) gl_cv_func_fdopen_works="guessing no" ;;
- *) gl_cv_func_fdopen_works="guessing yes" ;;
- esac
- ])
- ])
- case "$gl_cv_func_fdopen_works" in
- *no) REPLACE_FDOPEN=1 ;;
- esac
+ [gl_cv_func_fdopen_works=yes],
+ [gl_cv_func_fdopen_works=no],
+ [case "$host_os" in
+ mingw*) gl_cv_func_fdopen_works="guessing no" ;;
+ *) gl_cv_func_fdopen_works="guessing yes" ;;
+ esac
+ ])
+ ])
+ case "$gl_cv_func_fdopen_works" in
+ *no) REPLACE_FDOPEN=1 ;;
+ esac
+ fi
])
dnl Prerequisites of lib/fdopen.c.
diff --git a/modules/fclose-tests b/modules/fclose-tests
index 6334f6594a..0f36e0d50e 100644
--- a/modules/fclose-tests
+++ b/modules/fclose-tests
@@ -2,6 +2,7 @@ Files:
tests/test-fclose.c
Depends-on:
+fdopen
configure.ac:
diff --git a/modules/fdopen b/modules/fdopen
index 4054b054da..45f47fdbe1 100644
--- a/modules/fdopen
+++ b/modules/fdopen
@@ -7,6 +7,7 @@ m4/fdopen.m4
Depends-on:
stdio
+msvc-inval [test $REPLACE_FDOPEN = 1]
configure.ac:
gl_FUNC_FDOPEN
diff --git a/modules/fflush-tests b/modules/fflush-tests
index a447521f1f..33c47c42e8 100644
--- a/modules/fflush-tests
+++ b/modules/fflush-tests
@@ -7,6 +7,7 @@ tests/macros.h
Depends-on:
binary-io
+fdopen
fseeko
configure.ac:
diff --git a/modules/fgetc-tests b/modules/fgetc-tests
index 25077f7ad1..d812a6f73d 100644
--- a/modules/fgetc-tests
+++ b/modules/fgetc-tests
@@ -5,6 +5,7 @@ tests/macros.h
Depends-on:
unistd
+fdopen
configure.ac:
diff --git a/modules/fputc-tests b/modules/fputc-tests
index a6c89583e1..8f6c2da892 100644
--- a/modules/fputc-tests
+++ b/modules/fputc-tests
@@ -5,6 +5,7 @@ tests/macros.h
Depends-on:
unistd
+fdopen
configure.ac:
diff --git a/modules/fread-tests b/modules/fread-tests
index c37901f8db..bb521a46d2 100644
--- a/modules/fread-tests
+++ b/modules/fread-tests
@@ -5,6 +5,7 @@ tests/macros.h
Depends-on:
unistd
+fdopen
configure.ac:
diff --git a/modules/freopen-tests b/modules/freopen-tests
index 95b59152e5..55e9d71c7e 100644
--- a/modules/freopen-tests
+++ b/modules/freopen-tests
@@ -4,6 +4,7 @@ tests/signature.h
tests/macros.h
Depends-on:
+fdopen
configure.ac:
diff --git a/modules/fseeko-tests b/modules/fseeko-tests
index 470a4e4e0a..22e1e2b472 100644
--- a/modules/fseeko-tests
+++ b/modules/fseeko-tests
@@ -11,6 +11,7 @@ tests/macros.h
m4/ungetc.m4
Depends-on:
+fdopen
configure.ac:
gl_FUNC_UNGETC_WORKS
diff --git a/modules/ftello-tests b/modules/ftello-tests
index 3c216d85a7..90d269eae7 100644
--- a/modules/ftello-tests
+++ b/modules/ftello-tests
@@ -11,6 +11,7 @@ m4/ungetc.m4
Depends-on:
binary-io
+fdopen
configure.ac:
gl_FUNC_UNGETC_WORKS
diff --git a/modules/fwrite-tests b/modules/fwrite-tests
index 00d8e7e876..56d507498c 100644
--- a/modules/fwrite-tests
+++ b/modules/fwrite-tests
@@ -5,6 +5,7 @@ tests/macros.h
Depends-on:
unistd
+fdopen
configure.ac: