libksba-1.0.5 and FreeBSD 5.0 IA32: how to make the build succeed

Nelson H. F. Beebe beebe at math.utah.edu
Wed Jan 14 01:38:13 CET 2009


A build of libksba-1.0.5 on FreeBSD 5.0 IA32 failed with

	gcc -DHAVE_CONFIG_H -I. -I.. -I.. -I../include    -I/usr/local/include \
		-Wall -Wcast-align -Wshadow -Wstrict-prototypes -Wpointer-arith \
		-MT putc_unlocked.o -MD -MP -MF .deps/putc_unlocked.Tpo -c -o \
		putc_unlocked.o putc_unlocked.c
	putc_unlocked.c:28: error: redefinition of '__sputc'
	/usr/local/lib/gcc/i386-unknown-freebsd5.0/3.4.3/include/stdio.h:405: error:
	previous definition of '__sputc' was here

Examination of <stdio.h> turned up these blocks:

	#if __POSIX_VISIBLE >= 199506
	int	 ftrylockfile(FILE *);
	void	 flockfile(FILE *);
	void	 funlockfile(FILE *);

	/*
	 * These are normally used through macros as defined below, but POSIX
	 * requires functions as well.
	 */
	int	 getc_unlocked(FILE *);
	int	 getchar_unlocked(void);
	int	 putc_unlocked(int, FILE *);
	int	 putchar_unlocked(int);
	#endif
	#if __POSIX_VISIBLE >= 199506
	#define	getc_unlocked(fp)	__sgetc(fp)
	#define	putc_unlocked(x, fp)	__sputc(x, fp)

	#define	getchar_unlocked()	getc_unlocked(stdin)
	#define	putchar_unlocked(x)	putc_unlocked(x, stdout)
	#endif

I therefore made the following change to the source code of
libassuan-1.0.5:

% diff -c ./src/putc_unlocked.c.org ./src/putc_unlocked.c
*** ./src/putc_unlocked.c.org   Thu Aug 23 23:29:48 2007
--- ./src/putc_unlocked.c       Tue Jan 13 17:29:01 2009
***************
*** 23,30 ****
--- 23,32 ----

  #include <stdio.h>

+ #if !defined(putc_unlocked)
  int
  putc_unlocked (int c, FILE *stream)
  {
    return putc (c, stream);
  }
+ #endif

I restarted the build, which was successful, and all tests passed, so
I installed the library.

I suspect the correct way to fix this is not to supply a private
definition of putc_unlocked() if there is already a working definition
in <stdio.h>, which is likely to be the case on pretty much all Unix
platforms, because they support POSIX specs.  A configure-time test
can likely do this nicely.  The function in src/putc_unlocked.c could
then be bracketed with

#if !defined(HAVE_PUTC_UNLOCKED)
...
#endif

I note this requirement in the POSIX Standard (IEEE Std 1003.1-2001):

15969               Versions of the functions getc( ), getchar( ), putc( ), and putchar( ) respectively named
15970               getc_unlocked ( ), getchar_unlocked( ), putc_unlocked( ), and putchar_unlocked( ) shall be provided
15971               which are functionally equivalent to the original versions, with the exception that they are not
15972               required to be implemented in a thread-safe manner. They may only safely be used within a
15973               scope protected by flockfile ( ) (or ftrylockfile ( )) and funlockfile ( ). These functions may safely be
15974               used in a multi-threaded program if and only if they are called while the invoking thread owns
15975               the (FILE *) object, as is the case after a successful call to the flockfile ( ) or ftrylockfile ( ) functions.

Thus, any change in this area needs to think carefully about
thread ramifications.

-------------------------------------------------------------------------------
- Nelson H. F. Beebe                    Tel: +1 801 581 5254                  -
- University of Utah                    FAX: +1 801 581 4148                  -
- Department of Mathematics, 110 LCB    Internet e-mail: beebe at math.utah.edu  -
- 155 S 1400 E RM 233                       beebe at acm.org  beebe at computer.org -
- Salt Lake City, UT 84112-0090, USA    URL: http://www.math.utah.edu/~beebe/ -
-------------------------------------------------------------------------------



More information about the Gnupg-devel mailing list