threads / patch / 5084

patch, 10 partsFix header breakage with _XOPEN_SOURCE.

Subject: [PATCH 6/10] Fix header breakage with _XOPEN_SOURCE.

## tl;dr

5 messages between Aug 2, 2006 and Aug 5, 2006. Diffs are folded; open one to read it.

replies: 4people: 3as markdown or json

Ramsay Jones· Aug 2, 2006, 01:03 UTC · lore

convert-objects.c sets _XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED before including <time.h>, in order to get the declaration of strptime(). This leads to breakage in cache.h, due to S_ISLNK and S_IFLNK no longer being defined by <sys/stat.h>. These definitions are protected by the __USE_BSD symbol, which is not set when _XOPEN_SOURCE is set. Moving the #defines and #include <time.h> below all other #includes does not fix the problem, however, since now _USE_XOPEN, which protects the declaration of strptime(), is now not defined (don't ask!).

The fix is to #define _GNU_SOURCE, which enables the definition of practically everything.

Signed-off-by: Ramsay Allan Jones <ramsay@ramsay1.demon.co.uk>
---
 convert-objects.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
Show changes to convert-objects.c +1 −0
diff --git a/convert-objects.c b/convert-objects.c
index 0fabd89..971ad6d 100644
--- a/convert-objects.c
+++ b/convert-objects.c
@@ -1,5 +1,6 @@
 #define _XOPEN_SOURCE 500 /* glibc2 and AIX 5.3L need this */
 #define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */
+#define _GNU_SOURCE
 #include <time.h>
 #include "cache.h"
 #include "blob.h"
-- 
1.4.1


From 72f745c4c1e366a0f1fc75ec8da55a3cfb5457c7 Mon Sep 17 00:00:00 2001
From: Ramsay Allan Jones <ramsay@ramsay1.demon.co.uk>
Date: Sun, 30 Jul 2006 16:52:09 +0100
Subject: [PATCH 6/10] Fix header breakage with _XOPEN_SOURCE.

