mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 00:14:32 +09:00
errno-util: avoid double evaluation in STRERROR_OR_EOF()
Follow-up for f69ae8585f.
This commit is contained in:
10
src/basic/errno-util.c
Normal file
10
src/basic/errno-util.c
Normal file
@@ -0,0 +1,10 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "errno-util.h"
|
||||
|
||||
const char* strerror_or_eof(int errnum, char *buf, size_t buflen) {
|
||||
if (errnum != 0)
|
||||
return strerror_r(ABS(errnum), buf, buflen);
|
||||
|
||||
return "Unexpected EOF";
|
||||
}
|
||||
@@ -15,10 +15,9 @@
|
||||
* Note that we use the GNU variant of strerror_r() here. */
|
||||
#define STRERROR(errnum) strerror_r(ABS(errnum), (char[ERRNO_BUF_LEN]){}, ERRNO_BUF_LEN)
|
||||
|
||||
/* A helper to print an error message or message for functions that return 0 on EOF.
|
||||
* Note that we can't use ({ … }) to define a temporary variable, so errnum is
|
||||
* evaluated twice. */
|
||||
#define STRERROR_OR_EOF(errnum) ((errnum) != 0 ? STRERROR(errnum) : "Unexpected EOF")
|
||||
/* A helper to print an error message or message for functions that return 0 on EOF. */
|
||||
const char* strerror_or_eof(int errnum, char *buf, size_t buflen);
|
||||
#define STRERROR_OR_EOF(errnum) strerror_or_eof(errnum, (char[ERRNO_BUF_LEN]){}, ERRNO_BUF_LEN)
|
||||
|
||||
static inline void _reset_errno_(int *saved_errno) {
|
||||
if (*saved_errno < 0) /* Invalidated by UNPROTECT_ERRNO? */
|
||||
|
||||
@@ -31,6 +31,7 @@ basic_sources = files(
|
||||
'env-file.c',
|
||||
'env-util.c',
|
||||
'errno-list.c',
|
||||
'errno-util.c',
|
||||
'escape.c',
|
||||
'ether-addr-util.c',
|
||||
'extract-word.c',
|
||||
|
||||
Reference in New Issue
Block a user