summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 446c6fa)
raw | patch | inline | side by side (parent: 446c6fa)
author | Ramsay Allan Jones <ramsay@ramsay1.demon.co.uk> | |
Sun, 30 Jul 2006 15:38:28 +0000 (16:38 +0100) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Wed, 2 Aug 2006 07:27:18 +0000 (00:27 -0700) |
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>
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>
Makefile | patch | blob | history | |
alloc.c | patch | blob | history | |
mktag.c | patch | blob | history |
diff --git a/Makefile b/Makefile
index 6df93c18fc3589592bc6598fd04bf9cf3ba7799e..e66e9b16a523223f135d7c57baa1339b8112efe9 100644 (file)
--- a/Makefile
+++ b/Makefile
# Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks
# d_type in struct dirent (latest Cygwin -- will be fixed soonish).
#
+# Define NO_C99_FORMAT if your formatted IO functions (printf/scanf et.al.)
+# do not support the 'size specifiers' introduced by C99, namely ll, hh,
+# j, z, t. (representing long long int, char, intmax_t, size_t, ptrdiff_t).
+# some c compilers supported these specifiers prior to C99 as an extension.
+#
# Define NO_STRCASESTR if you don't have strcasestr.
#
# Define NO_STRLCPY if you don't have strlcpy.
ifdef NO_D_INO_IN_DIRENT
ALL_CFLAGS += -DNO_D_INO_IN_DIRENT
endif
+ifdef NO_C99_FORMAT
+ ALL_CFLAGS += -DNO_C99_FORMAT
+endif
ifdef NO_SYMLINK_HEAD
ALL_CFLAGS += -DNO_SYMLINK_HEAD
endif
index e3b22f43228cae90290150ad2a5c81ed97f337de..460db192d5a7de4073eb89972871720dd1c8fe1e 100644 (file)
--- a/alloc.c
+++ b/alloc.c
DEFINE_ALLOCATOR(commit)
DEFINE_ALLOCATOR(tag)
+#ifdef NO_C99_FORMAT
+#define SZ_FMT "%u"
+#else
+#define SZ_FMT "%zu"
+#endif
+
+static void report(const char* name, unsigned int count, size_t size)
+{
+ fprintf(stderr, "%10s: %8u (" SZ_FMT " kB)\n", name, count, size);
+}
+
+#undef SZ_FMT
+
#define REPORT(name) \
- fprintf(stderr, "%10s: %8u (%zu kB)\n", #name, name##_allocs, name##_allocs*sizeof(struct name) >> 10)
+ report(#name, name##_allocs, name##_allocs*sizeof(struct name) >> 10)
void alloc_report(void)
{
index fa4a9e6003b5014fb8e222ad8813ce5954f9a38a..09b6e437d46a71b0123b5cb791cc537cf946e7a1 100644 (file)
--- a/mktag.c
+++ b/mktag.c
return ret;
}
+#ifdef NO_C99_FORMAT
+#define PD_FMT "%d"
+#else
+#define PD_FMT "%td"
+#endif
+
static int verify_tag(char *buffer, unsigned long size)
{
int typelen;
/* Verify tag-line */
tag_line = strchr(type_line, '\n');
if (!tag_line)
- return error("char%td: could not find next \"\\n\"", type_line - buffer);
+ return error("char" PD_FMT ": could not find next \"\\n\"", type_line - buffer);
tag_line++;
if (memcmp(tag_line, "tag ", 4) || tag_line[4] == '\n')
- return error("char%td: no \"tag \" found", tag_line - buffer);
+ return error("char" PD_FMT ": no \"tag \" found", tag_line - buffer);
/* Get the actual type */
typelen = tag_line - type_line - strlen("type \n");
if (typelen >= sizeof(type))
- return error("char%td: type too long", type_line+5 - buffer);
+ return error("char" PD_FMT ": type too long", type_line+5 - buffer);
memcpy(type, type_line+5, typelen);
type[typelen] = 0;
break;
if (c > ' ')
continue;
- return error("char%td: could not verify tag name", tag_line - buffer);
+ return error("char" PD_FMT ": could not verify tag name", tag_line - buffer);
}
/* Verify the tagger line */
tagger_line = tag_line;
if (memcmp(tagger_line, "tagger", 6) || (tagger_line[6] == '\n'))
- return error("char%td: could not find \"tagger\"", tagger_line - buffer);
+ return error("char" PD_FMT ": could not find \"tagger\"", tagger_line - buffer);
/* TODO: check for committer info + blank line? */
/* Also, the minimum length is probably + "tagger .", or 63+8=71 */
return 0;
}
+#undef PD_FMT
+
int main(int argc, char **argv)
{
unsigned long size = 4096;