Skip to content

Commit bf99aed

Browse files
committed
Global: replaces %m for %s + strerror(errno)
Not portable This reverts aabab6d
1 parent 397822d commit bf99aed

6 files changed

Lines changed: 39 additions & 39 deletions

File tree

src/common/impl/netif_linux.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ bool ffNetifGetDefaultRouteImplV4(FFNetifDefaultRouteResult* result)
1414
FF_AUTO_CLOSE_FD int sock_fd = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE);
1515
if (sock_fd < 0)
1616
{
17-
FF_DEBUG("Failed to create netlink socket: %m");
17+
FF_DEBUG("Failed to create netlink socket: %s", strerror(errno));
1818
return false;
1919
}
2020
FF_DEBUG("Created netlink socket: fd=%d", sock_fd);
@@ -30,7 +30,7 @@ bool ffNetifGetDefaultRouteImplV4(FFNetifDefaultRouteResult* result)
3030
};
3131

3232
if (bind(sock_fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
33-
FF_DEBUG("Failed to bind socket: %m");
33+
FF_DEBUG("Failed to bind socket: %s", strerror(errno));
3434
return false;
3535
}
3636
FF_DEBUG("Successfully bound socket");
@@ -97,7 +97,7 @@ bool ffNetifGetDefaultRouteImplV4(FFNetifDefaultRouteResult* result)
9797
(struct sockaddr*)&src_addr, &src_addr_len);
9898

9999
if (received < 0) {
100-
FF_DEBUG("Failed to receive netlink response: %m");
100+
FF_DEBUG("Failed to receive netlink response: %s", strerror(errno));
101101
return false;
102102
}
103103

@@ -230,7 +230,7 @@ bool ffNetifGetDefaultRouteImplV6(FFNetifDefaultRouteResult* result)
230230
FF_AUTO_CLOSE_FD int sock_fd = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE);
231231
if (sock_fd < 0)
232232
{
233-
FF_DEBUG("Failed to create netlink socket: %m");
233+
FF_DEBUG("Failed to create netlink socket: %s", strerror(errno));
234234
return false;
235235
}
236236
FF_DEBUG("Created netlink socket: fd=%d", sock_fd);
@@ -246,7 +246,7 @@ bool ffNetifGetDefaultRouteImplV6(FFNetifDefaultRouteResult* result)
246246
};
247247

248248
if (bind(sock_fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
249-
FF_DEBUG("Failed to bind socket: %m");
249+
FF_DEBUG("Failed to bind socket: %s", strerror(errno));
250250
return false;
251251
}
252252
FF_DEBUG("Successfully bound socket");
@@ -313,7 +313,7 @@ bool ffNetifGetDefaultRouteImplV6(FFNetifDefaultRouteResult* result)
313313
(struct sockaddr*)&src_addr, &src_addr_len);
314314

315315
if (received < 0) {
316-
FF_DEBUG("Failed to receive netlink response: %m");
316+
FF_DEBUG("Failed to receive netlink response: %s", strerror(errno));
317317
return false;
318318
}
319319

