summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/async.c1
-rw-r--r--src/basic/errno-util.h29
-rw-r--r--src/basic/fs-util.h2
-rw-r--r--src/basic/log.c2
-rw-r--r--src/basic/meson.build1
-rw-r--r--src/basic/rm-rf.h2
-rw-r--r--src/basic/selinux-util.c2
-rw-r--r--src/basic/util.h25
8 files changed, 35 insertions, 29 deletions
diff --git a/src/basic/async.c b/src/basic/async.c
index c45ca01847..daa95cd102 100644
--- a/src/basic/async.c
+++ b/src/basic/async.c
@@ -6,6 +6,7 @@
#include <unistd.h>
#include "async.h"
+#include "errno-util.h"
#include "fd-util.h"
#include "log.h"
#include "macro.h"
diff --git a/src/basic/errno-util.h b/src/basic/errno-util.h
new file mode 100644
index 0000000000..2d72b8ce9e
--- /dev/null
+++ b/src/basic/errno-util.h
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+#pragma once
+
+#include "macro.h"
+
+static inline void _reset_errno_(int *saved_errno) {
+ if (*saved_errno < 0) /* Invalidated by UNPROTECT_ERRNO? */
+ return;
+
+ errno = *saved_errno;
+}
+
+#define PROTECT_ERRNO \
+ _cleanup_(_reset_errno_) _unused_ int _saved_errno_ = errno
+
+#define UNPROTECT_ERRNO \
+ do { \
+ errno = _saved_errno_; \
+ _saved_errno_ = -1; \
+ } while (false)
+
+static inline int negative_errno(void) {
+ /* This helper should be used to shut up gcc if you know 'errno' is
+ * negative. Instead of "return -errno;", use "return negative_errno();"
+ * It will suppress bogus gcc warnings in case it assumes 'errno' might
+ * be 0 and thus the caller's error-handling might not be triggered. */
+ assert_return(errno > 0, -EINVAL);
+ return -errno;
+}
diff --git a/src/basic/fs-util.h b/src/basic/fs-util.h
index 9c9044669d..b9651205e6 100644
--- a/src/basic/fs-util.h
+++ b/src/basic/fs-util.h
@@ -10,8 +10,8 @@
#include <sys/types.h>
#include <unistd.h>
+#include "errno-util.h"
#include "time-util.h"
-#include "util.h"
int unlink_noerrno(const char *path);
diff --git a/src/basic/log.c b/src/basic/log.c
index 84621932db..3b7bff3a97 100644
--- a/src/basic/log.c
+++ b/src/basic/log.c
@@ -19,6 +19,7 @@
#include "sd-messages.h"
#include "alloc-util.h"
+#include "errno-util.h"
#include "fd-util.h"
#include "format-util.h"
#include "io-util.h"
@@ -37,7 +38,6 @@
#include "terminal-util.h"
#include "time-util.h"
#include "utf8.h"
-#include "util.h"
#define SNDBUF_SIZE (8*1024*1024)
diff --git a/src/basic/meson.build b/src/basic/meson.build
index c666ab941f..1f7ef8683a 100644
--- a/src/basic/meson.build
+++ b/src/basic/meson.build
@@ -45,6 +45,7 @@ basic_sources = files('''
env-util.h
errno-list.c
errno-list.h
+ errno-util.h
escape.c
escape.h
ether-addr-util.c
diff --git a/src/basic/rm-rf.h b/src/basic/rm-rf.h
index 3ee2b97e37..d42ebef434 100644
--- a/src/basic/rm-rf.h
+++ b/src/basic/rm-rf.h
@@ -3,7 +3,7 @@
#include <sys/stat.h>
-#include "util.h"
+#include "errno-util.h"
typedef enum RemoveFlags {
REMOVE_ONLY_DIRECTORIES = 1 << 0,
diff --git a/src/basic/selinux-util.c b/src/basic/selinux-util.c
index dc06f3d074..375da920f7 100644
--- a/src/basic/selinux-util.c
+++ b/src/basic/selinux-util.c
@@ -16,6 +16,7 @@
#endif
#include "alloc-util.h"
+#include "errno-util.h"
#include "fd-util.h"
#include "log.h"
#include "macro.h"
@@ -23,7 +24,6 @@
#include "selinux-util.h"
#include "stdio-util.h"
#include "time-util.h"
-#include "util.h"
#if HAVE_SELINUX
DEFINE_TRIVIAL_CLEANUP_FUNC(char*, freecon);
diff --git a/src/basic/util.h b/src/basic/util.h
index f6f005a29b..d1a8a8f3b4 100644
--- a/src/basic/util.h
+++ b/src/basic/util.h
@@ -63,31 +63,6 @@ void in_initrd_force(bool value);
int on_ac_power(void);
-static inline void _reset_errno_(int *saved_errno) {
- if (*saved_errno < 0) /* Invalidated by UNPROTECT_ERRNO? */
- return;
-
- errno = *saved_errno;
-}
-
-#define PROTECT_ERRNO \
- _cleanup_(_reset_errno_) _unused_ int _saved_errno_ = errno
-
-#define UNPROTECT_ERRNO \
- do { \
- errno = _saved_errno_; \
- _saved_errno_ = -1; \
- } while (false)
-
-static inline int negative_errno(void) {
- /* This helper should be used to shut up gcc if you know 'errno' is
- * negative. Instead of "return -errno;", use "return negative_errno();"
- * It will suppress bogus gcc warnings in case it assumes 'errno' might
- * be 0 and thus the caller's error-handling might not be triggered. */
- assert_return(errno > 0, -EINVAL);
- return -errno;
-}
-
static inline unsigned u64log2(uint64_t n) {
#if __SIZEOF_LONG_LONG__ == 8
return (n > 1) ? (unsigned) __builtin_clzll(n) ^ 63U : 0;