mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-24 18:20:07 +01:00
This is a direct dump from systemd git on 2016-09-07, git commit
c5d5fc91eba8541a3a86ff6b839a2b6e824f4149.
======
SYSTEMD_DIR=../systemd
COMMIT=c5d5fc91eba8541a3a86ff6b839a2b6e824f4149
(
cd "$SYSTEMD_DIR"
git checkout "$COMMIT"
git reset --hard
git clean -fdx
)
git ls-files :/src/systemd/src/ | xargs -d '\n' rm -f
nm_copy_sd() {
mkdir -p "./src/systemd/$(dirname "$1")"
cp "$SYSTEMD_DIR/$1" "./src/systemd/$1"
}
nm_copy_sd "src/basic/alloc-util.c"
nm_copy_sd "src/basic/alloc-util.h"
nm_copy_sd "src/basic/async.h"
nm_copy_sd "src/basic/escape.c"
nm_copy_sd "src/basic/escape.h"
nm_copy_sd "src/basic/ether-addr-util.c"
nm_copy_sd "src/basic/ether-addr-util.h"
nm_copy_sd "src/basic/extract-word.c"
nm_copy_sd "src/basic/extract-word.h"
nm_copy_sd "src/basic/fileio.c"
nm_copy_sd "src/basic/fileio.h"
nm_copy_sd "src/basic/fd-util.c"
nm_copy_sd "src/basic/fd-util.h"
nm_copy_sd "src/basic/fs-util.c"
nm_copy_sd "src/basic/fs-util.h"
nm_copy_sd "src/basic/hash-funcs.c"
nm_copy_sd "src/basic/hash-funcs.h"
nm_copy_sd "src/basic/hashmap.c"
nm_copy_sd "src/basic/hashmap.h"
nm_copy_sd "src/basic/hexdecoct.c"
nm_copy_sd "src/basic/hexdecoct.h"
nm_copy_sd "src/basic/hostname-util.c"
nm_copy_sd "src/basic/hostname-util.h"
nm_copy_sd "src/basic/in-addr-util.c"
nm_copy_sd "src/basic/in-addr-util.h"
nm_copy_sd "src/basic/io-util.c"
nm_copy_sd "src/basic/io-util.h"
nm_copy_sd "src/basic/list.h"
nm_copy_sd "src/basic/log.h"
nm_copy_sd "src/basic/macro.h"
nm_copy_sd "src/basic/mempool.h"
nm_copy_sd "src/basic/mempool.c"
nm_copy_sd "src/basic/parse-util.c"
nm_copy_sd "src/basic/parse-util.h"
nm_copy_sd "src/basic/path-util.c"
nm_copy_sd "src/basic/path-util.h"
nm_copy_sd "src/basic/prioq.h"
nm_copy_sd "src/basic/prioq.c"
nm_copy_sd "src/basic/random-util.c"
nm_copy_sd "src/basic/random-util.h"
nm_copy_sd "src/basic/refcnt.h"
nm_copy_sd "src/basic/set.h"
nm_copy_sd "src/basic/signal-util.h"
nm_copy_sd "src/basic/siphash24.c"
nm_copy_sd "src/basic/siphash24.h"
nm_copy_sd "src/basic/socket-util.c"
nm_copy_sd "src/basic/socket-util.h"
nm_copy_sd "src/basic/sparse-endian.h"
nm_copy_sd "src/basic/stdio-util.h"
nm_copy_sd "src/basic/string-table.c"
nm_copy_sd "src/basic/string-table.h"
nm_copy_sd "src/basic/string-util.c"
nm_copy_sd "src/basic/string-util.h"
nm_copy_sd "src/basic/strv.c"
nm_copy_sd "src/basic/strv.h"
nm_copy_sd "src/basic/time-util.c"
nm_copy_sd "src/basic/time-util.h"
nm_copy_sd "src/basic/umask-util.h"
nm_copy_sd "src/basic/unaligned.h"
nm_copy_sd "src/basic/utf8.c"
nm_copy_sd "src/basic/utf8.h"
nm_copy_sd "src/basic/util.c"
nm_copy_sd "src/basic/util.h"
nm_copy_sd "src/libsystemd-network/arp-util.c"
nm_copy_sd "src/libsystemd-network/arp-util.h"
nm_copy_sd "src/libsystemd-network/dhcp6-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp6-lease-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp6-network.c"
nm_copy_sd "src/libsystemd-network/dhcp6-option.c"
nm_copy_sd "src/libsystemd-network/dhcp6-protocol.h"
nm_copy_sd "src/libsystemd-network/dhcp-identifier.c"
nm_copy_sd "src/libsystemd-network/dhcp-identifier.h"
nm_copy_sd "src/libsystemd-network/dhcp-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp-lease-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp-network.c"
nm_copy_sd "src/libsystemd-network/dhcp-option.c"
nm_copy_sd "src/libsystemd-network/dhcp-packet.c"
nm_copy_sd "src/libsystemd-network/dhcp-protocol.h"
nm_copy_sd "src/libsystemd-network/lldp-internal.h"
nm_copy_sd "src/libsystemd-network/lldp-neighbor.c"
nm_copy_sd "src/libsystemd-network/lldp-neighbor.h"
nm_copy_sd "src/libsystemd-network/lldp-network.c"
nm_copy_sd "src/libsystemd-network/lldp-network.h"
nm_copy_sd "src/libsystemd-network/network-internal.c"
nm_copy_sd "src/libsystemd-network/network-internal.h"
nm_copy_sd "src/libsystemd-network/sd-dhcp6-client.c"
nm_copy_sd "src/libsystemd-network/sd-dhcp6-lease.c"
nm_copy_sd "src/libsystemd-network/sd-dhcp-client.c"
nm_copy_sd "src/libsystemd-network/sd-dhcp-lease.c"
nm_copy_sd "src/libsystemd-network/sd-ipv4ll.c"
nm_copy_sd "src/libsystemd-network/sd-ipv4acd.c"
nm_copy_sd "src/libsystemd-network/sd-lldp.c"
nm_copy_sd "src/libsystemd/sd-event/sd-event.c"
nm_copy_sd "src/libsystemd/sd-id128/id128-util.c"
nm_copy_sd "src/libsystemd/sd-id128/id128-util.h"
nm_copy_sd "src/libsystemd/sd-id128/sd-id128.c"
nm_copy_sd "src/shared/dns-domain.c"
nm_copy_sd "src/shared/dns-domain.h"
nm_copy_sd "src/systemd/_sd-common.h"
nm_copy_sd "src/systemd/sd-dhcp6-client.h"
nm_copy_sd "src/systemd/sd-dhcp6-lease.h"
nm_copy_sd "src/systemd/sd-dhcp-client.h"
nm_copy_sd "src/systemd/sd-dhcp-lease.h"
nm_copy_sd "src/systemd/sd-event.h"
nm_copy_sd "src/systemd/sd-ndisc.h"
nm_copy_sd "src/systemd/sd-id128.h"
nm_copy_sd "src/systemd/sd-ipv4acd.h"
nm_copy_sd "src/systemd/sd-ipv4ll.h"
nm_copy_sd "src/systemd/sd-lldp.h"
201 lines
6.7 KiB
C
201 lines
6.7 KiB
C
#pragma once
|
|
|
|
/***
|
|
This file is part of systemd.
|
|
|
|
Copyright 2010 Lennart Poettering
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
(at your option) any later version.
|
|
|
|
systemd is distributed in the hope that it will be useful, but
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
***/
|
|
|
|
#include <alloca.h>
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <string.h>
|
|
|
|
#include "macro.h"
|
|
|
|
/* What is interpreted as whitespace? */
|
|
#define WHITESPACE " \t\n\r"
|
|
#define NEWLINE "\n\r"
|
|
#define QUOTES "\"\'"
|
|
#define COMMENTS "#;"
|
|
#define GLOB_CHARS "*?["
|
|
#define DIGITS "0123456789"
|
|
#define LOWERCASE_LETTERS "abcdefghijklmnopqrstuvwxyz"
|
|
#define UPPERCASE_LETTERS "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
#define LETTERS LOWERCASE_LETTERS UPPERCASE_LETTERS
|
|
#define ALPHANUMERICAL LETTERS DIGITS
|
|
#define HEXDIGITS DIGITS "abcdefABCDEF"
|
|
|
|
#define streq(a,b) (strcmp((a),(b)) == 0)
|
|
#define strneq(a, b, n) (strncmp((a), (b), (n)) == 0)
|
|
#define strcaseeq(a,b) (strcasecmp((a),(b)) == 0)
|
|
#define strncaseeq(a, b, n) (strncasecmp((a), (b), (n)) == 0)
|
|
|
|
int strcmp_ptr(const char *a, const char *b) _pure_;
|
|
|
|
static inline bool streq_ptr(const char *a, const char *b) {
|
|
return strcmp_ptr(a, b) == 0;
|
|
}
|
|
|
|
static inline const char* strempty(const char *s) {
|
|
return s ? s : "";
|
|
}
|
|
|
|
static inline const char* strnull(const char *s) {
|
|
return s ? s : "(null)";
|
|
}
|
|
|
|
static inline const char *strna(const char *s) {
|
|
return s ? s : "n/a";
|
|
}
|
|
|
|
static inline bool isempty(const char *p) {
|
|
return !p || !p[0];
|
|
}
|
|
|
|
static inline const char *empty_to_null(const char *p) {
|
|
return isempty(p) ? NULL : p;
|
|
}
|
|
|
|
static inline const char *strdash_if_empty(const char *str) {
|
|
return isempty(str) ? "-" : str;
|
|
}
|
|
|
|
static inline char *startswith(const char *s, const char *prefix) {
|
|
size_t l;
|
|
|
|
l = strlen(prefix);
|
|
if (strncmp(s, prefix, l) == 0)
|
|
return (char*) s + l;
|
|
|
|
return NULL;
|
|
}
|
|
|
|
static inline char *startswith_no_case(const char *s, const char *prefix) {
|
|
size_t l;
|
|
|
|
l = strlen(prefix);
|
|
if (strncasecmp(s, prefix, l) == 0)
|
|
return (char*) s + l;
|
|
|
|
return NULL;
|
|
}
|
|
|
|
char *endswith(const char *s, const char *postfix) _pure_;
|
|
char *endswith_no_case(const char *s, const char *postfix) _pure_;
|
|
|
|
char *first_word(const char *s, const char *word) _pure_;
|
|
|
|
const char* split(const char **state, size_t *l, const char *separator, bool quoted);
|
|
|
|
#define FOREACH_WORD(word, length, s, state) \
|
|
_FOREACH_WORD(word, length, s, WHITESPACE, false, state)
|
|
|
|
#define FOREACH_WORD_SEPARATOR(word, length, s, separator, state) \
|
|
_FOREACH_WORD(word, length, s, separator, false, state)
|
|
|
|
#define FOREACH_WORD_QUOTED(word, length, s, state) \
|
|
_FOREACH_WORD(word, length, s, WHITESPACE, true, state)
|
|
|
|
#define _FOREACH_WORD(word, length, s, separator, quoted, state) \
|
|
for ((state) = (s), (word) = split(&(state), &(length), (separator), (quoted)); (word); (word) = split(&(state), &(length), (separator), (quoted)))
|
|
|
|
char *strappend(const char *s, const char *suffix);
|
|
char *strnappend(const char *s, const char *suffix, size_t length);
|
|
|
|
char *strjoin(const char *x, ...) _sentinel_;
|
|
|
|
#define strjoina(a, ...) \
|
|
({ \
|
|
const char *_appendees_[] = { a, __VA_ARGS__ }; \
|
|
char *_d_, *_p_; \
|
|
int _len_ = 0; \
|
|
unsigned _i_; \
|
|
for (_i_ = 0; _i_ < ELEMENTSOF(_appendees_) && _appendees_[_i_]; _i_++) \
|
|
_len_ += strlen(_appendees_[_i_]); \
|
|
_p_ = _d_ = alloca(_len_ + 1); \
|
|
for (_i_ = 0; _i_ < ELEMENTSOF(_appendees_) && _appendees_[_i_]; _i_++) \
|
|
_p_ = stpcpy(_p_, _appendees_[_i_]); \
|
|
*_p_ = 0; \
|
|
_d_; \
|
|
})
|
|
|
|
char *strstrip(char *s);
|
|
char *delete_chars(char *s, const char *bad);
|
|
char *truncate_nl(char *s);
|
|
|
|
char ascii_tolower(char x);
|
|
char *ascii_strlower(char *s);
|
|
char *ascii_strlower_n(char *s, size_t n);
|
|
|
|
char ascii_toupper(char x);
|
|
char *ascii_strupper(char *s);
|
|
|
|
int ascii_strcasecmp_n(const char *a, const char *b, size_t n);
|
|
int ascii_strcasecmp_nn(const char *a, size_t n, const char *b, size_t m);
|
|
|
|
bool chars_intersect(const char *a, const char *b) _pure_;
|
|
|
|
static inline bool _pure_ in_charset(const char *s, const char* charset) {
|
|
assert(s);
|
|
assert(charset);
|
|
return s[strspn(s, charset)] == '\0';
|
|
}
|
|
|
|
bool string_has_cc(const char *p, const char *ok) _pure_;
|
|
|
|
char *ellipsize_mem(const char *s, size_t old_length_bytes, size_t new_length_columns, unsigned percent);
|
|
char *ellipsize(const char *s, size_t length, unsigned percent);
|
|
|
|
bool nulstr_contains(const char*nulstr, const char *needle);
|
|
|
|
char* strshorten(char *s, size_t l);
|
|
|
|
char *strreplace(const char *text, const char *old_string, const char *new_string);
|
|
|
|
char *strip_tab_ansi(char **p, size_t *l);
|
|
|
|
char *strextend(char **x, ...) _sentinel_;
|
|
|
|
char *strrep(const char *s, unsigned n);
|
|
|
|
int split_pair(const char *s, const char *sep, char **l, char **r);
|
|
|
|
int free_and_strdup(char **p, const char *s);
|
|
|
|
/* Normal memmem() requires haystack to be nonnull, which is annoying for zero-length buffers */
|
|
static inline void *memmem_safe(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen) {
|
|
|
|
if (needlelen <= 0)
|
|
return (void*) haystack;
|
|
|
|
if (haystacklen < needlelen)
|
|
return NULL;
|
|
|
|
assert(haystack);
|
|
assert(needle);
|
|
|
|
return memmem(haystack, haystacklen, needle, needlelen);
|
|
}
|
|
|
|
void* memory_erase(void *p, size_t l);
|
|
char *string_erase(char *x);
|
|
|
|
char *string_free_erase(char *s);
|
|
DEFINE_TRIVIAL_CLEANUP_FUNC(char *, string_free_erase);
|
|
#define _cleanup_string_free_erase_ _cleanup_(string_free_erasep)
|
|
|
|
bool string_is_safe(const char *p) _pure_;
|