src/common/impl/networking_linux.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static const char* tryNonThreadingFastPath(FFNetworkingState* state)
4343
TCP_FASTOPEN
4444
#endif
4545
, &flag, sizeof(flag)) != 0) {
46-
FF_DEBUG("Failed to set TCP_FASTOPEN option: %m");
46+
FF_DEBUG("Failed to set TCP_FASTOPEN option: %s", strerror(errno));
4747
return "setsockopt(TCP_FASTOPEN) failed";
4848
} else {
4949
#if __linux__ || __GNU__
@@ -73,7 +73,7 @@ static const char* tryNonThreadingFastPath(FFNetworkingState* state)
7373
state->addr->ai_addrlen);
7474
#else
7575
if (fcntl(state->sockfd, F_SETFL, O_NONBLOCK) == -1) {
76-
FF_DEBUG("fcntl(F_SETFL) failed: %m");
76+
FF_DEBUG("fcntl(F_SETFL) failed: %s", strerror(errno));
7777
return "fcntl(F_SETFL) failed";
7878
}
7979
FF_DEBUG("Using connectx() to send %u bytes of data", state->command.length);
@@ -90,7 +90,7 @@ static const char* tryNonThreadingFastPath(FFNetworkingState* state)
9090
.iov_len = state->command.length,
9191
}, 1, &sent, NULL) != 0) sent = 0;
9292
if (fcntl(state->sockfd, F_SETFL, 0) == -1) {
93-
FF_DEBUG("fcntl(F_SETFL) failed: %m");
93+
FF_DEBUG("fcntl(F_SETFL) failed: %s", strerror(errno));
9494
return "fcntl(F_SETFL) failed";
9595
}
9696
#endif
@@ -108,7 +108,7 @@ static const char* tryNonThreadingFastPath(FFNetworkingState* state)
108108
#else
109109
"sendto()"
110110
#endif
111-
" %s (sent=%zd, %m)", errno == 0 ? "succeeded" : "was in progress", sent);
111+
" %s (sent=%zd, %s)", errno == 0 ? "succeeded" : "was in progress", sent, strerror(errno));
112112
freeaddrinfo(state->addr);
113113
state->addr = NULL;
114114
ffStrbufDestroy(&state->command);
@@ -121,7 +121,7 @@ static const char* tryNonThreadingFastPath(FFNetworkingState* state)
121121
#else
122122
"sendto()"
123123
#endif
124-
" failed: %m");
124+
" failed: %s", strerror(errno));
125125
#ifdef __APPLE__
126126
return "connectx() failed";
127127
#else
@@ -142,7 +142,7 @@ static const char* connectAndSend(FFNetworkingState* state)
142142
FF_DEBUG("Attempting connect() to server...");
143143
if(connect(state->sockfd, state->addr->ai_addr, state->addr->ai_addrlen) == -1)
144144
{
145-
FF_DEBUG("connect() failed: %m");
145+
FF_DEBUG("connect() failed: %s", strerror(errno));
146146
ret = "connect() failed";
147147
goto error;
148148
}
@@ -151,7 +151,7 @@ static const char* connectAndSend(FFNetworkingState* state)
151151
FF_DEBUG("Attempting to send %u bytes of data...", state->command.length);
152152
if(send(state->sockfd, state->command.chars, state->command.length, 0) < 0)
153153
{
154-
FF_DEBUG("send() failed: %m");
154+
FF_DEBUG("send() failed: %s", strerror(errno));
155155
ret = "send() failed";
156156
goto error;
157157
}
@@ -226,7 +226,7 @@ static const char* initNetworkingState(FFNetworkingState* state, const char* hos
226226
state->sockfd = socket(state->addr->ai_family, state->addr->ai_socktype, state->addr->ai_protocol);
227227
if(state->sockfd == -1)
228228
{
229-
FF_DEBUG("socket() failed: %m");
229+
FF_DEBUG("socket() failed: %s", strerror(errno));
230230
ret = "socket() failed";
231231
goto error;
232232
}
@@ -236,7 +236,7 @@ static const char* initNetworkingState(FFNetworkingState* state, const char* hos
236236
#ifdef TCP_NODELAY
237237
// Disable Nagle's algorithm to reduce small packet transmission delay
238238
if (setsockopt(state->sockfd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag)) != 0) {
239-
FF_DEBUG("Failed to set TCP_NODELAY: %m");
239+
FF_DEBUG("Failed to set TCP_NODELAY: %s", strerror(errno));
240240
} else {
241241
FF_DEBUG("Successfully disabled Nagle's algorithm");
242242
}
@@ -245,7 +245,7 @@ static const char* initNetworkingState(FFNetworkingState* state, const char* hos
245245
#ifdef TCP_QUICKACK
246246
// Set TCP_QUICKACK option to avoid delayed acknowledgments
247247
if (setsockopt(state->sockfd, IPPROTO_TCP, TCP_QUICKACK, &flag, sizeof(flag)) != 0) {
248-
FF_DEBUG("Failed to set TCP_QUICKACK: %m");
248+
FF_DEBUG("Failed to set TCP_QUICKACK: %s", strerror(errno));
249249
} else {
250250
FF_DEBUG("Successfully enabled TCP quick acknowledgment");
251251
}
@@ -398,7 +398,7 @@ const char* ffNetworkingRecvHttpResponse(FFNetworkingState* state, FFstrbuf* buf
398398
}
399399
else if (pollRes == -1)
400400
{
401-
FF_DEBUG("poll() failed: %m");
401+
FF_DEBUG("poll() failed: %s", strerror(errno));
402402
close(state->sockfd);
403403
state->sockfd = -1;
404404
return "poll() failed";
@@ -418,7 +418,7 @@ const char* ffNetworkingRecvHttpResponse(FFNetworkingState* state, FFstrbuf* buf
418418

419419
if (shutdown(state->sockfd, SHUT_WR) == -1)
420420
{
421-
FF_DEBUG("Failed to shutdown socket send: %m");
421+
FF_DEBUG("Failed to shutdown socket send: %s", strerror(errno));
422422
// Not a critical error, continue anyway
423423
}
424424

@@ -439,7 +439,7 @@ const char* ffNetworkingRecvHttpResponse(FFNetworkingState* state, FFstrbuf* buf
439439
if (received == 0) {
440440
FF_DEBUG("Connection closed (received=0)");
441441
} else {
442-
FF_DEBUG("Reception failed: %m");
442+
FF_DEBUG("Reception failed: %s", strerror(errno));
443443
}
444444
break;
445445
}

src/common/impl/smbiosHelper.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
286286

287287
FF_AUTO_CLOSE_FD int fd = open("/dev/mem", O_RDONLY | O_CLOEXEC);
288288
if (fd < 0) {
289-
FF_DEBUG("Failed to open /dev/mem: %m");
289+
FF_DEBUG("Failed to open /dev/mem: %s", strerror(errno));
290290
return NULL;
291291
}
292292
FF_DEBUG("/dev/mem opened successfully with fd=%d", fd);
@@ -301,7 +301,7 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
301301
// https://stackoverflow.com/questions/69372330/how-to-read-dev-mem-using-read
302302
void* p = mmap(NULL, sizeof(entryPoint), PROT_READ, MAP_SHARED, fd, entryAddress);
303303
if (p == MAP_FAILED) {
304-
FF_DEBUG("mmap failed: %m");
304+
FF_DEBUG("mmap failed: %s", strerror(errno));
305305
return NULL;
306306
}
307307
memcpy(&entryPoint, p, sizeof(entryPoint));
@@ -322,7 +322,7 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
322322

323323
FF_AUTO_CLOSE_FD int fd = open("/dev/smbios", O_RDONLY | O_CLOEXEC);
324324
if (fd < 0) {
325-
FF_DEBUG("Failed to open /dev/smbios: %m");
325+
FF_DEBUG("Failed to open /dev/smbios: %s", strerror(errno));
326326
return NULL;
327327
}
328328
FF_DEBUG("/dev/smbios opened successfully with fd=%d", fd);
@@ -337,14 +337,14 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
337337
FF_DEBUG("Got SMBIOS address from sysctl: 0x%lx", (unsigned long)addr);
338338

339339
if (pread(fd, &entryPoint, sizeof(entryPoint), addr) < 1) {
340-
FF_DEBUG("Failed to read SMBIOS entry point: %m");
340+
FF_DEBUG("Failed to read SMBIOS entry point: %s", strerror(errno));
341341
return NULL;
342342
}
343343
FF_DEBUG("Successfully read SMBIOS entry point");
344344
#else
345345
FF_DEBUG("Reading SMBIOS entry point from /dev/smbios");
346346
if (ffReadFDData(fd, sizeof(entryPoint), &entryPoint) < 1) {
347-
FF_DEBUG("Failed to read SMBIOS entry point: %m");
347+
FF_DEBUG("Failed to read SMBIOS entry point: %s", strerror(errno));
348348
return NULL;
349349
}
350350
FF_DEBUG("Successfully read SMBIOS entry point");
@@ -402,7 +402,7 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
402402
void* p = mmap(NULL, tableLength, PROT_READ, MAP_SHARED, fd, tableAddress);
403403
if (p == MAP_FAILED)
404404
{
405-
FF_DEBUG("mmap failed: %m");
405+
FF_DEBUG("mmap failed: %s", strerror(errno));
406406
ffStrbufDestroy(&buffer); // free buffer and reset state
407407
return NULL;
408408
}
@@ -431,7 +431,7 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
431431
#endif
432432
, O_RDONLY | O_CLOEXEC);
433433
if (fd < 0) {
434-
FF_DEBUG("Failed to open memory device: %m");
434+
FF_DEBUG("Failed to open memory device: %s", strerror(errno));
435435
return NULL;
436436
}
437437
FF_DEBUG("Memory device opened successfully with fd=%d", fd);
@@ -443,7 +443,7 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
443443
// which is not available via EFIIOC_GET_TABLE.
444444
FF_AUTO_FREE uint8_t* smBiosBase = malloc(0x10000);
445445
if (pread(fd, smBiosBase, 0x10000, 0xF0000) != 0x10000) {
446-
FF_DEBUG("Failed to read SMBIOS memory region: %m");
446+
FF_DEBUG("Failed to read SMBIOS memory region: %s", strerror(errno));
447447
return NULL;
448448
}
449449
FF_DEBUG("Successfully read 0x10000 bytes from physical address 0xF0000");
@@ -496,7 +496,7 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
496496
FF_DEBUG("Successfully read SMBIOS table data: %u bytes", tableLength);
497497
}
498498
else {
499-
FF_DEBUG("Failed to read SMBIOS table data: %m");
499+
FF_DEBUG("Failed to read SMBIOS table data: %s", strerror(errno));
500500
return NULL;
501501
}
502502
}

src/detection/dns/dns_apple.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ static const char* detectDnsFromConf(const char* path, FFDNSOptions* options, FF
1515
FF_AUTO_CLOSE_FILE FILE* file = fopen(path, "r");
1616
if (!file)
1717
{
18-
FF_DEBUG("Failed to open %s: %m", path);
18+
FF_DEBUG("Failed to open %s: %s", path, strerror(errno));
1919
return "fopen(path, r) failed";
2020
}
2121

src/detection/dns/dns_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static const char* detectDnsFromConf(const char* path, FFDNSOptions* options, FF
1818
FF_AUTO_CLOSE_FILE FILE* file = fopen(path, "r");
1919
if (!file)
2020
{
21-
FF_DEBUG("Failed to open %s: %m", path);
21+
FF_DEBUG("Failed to open %s: %s", path, strerror(errno));
2222
return "fopen(path, r) failed";
2323
}
2424

src/detection/wifi/wifi_linux.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ static const char* detectWifiWithIoctls(FFWifiResult* item)
375375
FF_AUTO_CLOSE_FD int sock = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
376376
if(sock < 0)
377377
{
378-
FF_DEBUG("Failed to create socket: %m");
378+
FF_DEBUG("Failed to create socket: %s", strerror(errno));
379379
return "socket() failed";
380380
}
381381

@@ -395,7 +395,7 @@ static const char* detectWifiWithIoctls(FFWifiResult* item)
395395
FF_DEBUG("SSID: %s", item->conn.ssid.chars);
396396
}
397397
else
398-
FF_DEBUG("Failed to get SSID via ioctl: %m");
398+
FF_DEBUG("Failed to get SSID via ioctl: %s", strerror(errno));
399399

400400
// Get protocol name
401401
FF_DEBUG("Getting protocol name via ioctl");
@@ -408,7 +408,7 @@ static const char* detectWifiWithIoctls(FFWifiResult* item)
408408
FF_DEBUG("Protocol: %s", item->conn.protocol.chars);
409409
}
410410
else
411-
FF_DEBUG("Failed to get protocol name via ioctl: %m");
411+
FF_DEBUG("Failed to get protocol name via ioctl: %s", strerror(errno));
412412

413413
// Get BSSID
414414
FF_DEBUG("Getting BSSID via ioctl");
@@ -420,7 +420,7 @@ static const char* detectWifiWithIoctls(FFWifiResult* item)
420420
FF_DEBUG("BSSID: %s", item->conn.bssid.chars);
421421
}
422422
else
423-
FF_DEBUG("Failed to get BSSID via ioctl: %m");
423+
FF_DEBUG("Failed to get BSSID via ioctl: %s", strerror(errno));
424424

