bug-gnulib
[Top][All Lists]
Advanced

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

[Bug-gnulib] getpass.c and use of putc_unlocked


From: Simon Josefsson
Subject: [Bug-gnulib] getpass.c and use of putc_unlocked
Date: Mon, 01 Nov 2004 00:33:38 +0100
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3.50 (gnu/linux)

I got this surprising error on FreeBSD:

/tmp/jas4711/gsasl-0.2.0/gl/getpass.c:192: undefined reference to 
`putc_unlocked'

Surprising, because getpass.c looks like this:

#include <stdio.h>
...
#if _LIBC
# define flockfile(s) _IO_flockfile (s)
# define funlockfile(s) _IO_funlockfile (s)
#elif USE_UNLOCKED_IO
# include "unlocked-io.h"
#else
# undef fflush_unlocked
# define fflush_unlocked(x) fflush (x)
# undef flockfile
# define flockfile(x) ((void) 0)
# undef funlockfile
# define funlockfile(x) ((void) 0)
# undef fputs_unlocked
# define fputs_unlocked(str,stream) fputs (str, stream)
# undef putc_unlocked
# define putc_unlocked(c,stream) putc (c, stream)
#endif
...
                putc_unlocked ('\n', out);

The problem is that FreeBSD stdio.h contain:

#define putc(x, fp)     putc_unlocked(x, fp)

So getpass.c translate the call to putc_unlocked into a call to putc,
which stdio.h translate back to putc_unlocked.  And there is no symbol
putc_unlocked, as per the error.

I believe POSIX allow for putc to be a macro, so FreeBSD's stdio.h is
arguable correct.

However, if POSIX also guarantee that putc is also provided as a
symbol, the following patch might be the right thing(1).  It does work
on FreeBSD.  Does anyone know for sure?  I know it is a horrible
solution, but it seem to fit nicely with the rest of the file...

Btw, why can't we simply remove the calls to flockfile + funlockfile,
and use putc?  Is there any benefit from using flockfile +
putc_unlocked + funlockfile that I'm missing?  I won't buy that
efficiency is a consideration, getpass is typically only run once for
very short strings.

Thanks.

(1): Perhaps the really right thing to do with getpass.c is to rewrite
   it.

--- getpass.c   12 Oct 2004 15:27:43 +0200      1.9
+++ getpass.c   01 Nov 2004 00:24:09 +0100      
@@ -67,6 +67,7 @@
 # undef fputs_unlocked
 # define fputs_unlocked(str,stream) fputs (str, stream)
 # undef putc_unlocked
+# undef putc
 # define putc_unlocked(c,stream) putc (c, stream)
 #endif
 




reply via email to

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