Commit graph

26 commits

Author SHA1 Message Date
Richard Maw 6868560773 util: change unquote_*_word to extract_*_word
It now takes a separators argument, which defaults to WHITESPACE if NULL
is passed.
2015-08-07 15:50:42 +00:00
Richard Maw 53f0db7177 unquote_first_word: set *p=NULL on termination
To add a flag to allow an empty string to be parsed as an argument, we
need to be able to distinguish between the end of the string, and after
the end of the string, so when we *do* reach the end, let's set *p to
this state.
2015-08-07 15:50:42 +00:00
Zbigniew Jędrzejewski-Szmek 73974f6768 Merge branch 'hostnamectl-dot-v2'
Manual merge of https://github.com/systemd/systemd/pull/751.
2015-08-05 21:02:41 -04:00
Zbigniew Jędrzejewski-Szmek 8fb4944358 hostname-util: add relax parameter to hostname_is_valid
Tests are modified to check behaviour with relax and without relax.
New tests are added for hostname_cleanup().
Tests are moved a new file (test-hostname-util) because there's
now a bunch of them.

New parameter is not used anywhere, except in tests, so there should
be no observable change.
2015-08-05 20:49:20 -04:00
WaLyong Cho 7b9c9ab810 util: add getxattr helper apis
To get xattr of given path or fd on newly allocated buffer, add new
helper api getxattr_malloc() and fgetxattr_malloc().
2015-08-04 21:09:48 +09:00
Namhyung Kim c030a850ba busctl: add and use strcmp_ptr()
In member_compare_func(), it compares interface, type and name of
members.  But as it can contain NULL pointer, it needs to check them
before calling strcmp().  So make it as a separate strcmp_ptr
function (named after streq_ptr) so that it can be used by others.

Also let streq_ptr() to use it in order to make the code simpler.
2015-08-01 02:16:24 +09:00
Tom Gundersen 75c0cab158 util: base32hex - explain distinction with base32 2015-07-27 20:34:47 +02:00
Daniel Mack b83b298102 Merge pull request #704 from richardmaw-codethink/empty-arg-unquote
unquote_first_word: parse ` '' ` as an empty argument instead of no arg
2015-07-24 19:49:29 +02:00
Richard Maw 14e685c29d unquote_first_word: parse '' as an empty argument instead of no argument 2015-07-24 09:29:46 +00:00
Daniel Mack 42921716a4 Merge pull request #588 from teg/resolved-nsec
resolved: add basic NSEC and NSEC3 support
2015-07-15 17:27:35 -04:00
Tom Gundersen 919a7f5f1c basic: util - add base32hexmem() function similar to hexmem()
This implements more of RFC4648.
2015-07-14 22:14:08 +02:00
Tom Gundersen 2a2953b355 basic: util - fix memleak on error in unbase64mem() 2015-07-14 21:14:45 +02:00
Tom Gundersen 13a5d76b32 basic: util - add base64mem() function similar to hexmem()
This implements RFC4648 for a slightly more compact representation of
binary data compared to hex (6 bits per character rather than 4).
2015-07-12 19:24:14 +02:00
Tom Gundersen 30494563f2 basic: util - fix errorhandling in unhexmem()
We were ignoring failures from unhexchar, which meant that invalid
hex characters were being turned into garbage rather than the string
rejected.

Fix this by making unhexmem return an error code, also change the API
slightly, to return the size of the returned memory, reflecting the
fact that the memory is a binary blob,and not a string.

For convenience, still append a trailing NULL byte to the returned
memory (not included in the returned size), allowing callers to
treat it as a string without doing a second copy.
2015-07-12 19:11:34 +02:00
Lennart Poettering 64ee7ab462 util: make sure we don't clobber errno in error path 2015-07-11 14:19:36 -03:00
cee1 ac5213569c basic/util.c fopen_temporary(): close fd if failed 2015-07-09 10:41:23 -04:00
Daniel Mack 4c1fc3e404 fileio: consolidate write_string_file*()
Merge write_string_file(), write_string_file_no_create() and
write_string_file_atomic() into write_string_file() and provide a flags mask
that allows combinations of atomic writing, newline appending and automatic
file creation. Change all users accordingly.
2015-07-06 19:19:25 -04:00
Lennart Poettering 200edc2bcf Merge pull request #473 from richardmaw-codethink/machinectl-import-earlier-than-3-15
util: fall back in rename_noreplace when renameat2 isn't implemented
2015-07-03 10:11:33 +02:00
Richard Maw 715d759905 util: fall back in rename_noreplace when renameat2 isn't implemented
According to README we only need 3.7, and while it may also make sense
to bump that requirement when appropriate, it's trivial to fall back
when renameat2 is not available.
2015-07-02 14:47:04 +01:00
Eric Biggers 843f6bf4ef util: fix incorrect escape sequence in string_is_safe() 2015-06-28 20:02:44 +02:00
Filipe Brandenburger b59292b296 util: Introduce unquote_first_word_and_warn
It will try to unquot_first_word, but if it runs into escaping problems
it will retry it adding UNQUOTE_CUNESCAPE_RELAX to the flags.  If it
succeeds on the second try, it will log a warning about it.  If it fails
both times, it will log an error.

Add test cases to confirm it behaves as expected.
2015-06-17 11:12:12 -07:00
Filipe Brandenburger d6293c070e util: New flag UNQUOTE_UNESCAPE_RELAX for unquote_first_word
The new flag UNQUOTE_UNESCAPE_RELAX preserves unrecognized escape
sequences verbatim in unquote_first_word, either when it's a trailing
backslash (similar to UNQUOTE_RELAX, but in this case keep the extra
backslash in the output) or in the middle of a sequence string.

Add unit test cases to ensure the new flag works as expected and to
prevent regressions from being introduced.

Tested with a follow up commit converting config_parse_exec() to start
using unquote_first_word, in which case this flags makes it possible to
preserve unrecognized escape sequences.

Relevant bug: https://bugs.freedesktop.org/show_bug.cgi?id=90794
2015-06-17 11:12:11 -07:00
Filipe Brandenburger 05654e712f util: Refactor common cunescape block in unquote_first_word 2015-06-17 11:12:11 -07:00
Simon McVittie 11c9f1e48a Stop talking about the "XDG" version of basename()
XDG refers to X Desktop Group, a former name for freedesktop.org.
This group is responsible for specifications like basedirs,
.desktop files and icon naming, but as far as I know, it has never
tried to redefine basename().

I think these references were meant to say XPG (X/Open Portability
Guide), a precursor of POSIX. POSIX is better-known and less easily
confused with XDG, and is how the basename(3) man page describes
the libgen.h version of basename().

The other version of basename() is glibc-specific and is described
in basename(3) as "the GNU version"; specifically mention that
version, to disambiguate.
2015-06-17 11:23:46 +01:00
Lennart Poettering 14bcf25c8b util: when creating temporary file names, allow including extra id string in it
This adds a "char *extra" parameter to tempfn_xxxxxx(), tempfn_random(),
tempfn_ranomd_child(). If non-NULL this string is included in the middle
of the newly created file name. This is useful for being able to
distuingish the kind of temporary file when we see one.

This also adds tests for the three call.

For now, we don't make use of this at all, but port all users over.
2015-06-15 19:28:55 +02:00
Kay Sievers a095315b3c build-sys: split internal basic/ library from shared/
basic/      can be used by everything
            cannot use anything outside of basic/

libsystemd/ can use basic/
            cannot use shared/

shared/     can use libsystemd/
2015-06-11 10:52:46 +02:00
Renamed from src/shared/util.c (Browse further)