Page MenuHome GnuPG

gpgme-1.24.1 and gpgme-1.24.2 do not compile on Mac OS X 10.4.11, Tiger, because of problem with strcasecmp/strncasecmp in gpgme-tool.c
Open, NormalPublic

Description

When compiling this error happens:

> Making all in src
> make[2]: Entering directory `/opt/local/var/macports/build/nue.de.rsync.macports.org_macports_release_tarballs_ports_devel_gpgme/gpgme/work/gpgme-1.24.1/src'
> /opt/local/bin/gcc-mp-14 -DHAVE_CONFIG_H -I. -I../conf   -I/opt/local/include -I/opt/local/include -I/opt/local/include  -pipe -Os -arch ppc -Wall -Wcast-align -Wshadow -Wstrict-prototypes -Wno-format-y2k -Wno-missing-field-initializers -Wno-sign-compare -Wno-format-zero-length -Wno-format-truncation -Wno-sizeof-pointer-div -MT gpgme-tool.o -MD -MP -MF .deps/gpgme-tool.Tpo -c -o gpgme-tool.o gpgme-tool.c
> gpgme-tool.c: In function 'gt_protocol_from_name':
> gpgme-tool.c:1325:9: error: implicit declaration of function 'strcasecmp' [-Wimplicit-function-declaration]
>  1325 |   if (! strcasecmp (name, gpgme_get_protocol_name (GPGME_PROTOCOL_OpenPGP)))
>       |         ^~~~~~~~~~
> gpgme-tool.c: In function 'server_parse_fd':
> gpgme-tool.c:1865:9: error: implicit declaration of function 'strncasecmp' [-Wimplicit-function-declaration]
>  1865 |   if (! strncasecmp (line, "file=", 5))
>       |         ^~~~~~~~~~~
> gpgme-tool.c:1865:37: warning: 'strncasecmp' argument 3 type is 'int' where 'long unsigned int' is expected in a call to built-in function declared without prototype [-Wbuiltin-declaration-mismatch]
>  1865 |   if (! strncasecmp (line, "file=", 5))
>       |                                     ^
> <built-in>: note: built-in 'strncasecmp' declared here
> make[2]: *** [gpgme-tool.o] Error 1

The two functions are declared in:

/usr/include/string.h:

  102	#ifndef _POSIX_C_SOURCE
  103	char	*strnstr(const char *, const char *, size_t);
  104	#endif	/* !_POSIX_C_SOURCE */
  105	char	*strpbrk(const char *, const char *);
  106	char	*strrchr(const char *, int);
  107	size_t	 strspn(const char *, const char *);
  108	char	*strstr(const char *, const char *);
  109	char	*strtok(char *, const char *);
  110	size_t	 strxfrm(char *, const char *, size_t);
  111	
  112	/* Nonstandard routines */
  113	#ifndef _ANSI_SOURCE
  114	void	*memccpy(void *, const void *, int, size_t);
  115	char	*strtok_r(char *, const char *, char **);
  116	char	*strdup(const char *);
  117	#ifndef _POSIX_C_SOURCE
  118	int	 bcmp(const void *, const void *, size_t);
  119	void	 bcopy(const void *, void *, size_t);
  120	void	 bzero(void *, size_t);
  121	int	 ffs(int);
  122	char	*index(const char *, int);
  123	char	*rindex(const char *, int);
  124	int	 strcasecmp(const char *, const char *);
  125	size_t	 strlcat(char *, const char *, size_t);
  126	size_t	 strlcpy(char *, const char *, size_t);
  127	void	 strmode(int, char *);
  128	int	 strncasecmp(const char *, const char *, size_t);
  129	char	*strsep(char **, const char *);
  130	char	*strsignal(int sig);
  131	void	 swab(const void * __restrict, void * __restrict, ssize_t);
  132	#endif	/* !_POSIX_C_SOURCE */
  133	#endif 	/* !_ANSI_SOURCE */

/usr/include/strings.h:

   58	#if !defined(_XOPEN_SOURCE) && !defined(_POSIX_C_SOURCE)
   59	
   60	#include <string.h>
   61	
   62	#else
   63	
   64	#include <_types.h>
   65	
   66	#ifndef	_SIZE_T
   67	#define	_SIZE_T
   68	typedef	__darwin_size_t	size_t;
   69	#endif
   70	
   71	int      bcmp(const void *, const void *, size_t);
   72	void     bcopy(const void *, void *, size_t);
   73	void     bzero(void *, size_t);
   74	int      ffs(int);
   75	char    *index(const char *, int);
   76	char    *rindex(const char *, int); 
   77	int      strcasecmp(const char *, const char *);
   78	int      strncasecmp(const char *, const char *, size_t);
   79	
   80	#endif  /* _POSIX_C_SOURCE */

When substituting #include <string.h> with #include <strings.h> memcpy() is not found.

Mac OS X 10.4.11 is darwin 8.11.0.

Details

Version
1.24.1, 1.24.2

Event Timeline

ballapete triaged this task as Normal priority.Feb 16 2025, 3:57 PM
ballapete created this task.
ballapete created this object in space S1 Public.

I tried to apply crude patches. Since _POSIX_C_SOURCE is defined when <string.h> is included (in pre-compiled source I see

# 235 "/usr/include/sys/cdefs.h" 3 4
#define __DARWIN_UNIX03 1
# 244 "/usr/include/sys/cdefs.h" 3 4
#define __DARWIN_ALIAS(sym) __asm("_" __STRING(sym) "$UNIX2003")
# 287 "/usr/include/sys/cdefs.h" 3 4
#undef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 199506L
# 305 "/usr/include/sys/cdefs.h" 3 4
#define __DARWIN_NO_LONG_LONG (defined(__STRICT_ANSI__) && (__STDC_VERSION__-0 < 199901L) && !defined(__GNUG__))
# 321 "/usr/include/sys/cdefs.h" 3 4

from where I'll later copy two lines) it's probably OK when I undefine it before the C header gets included. So I applied this patch to gpgme-tool.c:

diff -u gpgme-tool.c~ gpgme-tool.c
--- gpgme-tool.c~	2024-08-13 08:49:35.000000000 +0200
+++ gpgme-tool.c	2025-04-11 17:51:33.000000000 +0200
@@ -25,7 +25,9 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#undef _POSIX_C_SOURCE
 #include <string.h>
+#define _POSIX_C_SOURCE 199506L
 #include <errno.h>
 #include <getopt.h>
 #include <ctype.h>

The file now compiled. Some more files show similar behaviour on Tiger:

libtool: compile:  /opt/local/bin/gcc-mp-14 -DHAVE_CONFIG_H -I. -I../conf -I/opt/local/include -I/opt/local/include -I/opt/local/include -pipe -Os -arch ppc -Wall -Wcast-align -Wshadow -Wstrict-prototypes -Wno-format-y2k -Wno-missing-field-initializers -Wno-sign-compare -Wno-format-zero-length -Wno-format-truncation -Wno-sizeof-pointer-div -MT key.lo -MD -MP -MF .deps/key.Tpo -c key.c  -fno-common -DPIC -o .libs/key.o
key.c: In function '_gpgme_key_append_name':
key.c:240:11: error: implicit declaration of function 'strcasecmp' [-Wimplicit-function-declaration]
  240 |       && !strcasecmp (uid->name, uid->address))
      |           ^~~~~~~~~~
make[2]: *** [key.lo] Error 1

which leads to:

--- key.c~	2024-09-09 16:58:10.000000000 +0200
+++ key.c	2025-04-11 18:15:03.000000000 +0200
@@ -23,7 +23,9 @@
 #include <config.h>
 #endif
 #include <stdlib.h>
+#undef _POSIX_C_SOURCE
 #include <string.h>
+#define _POSIX_C_SOURCE 199506L
 #include <assert.h>
 #include <errno.h>

A more complicated case is this one:

libtool: compile:  /opt/local/bin/gcc-mp-14 -DHAVE_CONFIG_H -I. -I../conf -I/opt/local/include -I/opt/local/include -I/opt/local/include -pipe -Os -arch ppc -Wall -Wcast-align -Wshadow -Wstrict-prototypes -Wno-format-y2k -Wno-missing-field-initializers -Wno-sign-compare -Wno-format-zero-length -Wno-format-truncation -Wno-sizeof-pointer-div -MT conversion.lo -MD -MP -MF .deps/conversion.Tpo -c conversion.c  -fno-common -DPIC -o .libs/conversion.o
conversion.c: In function 'do_strconcat':
conversion.c:85:13: error: implicit declaration of function 'stpcpy' [-Wimplicit-function-declaration]
   85 |         p = stpcpy (p, argv[argc]);
      |             ^~~~~~
conversion.c:85:13: warning: incompatible implicit declaration of built-in function 'stpcpy' [-Wbuiltin-declaration-mismatch]
conversion.c: In function '_gpgme_parse_timestamp':
conversion.c:605:14: error: implicit declaration of function 'timegm'; did you mean 'time'? [-Wimplicit-function-declaration]
  605 |       return timegm (&buf);
      |              ^~~~~~
      |              time
make[2]: *** [conversion.lo] Error 1
make[2]: Leaving directory `/opt/local/var/macports/build/nue.de.rsync.macports.org_macports_release_tarballs_ports_devel_gpgme/gpgme/work/gpgme-1.24.2/src'

