]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
errno-util: return const string from strerror_safe()
authorThomas Haller <thaller@redhat.com>
Fri, 26 Jul 2019 08:57:26 +0000 (10:57 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 26 Jul 2019 16:42:49 +0000 (18:42 +0200)
C's strerror() function does not return a "const char *" pointer
for the string. That has historic reasons and C99 even comments
that "[t]he array pointed to shall not be modified by the program".

Make the strerror_safe() wrapper correct this and be more strict
in this regard.

src/basic/errno-util.h

index 34859d6d8a970fa4c62bc6bbbaf557d894030eeb..6053cde62dd4279fcfa43c133703bfea9f27b7d9 100644 (file)
@@ -31,7 +31,7 @@ static inline int negative_errno(void) {
         return -errno;
 }
 
-static inline char *strerror_safe(int error) {
+static inline const char *strerror_safe(int error) {
         /* 'safe' here does NOT mean thread safety. */
         return strerror(abs(error));
 }