]> git.ipfire.org Git - thirdparty/git.git/commitdiff
unbreak and eliminate NO_C99_FORMAT
authorJonathan Nieder <jrnieder@gmail.com>
Wed, 16 Mar 2011 05:15:31 +0000 (00:15 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 17 Mar 2011 22:30:49 +0000 (15:30 -0700)
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>
Makefile
alloc.c
config.mak.in
configure.ac
sha1_file.c

index 775ee838c332c7311df34a98448fc3723c6bd95e..d9243aad9b734b241517e2d5b24715a104c85f4c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -45,11 +45,6 @@ all::
 # Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks
 # d_type in struct dirent (Cygwin 1.5, fixed in Cygwin 1.7).
 #
-# 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_MEMMEM if you don't have memmem.
@@ -870,7 +865,6 @@ ifeq ($(uname_S),SunOS)
                NO_UNSETENV = YesPlease
                NO_SETENV = YesPlease
                NO_STRLCPY = YesPlease
-               NO_C99_FORMAT = YesPlease
                NO_STRTOUMAX = YesPlease
                GIT_TEST_CMP = cmp
        endif
@@ -881,21 +875,18 @@ ifeq ($(uname_S),SunOS)
                NO_UNSETENV = YesPlease
                NO_SETENV = YesPlease
                NO_STRLCPY = YesPlease
-               NO_C99_FORMAT = YesPlease
                NO_STRTOUMAX = YesPlease
                GIT_TEST_CMP = cmp
        endif
        ifeq ($(uname_R),5.8)
                NO_UNSETENV = YesPlease
                NO_SETENV = YesPlease
-               NO_C99_FORMAT = YesPlease
                NO_STRTOUMAX = YesPlease
                GIT_TEST_CMP = cmp
        endif
        ifeq ($(uname_R),5.9)
                NO_UNSETENV = YesPlease
                NO_SETENV = YesPlease
-               NO_C99_FORMAT = YesPlease
                NO_STRTOUMAX = YesPlease
                GIT_TEST_CMP = cmp
        endif
@@ -1074,7 +1065,6 @@ ifeq ($(uname_S),Windows)
        NO_MEMMEM = YesPlease
        # NEEDS_LIBICONV = YesPlease
        NO_ICONV = YesPlease
-       NO_C99_FORMAT = YesPlease
        NO_STRTOUMAX = YesPlease
        NO_STRTOULL = YesPlease
        NO_MKDTEMP = YesPlease
@@ -1151,7 +1141,6 @@ ifneq (,$(findstring MINGW,$(uname_S)))
        NO_MEMMEM = YesPlease
        NEEDS_LIBICONV = YesPlease
        OLD_ICONV = YesPlease
-       NO_C99_FORMAT = YesPlease
        NO_STRTOUMAX = YesPlease
        NO_MKDTEMP = YesPlease
        NO_MKSTEMPS = YesPlease
@@ -1354,9 +1343,6 @@ endif
 ifdef NO_NSEC
        BASIC_CFLAGS += -DNO_NSEC
 endif
-ifdef NO_C99_FORMAT
-       BASIC_CFLAGS += -DNO_C99_FORMAT
-endif
 ifdef SNPRINTF_RETURNS_BOGUS
        COMPAT_CFLAGS += -DSNPRINTF_RETURNS_BOGUS
        COMPAT_OBJS += compat/snprintf.o
diff --git a/alloc.c b/alloc.c
index 6ef6753d180afad29bc335854150c824b9de8a18..aeae55c976802264d714282218e58a858a9c68b5 100644 (file)
--- a/alloc.c
+++ b/alloc.c
@@ -51,19 +51,12 @@ DEFINE_ALLOCATOR(commit, struct commit)
 DEFINE_ALLOCATOR(tag, struct tag)
 DEFINE_ALLOCATOR(object, union any_object)
 
-#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);
+       fprintf(stderr, "%10s: %8u (%"PRIuMAX" kB)\n",
+                       name, count, (uintmax_t) size);
 }
 
-#undef SZ_FMT
-
 #define REPORT(name)   \
     report(#name, name##_allocs, name##_allocs*sizeof(struct name) >> 10)
 
index 961497305777fcbd67001fdae1335fcfe2910e88..e378534cbd57add4a6c75b8eb45353e8a9322914 100644 (file)
@@ -43,7 +43,6 @@ NO_D_INO_IN_DIRENT=@NO_D_INO_IN_DIRENT@
 NO_D_TYPE_IN_DIRENT=@NO_D_TYPE_IN_DIRENT@
 NO_SOCKADDR_STORAGE=@NO_SOCKADDR_STORAGE@
 NO_IPV6=@NO_IPV6@
-NO_C99_FORMAT=@NO_C99_FORMAT@
 NO_HSTRERROR=@NO_HSTRERROR@
 NO_STRCASESTR=@NO_STRCASESTR@
 NO_STRTOK_R=@NO_STRTOK_R@
index 20039c546f1cc91575771acbe6f52de6778bea89..dd0790725b2efaa15c50eddf55e784ddd6566dff 100644 (file)
@@ -686,30 +686,6 @@ AC_CHECK_TYPE([struct addrinfo],[
 ])
 AC_SUBST(NO_IPV6)
 #
-# 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.
-AC_CACHE_CHECK([whether formatted IO functions support C99 size specifiers],
- [ac_cv_c_c99_format],
-[# Actually git uses only %z (%zu) in alloc.c, and %t (%td) in mktag.c
-AC_RUN_IFELSE(
-       [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
-               [[char buf[64];
-               if (sprintf(buf, "%lld%hhd%jd%zd%td", (long long int)1, (char)2, (intmax_t)3, (size_t)4, (ptrdiff_t)5) != 5)
-                 return 1;
-               else if (strcmp(buf, "12345"))
-                 return 2;]])],
-       [ac_cv_c_c99_format=yes],
-       [ac_cv_c_c99_format=no])
-])
-if test $ac_cv_c_c99_format = no; then
-       NO_C99_FORMAT=YesPlease
-else
-       NO_C99_FORMAT=
-fi
-AC_SUBST(NO_C99_FORMAT)
-#
 # Define NO_REGEX if you have no or inferior regex support in your C library.
 AC_CACHE_CHECK([whether the platform regex can handle null bytes],
  [ac_cv_c_excellent_regex], [
index 27730c334cb433ef749a0efc5353a7f38032559c..ea99f6f313e8e6071b37706dd7e7b2a76463a311 100644 (file)
 #endif
 #endif
 
-#ifdef NO_C99_FORMAT
-#define SZ_FMT "lu"
-static unsigned long sz_fmt(size_t s) { return (unsigned long)s; }
-#else
-#define SZ_FMT "zu"
-static size_t sz_fmt(size_t s) { return s; }
-#endif
+#define SZ_FMT PRIuMAX
+static inline uintmax_t sz_fmt(size_t s) { return s; }
 
 const unsigned char null_sha1[20];