Two functions need help. In /usr/include/time.h we have:

142	#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE)
143	char *asctime_r(const struct tm *, char *);
144	char *ctime_r(const time_t *, char *);
145	struct tm *gmtime_r(const time_t *, struct tm *);
146	struct tm *localtime_r(const time_t *, struct tm *);
147	time_t posix2time(time_t);
148	#if !__DARWIN_UNIX03
149	char *timezone(int, int);
150	#endif /* !__DARWIN_UNIX03 */
151	void tzsetwall(void);
152	time_t time2posix(time_t);
153	time_t timelocal(struct tm * const);
154	time_t timegm(struct tm * const);
155	#endif /* neither ANSI nor POSIX */

So the patch becomes:

--- conversion.c~	2024-11-14 11:48:12.000000000 +0100
+++ conversion.c	2025-04-11 18:08:22.000000000 +0200
@@ -24,12 +24,16 @@
 #endif
 
 #include <stdlib.h>
+#undef _POSIX_C_SOURCE
 #include <string.h>
+#define _POSIX_C_SOURCE 199506L
 #ifdef HAVE_SYS_TYPES_H
   /* Solaris 8 needs sys/types.h before time.h.  */
 # include <sys/types.h>
 #endif
+#undef _POSIX_C_SOURCE
 #include <time.h>
