util.c revision 4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore This file is part of systemd.
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore Copyright 2010 Lennart Poettering
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore systemd is free software; you can redistribute it and/or modify it
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore under the terms of the GNU Lesser General Public License as published by
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore the Free Software Foundation; either version 2.1 of the License, or
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore (at your option) any later version.
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore systemd is distributed in the hope that it will be useful, but
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore WITHOUT ANY WARRANTY; without even the implied warranty of
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
538aa54d819fa7751ca82bcc30d4ed8c57ec2ef2Garrett D'Amore Lesser General Public License for more details.
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore You should have received a copy of the GNU Lesser General Public License
538aa54d819fa7751ca82bcc30d4ed8c57ec2ef2Garrett D'Amore along with systemd; If not, see <http://www.gnu.org/licenses/>.
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <glob.h>
#include <grp.h>
#include <langinfo.h>
#include <libintl.h>
#include <limits.h>
#include <locale.h>
#include <poll.h>
#include <pwd.h>
#include <sched.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
/* When we include libgen.h because we need dirname() we immediately
* undefine basename() since libgen.h defines it as a macro to the
#include <libgen.h>
#ifdef HAVE_SYS_AUXV_H
#include "build.h"
#include "def.h"
#include "device-nodes.h"
#include "env-util.h"
#include "escape.h"
#include "exit-status.h"
#include "fileio.h"
#include "formats-util.h"
#include "gunicode.h"
#include "hashmap.h"
#include "hostname-util.h"
#include "ioprio.h"
#include "log.h"
#include "macro.h"
#include "missing.h"
#include "mkdir.h"
#include "path-util.h"
#include "process-util.h"
#include "random-util.h"
#include "signal-util.h"
#include "sparse-endian.h"
#include "strv.h"
#include "terminal-util.h"
#include "utf8.h"
#include "virt.h"
#include "util.h"
int saved_argc = 0;
return pgsz;
assert(r > 0);
return pgsz;
int strcmp_ptr(const char *a, const char *b) {
return strcmp(a, b);
bool streq_ptr(const char *a, const char *b) {
return strcmp_ptr(a, b) == 0;
assert(s);
if (pl == 0)
return (char*) s + sl;
return NULL;
return NULL;
assert(s);
if (pl == 0)
return (char*) s + sl;
return NULL;
return NULL;
assert(s);
return NULL;
if (wl == 0)
return NULL;
p = s + wl;
return NULL;
* https://sites.google.com/site/michaelsafyan/software-engineering/checkforeintrwheninvokingclosethinkagain
return -errno;
if (fd >= 0) {
for (i = 0; i < n_fd; i++)
assert(f);
if (fclose(f) == 0)
return -errno;
return NULL;
return NULL;
return -errno;
int parse_boolean(const char *v) {
assert(v);
if (streq(v, "1") || strcaseeq(v, "yes") || strcaseeq(v, "y") || strcaseeq(v, "true") || strcaseeq(v, "t") || strcaseeq(v, "on"))
else if (streq(v, "0") || strcaseeq(v, "no") || strcaseeq(v, "n") || strcaseeq(v, "false") || strcaseeq(v, "f") || strcaseeq(v, "off"))
return -EINVAL;
unsigned long ul = 0;
assert(s);
return -ERANGE;
if (pid <= 0)
return -ERANGE;
unsigned long ul = 0;
assert(s);
return -ERANGE;
if (ret_uid)
char *x = NULL;
assert(s);
errno = 0;
l = strtoul(s, &x, 0);
if (!x || x == s || *x || errno)
return -ERANGE;
*ret_u = (unsigned) l;
char *x = NULL;
assert(s);
errno = 0;
l = strtol(s, &x, 0);
if (!x || x == s || *x || errno)
return -ERANGE;
*ret_i = (int) l;
char *x = NULL;
assert(s);
errno = 0;
l = strtoul(s, &x, 0);
if (!x || x == s || *x || errno)
if ((unsigned long) (uint8_t) l != l)
return -ERANGE;
char *x = NULL;
assert(s);
errno = 0;
l = strtoul(s, &x, 0);
if (!x || x == s || *x || errno)
if ((unsigned long) (uint16_t) l != l)
return -ERANGE;
char *x = NULL;
assert(s);
errno = 0;
l = strtol(s, &x, 0);
if (!x || x == s || *x || errno)
if ((long) (int16_t) l != l)
return -ERANGE;
char *x = NULL;
assert(s);
errno = 0;
l = strtoull(s, &x, 0);
if (!x || x == s || *x || errno)
*ret_llu = l;
char *x = NULL;
assert(s);
errno = 0;
l = strtoll(s, &x, 0);
if (!x || x == s || *x || errno)
*ret_lli = l;
char *x = NULL;
assert(s);
return -errno;
errno = 0;
if (!x || x == s || *x || errno) {
*ret_d = (double) d;
bool escaped = false;
if (escaped)
escaped = false;
escaped = true;
return n - escaped;
const char *current;
if (!*current) {
return NULL;
if (!*current) {
return NULL;
return NULL;
} else if (quoted) {
return NULL;
return current;
mode_t u;
umask(u);
char *truncate_nl(char *s) {
assert(s);
size_t a;
if (!s && !suffix)
if (!suffix)
return strdup(s);
assert(s);
a = strlen(s);
return NULL;
return NULL;
memcpy(r, s, a);
assert(p);
ssize_t n;
c = new(char, l);
return -ENOMEM;
r = -errno;
free(c);
*ret = c;
free(c);
char *value;
if (!value)
return -ENOENT;
if (!value)
return -ENOMEM;
int readlink_and_make_absolute(const char *p, char **r) {
assert(p);
assert(r);
return -ENOMEM;
int readlink_and_canonicalize(const char *p, char **r) {
assert(p);
assert(r);
j = readlink_and_make_absolute(p, &t);
s = canonicalize_file_name(t);
free(t);
path_kill_slashes(*r);
char *strstrip(char *s) {
for (e = strchr(s, 0); e > s; e --)
char *e, *ret;
size_t k;
if (!ret)
return NULL;
return ret;
size_t l;
return -ENOMEM;
free(t);
r = rmdir(t);
free(t);
return -errno;
char hexchar(int x) {
int unhexchar(char c) {
return -EINVAL;
const uint8_t *x;
return NULL;
for (x = p; x < (const uint8_t*) p + l; x++) {
uint8_t *z;
assert(p);
return -ENOMEM;
a = unhexchar(x[0]);
*mem = r;
r = NULL;
/* https://tools.ietf.org/html/rfc4648#section-6
char base32hexchar(int x) {
int unbase32hexchar(char c) {
unsigned offset;
return -EINVAL;
const uint8_t *x;
if (padding)
return NULL;
if (padding)
if (padding) {
if (padding) {
if (padding) {
uint8_t *z;
unsigned pad = 0;
assert(p);
return -EINVAL;
if (padding) {
pad ++;
return -EINVAL;
return -ENOMEM;
a = unbase32hexchar(x[0]);
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
a = unbase32hexchar(x[0]);
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
a = unbase32hexchar(x[0]);
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
a = unbase32hexchar(x[0]);
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
a = unbase32hexchar(x[0]);
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
*mem = r;
r = NULL;
/* https://tools.ietf.org/html/rfc4648#section-4 */
char base64char(int x) {
int unbase64char(char c) {
unsigned offset;
return offset;
offset ++;
return offset;
return -EINVAL;
const uint8_t *x;
return NULL;
uint8_t *z;
assert(p);
return -EINVAL;
return -ENOMEM;
a = unbase64char(x[0]);
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
a = unbase64char(x[0]);
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
a = unbase64char(x[0]);
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
*mem = r;
r = NULL;
char octchar(int x) {
int unoctchar(char c) {
return -EINVAL;
char decchar(int x) {
int undecchar(char c) {
return -EINVAL;
char *ascii_strlower(char *t) {
assert(t);
if (flags < 0)
return -errno;
if (nonblock)
return -errno;
if (flags < 0)
return -errno;
if (cloexec)
return -errno;
for (i = 0; i < n_fdset; i++)
int fd;
r = -errno;
r = -errno;
bool chars_intersect(const char *a, const char *b) {
if (strchr(b, *p))
static const char table[] =
fstype = x;
ssize_t l;
return -errno;
return -errno;
void safe_close_pair(int p[]) {
assert(p);
p[0] = safe_close(p[0]);
ssize_t n = 0;
return -EINVAL;
ssize_t k;
return n > 0 ? n : -errno;
nbytes -= k;
} while (nbytes > 0);
ssize_t n;
return -EIO;
return -EINVAL;
ssize_t k;
return -errno;
return -EIO;
nbytes -= k;
} while (nbytes > 0);
struct table {
const char *suffix;
unsigned long long factor;
assert(t);
unsigned long long l, tmp;
double frac = 0;
return -ERANGE;
errno = 0;
if (errno > 0)
return -errno;
return -EINVAL;
unsigned long long l2;
char *e2;
if (errno > 0)
return -errno;
for (; e < e2; e++)
if (i >= n_entries)
return -EINVAL;
return -ERANGE;
return -ERANGE;
r += tmp;
if ((unsigned long long) (uint64_t) r != r)
return -ERANGE;
*size = r;
return -errno;
return NULL;
if (dir != d) {
free(d);
return dir2;
return dir;
if (saved_argc > 0) {
if (saved_argv[0])
if (!saved_argv[i])
long bufsize;
char *name;
if (uid == 0)
if (bufsize <= 0)
if (!buf)
return NULL;
return NULL;
return name;
char* getlogname_malloc(void) {
char *getusername_malloc(void) {
return strdup(e);
assert(s);
struct statfs s;
return -errno;
if (fd < 0)
return -errno;
struct statfs s;
return -errno;
return is_temporary_fs(&s);
return -errno;
return -errno;
return -errno;
return -errno;
struct stat a, b;
return -errno;
return -errno;
int running_in_chroot(void) {
int ret;
if (ret < 0)
return ret;
return ret == 0;
static char *ascii_ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigned percent) {
size_t x;
assert(s);
return NULL;
memcpy(r, s, x);
size_t x;
assert(s);
if (ascii_is_valid(s))
c = utf8_encoded_to_unichar(i);
return NULL;
j = utf8_prev_char(j);
c = utf8_encoded_to_unichar(j);
return NULL;
assert(i <= j);
j = utf8_next_char(j);
len = i - s;
return NULL;
if (parents)
if (fd < 0)
return -errno;
if (mode > 0) {
return -errno;
return -errno;
return -errno;
size_t l;
assert(s);
l = strlen(s);
return strdup(s);
return strdup(s);
sync();
pause();
return -errno;
return -errno;
int nfd;
DIR *d;
if (nfd < 0)
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
char *fstab_node_to_udev_node(const char *p) {
assert(p);
return strdup(p);
char **directory;
(void) reset_all_signal_handlers();
(void) reset_signal_mask();
if (!pids)
return log_oom();
if (!seen)
return log_oom();
return log_oom();
if (!path)
return log_oom();
if (pid < 0) {
} else if (pid == 0) {
if (!argv) {
return log_oom();
char *name;
if (executor_pid < 0) {
} else if (executor_pid == 0) {
if (!nulstr)
bool plymouth_running(void) {
assert(s);
if (l < strlen(s))
return -errno;
return -errno;
FILE *f;
int r, fd;
if (fd < 0) {
free(t);
return -errno;
unlink_noerrno(t);
free(t);
return -errno;
*_f = f;
*_temp_path = t;
return -errno;
unlink_noerrno(t);
return -errno;
return -errno;
return -EINVAL;
return -errno;
unlink_noerrno(t);
return -errno;
return -errno;
unlink_noerrno(t);
return -errno;
size_t k;
return -EINVAL;
return -ENOMEM;
*path = f;
int get_user_creds(
const char **username,
const char **home,
const char **shell) {
struct passwd *p;
uid_t u;
if (uid)
*uid = 0;
if (gid)
*gid = 0;
if (home)
if (shell)
errno = 0;
p = getpwuid(u);
errno = 0;
if (uid)
if (gid)
if (home)
if (shell)
struct passwd *p;
if (uid == 0)
return NULL;
struct group *p;
if (gid == 0)
return NULL;
struct group *g;
if (gid)
*gid = 0;
errno = 0;
errno = 0;
if (gid)
int ngroups_max, r, i;
return -errno;
errno = 0;
if (k == GLOB_NOMATCH)
else if (k == GLOB_NOSPACE)
return -ENOMEM;
errno = 0;
if (k == GLOB_NOMATCH)
return -ENOENT;
else if (k == GLOB_NOSPACE)
return -ENOMEM;
assert(d);
return -errno;
return -errno;
errno = 0;
return -errno;
if (!de)
if (list) {
return -ENOMEM;
return -ENOMEM;
l[++n] = NULL;
if (list) {
*list = l;
char *strjoin(const char *x, ...) {
size_t l;
l = strlen(x);
size_t n;
n = strlen(t);
return NULL;
return NULL;
p = stpcpy(r, x);
p = stpcpy(p, t);
bool is_main_thread(void) {
return cached > 0;
return -ENOMEM;
free(p);
*ret = d;
return -ENOMEM;
free(p);
return -ENOENT;
return -ENOMEM;
r = read_one_line_file(p, &s);
free(p);
free(s);
return -EINVAL;
return -ENOMEM;
free(p);
return -ENOENT;
static const char *const ioprio_class_table[] = {
static const char *const sigchld_code_table[] = {
static const char *const log_level_table[] = {
static const char* const sched_policy_table[] = {
static const char* const ip_tos_table[] = {
bool kexec_loaded(void) {
bool loaded = false;
loaded = true;
free(s);
return loaded;
case O_RDONLY:
return PROT_READ;
case O_WRONLY:
return PROT_WRITE;
case O_RDWR:
return -EINVAL;
const char *suffix;
} table[] = {
return NULL;
goto finish;
return buf;
assert(p);
r = malloc(l);
return NULL;
memcpy(r, p, l);
int r, value;
value = (int) n;
return -errno;
int r, value;
value = (int) n;
return -errno;
if (agent_pid < 0) {
return -errno;
if (agent_pid != 0) {
(void) reset_all_signal_handlers();
(void) reset_signal_mask();
int fd;
if (fd < 0) {
if (!stdout_is_tty)
if (!stderr_is_tty)
return -errno;
return -errno;
if (isempty(p))
return ascii_is_valid(p);
if (isempty(p))
return ascii_is_valid(p);
bool in_initrd(void) {
struct statfs s;
if (saved >= 0)
return saved;
* 1. the flag file /etc/initrd-release must exist
is_temporary_fs(&s);
return saved;
struct passwd *p;
uid_t u;
if (e && path_is_absolute(e)) {
h = strdup(e);
return -ENOMEM;
*_h = h;
u = getuid();
return -ENOMEM;
*_h = h;
errno = 0;
p = getpwuid(u);
return -EINVAL;
return -ENOMEM;
*_h = h;
struct passwd *p;
uid_t u;
s = strdup(e);
return -ENOMEM;
*_s = s;
u = getuid();
return -ENOMEM;
*_s = s;
errno = 0;
p = getpwuid(u);
return -EINVAL;
return -ENOMEM;
*_s = s;
bool filename_is_valid(const char *p) {
if (isempty(p))
bool string_is_safe(const char *p) {
assert(p);
bool path_is_safe(const char *p) {
if (isempty(p))
int comparison;
u = nmemb;
if (comparison < 0)
u = idx;
else if (comparison > 0)
return NULL;
void init_gettext(void) {
bool is_locale_utf8(void) {
const char *set;
if (cached_answer >= 0)
goto out;
cached_answer = true;
goto out;
if (!set) {
cached_answer = true;
goto out;
cached_answer = true;
goto out;
if (!set) {
cached_answer = true;
goto out;
out:
return (bool) cached_answer;
return NULL;
f = text;
goto oom;
l = nl;
f += old_len;
oom:
free(r);
return NULL;
FILE *f;
return NULL;
switch (state) {
case STATE_OTHER:
fputc(*i, f);
case STATE_ESCAPE:
fputc(*i, f);
case STATE_BRACKET:
if (ferror(f)) {
fclose(f);
return NULL;
fclose(f);
if (_isz)
return obuf;
int on_ac_power(void) {
ssize_t n;
errno = 0;
return -errno;
if (!de)
if (device < 0) {
return -errno;
if (fd < 0) {
return -errno;
return -errno;
if (fd < 0) {
return -errno;
return -errno;
return -EIO;
found_online = true;
found_offline = true;
return -EIO;
static int search_and_fopen_internal(const char *path, const char *mode, const char *root, char **search, FILE **_f) {
return -ENOMEM;
FILE *f;
if (root)
return -ENOMEM;
*_f = f;
return -errno;
return -ENOENT;
int search_and_fopen(const char *path, const char *mode, const char *root, const char **search, FILE **_f) {
FILE *f;
*_f = f;
return -errno;
if (!copy)
return -ENOMEM;
int search_and_fopen_nulstr(const char *path, const char *mode, const char *root, const char *search, FILE **_f) {
FILE *f;
*_f = f;
return -errno;
return -ENOMEM;
char *strextend(char **x, ...) {
size_t f, l;
assert(x);
l = f = *x ? strlen(*x) : 0;
size_t n;
n = strlen(t);
return NULL;
return NULL;
p = stpcpy(p, t);
char *strrep(const char *s, unsigned n) {
size_t l;
assert(s);
l = strlen(s);
return NULL;
p = stpcpy(p, s);
assert(p);
return NULL;
q = realloc(*p, a);
return NULL;
uint8_t *q;
assert(p);
return NULL;
bool id128_is_valid(const char *s) {
size_t i, l;
l = strlen(s);
assert(s);
assert(l);
assert(r);
return -EINVAL;
return -EINVAL;
a = strndup(s, x - s);
return -ENOMEM;
free(a);
return -ENOMEM;
int shall_restore_state(void) {
if (detect_container() > 0)
p = line;
if (value)
*(value++) = 0;
bool found = false;
p = line;
if (value) {
found = true;
found = true;
if (value) {
return found;
return -EINVAL;
if (r == -ENOENT)
return -EHOSTDOWN;
return -EIO;
return -EIO;
return -EIO;
int namespace_open(pid_t pid, int *pidns_fd, int *mntns_fd, int *netns_fd, int *userns_fd, int *root_fd) {
if (mntns_fd) {
const char *mntns;
if (mntnsfd < 0)
return -errno;
if (pidns_fd) {
const char *pidns;
if (pidnsfd < 0)
return -errno;
if (netns_fd) {
const char *netns;
if (netnsfd < 0)
return -errno;
if (userns_fd) {
const char *userns;
return -errno;
if (root_fd) {
const char *root;
if (rfd < 0)
return -errno;
if (pidns_fd)
if (mntns_fd)
if (netns_fd)
if (userns_fd)
if (root_fd)
if (userns_fd >= 0) {
return -ENOMEM;
if (pidns_fd >= 0)
return -errno;
if (mntns_fd >= 0)
return -errno;
if (netns_fd >= 0)
return -errno;
if (userns_fd >= 0)
return -errno;
if (root_fd >= 0) {
return -errno;
return -errno;
return reset_uid_gid();
struct ucred u;
return -errno;
if (n != sizeof(struct ucred))
return -EIO;
if (u.pid <= 0)
return -ENODATA;
return -ENODATA;
return -ENODATA;
*ucred = u;
s = new0(char, n);
return -ENOMEM;
free(s);
return -errno;
s = new0(char, n);
return -ENOMEM;
free(s);
return -errno;
if (isempty(s)) {
free(s);
return -EOPNOTSUPP;
*ret = s;
int fd;
if (fd < 0)
return -errno;
return fd;
int fd;
#ifdef O_TMPFILE
if (fd >= 0)
return fd;
if (fd < 0)
return fd;
unlink(p);
return fd;
return -errno;
log_warning("Configuration file %s is marked executable. Please remove executable permission bits. Proceeding anyway.", path);
log_warning("Configuration file %s is marked world-writable. Please remove world writability permission bits. Proceeding anyway.", path);
log_warning("Configuration file %s is marked world-inaccessible. This has no effect as configuration data is accessible via APIs without restrictions. Proceeding anyway.", path);
unsigned long personality_from_string(const char *p) {
#if defined(__x86_64__)
return PER_LINUX32;
return PER_LINUX;
return PER_LINUX;
return PER_LINUX32;
return PER_LINUX;
return PER_LINUX;
return PERSONALITY_INVALID;
const char* personality_to_string(unsigned long p) {
#if defined(__x86_64__)
if (p == PER_LINUX32)
if (p == PER_LINUX)
if (p == PER_LINUX)
if (p == PER_LINUX)
if (p == PER_LINUX32)
if (p == PER_LINUX)
return NULL;
long mem;
const uint8_t *b = p;
assert(s == 0 || b);
size_t i;
if (param) {
bool again;
again = false;
if (!proc_self_mountinfo)
return -errno;
&path);
if (k == EOF)
r = -errno;
again = true;
} while (again);
return -errno;
if (!cleaned)
return -ENOMEM;
if (!done)
return -ENOMEM;
bool top_autofs = false;
unsigned long orig_flags;
if (!todo)
return -ENOMEM;
if (!proc_self_mountinfo)
return -errno;
&path,
&type);
if (k == EOF)
p = NULL;
if (r == -EEXIST)
return -errno;
orig_flags = 0;
return -errno;
return -ENOMEM;
if (r == -EEXIST || r == 0)
orig_flags = 0;
return -errno;
assert(f);
errno = 0;
fflush(f);
if (ferror(f))
const char *fn;
assert(p);
return -EINVAL;
return -ENOMEM;
const char *fn;
uint64_t u;
assert(p);
return -EINVAL;
if (!extra)
return -ENOMEM;
u = random_u64();
uint64_t u;
assert(p);
if (!extra)
return -ENOMEM;
u = random_u64();
.l_start = 0,
.l_len = 0,
const char *path;
int fd, r;
if (root)
if (fd < 0)
return -errno;
return -errno;
return fd;
return -errno;
if (follow)
return -errno;
return -errno;
int free_and_strdup(char **p, const char *s) {
assert(p);
if (streq_ptr(*p, s))
t = strdup(s);
return -ENOMEM;
t = NULL;
free(*p);
ssize_t fgetxattrat_fake(int dirfd, const char *filename, const char *attribute, void *value, size_t size, int flags) {
ssize_t l;
fd = openat(dirfd, filename, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_PATH|(flags & AT_SYMLINK_NOFOLLOW ? O_NOFOLLOW : 0));
if (fd < 0)
return -errno;
return -errno;
uint64_t u;
return -EIO;
ssize_t n;
return -errno;
if (n != sizeof(le))
return -EIO;
ssize_t n;
return -errno;
if (n != sizeof(le))
return -EIO;
ssize_t n;
assert(p);
return -errno;
if (n != sizeof(le))
return -EIO;
if (usec <= 0)
return -errno;
int same_fd(int a, int b) {
assert(a >= 0);
assert(b >= 0);
return -errno;
return -errno;
return -errno;
if (fa < 0)
return -errno;
if (fb < 0)
return -errno;
return -errno;
return -ENOTTY;
if (mask == 0)
return -errno;
return -errno;
assert(p);
if (mask == 0)
if (fd < 0)
return -errno;
return -errno;
return -ENOTTY;
return -errno;
assert(p);
if (fd < 0)
return -errno;
size_t n = 0;
while (sz > 0) {
sz--;
const uint8_t *q, *w, *e;
ssize_t l;
e = q + sz;
size_t n;
n = nul_length(q, e - q);
if ((n > run_length) ||
return -errno;
return -EIO;
return -errno;
return -errno;
return -EIO;
return q - (const uint8_t*) p;
if (!pid)
assert(p);
assert(*p);
if (with_facility)
size_t i;
if (!key)
for (i = 0; i < len; ++i)
return (ssize_t) i;
int ret;
if (ret >= 0)
return -errno;
if (ret < 0)
return -errno;
if (ret < 0) {
return -errno;
assert(s);
errno = 0;
if (errno != 0)
return -errno;
return -EINVAL;
return -ERANGE;
return -errno;
return -errno;
return -errno;
return -errno;
int reset_uid_gid(void) {
return -errno;
if (setresgid(0, 0, 0) < 0)
return -errno;
if (setresuid(0, 0, 0) < 0)
return -errno;
size_t l;
ssize_t n;
v = new0(char, l);
return -ENOMEM;
if (allow_symlink)
if (n >= 0 && (size_t) n < l) {
*value = v;
free(v);
return -errno;
if (allow_symlink)
return -errno;
size_t l;
ssize_t n;
v = new0(char, l);
return -ENOMEM;
if (n >= 0 && (size_t) n < l) {
*value = v;
free(v);
return -errno;
return -errno;
} control = {};
return -errno;
} control = {};
return -errno;
if (!found) {
return -EIO;
int version(void) {
bool fdname_is_valid(const char *s) {
void string_erase(char *x) {
char *string_free_erase(char *s) {
return NULL;
string_erase(s);
return mfree(s);