unbreak and eliminate NO_C99_FORMAT
In the spirit of v1.5.0.2~21 (Check for PRIuMAX rather than NO_C99_FORMAT in fast-import.c, 2007-02-20), use PRIuMAX from git-compat-util.h on all platforms instead of C99-specific formats like %zu with dangerous fallbacks to %u or %lu. So now C99-challenged platforms can build git without provoking warnings or errors from printf, even if pointers do not have the same size as an int or long. The need for a fallback PRIuMAX is detected in git-compat-util.h with "#ifndef PRIuMAX". So while at it, simplify the Makefile and configure script by eliminating the NO_C99_FORMAT knob altogether. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Mar 16, 2011 at 00:15 UTC
28bd70d811391be10c55ce4aee1b6ee991d7a86b
5 files changed
+4
-55
Makefile
-14
@@ -45,11 +45,6 @@ all::
45
# Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks
46
# d_type in struct dirent (Cygwin 1.5, fixed in Cygwin 1.7).
47
#
48
-# Define NO_C99_FORMAT if your formatted IO functions (printf/scanf et.al.)
49
-# do not support the 'size specifiers' introduced by C99, namely ll, hh,
50
-# j, z, t. (representing long long int, char, intmax_t, size_t, ptrdiff_t).
51
-# some C compilers supported these specifiers prior to C99 as an extension.
52
-#
48
# Define NO_STRCASESTR if you don't have strcasestr.
49
#
50
# Define NO_MEMMEM if you don't have memmem.
@@ -870,7 +865,6 @@ ifeq ($(uname_S),SunOS)
865
NO_UNSETENV = YesPlease
866
NO_SETENV = YesPlease
867
NO_STRLCPY = YesPlease
873
- NO_C99_FORMAT = YesPlease
868
NO_STRTOUMAX = YesPlease
869
GIT_TEST_CMP = cmp
870
endif
@@ -881,21 +875,18 @@ ifeq ($(uname_S),SunOS)
875
NO_UNSETENV = YesPlease
876
NO_SETENV = YesPlease
877
NO_STRLCPY = YesPlease
884
- NO_C99_FORMAT = YesPlease
878
NO_STRTOUMAX = YesPlease
879
GIT_TEST_CMP = cmp
880
endif
881
ifeq ($(uname_R),5.8)
882
NO_UNSETENV = YesPlease
883
NO_SETENV = YesPlease
891
- NO_C99_FORMAT = YesPlease
884
NO_STRTOUMAX = YesPlease
885
GIT_TEST_CMP = cmp
886
endif
887
ifeq ($(uname_R),5.9)
888
NO_UNSETENV = YesPlease
889
NO_SETENV = YesPlease
898
- NO_C99_FORMAT = YesPlease
890
NO_STRTOUMAX = YesPlease
891
GIT_TEST_CMP = cmp
892
endif
@@ -1074,7 +1065,6 @@ ifeq ($(uname_S),Windows)
1065
NO_MEMMEM = YesPlease
1066
# NEEDS_LIBICONV = YesPlease
1067
NO_ICONV = YesPlease
1077
- NO_C99_FORMAT = YesPlease
1068
NO_STRTOUMAX = YesPlease
1069
NO_STRTOULL = YesPlease
1070
NO_MKDTEMP = YesPlease
@@ -1151,7 +1141,6 @@ ifneq (,$(findstring MINGW,$(uname_S)))
1141
NO_MEMMEM = YesPlease
1142
NEEDS_LIBICONV = YesPlease
1143
OLD_ICONV = YesPlease
1154
- NO_C99_FORMAT = YesPlease
1144
NO_STRTOUMAX = YesPlease
1145
NO_MKDTEMP = YesPlease
1146
NO_MKSTEMPS = YesPlease
@@ -1354,9 +1343,6 @@ endif
1343
ifdef NO_NSEC
1344
BASIC_CFLAGS += -DNO_NSEC
1345
endif
1357
-ifdef NO_C99_FORMAT
1358
- BASIC_CFLAGS += -DNO_C99_FORMAT
1359
-endif
1346
ifdef SNPRINTF_RETURNS_BOGUS
1347
COMPAT_CFLAGS += -DSNPRINTF_RETURNS_BOGUS
1348
COMPAT_OBJS += compat/snprintf.o
alloc.c
+2
-9
@@ -51,19 +51,12 @@ DEFINE_ALLOCATOR(commit, struct commit)
51
DEFINE_ALLOCATOR(tag, struct tag)
52
DEFINE_ALLOCATOR(object, union any_object)
53
54
-#ifdef NO_C99_FORMAT
55
-#define SZ_FMT "%u"
56
-#else
57
-#define SZ_FMT "%zu"
58
-#endif
59
-
54
static void report(const char *name, unsigned int count, size_t size)
55
{
62
- fprintf(stderr, "%10s: %8u (" SZ_FMT " kB)\n", name, count, size);
56
+ fprintf(stderr, "%10s: %8u (%"PRIuMAX" kB)\n",
57
+ name, count, (uintmax_t) size);
58
}
59
65
-#undef SZ_FMT
66
-
60
#define REPORT(name) \
61
report(#name, name##_allocs, name##_allocs*sizeof(struct name) >> 10)
62
config.mak.in
-1
@@ -43,7 +43,6 @@ NO_D_INO_IN_DIRENT=@NO_D_INO_IN_DIRENT@
43
NO_D_TYPE_IN_DIRENT=@NO_D_TYPE_IN_DIRENT@
44
NO_SOCKADDR_STORAGE=@NO_SOCKADDR_STORAGE@
45
NO_IPV6=@NO_IPV6@
46
-NO_C99_FORMAT=@NO_C99_FORMAT@
46
NO_HSTRERROR=@NO_HSTRERROR@
47
NO_STRCASESTR=@NO_STRCASESTR@
48
NO_STRTOK_R=@NO_STRTOK_R@
configure.ac
-24
@@ -686,30 +686,6 @@ AC_CHECK_TYPE([struct addrinfo],[
686
])
687
AC_SUBST(NO_IPV6)
688
#
689
-# Define NO_C99_FORMAT if your formatted IO functions (printf/scanf et.al.)
690
-# do not support the 'size specifiers' introduced by C99, namely ll, hh,
691
-# j, z, t. (representing long long int, char, intmax_t, size_t, ptrdiff_t).
692
-# some C compilers supported these specifiers prior to C99 as an extension.
693
-AC_CACHE_CHECK([whether formatted IO functions support C99 size specifiers],
694
- [ac_cv_c_c99_format],
695
-[# Actually git uses only %z (%zu) in alloc.c, and %t (%td) in mktag.c
696
-AC_RUN_IFELSE(
697
- [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
698
- [[char buf[64];
699
- if (sprintf(buf, "%lld%hhd%jd%zd%td", (long long int)1, (char)2, (intmax_t)3, (size_t)4, (ptrdiff_t)5) != 5)
700
- return 1;
701
- else if (strcmp(buf, "12345"))
702
- return 2;]])],
703
- [ac_cv_c_c99_format=yes],
704
- [ac_cv_c_c99_format=no])
705
-])
706
-if test $ac_cv_c_c99_format = no; then
707
- NO_C99_FORMAT=YesPlease
708
-else
709
- NO_C99_FORMAT=
710
-fi
711
-AC_SUBST(NO_C99_FORMAT)
712
-#
689
# Define NO_REGEX if you have no or inferior regex support in your C library.
690
AC_CACHE_CHECK([whether the platform regex can handle null bytes],
691
[ac_cv_c_excellent_regex], [
sha1_file.c
+2
-7
@@ -25,13 +25,8 @@
25
#endif
26
#endif
27
28
-#ifdef NO_C99_FORMAT
29
-#define SZ_FMT "lu"
30
-static unsigned long sz_fmt(size_t s) { return (unsigned long)s; }
31
-#else
32
-#define SZ_FMT "zu"
33
-static size_t sz_fmt(size_t s) { return s; }
34
-#endif
28
+#define SZ_FMT PRIuMAX
29
+static inline uintmax_t sz_fmt(size_t s) { return s; }
30
31
const unsigned char null_sha1[20];
32