Global: replaces %m for %s + strerror(errno)

Not portable

This reverts aabab6dff5
This commit is contained in:
李通洲
2026-03-26 19:54:10 +08:00
parent 397822d0db
commit bf99aeda92
6 changed files with 39 additions and 39 deletions
+6 -6
View File
@@ -14,7 +14,7 @@ bool ffNetifGetDefaultRouteImplV4(FFNetifDefaultRouteResult* result)
FF_AUTO_CLOSE_FD int sock_fd = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE);
if (sock_fd < 0)
{
FF_DEBUG("Failed to create netlink socket: %m");
FF_DEBUG("Failed to create netlink socket: %s", strerror(errno));
return false;
}
FF_DEBUG("Created netlink socket: fd=%d", sock_fd);
@@ -30,7 +30,7 @@ bool ffNetifGetDefaultRouteImplV4(FFNetifDefaultRouteResult* result)
};
if (bind(sock_fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
FF_DEBUG("Failed to bind socket: %m");
FF_DEBUG("Failed to bind socket: %s", strerror(errno));
return false;
}
FF_DEBUG("Successfully bound socket");
@@ -97,7 +97,7 @@ bool ffNetifGetDefaultRouteImplV4(FFNetifDefaultRouteResult* result)
(struct sockaddr*)&src_addr, &src_addr_len);
if (received < 0) {
FF_DEBUG("Failed to receive netlink response: %m");
FF_DEBUG("Failed to receive netlink response: %s", strerror(errno));
return false;
}
@@ -230,7 +230,7 @@ bool ffNetifGetDefaultRouteImplV6(FFNetifDefaultRouteResult* result)
FF_AUTO_CLOSE_FD int sock_fd = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE);
if (sock_fd < 0)
{
FF_DEBUG("Failed to create netlink socket: %m");
FF_DEBUG("Failed to create netlink socket: %s", strerror(errno));
return false;
}
FF_DEBUG("Created netlink socket: fd=%d", sock_fd);
@@ -246,7 +246,7 @@ bool ffNetifGetDefaultRouteImplV6(FFNetifDefaultRouteResult* result)
};
if (bind(sock_fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
FF_DEBUG("Failed to bind socket: %m");
FF_DEBUG("Failed to bind socket: %s", strerror(errno));
return false;
}
FF_DEBUG("Successfully bound socket");
@@ -313,7 +313,7 @@ bool ffNetifGetDefaultRouteImplV6(FFNetifDefaultRouteResult* result)
(struct sockaddr*)&src_addr, &src_addr_len);
if (received < 0) {
FF_DEBUG("Failed to receive netlink response: %m");
FF_DEBUG("Failed to receive netlink response: %s", strerror(errno));
return false;
}
+13 -13
View File
@@ -43,7 +43,7 @@ static const char* tryNonThreadingFastPath(FFNetworkingState* state)
TCP_FASTOPEN
#endif
, &flag, sizeof(flag)) != 0) {
FF_DEBUG("Failed to set TCP_FASTOPEN option: %m");
FF_DEBUG("Failed to set TCP_FASTOPEN option: %s", strerror(errno));
return "setsockopt(TCP_FASTOPEN) failed";
} else {
#if __linux__ || __GNU__
@@ -73,7 +73,7 @@ static const char* tryNonThreadingFastPath(FFNetworkingState* state)
state->addr->ai_addrlen);
#else
if (fcntl(state->sockfd, F_SETFL, O_NONBLOCK) == -1) {
FF_DEBUG("fcntl(F_SETFL) failed: %m");
FF_DEBUG("fcntl(F_SETFL) failed: %s", strerror(errno));
return "fcntl(F_SETFL) failed";
}
FF_DEBUG("Using connectx() to send %u bytes of data", state->command.length);
@@ -90,7 +90,7 @@ static const char* tryNonThreadingFastPath(FFNetworkingState* state)
.iov_len = state->command.length,
}, 1, &sent, NULL) != 0) sent = 0;
if (fcntl(state->sockfd, F_SETFL, 0) == -1) {
FF_DEBUG("fcntl(F_SETFL) failed: %m");
FF_DEBUG("fcntl(F_SETFL) failed: %s", strerror(errno));
return "fcntl(F_SETFL) failed";
}
#endif
@@ -108,7 +108,7 @@ static const char* tryNonThreadingFastPath(FFNetworkingState* state)
#else
"sendto()"
#endif
" %s (sent=%zd, %m)", errno == 0 ? "succeeded" : "was in progress", sent);
" %s (sent=%zd, %s)", errno == 0 ? "succeeded" : "was in progress", sent, strerror(errno));
freeaddrinfo(state->addr);
state->addr = NULL;
ffStrbufDestroy(&state->command);
@@ -121,7 +121,7 @@ static const char* tryNonThreadingFastPath(FFNetworkingState* state)
#else
"sendto()"
#endif
" failed: %m");
" failed: %s", strerror(errno));
#ifdef __APPLE__
return "connectx() failed";
#else
@@ -142,7 +142,7 @@ static const char* connectAndSend(FFNetworkingState* state)
FF_DEBUG("Attempting connect() to server...");
if(connect(state->sockfd, state->addr->ai_addr, state->addr->ai_addrlen) == -1)
{
FF_DEBUG("connect() failed: %m");
FF_DEBUG("connect() failed: %s", strerror(errno));
ret = "connect() failed";
goto error;
}
@@ -151,7 +151,7 @@ static const char* connectAndSend(FFNetworkingState* state)
FF_DEBUG("Attempting to send %u bytes of data...", state->command.length);
if(send(state->sockfd, state->command.chars, state->command.length, 0) < 0)
{
FF_DEBUG("send() failed: %m");
FF_DEBUG("send() failed: %s", strerror(errno));
ret = "send() failed";
goto error;
}
@@ -226,7 +226,7 @@ static const char* initNetworkingState(FFNetworkingState* state, const char* hos
state->sockfd = socket(state->addr->ai_family, state->addr->ai_socktype, state->addr->ai_protocol);
if(state->sockfd == -1)
{
FF_DEBUG("socket() failed: %m");
FF_DEBUG("socket() failed: %s", strerror(errno));
ret = "socket() failed";
goto error;
}
@@ -236,7 +236,7 @@ static const char* initNetworkingState(FFNetworkingState* state, const char* hos
#ifdef TCP_NODELAY
// Disable Nagle's algorithm to reduce small packet transmission delay
if (setsockopt(state->sockfd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag)) != 0) {
FF_DEBUG("Failed to set TCP_NODELAY: %m");
FF_DEBUG("Failed to set TCP_NODELAY: %s", strerror(errno));
} else {
FF_DEBUG("Successfully disabled Nagle's algorithm");
}
@@ -245,7 +245,7 @@ static const char* initNetworkingState(FFNetworkingState* state, const char* hos
#ifdef TCP_QUICKACK
// Set TCP_QUICKACK option to avoid delayed acknowledgments
if (setsockopt(state->sockfd, IPPROTO_TCP, TCP_QUICKACK, &flag, sizeof(flag)) != 0) {
FF_DEBUG("Failed to set TCP_QUICKACK: %m");
FF_DEBUG("Failed to set TCP_QUICKACK: %s", strerror(errno));
} else {
FF_DEBUG("Successfully enabled TCP quick acknowledgment");
}
@@ -398,7 +398,7 @@ const char* ffNetworkingRecvHttpResponse(FFNetworkingState* state, FFstrbuf* buf
}
else if (pollRes == -1)
{
FF_DEBUG("poll() failed: %m");
FF_DEBUG("poll() failed: %s", strerror(errno));
close(state->sockfd);
state->sockfd = -1;
return "poll() failed";
@@ -418,7 +418,7 @@ const char* ffNetworkingRecvHttpResponse(FFNetworkingState* state, FFstrbuf* buf
if (shutdown(state->sockfd, SHUT_WR) == -1)
{
FF_DEBUG("Failed to shutdown socket send: %m");
FF_DEBUG("Failed to shutdown socket send: %s", strerror(errno));
// Not a critical error, continue anyway
}
@@ -439,7 +439,7 @@ const char* ffNetworkingRecvHttpResponse(FFNetworkingState* state, FFstrbuf* buf
if (received == 0) {
FF_DEBUG("Connection closed (received=0)");
} else {
FF_DEBUG("Reception failed: %m");
FF_DEBUG("Reception failed: %s", strerror(errno));
}
break;
}
+9 -9
View File
@@ -286,7 +286,7 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
FF_AUTO_CLOSE_FD int fd = open("/dev/mem", O_RDONLY | O_CLOEXEC);
if (fd < 0) {
FF_DEBUG("Failed to open /dev/mem: %m");
FF_DEBUG("Failed to open /dev/mem: %s", strerror(errno));
return NULL;
}
FF_DEBUG("/dev/mem opened successfully with fd=%d", fd);
@@ -301,7 +301,7 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
// https://stackoverflow.com/questions/69372330/how-to-read-dev-mem-using-read
void* p = mmap(NULL, sizeof(entryPoint), PROT_READ, MAP_SHARED, fd, entryAddress);
if (p == MAP_FAILED) {
FF_DEBUG("mmap failed: %m");
FF_DEBUG("mmap failed: %s", strerror(errno));
return NULL;
}
memcpy(&entryPoint, p, sizeof(entryPoint));
@@ -322,7 +322,7 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
FF_AUTO_CLOSE_FD int fd = open("/dev/smbios", O_RDONLY | O_CLOEXEC);
if (fd < 0) {
FF_DEBUG("Failed to open /dev/smbios: %m");
FF_DEBUG("Failed to open /dev/smbios: %s", strerror(errno));
return NULL;
}
FF_DEBUG("/dev/smbios opened successfully with fd=%d", fd);
@@ -337,14 +337,14 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
FF_DEBUG("Got SMBIOS address from sysctl: 0x%lx", (unsigned long)addr);
if (pread(fd, &entryPoint, sizeof(entryPoint), addr) < 1) {
FF_DEBUG("Failed to read SMBIOS entry point: %m");
FF_DEBUG("Failed to read SMBIOS entry point: %s", strerror(errno));
return NULL;
}
FF_DEBUG("Successfully read SMBIOS entry point");
#else
FF_DEBUG("Reading SMBIOS entry point from /dev/smbios");
if (ffReadFDData(fd, sizeof(entryPoint), &entryPoint) < 1) {
FF_DEBUG("Failed to read SMBIOS entry point: %m");
FF_DEBUG("Failed to read SMBIOS entry point: %s", strerror(errno));
return NULL;
}
FF_DEBUG("Successfully read SMBIOS entry point");
@@ -402,7 +402,7 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
void* p = mmap(NULL, tableLength, PROT_READ, MAP_SHARED, fd, tableAddress);
if (p == MAP_FAILED)
{
FF_DEBUG("mmap failed: %m");
FF_DEBUG("mmap failed: %s", strerror(errno));
ffStrbufDestroy(&buffer); // free buffer and reset state
return NULL;
}
@@ -431,7 +431,7 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
#endif
, O_RDONLY | O_CLOEXEC);
if (fd < 0) {
FF_DEBUG("Failed to open memory device: %m");
FF_DEBUG("Failed to open memory device: %s", strerror(errno));
return NULL;
}
FF_DEBUG("Memory device opened successfully with fd=%d", fd);
@@ -443,7 +443,7 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
// which is not available via EFIIOC_GET_TABLE.
FF_AUTO_FREE uint8_t* smBiosBase = malloc(0x10000);
if (pread(fd, smBiosBase, 0x10000, 0xF0000) != 0x10000) {
FF_DEBUG("Failed to read SMBIOS memory region: %m");
FF_DEBUG("Failed to read SMBIOS memory region: %s", strerror(errno));
return NULL;
}
FF_DEBUG("Successfully read 0x10000 bytes from physical address 0xF0000");
@@ -496,7 +496,7 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
FF_DEBUG("Successfully read SMBIOS table data: %u bytes", tableLength);
}
else {
FF_DEBUG("Failed to read SMBIOS table data: %m");
FF_DEBUG("Failed to read SMBIOS table data: %s", strerror(errno));
return NULL;
}
}
+1 -1
View File
@@ -15,7 +15,7 @@ static const char* detectDnsFromConf(const char* path, FFDNSOptions* options, FF
FF_AUTO_CLOSE_FILE FILE* file = fopen(path, "r");
if (!file)
{
FF_DEBUG("Failed to open %s: %m", path);
FF_DEBUG("Failed to open %s: %s", path, strerror(errno));
return "fopen(path, r) failed";
}
+1 -1
View File
@@ -18,7 +18,7 @@ static const char* detectDnsFromConf(const char* path, FFDNSOptions* options, FF
FF_AUTO_CLOSE_FILE FILE* file = fopen(path, "r");
if (!file)
{
FF_DEBUG("Failed to open %s: %m", path);
FF_DEBUG("Failed to open %s: %s", path, strerror(errno));
return "fopen(path, r) failed";
}
+9 -9
View File
@@ -375,7 +375,7 @@ static const char* detectWifiWithIoctls(FFWifiResult* item)
FF_AUTO_CLOSE_FD int sock = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if(sock < 0)
{
FF_DEBUG("Failed to create socket: %m");
FF_DEBUG("Failed to create socket: %s", strerror(errno));
return "socket() failed";
}
@@ -395,7 +395,7 @@ static const char* detectWifiWithIoctls(FFWifiResult* item)
FF_DEBUG("SSID: %s", item->conn.ssid.chars);
}
else
FF_DEBUG("Failed to get SSID via ioctl: %m");
FF_DEBUG("Failed to get SSID via ioctl: %s", strerror(errno));
// Get protocol name
FF_DEBUG("Getting protocol name via ioctl");
@@ -408,7 +408,7 @@ static const char* detectWifiWithIoctls(FFWifiResult* item)
FF_DEBUG("Protocol: %s", item->conn.protocol.chars);
}
else
FF_DEBUG("Failed to get protocol name via ioctl: %m");
FF_DEBUG("Failed to get protocol name via ioctl: %s", strerror(errno));
// Get BSSID
FF_DEBUG("Getting BSSID via ioctl");
@@ -420,7 +420,7 @@ static const char* detectWifiWithIoctls(FFWifiResult* item)
FF_DEBUG("BSSID: %s", item->conn.bssid.chars);
}
else
FF_DEBUG("Failed to get BSSID via ioctl: %m");
FF_DEBUG("Failed to get BSSID via ioctl: %s", strerror(errno));
// Get bitrate
FF_DEBUG("Getting bitrate via ioctl");
@@ -430,7 +430,7 @@ static const char* detectWifiWithIoctls(FFWifiResult* item)
FF_DEBUG("TX bitrate: %.2f Mbps", item->conn.txRate);
}
else
FF_DEBUG("Failed to get bitrate via ioctl: %m");
FF_DEBUG("Failed to get bitrate via ioctl: %s", strerror(errno));
// Get frequency/channel
FF_DEBUG("Getting frequency via ioctl");
@@ -460,7 +460,7 @@ static const char* detectWifiWithIoctls(FFWifiResult* item)
}
}
else
FF_DEBUG("Failed to get frequency via ioctl: %m");
FF_DEBUG("Failed to get frequency via ioctl: %s", strerror(errno));
// Get signal strength
FF_DEBUG("Getting signal stats via ioctl");
@@ -476,7 +476,7 @@ static const char* detectWifiWithIoctls(FFWifiResult* item)
FF_DEBUG("Signal level: %d dBm, quality: %.0f%%", level, item->conn.signalQuality);
}
else
FF_DEBUG("Failed to get signal stats via ioctl: %m");
FF_DEBUG("Failed to get signal stats via ioctl: %s", strerror(errno));
// Get security info
FF_DEBUG("Getting security info via ioctl");
@@ -515,7 +515,7 @@ static const char* detectWifiWithIoctls(FFWifiResult* item)
}
}
else
FF_DEBUG("Failed to get security info via ioctl: %m");
FF_DEBUG("Failed to get security info via ioctl: %s", strerror(errno));
FF_DEBUG("ioctl wifi detection completed");
return NULL;
@@ -528,7 +528,7 @@ const char* ffDetectWifi(FF_MAYBE_UNUSED FFlist* result)
struct if_nameindex* infs = if_nameindex();
if(!infs)
{
FF_DEBUG("if_nameindex() failed: %m");
FF_DEBUG("if_nameindex() failed: %s", strerror(errno));
return "if_nameindex() failed";
}