if (feof(f))
return 0;
- return errno > 0 ? -errno : -EIO;
+ return errno_or_else(EIO);
}
if (ul <= 0)
if (nftw(fs, trim_cb, 64, FTW_DEPTH|FTW_MOUNT|FTW_PHYS) != 0) {
if (errno == ENOENT)
r = 0;
- else if (errno > 0)
- r = -errno;
else
- r = -EIO;
+ r = errno_or_else(EIO);
}
if (delete_root) {
if (feof(f))
break;
- if (ferror(f) && errno > 0)
- return -errno;
+ if (ferror(f))
+ return errno_or_else(EIO);
return -EBADMSG;
}
errno = 0;
k = fread(buf, 1, l + accept_extra_nl + 1, f);
if (ferror(f))
- return errno > 0 ? -errno : -EIO;
+ return errno_or_else(EIO);
if (k != l && k != l + accept_extra_nl)
return 0;
l += k;
if (ferror(f)) {
- r = errno > 0 ? -errno : -EIO;
+ r = errno_or_else(EIO);
goto finalize;
}
fflush(f);
if (ferror(f))
- return errno > 0 ? -errno : -EIO;
+ return errno_or_else(EIO);
return 0;
}
k = fgetc(f);
if (k == EOF) {
if (ferror(f))
- return errno > 0 ? -errno : -EIO;
+ return errno_or_else(EIO);
if (ret)
*ret = 0;
#include <unistd.h>
#include "dirent-util.h"
+#include "errno-util.h"
#include "glob-util.h"
#include "macro.h"
#include "path-util.h"
errno = 0;
k = glob(path, flags | GLOB_ALTDIRFUNC, NULL, pglob);
-
if (k == GLOB_NOMATCH)
return -ENOENT;
if (k == GLOB_NOSPACE)
return -ENOMEM;
if (k != 0)
- return errno > 0 ? -errno : -EIO;
+ return errno_or_else(EIO);
if (strv_isempty(pglob->gl_pathv))
return -ENOENT;
#include <stdlib.h>
#include "alloc-util.h"
+#include "errno-util.h"
#include "in-addr-util.h"
#include "macro.h"
#include "parse-util.h"
errno = 0;
if (!inet_ntop(family, u, x, l))
- return errno > 0 ? -errno : -EINVAL;
+ return errno_or_else(EINVAL);
*ret = TAKE_PTR(x);
return 0;
errno = 0;
if (!inet_ntop(family, u, x, l))
- return errno > 0 ? -errno : -EINVAL;
+ return errno_or_else(EINVAL);
p = x + strlen(x);
l -= strlen(x);
errno = 0;
if (!inet_ntop(family, u, x, l))
- return errno > 0 ? -errno : -EINVAL;
+ return errno_or_else(EINVAL);
sprintf(strchr(x, 0), "%%%i", ifindex);
errno = 0;
if (inet_pton(family, s, ret ?: &buffer) <= 0)
- return errno > 0 ? -errno : -EINVAL;
+ return errno_or_else(EINVAL);
return 0;
}
errno = 0;
if (inet_pton(AF_INET6, n, &a->sockaddr.in6.sin6_addr) <= 0)
- return errno > 0 ? -errno : -EINVAL;
+ return errno_or_else(EINVAL);
e++;
if (*e != ':')
#include <utmp.h>
#include "alloc-util.h"
+#include "errno-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "format-util.h"
p = getpwnam(*username);
}
if (!p) {
- r = errno > 0 ? -errno : -ESRCH;
+ r = errno_or_else(ESRCH);
/* If the user requested that we only synthesize as fallback, do so now */
if (FLAGS_SET(flags, USER_CREDS_PREFER_NSS)) {
}
if (!g)
- return errno > 0 ? -errno : -ESRCH;
+ return errno_or_else(ESRCH);
if (gid) {
if (!gid_is_valid(g->gr_gid))
errno = 0;
p = getpwuid(u);
if (!p)
- return errno > 0 ? -errno : -ESRCH;
+ return errno_or_else(ESRCH);
if (!path_is_valid(p->pw_dir) ||
!path_is_absolute(p->pw_dir))
errno = 0;
p = getpwuid(u);
if (!p)
- return errno > 0 ? -errno : -ESRCH;
+ return errno_or_else(ESRCH);
if (!path_is_valid(p->pw_shell) ||
!path_is_absolute(p->pw_shell))
errno = 0;
if (putpwent(pw, stream) != 0)
- return errno > 0 ? -errno : -EIO;
+ return errno_or_else(EIO);
return 0;
}
errno = 0;
if (putspent(sp, stream) != 0)
- return errno > 0 ? -errno : -EIO;
+ return errno_or_else(EIO);
return 0;
}
errno = 0;
if (putgrent(gr, stream) != 0)
- return errno > 0 ? -errno : -EIO;
+ return errno_or_else(EIO);
return 0;
}
errno = 0;
if (putsgent(sg, stream) != 0)
- return errno > 0 ? -errno : -EIO;
+ return errno_or_else(EIO);
return 0;
}
errno = 0;
p = fgetpwent(stream);
if (!p && errno != ENOENT)
- return errno > 0 ? -errno : -EIO;
+ return errno_or_else(EIO);
*pw = p;
return !!p;
errno = 0;
s = fgetspent(stream);
if (!s && errno != ENOENT)
- return errno > 0 ? -errno : -EIO;
+ return errno_or_else(EIO);
*sp = s;
return !!s;
errno = 0;
g = fgetgrent(stream);
if (!g && errno != ENOENT)
- return errno > 0 ? -errno : -EIO;
+ return errno_or_else(EIO);
*gr = g;
return !!g;
errno = 0;
s = fgetsgent(stream);
if (!s && errno != ENOENT)
- return errno > 0 ? -errno : -EIO;
+ return errno_or_else(EIO);
*sg = s;
return !!s;
#include "cgroup.h"
#include "dbus-cgroup.h"
#include "dbus-util.h"
+#include "errno-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "limits-util.h"
errno = 0;
if (!inet_ntop(item->family, &item->address, buffer, sizeof(buffer)))
- return errno > 0 ? -errno : -EINVAL;
+ return errno_or_else(EINVAL);
fprintf(f, "%s=%s/%u\n", name, buffer, item->prefixlen);
}
errno = 0;
p = getpwuid(num);
if (!p)
- return errno > 0 ? -errno : -ESRCH;
+ return errno_or_else(ESRCH);
gid = p->pw_gid;
}
*/
errno = 0;
ngroups_max = (int) sysconf(_SC_NGROUPS_MAX);
- if (ngroups_max <= 0) {
- if (errno > 0)
- return -errno;
- else
- return -EOPNOTSUPP; /* For all other values */
- }
+ if (ngroups_max <= 0)
+ return errno_or_else(EOPNOTSUPP);
l_gids = new(gid_t, ngroups_max);
if (!l_gids)
#include <unistd.h>
#include "alloc-util.h"
+#include "errno-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "generator.h"
errno = 0;
if (isatty(fd) <= 0)
- return errno > 0 ? -errno : -EIO;
+ return errno_or_else(EIO);
return 0;
}
#include "cgroup-util.h"
#include "conf-parser.h"
#include "device-util.h"
+#include "errno-util.h"
#include "fd-util.h"
#include "limits-util.h"
#include "logind.h"
errno = 0;
p = getpwuid(uid);
if (!p)
- return errno > 0 ? -errno : -ENOENT;
+ return errno_or_else(ENOENT);
return manager_add_user(m, uid, p->pw_gid, p->pw_name, p->pw_dir, _user);
}
errno = 0;
pw = getpwuid(uid);
if (!pw)
- return errno > 0 ? -errno : -ENOENT;
+ return errno_or_else(ENOENT);
r = bus_verify_polkit_async(
message,
#include "bus-error.h"
#include "bus-util.h"
#include "env-file.h"
+#include "errno-util.h"
#include "escape.h"
#include "extract-word.h"
#include "fd-util.h"
k = fscanf(f, UID_FMT " " UID_FMT " " UID_FMT "\n", &uid_base, &uid_shift, &uid_range);
if (k != 3) {
if (ferror(f))
- return -errno;
+ return errno_or_else(EIO);
return -EBADMSG;
}
k = fscanf(f, GID_FMT " " GID_FMT " " GID_FMT "\n", &gid_base, &gid_shift, &gid_range);
if (k != 3) {
if (ferror(f))
- return -errno;
+ return errno_or_else(EIO);
return -EBADMSG;
}
#include "bus-common-errors.h"
#include "bus-util.h"
#include "cgroup-util.h"
+#include "errno-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "format-util.h"
errno = 0;
n = fread(&success, 1, sizeof(success), f);
if (n != sizeof(success))
- return ret < 0 ? ret : (errno != 0 ? -errno : -EIO);
+ return ret < 0 ? ret : errno_or_else(EIO);
if (ret < 0) {
_cleanup_free_ char *name = NULL;
errno = 0;
n = fread(&size, 1, sizeof(size), f);
if (n != sizeof(size))
- return errno != 0 ? -errno : -EIO;
+ return errno_or_else(EIO);
r = sd_bus_message_append(reply, "(st)", name, size);
if (r < 0)
if (k < 0 && feof(f))
break;
if (k != 3) {
- if (ferror(f) && errno > 0)
- return -errno;
+ if (ferror(f))
+ return errno_or_else(EIO);
return -EIO;
}
if (k < 0 && feof(f))
break;
if (k != 3) {
- if (ferror(f) && errno > 0)
- return -errno;
+ if (ferror(f))
+ return errno_or_else(EIO);
return -EIO;
}
if (k < 0 && feof(f))
break;
if (k != 3) {
- if (ferror(f) && errno > 0)
- return -errno;
+ if (ferror(f))
+ return errno_or_else(EIO);
return -EIO;
}
if (k < 0 && feof(f))
break;
if (k != 3) {
- if (ferror(f) && errno > 0)
- return -errno;
+ if (ferror(f))
+ return errno_or_else(EIO);
return -EIO;
}
errno = 0;
b = blkid_new_probe_from_filename(node);
if (!b)
- return -errno ?: -ENOMEM;
+ return errno_or_else(ENOMEM);
blkid_probe_enable_superblocks(b, 1);
blkid_probe_set_superblocks_flags(b, BLKID_SUBLKS_TYPE);
return -EUCLEAN;
}
if (r != 0)
- return -errno ?: -EIO;
+ return errno_or_else(EIO);
(void) blkid_probe_lookup_value(b, "TYPE", &fstype, NULL);
errno = 0;
r = blkid_probe_set_device(b, fd, 0, 0);
if (r != 0)
- return -errno ?: -ENOMEM;
+ return errno_or_else(ENOMEM);
if ((flags & DISSECT_IMAGE_GPT_ONLY) == 0) {
/* Look for file system superblocks, unless we only shall look for GPT partition tables */
if (IN_SET(r, -2, 1))
return log_debug_errno(SYNTHETIC_ERRNO(ENOPKG), "Failed to identify any partition table.");
if (r != 0)
- return -errno ?: -EIO;
+ return errno_or_else(EIO);
m = new0(DissectedImage, 1);
if (!m)
errno = 0;
pl = blkid_probe_get_partitions(b);
if (!pl)
- return -errno ?: -ENOMEM;
+ return errno_or_else(ENOMEM);
r = loop_wait_for_partitions_to_appear(fd, d, blkid_partlist_numof_partitions(pl), flags, &e);
if (r < 0)
#include "blkid-util.h"
#include "device-util.h"
#include "efivars.h"
+#include "errno-util.h"
#include "fd-util.h"
#include "gpt.h"
#include "parse-util.h"
errno = 0;
pl = blkid_probe_get_partitions(pr);
if (!pl)
- return -errno ?: -ENOMEM;
+ return errno_or_else(ENOMEM);
nvals = blkid_partlist_numof_partitions(pl);
for (i = 0; i < nvals; i++) {