mirror of
https://git.openafs.org/openafs.git
synced 2025-01-18 23:10:58 +00:00
Detect and use %zu for size_t when available
Commit db949b7fad
was incorrect and
generated warnings on many platforms; we cannot determine the correct
format string for a size_t at compile-time. Instead use the %z length
modifier when we can detect that it is safe to use. Otherwise, fall back
to just %lu on Unix, since it is reasonable to assume
sizeof(size_t) == sizeof(unsigned long) on Unix.
Reviewed-on: http://gerrit.openafs.org/647
Reviewed-by: Russ Allbery <rra@stanford.edu>
Reviewed-by: Simon Wilkinson <sxw@inf.ed.ac.uk>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>
This commit is contained in:
parent
1fa650cee2
commit
58628eb745
@ -334,6 +334,7 @@ AC_PROG_YACC
|
|||||||
AM_PROG_LEX
|
AM_PROG_LEX
|
||||||
|
|
||||||
OPENAFS_CHECK_BIGENDIAN
|
OPENAFS_CHECK_BIGENDIAN
|
||||||
|
OPENAFS_PRINTF_TAKES_Z_LEN
|
||||||
|
|
||||||
AC_MSG_CHECKING(your OS)
|
AC_MSG_CHECKING(your OS)
|
||||||
system=$host
|
system=$host
|
||||||
|
27
src/cf/sizet.m4
Normal file
27
src/cf/sizet.m4
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
AC_DEFUN([OPENAFS_PRINTF_TAKES_Z_LEN],
|
||||||
|
[
|
||||||
|
AC_CACHE_CHECK([whether printf understands the %z length modifier],
|
||||||
|
[openafs_cv_printf_takes_z], [
|
||||||
|
AC_TRY_RUN([
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
char buf[8];
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
snprintf(buf, 8, "%zu", sizeof(char));
|
||||||
|
if (buf[0] == '1' && buf[1] == '\0') {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
[openafs_cv_printf_takes_z="yes"],
|
||||||
|
[openafs_cv_printf_takes_z="no"],
|
||||||
|
[openafs_cv_printf_takes_z="no"])
|
||||||
|
])
|
||||||
|
|
||||||
|
if test "x$openafs_cv_printf_takes_z" = "xyes"; then
|
||||||
|
AC_DEFINE([PRINTF_TAKES_Z_LEN], 1, [define if printf and friends understand the %z length modifier])
|
||||||
|
fi
|
||||||
|
])
|
@ -282,19 +282,19 @@ typedef struct afsUUID afsUUID;
|
|||||||
* windows use a different format string
|
* windows use a different format string
|
||||||
*/
|
*/
|
||||||
#ifdef AFS_NT40_ENV
|
#ifdef AFS_NT40_ENV
|
||||||
#define AFS_INT64_FMT "I64d"
|
# define AFS_INT64_FMT "I64d"
|
||||||
#define AFS_UINT64_FMT "I64u"
|
# define AFS_UINT64_FMT "I64u"
|
||||||
#define AFS_PTR_FMT "Ip"
|
# define AFS_PTR_FMT "Ip"
|
||||||
#define AFS_SIZET_FMT "Iu"
|
# define AFS_SIZET_FMT "Iu"
|
||||||
#else
|
#else
|
||||||
#define AFS_INT64_FMT "lld"
|
# define AFS_INT64_FMT "lld"
|
||||||
#define AFS_UINT64_FMT "llu"
|
# define AFS_UINT64_FMT "llu"
|
||||||
#define AFS_PTR_FMT "p"
|
# define AFS_PTR_FMT "p"
|
||||||
#ifdef AFS_64BITPOINTER_ENV
|
# ifdef PRINTF_TAKES_Z_LEN
|
||||||
#define AFS_SIZET_FMT "lu"
|
# define AFS_SIZET_FMT "zu"
|
||||||
#else
|
# else
|
||||||
#define AFS_SIZET_FMT "u"
|
# define AFS_SIZET_FMT "lu"
|
||||||
#endif /* AFS_64BITPOINTER_ENV */
|
# endif /* PRINTF_TAKES_Z_LEN */
|
||||||
#endif /* AFS_NT40_ENV */
|
#endif /* AFS_NT40_ENV */
|
||||||
|
|
||||||
/* Functions to safely cast afs_int32 and afs_uint32 so they can be used in
|
/* Functions to safely cast afs_int32 and afs_uint32 so they can be used in
|
||||||
|
Loading…
Reference in New Issue
Block a user