+#define _POSIX_C_SOURCE 199506L
 #include <errno.h>
 #include <stdarg.h>
 #include <assert.h>

And there's this one:

libtool: compile:  /opt/local/bin/gcc-mp-14 -DHAVE_CONFIG_H -I. -I../conf -I/opt/local/include -I/opt/local/include -I/opt/local/include -pipe -Os -arch ppc -Wall -Wcast-align -Wshadow -Wstrict-prototypes -Wno-format-y2k -Wno-missing-field-initializers -Wno-sign-compare -Wno-format-zero-length -Wno-format-truncation -Wno-sizeof-pointer-div -MT vfs-mount.lo -MD -MP -MF .deps/vfs-mount.Tpo -c vfs-mount.c  -fno-common -DPIC -o .libs/vfs-mount.o
vfs-mount.c: In function '_gpgme_vfs_mount_status_handler':
vfs-mount.c:71:9: error: implicit declaration of function 'strcasecmp' [-Wimplicit-function-declaration]
   71 |   if (! strcasecmp ("MOUNTPOINT", code))
      |         ^~~~~~~~~~
make[2]: *** [vfs-mount.lo] Error 1

vfs-mount.c does not include <string.h>, it's done via "debug.h".

--- debug.h~	2024-08-13 08:49:35.000000000 +0200
+++ debug.h	2025-04-11 18:29:26.000000000 +0200
@@ -21,7 +21,9 @@
 #ifndef DEBUG_H
 #define DEBUG_H
 
+#undef _POSIX_C_SOURCE
 #include <string.h>
+#define _POSIX_C_SOURCE 199506L
 #ifdef HAVE_STDINT_H
 #include <stdint.h>
 #endif

Step by step GpgME built. Configure found:

checking for string.h... yes
checking for strings.h... yes

checking for timegm... yes

I finally erased the source from my disk and prepared a patch set (see attachment) that was applied automatically for next build. Which was successful. So for me a solution seems to exist…

patch set used.