Skip to content

Commit

Permalink
Replace %jd and %ju with PRI[du]MAX
Browse files Browse the repository at this point in the history
  • Loading branch information
jimklimov committed Jun 23, 2022
1 parent f951dce commit 2f877ef
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion clients/nutclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void Socket::connect(const std::string& host, uint16_t port)
throw nut::UnknownHostException();
}

snprintf(sport, sizeof(sport), "%ju", static_cast<uintmax_t>(port));
snprintf(sport, sizeof(sport), "%" PRIuMAX, static_cast<uintmax_t>(port));

memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
Expand Down
2 changes: 1 addition & 1 deletion clients/upsclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ int upscli_tryconnect(UPSCONN_t *ups, const char *host, uint16_t port, int flags
return -1;
}

snprintf(sport, sizeof(sport), "%ju", (uintmax_t)port);
snprintf(sport, sizeof(sport), "%" PRIuMAX, (uintmax_t)port);

memset(&hints, 0, sizeof(hints));

Expand Down
4 changes: 2 additions & 2 deletions common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ void writepid(const char *name)

if (pidf) {
intmax_t pid = (intmax_t)getpid();
upsdebugx(1, "Saving PID %jd into %s", pid, fn);
fprintf(pidf, "%jd\n", pid);
upsdebugx(1, "Saving PID %" PRIdMAX " into %s", pid, fn);
fprintf(pidf, "%" PRIdMAX "\n", pid);
fclose(pidf);
} else {
upslog_with_errno(LOG_NOTICE, "writepid: fopen %s", fn);
Expand Down
14 changes: 7 additions & 7 deletions drivers/libhid.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ static int refresh_report_buffer(reportbuf_t *rbuf, hid_dev_handle_t udev, HIDDa
if ((uintmax_t)r > (uintmax_t)USB_CTRL_CHARBUFSIZE_MAX) {
upsdebugx(2,
"%s: suggested buffer size %" PRIuSIZE " exceeds "
"USB_CTRL_CHARBUFSIZE_MAX %ju; "
"USB_CTRL_CHARBUFSIZE_MAX %" PRIuMAX "; "
"report will be constrained",
__func__, r, (uintmax_t)USB_CTRL_CHARBUFSIZE_MAX);
if ((uintmax_t)USB_CTRL_CHARBUFSIZE_MAX <= (uintmax_t)SIZE_MAX
Expand Down Expand Up @@ -312,7 +312,7 @@ static int set_item_buffered(reportbuf_t *rbuf, hid_dev_handle_t udev, HIDData_t
if ((uintmax_t)r > (uintmax_t)USB_CTRL_CHARBUFSIZE_MAX) {
upsdebugx(2,
"%s: suggested buffer size %" PRIuSIZE " exceeds "
"USB_CTRL_CHARBUFSIZE_MAX %ju; "
"USB_CTRL_CHARBUFSIZE_MAX %" PRIuMAX "; "
"item setting will be constrained",
__func__, r, (uintmax_t)USB_CTRL_CHARBUFSIZE_MAX);
if ((uintmax_t)USB_CTRL_CHARBUFSIZE_MAX <= (uintmax_t)SIZE_MAX
Expand Down Expand Up @@ -579,7 +579,7 @@ char *HIDGetIndexString(hid_dev_handle_t udev, const int Index, char *buf, size_
) {
upsdebugx(2,
"%s: requested index number is out of range, "
"expected %jd < %i < %ju",
"expected %" PRIdMAX " < %i < %" PRIuMAX,
__func__,
(intmax_t)USB_CTRL_STRINDEX_MIN,
Index,
Expand All @@ -591,7 +591,7 @@ char *HIDGetIndexString(hid_dev_handle_t udev, const int Index, char *buf, size_
if ((uintmax_t)buflen > (uintmax_t)USB_CTRL_CHARBUFSIZE_MAX) {
upsdebugx(2,
"%s: suggested buffer size %" PRIuSIZE " exceeds "
"USB_CTRL_CHARBUFSIZE_MAX %ju; "
"USB_CTRL_CHARBUFSIZE_MAX %" PRIuMAX "; "
"index string will be constrained",
__func__, buflen,
(uintmax_t)USB_CTRL_CHARBUFSIZE_MAX);
Expand Down Expand Up @@ -723,7 +723,7 @@ int HIDGetEvents(hid_dev_handle_t udev, HIDData_t **event, int eventsize)
/* FIXME: Should we try here, or plain abort? */
upsdebugx(2,
"%s: suggested buffer size %" PRIuSIZE " exceeds "
"USB_CTRL_CHARBUFSIZE_MAX %ju; "
"USB_CTRL_CHARBUFSIZE_MAX %" PRIuMAX "; "
"report will be constrained",
__func__, r, (uintmax_t)USB_CTRL_CHARBUFSIZE_MAX);

Expand Down Expand Up @@ -938,7 +938,7 @@ static int string_to_path(const char *string, HIDPath_t *path, usage_tables_t *u
/* Note: currently per hidtypes.h, HIDNode_t == uint32_t */
if (l < 0 || (uintmax_t)l > (uintmax_t)UINT32_MAX) {
upsdebugx(5, "string_to_path: badvalue (pathcomp): "
"%ld negative or %ju too large",
"%ld negative or %" PRIuMAX " too large",
l, (uintmax_t)l);
goto badvalue;
}
Expand All @@ -952,7 +952,7 @@ static int string_to_path(const char *string, HIDPath_t *path, usage_tables_t *u
int l = atoi(token + 1); /* +1: skip the bracket */
if (l < 0 || (uintmax_t)l > (uintmax_t)UINT32_MAX) {
upsdebugx(5, "string_to_path: badvalue(indexed): "
"%d negative or %ju too large",
"%d negative or %" PRIuMAX " too large",
l, (uintmax_t)l);
goto badvalue;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/libusb1.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ static int nut_libusb_open(libusb_device_handle **udevp,
) {
upsdebugx(2,
"Report descriptor length is out of range on this device: "
"should be %ji < %d < %ju",
"should be %ji < %d < %" PRIuMAX,
(intmax_t)USB_CTRL_CHARBUFSIZE_MIN, rdlen,
(uintmax_t)USB_CTRL_CHARBUFSIZE_MAX);
goto next_device;
Expand Down
2 changes: 1 addition & 1 deletion drivers/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ int main(int argc, char **argv)
}

/* The poll_interval may have been changed from the default */
dstate_setinfo("driver.parameter.pollinterval", "%jd", (intmax_t)poll_interval);
dstate_setinfo("driver.parameter.pollinterval", "%" PRIdMAX, (intmax_t)poll_interval);

/* The synchronous option may have been changed from the default */
dstate_setinfo("driver.parameter.synchronous", "%s",
Expand Down
2 changes: 1 addition & 1 deletion drivers/nutdrv_siemens_sitop.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void upsdrv_initups(void) {
*/
if (poll_interval > 5) {
upslogx(LOG_NOTICE,
"Option poll_interval is recommended to be lower than 5 (found: %jd)",
"Option poll_interval is recommended to be lower than 5 (found: %" PRIdMAX ")",
(intmax_t)poll_interval);
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/upscode2.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ void upsdrv_initups(void)
fatalx(EXIT_FAILURE, "Bad output_pace parameter: %s", str);
output_pace_usec = (useconds_t)temp;
}
upsdebugx(1, "output_pace = %ju uSec", (uintmax_t)output_pace_usec);
upsdebugx(1, "output_pace = %" PRIuMAX " uSec", (uintmax_t)output_pace_usec);

if ((str = getval("full_update_timer")) != NULL) {
int temp = atoi(str);
Expand Down
8 changes: 4 additions & 4 deletions server/upsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -803,21 +803,21 @@ static void poll_reload(void)
if ((intmax_t)ret < (intmax_t)maxconn) {
fatalx(EXIT_FAILURE,
"Your system limits the maximum number of connections to %ld\n"
"but you requested %jd. The server won't start until this\n"
"but you requested %" PRIdMAX ". The server won't start until this\n"
"problem is resolved.\n", ret, (intmax_t)maxconn);
}

if (1 > maxconn) {
fatalx(EXIT_FAILURE,
"You requested %jd as maximum number of connections.\n"
"You requested %" PRIdMAX " as maximum number of connections.\n"
"The server won't start until this problem is resolved.\n", (intmax_t)maxconn);
}

/* How many items can we stuff into the array? */
size_t maxalloc = SIZE_MAX / sizeof(void *);
if ((uintmax_t)maxalloc < (uintmax_t)maxconn) {
fatalx(EXIT_FAILURE,
"You requested %jd as maximum number of connections, but we can only allocate %" PRIuSIZE ".\n"
"You requested %" PRIdMAX " as maximum number of connections, but we can only allocate %" PRIuSIZE ".\n"
"The server won't start until this problem is resolved.\n", (intmax_t)maxconn, maxalloc);
}

Expand Down Expand Up @@ -1154,7 +1154,7 @@ static void mainloop(void)
nfds++;
}

upsdebugx(2, "%s: polling %jd filedescriptors", __func__, (intmax_t)nfds);
upsdebugx(2, "%s: polling %" PRIdMAX " filedescriptors", __func__, (intmax_t)nfds);

ret = poll(fds, nfds, 2000);

Expand Down
4 changes: 2 additions & 2 deletions tools/nut-scanner/nut-scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,10 +566,10 @@ int main(int argc, char *argv[])
&& (uintmax_t)val > (uintmax_t)(nofile_limit.rlim_cur - RESERVE_FD_COUNT)
) {
upsdebugx(1, "Detected soft limit for "
"file descriptor count is %ju",
"file descriptor count is %" PRIuMAX,
(uintmax_t)nofile_limit.rlim_cur);
upsdebugx(1, "Detected hard limit for "
"file descriptor count is %ju",
"file descriptor count is %" PRIuMAX,
(uintmax_t)nofile_limit.rlim_max);

max_threads = (size_t)nofile_limit.rlim_cur;
Expand Down
4 changes: 2 additions & 2 deletions tools/nut-scanner/scan_xml_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,15 @@ static void * nutscan_scan_xml_http_generic(void * arg)
if (ip == NULL) {
upsdebugx(2,
"nutscan_scan_xml_http_generic() : scanning connected network segment(s) "
"with a broadcast, attempt %d of %d with a timeout of %jd usec",
"with a broadcast, attempt %d of %d with a timeout of %" PRIdMAX " usec",
(i + 1), MAX_RETRIES, (uintmax_t)usec_timeout);
sockAddress_udp.sin_addr.s_addr = INADDR_BROADCAST;
setsockopt(peerSocket, SOL_SOCKET, SO_BROADCAST, SOCK_OPT_CAST &sockopt_on,
sizeof(sockopt_on));
} else {
upsdebugx(2,
"nutscan_scan_xml_http_generic() : scanning IP '%s' with a unicast, "
"attempt %d of %d with a timeout of %jd usec",
"attempt %d of %d with a timeout of %" PRIdMAX " usec",
ip, (i + 1), MAX_RETRIES, (uintmax_t)usec_timeout);
inet_pton(AF_INET, ip, &(sockAddress_udp.sin_addr));
}
Expand Down

0 comments on commit 2f877ef

Please sign in to comment.