{"thread":{"id":"5081","subject":"[PATCH 5/10] Add NO_C99_FORMAT to support older compilers.","startedAt":"2006-08-02T01:03:34Z","lastAt":"2006-08-02T01:03:34Z","messageCount":1,"participants":["Ramsay Jones"],"isPatch":true,"patchVersion":1,"patchTotal":10},"messages":[{"id":"24538","messageId":"00b201c6b5cf$7a59c8c0$c47eedc1@ramsay1.demon.co.uk","threadId":"5081","inReplyTo":null,"subject":"[PATCH 5/10] Add NO_C99_FORMAT to support older compilers.","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsay1.demon.co.uk","sentAt":"2006-08-02T01:03:34Z","receivedAt":"2006-08-02T01:03:34Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"The NO_C99_FORMAT macro allows compilers that lack support for the\nll,hh,j,z,t size specifiers (eg. gcc 2.95.2) to adapt the code to avoid\nruntime errors in the formatted IO functions.\n\nSigned-off-by: Ramsay Allan Jones <ramsay@ramsay1.demon.co.uk>\n---\n Makefile |    8 ++++++++\n alloc.c  |   15 ++++++++++++++-\n mktag.c  |   18 +++++++++++++-----\n 3 files changed, 35 insertions(+), 6 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 180dbd0..2b72c79 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -24,6 +24,11 @@ #\n # Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks\n # d_type in struct dirent (latest Cygwin -- will be fixed soonish).\n #\n+# Define NO_C99_FORMAT if your formatted IO functions (printf/scanf et.al.)\n+# do not support the 'size specifiers' introduced by C99, namely ll, hh,\n+# j, z, t. (representing long long int, char, intmax_t, size_t, ptrdiff_t).\n+# some c compilers supported these specifiers prior to C99 as an extension.\n+#\n # Define NO_STRCASESTR if you don't have strcasestr.\n #\n # Define NO_STRLCPY if you don't have strlcpy.\n@@ -406,6 +411,9 @@ endif\n ifdef NO_D_INO_IN_DIRENT\n \tALL_CFLAGS += -DNO_D_INO_IN_DIRENT\n endif\n+ifdef NO_C99_FORMAT\n+\tALL_CFLAGS += -DNO_C99_FORMAT\n+endif\n ifdef NO_SYMLINK_HEAD\n \tALL_CFLAGS += -DNO_SYMLINK_HEAD\n endif\ndiff --git a/alloc.c b/alloc.c\nindex e3b22f4..460db19 100644\n--- a/alloc.c\n+++ b/alloc.c\n@@ -39,8 +39,21 @@ DEFINE_ALLOCATOR(tree)\n DEFINE_ALLOCATOR(commit)\n DEFINE_ALLOCATOR(tag)\n\n+#ifdef NO_C99_FORMAT\n+#define SZ_FMT \"%u\"\n+#else\n+#define SZ_FMT \"%zu\"\n+#endif\n+\n+static void report(const char* name, unsigned int count, size_t size)\n+{\n+    fprintf(stderr, \"%10s: %8u (\" SZ_FMT \" kB)\\n\", name, count, size);\n+}\n+\n+#undef SZ_FMT\n+\n #define REPORT(name)\t\\\n-\tfprintf(stderr, \"%10s: %8u (%zu kB)\\n\", #name, name##_allocs,\nname##_allocs*sizeof(struct name) >> 10)\n+    report(#name, name##_allocs, name##_allocs*sizeof(struct name) >> 10)\n\n void alloc_report(void)\n {\ndiff --git a/mktag.c b/mktag.c\nindex 9bae223..be41513 100644\n--- a/mktag.c\n+++ b/mktag.c\n@@ -39,6 +39,12 @@ static int verify_object(unsigned char *\n \treturn ret;\n }\n\n+#ifdef NO_C99_FORMAT\n+#define PD_FMT \"%d\"\n+#else\n+#define PD_FMT \"%td\"\n+#endif\n+\n static int verify_tag(char *buffer, unsigned long size)\n {\n \tint typelen;\n@@ -67,15 +73,15 @@ static int verify_tag(char *buffer, unsi\n \t/* Verify tag-line */\n \ttag_line = strchr(type_line, '\\n');\n \tif (!tag_line)\n-\t\treturn error(\"char%td: could not find next \\\"\\\\n\\\"\", type_line - buffer);\n+\t\treturn error(\"char\" PD_FMT \": could not find next \\\"\\\\n\\\"\", type_line -\nbuffer);\n \ttag_line++;\n \tif (memcmp(tag_line, \"tag \", 4) || tag_line[4] == '\\n')\n-\t\treturn error(\"char%td: no \\\"tag \\\" found\", tag_line - buffer);\n+\t\treturn error(\"char\" PD_FMT \": no \\\"tag \\\" found\", tag_line - buffer);\n\n \t/* Get the actual type */\n \ttypelen = tag_line - type_line - strlen(\"type \\n\");\n \tif (typelen >= sizeof(type))\n-\t\treturn error(\"char%td: type too long\", type_line+5 - buffer);\n+\t\treturn error(\"char\" PD_FMT \": type too long\", type_line+5 - buffer);\n\n \tmemcpy(type, type_line+5, typelen);\n \ttype[typelen] = 0;\n@@ -92,14 +98,14 @@ static int verify_tag(char *buffer, unsi\n \t\t\tbreak;\n \t\tif (c > ' ')\n \t\t\tcontinue;\n-\t\treturn error(\"char%td: could not verify tag name\", tag_line - buffer);\n+\t\treturn error(\"char\" PD_FMT \": could not verify tag name\", tag_line -\nbuffer);\n \t}\n\n \t/* Verify the tagger line */\n \ttagger_line = tag_line;\n\n \tif (memcmp(tagger_line, \"tagger\", 6) || (tagger_line[6] == '\\n'))\n-\t\treturn error(\"char%td: could not find \\\"tagger\\\"\", tagger_line - buffer);\n+\t\treturn error(\"char\" PD_FMT \": could not find \\\"tagger\\\"\", tagger_line -\nbuffer);\n\n \t/* TODO: check for committer info + blank line? */\n \t/* Also, the minimum length is probably + \"tagger .\", or 63+8=71 */\n@@ -108,6 +114,8 @@ static int verify_tag(char *buffer, unsi\n \treturn 0;\n }\n\n+#undef PD_FMT\n+\n int main(int argc, char **argv)\n {\n \tunsigned long size = 4096;\n--\n1.4.1\n\n\nFrom b1456ff7fa2b1a02f3cd71ef596f30df9d634d99 Mon Sep 17 00:00:00 2001\nFrom: Ramsay Allan Jones <ramsay@ramsay1.demon.co.uk>\nDate: Sun, 30 Jul 2006 16:38:28 +0100\nSubject: [PATCH 5/10] Add NO_C99_FORMAT to support older compilers.\n\nThe NO_C99_FORMAT macro allows compilers that lack support for the\nll,hh,j,z,t size specifiers (eg. gcc 2.95.2) to adapt the code to avoid\nruntime errors in the formatted IO functions.\n\nSigned-off-by: Ramsay Allan Jones <ramsay@ramsay1.demon.co.uk>\n---\n Makefile |    8 ++++++++\n alloc.c  |   15 ++++++++++++++-\n mktag.c  |   18 +++++++++++++-----\n 3 files changed, 35 insertions(+), 6 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 180dbd0..2b72c79 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -24,6 +24,11 @@ #\n # Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks\n # d_type in struct dirent (latest Cygwin -- will be fixed soonish).\n #\n+# Define NO_C99_FORMAT if your formatted IO functions (printf/scanf et.al.)\n+# do not support the 'size specifiers' introduced by C99, namely ll, hh,\n+# j, z, t. (representing long long int, char, intmax_t, size_t, ptrdiff_t).\n+# some c compilers supported these specifiers prior to C99 as an extension.\n+#\n # Define NO_STRCASESTR if you don't have strcasestr.\n #\n # Define NO_STRLCPY if you don't have strlcpy.\n@@ -406,6 +411,9 @@ endif\n ifdef NO_D_INO_IN_DIRENT\n \tALL_CFLAGS += -DNO_D_INO_IN_DIRENT\n endif\n+ifdef NO_C99_FORMAT\n+\tALL_CFLAGS += -DNO_C99_FORMAT\n+endif\n ifdef NO_SYMLINK_HEAD\n \tALL_CFLAGS += -DNO_SYMLINK_HEAD\n endif\ndiff --git a/alloc.c b/alloc.c\nindex e3b22f4..460db19 100644\n--- a/alloc.c\n+++ b/alloc.c\n@@ -39,8 +39,21 @@ DEFINE_ALLOCATOR(tree)\n DEFINE_ALLOCATOR(commit)\n DEFINE_ALLOCATOR(tag)\n \n+#ifdef NO_C99_FORMAT\n+#define SZ_FMT \"%u\"\n+#else\n+#define SZ_FMT \"%zu\"\n+#endif\n+\n+static void report(const char* name, unsigned int count, size_t size)\n+{\n+    fprintf(stderr, \"%10s: %8u (\" SZ_FMT \" kB)\\n\", name, count, size);\n+}\n+\n+#undef SZ_FMT\n+\n #define REPORT(name)\t\\\n-\tfprintf(stderr, \"%10s: %8u (%zu kB)\\n\", #name, name##_allocs, name##_allocs*sizeof(struct name) >> 10)\n+    report(#name, name##_allocs, name##_allocs*sizeof(struct name) >> 10)\n \n void alloc_report(void)\n {\ndiff --git a/mktag.c b/mktag.c\nindex 9bae223..be41513 100644\n--- a/mktag.c\n+++ b/mktag.c\n@@ -39,6 +39,12 @@ static int verify_object(unsigned char *\n \treturn ret;\n }\n \n+#ifdef NO_C99_FORMAT\n+#define PD_FMT \"%d\"\n+#else\n+#define PD_FMT \"%td\"\n+#endif\n+\n static int verify_tag(char *buffer, unsigned long size)\n {\n \tint typelen;\n@@ -67,15 +73,15 @@ static int verify_tag(char *buffer, unsi\n \t/* Verify tag-line */\n \ttag_line = strchr(type_line, '\\n');\n \tif (!tag_line)\n-\t\treturn error(\"char%td: could not find next \\\"\\\\n\\\"\", type_line - buffer);\n+\t\treturn error(\"char\" PD_FMT \": could not find next \\\"\\\\n\\\"\", type_line - buffer);\n \ttag_line++;\n \tif (memcmp(tag_line, \"tag \", 4) || tag_line[4] == '\\n')\n-\t\treturn error(\"char%td: no \\\"tag \\\" found\", tag_line - buffer);\n+\t\treturn error(\"char\" PD_FMT \": no \\\"tag \\\" found\", tag_line - buffer);\n \n \t/* Get the actual type */\n \ttypelen = tag_line - type_line - strlen(\"type \\n\");\n \tif (typelen >= sizeof(type))\n-\t\treturn error(\"char%td: type too long\", type_line+5 - buffer);\n+\t\treturn error(\"char\" PD_FMT \": type too long\", type_line+5 - buffer);\n \n \tmemcpy(type, type_line+5, typelen);\n \ttype[typelen] = 0;\n@@ -92,14 +98,14 @@ static int verify_tag(char *buffer, unsi\n \t\t\tbreak;\n \t\tif (c > ' ')\n \t\t\tcontinue;\n-\t\treturn error(\"char%td: could not verify tag name\", tag_line - buffer);\n+\t\treturn error(\"char\" PD_FMT \": could not verify tag name\", tag_line - buffer);\n \t}\n \n \t/* Verify the tagger line */\n \ttagger_line = tag_line;\n \n \tif (memcmp(tagger_line, \"tagger\", 6) || (tagger_line[6] == '\\n'))\n-\t\treturn error(\"char%td: could not find \\\"tagger\\\"\", tagger_line - buffer);\n+\t\treturn error(\"char\" PD_FMT \": could not find \\\"tagger\\\"\", tagger_line - buffer);\n \n \t/* TODO: check for committer info + blank line? */\n \t/* Also, the minimum length is probably + \"tagger .\", or 63+8=71 */\n@@ -108,6 +114,8 @@ static int verify_tag(char *buffer, unsi\n \treturn 0;\n }\n \n+#undef PD_FMT\n+\n int main(int argc, char **argv)\n {\n \tunsigned long size = 4096;\n-- \n1.4.1\n\n"}]}