Skip to content

Commit

Permalink
Drop macros for size_t printf formats
Browse files Browse the repository at this point in the history
Windows supports %zu as well, so we can drop these indirections.  They
also confuse gcc with respect to -Wformat and similar.
  • Loading branch information
petere committed Nov 10, 2020
1 parent 473617e commit 6d1b8c7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 25 deletions.
9 changes: 0 additions & 9 deletions usual/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,6 @@ typedef enum { true=1, false=0 } bool;
#define DLLIMPORT
#endif

#ifndef PRIdZ
#define PRIdZ "zd" /**< printf 'd' format specifier for ssize_t */
#define PRIiZ "zi" /**< printf 'i' format specifier for ssize_t */
#define PRIoZ "zo" /**< printf 'o' format specifier for size_t */
#define PRIuZ "zu" /**< printf 'u' format specifier for size_t */
#define PRIxZ "zx" /**< printf 'x' format specifier for size_t */
#define PRIXZ "zX" /**< printf 'X' format specifier for size_t */
#endif

/** give offset of a field inside struct */
#ifndef offsetof
#define offsetof(type, field) ((unsigned long)&(((type *)0)->field))
Expand Down
7 changes: 0 additions & 7 deletions usual/base_win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,4 @@ static inline struct group *getgrgid(gid_t gid) { return NULL; }

#endif

#define PRIdZ "Id"
#define PRIiZ "Ii"
#define PRIoZ "Io"
#define PRIuZ "Iu"
#define PRIxZ "Ix"
#define PRIXZ "IX"

#endif
12 changes: 6 additions & 6 deletions usual/safeio.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ ssize_t safe_recv(int fd, void *buf, size_t len, int flags)
if (res < 0 && errno == EINTR)
goto loop;
if (res < 0)
log_noise("safe_recv(%d, %" PRIuZ ") = %s", fd, len,
log_noise("safe_recv(%d, %zu) = %s", fd, len,
strerror_r(errno, ebuf, sizeof(ebuf)));
else if (cf_verbose > 2)
log_noise("safe_recv(%d, %" PRIuZ ") = %" PRIdZ, fd, len, res);
log_noise("safe_recv(%d, %zu) = %zd", fd, len, res);
return res;
}

Expand All @@ -73,10 +73,10 @@ ssize_t safe_send(int fd, const void *buf, size_t len, int flags)
if (res < 0 && errno == EINTR)
goto loop;
if (res < 0)
log_noise("safe_send(%d, %" PRIuZ ") = %s", fd, len,
log_noise("safe_send(%d, %zu) = %s", fd, len,
strerror_r(errno, ebuf, sizeof(ebuf)));
else if (cf_verbose > 2)
log_noise("safe_send(%d, %" PRIuZ ") = %" PRIdZ, fd, len, res);
log_noise("safe_send(%d, %zu) = %zd", fd, len, res);
return res;
}

Expand Down Expand Up @@ -126,7 +126,7 @@ ssize_t safe_recvmsg(int fd, struct msghdr *msg, int flags)
log_warning("safe_recvmsg(%d, msg, %d) = %s", fd, flags,
strerror_r(errno, ebuf, sizeof(ebuf)));
else if (cf_verbose > 2)
log_noise("safe_recvmsg(%d, msg, %d) = %" PRIdZ, fd, flags, res);
log_noise("safe_recvmsg(%d, msg, %d) = %zd", fd, flags, res);
return res;
}

Expand Down Expand Up @@ -156,7 +156,7 @@ ssize_t safe_sendmsg(int fd, const struct msghdr *msg, int flags)
goto loop;
}
} else if (cf_verbose > 2)
log_noise("safe_sendmsg(%d, msg, %d) = %" PRIdZ, fd, flags, res);
log_noise("safe_sendmsg(%d, msg, %d) = %zd", fd, flags, res);
return res;
}

Expand Down
6 changes: 3 additions & 3 deletions usual/talloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ static void report_cb(const void *ptr, int depth, int max_depth, int is_ref, voi
limitbuf[0] = 0;
if (name == MEMLIMIT_NAME) {
struct TLimit *lim = hdr2ptr(t);
snprintf(limitbuf, sizeof(limitbuf), "%s [cur=%" PRIuZ " max=%" PRIuZ "]",
snprintf(limitbuf, sizeof(limitbuf), "%s [cur=%zu max=%zu]",
name, lim->cur_size, lim->max_size);
name = limitbuf;
}
Expand All @@ -1531,15 +1531,15 @@ static void report_cb(const void *ptr, int depth, int max_depth, int is_ref, voi
talloc_report_depth_cb(ptr, 0, TALLOC_MAX_DEPTH, calc_bytes_and_count, &state);

if (depth == 0) {
fprintf(f, "talloc report on '%s' (total %" PRIuZ " bytes in %" PRIuZ " blocks)%s\n",
fprintf(f, "talloc report on '%s' (total %zu bytes in %zu blocks)%s\n",
name, state.bytes, state.count, limitbuf);
return;
}
if (is_ref) {
fprintf(f, "%*sreference to %s\n", indent, " ", name);
return;
}
fprintf(f, "%*s%-*s contains %6" PRIuZ " bytes in %6" PRIuZ " blocks%s\n",
fprintf(f, "%*s%-*s contains %6zu bytes in %6zu blocks%s\n",
indent, " ",
indent < 40 ? 40 - indent : 0, name,
state.bytes, state.count,
Expand Down

0 comments on commit 6d1b8c7

Please sign in to comment.