Add NO_C99_FORMAT to support older compilers.
The NO_C99_FORMAT macro allows compilers that lack support for the ll,hh,j,z,t size specifiers (eg. gcc 2.95.2) to adapt the code to avoid runtime errors in the formatted IO functions. Signed-off-by: Ramsay Allan Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Junio C Hamano <junkio@cox.net>
Ramsay Allan Jones committed
Jul 30, 2006 at 16:38 UTC
579d1fbfaf25550254014fa472faac95f88eb779
3 files changed
+35
-6
Makefile
+8
@@ -24,6 +24,11 @@ all:
24
# Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks
25
# d_type in struct dirent (latest Cygwin -- will be fixed soonish).
26
#
27
+# Define NO_C99_FORMAT if your formatted IO functions (printf/scanf et.al.)
28
+# do not support the 'size specifiers' introduced by C99, namely ll, hh,
29
+# j, z, t. (representing long long int, char, intmax_t, size_t, ptrdiff_t).
30
+# some c compilers supported these specifiers prior to C99 as an extension.
31
+#
32
# Define NO_STRCASESTR if you don't have strcasestr.
33
#
34
# Define NO_STRLCPY if you don't have strlcpy.
@@ -432,6 +437,9 @@ endif
437
ifdef NO_D_INO_IN_DIRENT
438
ALL_CFLAGS += -DNO_D_INO_IN_DIRENT
439
endif
440
+ifdef NO_C99_FORMAT
441
+ ALL_CFLAGS += -DNO_C99_FORMAT
442
+endif
443
ifdef NO_SYMLINK_HEAD
444
ALL_CFLAGS += -DNO_SYMLINK_HEAD
445
endif
alloc.c
+14
-1
@@ -39,8 +39,21 @@ DEFINE_ALLOCATOR(tree)
39
DEFINE_ALLOCATOR(commit)
40
DEFINE_ALLOCATOR(tag)
41
42
+#ifdef NO_C99_FORMAT
43
+#define SZ_FMT "%u"
44
+#else
45
+#define SZ_FMT "%zu"
46
+#endif
47
+
48
+static void report(const char* name, unsigned int count, size_t size)
49
+{
50
+ fprintf(stderr, "%10s: %8u (" SZ_FMT " kB)\n", name, count, size);
51
+}
52
+
53
+#undef SZ_FMT
54
+
55
#define REPORT(name) \
43
- fprintf(stderr, "%10s: %8u (%zu kB)\n", #name, name##_allocs, name##_allocs*sizeof(struct name) >> 10)
56
+ report(#name, name##_allocs, name##_allocs*sizeof(struct name) >> 10)
57
58
void alloc_report(void)
59
{
mktag.c
+13
-5
@@ -39,6 +39,12 @@ static int verify_object(unsigned char *sha1, const char *expected_type)
39
return ret;
40
}
41
42
+#ifdef NO_C99_FORMAT
43
+#define PD_FMT "%d"
44
+#else
45
+#define PD_FMT "%td"
46
+#endif
47
+
48
static int verify_tag(char *buffer, unsigned long size)
49
{
50
int typelen;
@@ -67,15 +73,15 @@ static int verify_tag(char *buffer, unsigned long size)
73
/* Verify tag-line */
74
tag_line = strchr(type_line, '\n');
75
if (!tag_line)
70
- return error("char%td: could not find next \"\\n\"", type_line - buffer);
76
+ return error("char" PD_FMT ": could not find next \"\\n\"", type_line - buffer);
77
tag_line++;
78
if (memcmp(tag_line, "tag ", 4) || tag_line[4] == '\n')
73
- return error("char%td: no \"tag \" found", tag_line - buffer);
79
+ return error("char" PD_FMT ": no \"tag \" found", tag_line - buffer);
80
81
/* Get the actual type */
82
typelen = tag_line - type_line - strlen("type \n");
83
if (typelen >= sizeof(type))
78
- return error("char%td: type too long", type_line+5 - buffer);
84
+ return error("char" PD_FMT ": type too long", type_line+5 - buffer);
85
86
memcpy(type, type_line+5, typelen);
87
type[typelen] = 0;
@@ -92,14 +98,14 @@ static int verify_tag(char *buffer, unsigned long size)
98
break;
99
if (c > ' ')
100
continue;
95
- return error("char%td: could not verify tag name", tag_line - buffer);
101
+ return error("char" PD_FMT ": could not verify tag name", tag_line - buffer);
102
}
103
104
/* Verify the tagger line */
105
tagger_line = tag_line;
106
107
if (memcmp(tagger_line, "tagger", 6) || (tagger_line[6] == '\n'))
102
- return error("char%td: could not find \"tagger\"", tagger_line - buffer);
108
+ return error("char" PD_FMT ": could not find \"tagger\"", tagger_line - buffer);
109
110
/* TODO: check for committer info + blank line? */
111
/* Also, the minimum length is probably + "tagger .", or 63+8=71 */
@@ -108,6 +114,8 @@ static int verify_tag(char *buffer, unsigned long size)
114
return 0;
115
}
116
117
+#undef PD_FMT
118
+
119
int main(int argc, char **argv)
120
{
121
unsigned long size = 4096;