425425
// Get bitrate
426426
FF_DEBUG("Getting bitrate via ioctl");
@@ -430,7 +430,7 @@ static const char* detectWifiWithIoctls(FFWifiResult* item)
430430
FF_DEBUG("TX bitrate: %.2f Mbps", item->conn.txRate);
431431
}
432432
else
433-
FF_DEBUG("Failed to get bitrate via ioctl: %m");
433+
FF_DEBUG("Failed to get bitrate via ioctl: %s", strerror(errno));
434434

435435
// Get frequency/channel
436436
FF_DEBUG("Getting frequency via ioctl");
@@ -460,7 +460,7 @@ static const char* detectWifiWithIoctls(FFWifiResult* item)
460460
}
461461
}
462462
else
463-
FF_DEBUG("Failed to get frequency via ioctl: %m");
463+
FF_DEBUG("Failed to get frequency via ioctl: %s", strerror(errno));
464464

465465
// Get signal strength
466466
FF_DEBUG("Getting signal stats via ioctl");
@@ -476,7 +476,7 @@ static const char* detectWifiWithIoctls(FFWifiResult* item)
476476
FF_DEBUG("Signal level: %d dBm, quality: %.0f%%", level, item->conn.signalQuality);
477477
}
478478
else
479-
FF_DEBUG("Failed to get signal stats via ioctl: %m");
479+
FF_DEBUG("Failed to get signal stats via ioctl: %s", strerror(errno));
480480

481481
// Get security info
482482
FF_DEBUG("Getting security info via ioctl");
@@ -515,7 +515,7 @@ static const char* detectWifiWithIoctls(FFWifiResult* item)
515515
}
516516
}
517517
else
518-
FF_DEBUG("Failed to get security info via ioctl: %m");
518+
FF_DEBUG("Failed to get security info via ioctl: %s", strerror(errno));
519519

520520
FF_DEBUG("ioctl wifi detection completed");
521521
return NULL;
@@ -528,7 +528,7 @@ const char* ffDetectWifi(FF_MAYBE_UNUSED FFlist* result)
528528
struct if_nameindex* infs = if_nameindex();
529529
if(!infs)
530530
{
531-
FF_DEBUG("if_nameindex() failed: %m");
531+
FF_DEBUG("if_nameindex() failed: %s", strerror(errno));
532532
return "if_nameindex() failed";
533533
}
534534

0 commit comments

Comments
 (0)