bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] freopen SEGFAULT on win32 with filename == NULL


From: Bruno Haible
Subject: Re: [PATCH] freopen SEGFAULT on win32 with filename == NULL
Date: Thu, 1 Sep 2011 22:16:55 +0200
User-agent: KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; )

Hello Claudio,

> >>  rpl_freopen (const char *filename, const char *mode, FILE *stream)
> >>  {
> >>  #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
> >> +#  ifdef _MSC_VER
> >> +  if (!filename) return NULL; /* would trigger a runtime error on MSVC */
> >> +#  endif
> >>    if (filename && strcmp (filename, "/dev/null") == 0)
> >>      filename = "NUL";
> >>  #endif
> >> 
> >> --------------------
> >
> > Unfortunately, freopen (NULL, ...) is not something gnulib can support
> > portably.
> 
> Just to clarify. That patch only tries to avoid a runtime crash when
>  trying to pass NULL as filename (when using the MSVC compiler). It
>  simply makes that function fail in this case (maybe errno should be
>  set too).

Yes, I understood this. But for gnulib there is no point in applying
this: It is not a great help to programs if a certain call succeeds on
some systems and fails on others. And on HP-UX and mingw in particular
we cannot make it work right.

POSIX asks for this call to return NULL and set errno if it fails. But
if the functionality is unportable anyway, I don't see the point.

It's better if programs use fcntl(F_SETFL), fseeko, and/or SET_BINARY
instead, whichever is more appropriate.

Bruno
-- 
In memoriam Nikolai Bryukhanov <http://en.wikipedia.org/wiki/Nikolai_Bryukhanov>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]