convert-objects.c sets _XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED before
including <time.h>, in order to get the declaration of strptime().
This leads to breakage in cache.h, due to S_ISLNK and S_IFLNK no longer
being defined by <sys/stat.h>.  These definitions are protected by the
__USE_BSD symbol, which is not set when _XOPEN_SOURCE is set.  Moving
the #defines and #include <time.h> below all other #includes does not
fix the problem, however, since now _USE_XOPEN, which protects the
declaration of strptime(), is now not defined (don't ask!).

The fix is to #define _GNU_SOURCE, which enables the definition of
practically everything.

Signed-off-by: Ramsay Allan Jones <ramsay@ramsay1.demon.co.uk>
---
 convert-objects.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/convert-objects.c b/convert-objects.c
index 0fabd89..971ad6d 100644
--- a/convert-objects.c
+++ b/convert-objects.c
@@ -1,5 +1,6 @@
 #define _XOPEN_SOURCE 500 /* glibc2 and AIX 5.3L need this */
 #define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */
+#define _GNU_SOURCE
 #include <time.h>
 #include "cache.h"
 #include "blob.h"
-- 
1.4.1
Junio C Hamano· Aug 2, 2006, 07:46 UTC · re: Ramsay Jones · lore

Re: [PATCH 6/10] Fix header breakage with _XOPEN_SOURCE.

"Ramsay Jones" <ramsay@ramsay1.demon.co.uk> writes:
Show 8 quoted lines
> convert-objects.c sets _XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED before
> including <time.h>, in order to get the declaration of strptime().
> This leads to breakage in cache.h, due to S_ISLNK and S_IFLNK no longer
> being defined by <sys/stat.h>.  These definitions are protected by the
> __USE_BSD symbol, which is not set when _XOPEN_SOURCE is set.  Moving
> the #defines and #include <time.h> below all other #includes does not
> fix the problem, however, since now _USE_XOPEN, which protects the
> declaration of strptime(), is now not defined (don't ask!).

Wouldn't including "cache.h" and friends first and including <time.h> last solve the problem, then?

This kind of change tends to fix one system while potentially breaking another, and we would need to be careful. Will queue for post 1.4.2 and have people scream if it breaks somebody, I guess.

Ramsay Jones· Aug 2, 2006, 18:47 UTC · re: Junio C Hamano · lore

RE: [PATCH 6/10] Fix header breakage with _XOPEN_SOURCE.

On Wed, 2006-08-02 at 8:46, Junio C Hamano wrote:
Show 15 quoted lines
> 
> "Ramsay Jones" <ramsay@ramsay1.demon.co.uk> writes:
> 
> > convert-objects.c sets _XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED before
> > including <time.h>, in order to get the declaration of strptime().
> > This leads to breakage in cache.h, due to S_ISLNK and S_IFLNK no longer
> > being defined by <sys/stat.h>.  These definitions are protected by the
> > __USE_BSD symbol, which is not set when _XOPEN_SOURCE is set.  Moving
> > the #defines and #include <time.h> below all other #includes does not
> > fix the problem, however, since now _USE_XOPEN, which protects the
> > declaration of strptime(), is now not defined (don't ask!).
> 
> Wouldn't including "cache.h" and friends first and including
> <time.h> last solve the problem, then?
> 

Not for me. It may be a glibc 2.1 specific problem, of course, but strptime() remains undeclared.

Show 5 quoted lines
> This kind of change tends to fix one system while potentially
> breaking another, and we would need to be careful.  Will queue
> for post 1.4.2 and have people scream if it breaks somebody, I
> guess.
> 

Yes, I had some concern about that myself. Unfortunately, you can't make it conditional on the glibc version macros; in order to get the macros, you have to include (one way or another) <features.h>, at which point it is already too late ...

Ramsay
Johannes Schindelin· Aug 4, 2006, 00:19 UTC · re: Ramsay Jones · lore

RE: [PATCH 6/10] Fix header breakage with _XOPEN_SOURCE.

Hi,
On Wed, 2 Aug 2006, Ramsay Jones wrote:
> [...] but strptime() remains undeclared.

Note that there is just one call to strptime() in the C sources: convert-objects.

Also, we have something more portable in git now: you might be able to substitute

	const char *next = strptime(buf, *fmt, &tm);
	if (next) {
by something like
	char buffer[50];
	int len = parse_date(buf, buffer, sizeof(buffer));
	const char *next = buf + len;
	if (len) {
		const char *tzstring = strchr(buffer, ' ') + 1;
		int tz = (int)strtol(tzstring, NULL, 10);
		tm = *time_to_tm(strtoul(buffer, NULL, 10), tz);
However, I did not test it, and this might be completely bogus.
Ciao,
Dscho
	
Ramsay Jones· Aug 5, 2006, 17:11 UTC · re: Johannes Schindelin · lore

RE: [PATCH 6/10] Fix header breakage with _XOPEN_SOURCE.

On Fri, 2006-08-04 at 1:20, Johannes Schindelin wrote:
Show 28 quoted lines
> Hi,
> 
> On Wed, 2 Aug 2006, Ramsay Jones wrote:
> 
> > [...] but strptime() remains undeclared.
> 
> Note that there is just one call to strptime() in the C sources: 
> convert-objects.
> 
> Also, we have something more portable in git now: you might be able to 
> substitute
> 
> 	const char *next = strptime(buf, *fmt, &tm);
> 	if (next) {
> 
> by something like
> 
> 	char buffer[50];
> 	int len = parse_date(buf, buffer, sizeof(buffer));
> 	const char *next = buf + len;
> 
> 	if (len) {
> 		const char *tzstring = strchr(buffer, ' ') + 1;
> 		int tz = (int)strtol(tzstring, NULL, 10);
> 		tm = *time_to_tm(strtoul(buffer, NULL, 10), tz);
> 
> However, I did not test it, and this might be completely bogus.
> 

Yes, I'm sure something like that could be done, but I really don't think we need anything that intrusive to fix such a simple problem. Indeed, I would rather Junio ignore the patch if it appears to cause anyone else a problem. I can maintain it locally (it's only one line!). After all, I'm pretty sure I'm the only idiot^H^H^H^H^H person using a six year old dev system.

Ramsay

← back to recent threads