Commit Graph

76 Commits

Author SHA1 Message Date
Yu Watanabe 4c70109600 tree-wide: use IN_SET macro (#6977) 2017-10-04 16:01:32 +02:00
Zbigniew Jędrzejewski-Szmek 4b9545f19e build-sys: change all HAVE_DECL_ macros to HAVE_
This is a legacy of autotools, where one detection routine used a different
prefix then the others.

$ git grep -e HAVE_DECL_ -l|xargs sed -i s/HAVE_DECL_/HAVE_/g
2017-10-03 10:32:34 +02:00
Lennart Poettering 47b33c7d52 string-util: optimize strshorten() a bit
There's no reason to determine the full length of the string, it's
sufficient to know whether it is larger than the intended size...
2017-07-31 18:20:28 +02:00
Lennart Poettering 7bf7ce28b5 string-util: add strlen_ptr() helper
strlen_ptr() is to strlen() what streq_ptr() is to streq(): i.e. it
handles NULL strings in a smart way.
2017-07-31 18:20:28 +02:00
Yu Watanabe 2d5dece8ec basic: cosmetic changes (#6440) 2017-07-24 19:32:34 -04:00
Vito Caputo db3f45e2d2 basic: use _unlocked() stdio in strip_tab_ansi() (#6385)
Trivial performance boost by explicitly bypassing the implicit
locking of stdio.

This significantly affects common cases of `journalctl` usage:

 Before:

  # time ./journalctl -b -1 > /dev/null
   real    0m26.628s
   user    0m26.495s
   sys     0m0.125s

  # time ./journalctl -b -1 > /dev/null
   real    0m27.069s
   user    0m26.936s
   sys     0m0.134s

  # time ./journalctl -b -1 > /dev/null
   real    0m26.727s
   user    0m26.607s
   sys     0m0.119s

 After:

  # time ./journalctl -b -1 > /dev/null
   real    0m23.394s
   user    0m23.244s
   sys     0m0.142s

  # time ./journalctl -b -1 > /dev/null
   real    0m23.283s
   user    0m23.160s
   sys     0m0.121s

  # time ./journalctl -b -1 > /dev/null
   real    0m23.274s
   user    0m23.125s
   sys     0m0.144s

Fixes https://github.com/systemd/systemd/issues/6341
2017-07-18 00:05:52 +02:00
Zbigniew Jędrzejewski-Szmek 2d26d8e07e treewide: replace homegrown memory_erase with explicit_bzero
explicit_bzero was added in glibc 2.25. Make use of it.

explicit_bzero is hardcoded to zero the memory, so string erase now
truncates the string, instead of overwriting it with 'x'. This causes
a visible difference only in the journalctl case.
2017-02-05 21:07:55 -05:00
Zbigniew Jędrzejewski-Szmek 605405c6cc tree-wide: drop NULL sentinel from strjoin
This makes strjoin and strjoina more similar and avoids the useless final
argument.

spatch -I . -I ./src -I ./src/basic -I ./src/basic -I ./src/shared -I ./src/shared -I ./src/network -I ./src/locale -I ./src/login -I ./src/journal -I ./src/journal -I ./src/timedate -I ./src/timesync -I ./src/nspawn -I ./src/resolve -I ./src/resolve -I ./src/systemd -I ./src/core -I ./src/core -I ./src/libudev -I ./src/udev -I ./src/udev/net -I ./src/udev -I ./src/libsystemd/sd-bus -I ./src/libsystemd/sd-event -I ./src/libsystemd/sd-login -I ./src/libsystemd/sd-netlink -I ./src/libsystemd/sd-network -I ./src/libsystemd/sd-hwdb -I ./src/libsystemd/sd-device -I ./src/libsystemd/sd-id128 -I ./src/libsystemd-network --sp-file coccinelle/strjoin.cocci --in-place $(git ls-files src/*.c)

git grep -e '\bstrjoin\b.*NULL' -l|xargs sed -i -r 's/strjoin\((.*), NULL\)/strjoin(\1)/'

This might have missed a few cases (spatch has a really hard time dealing
with _cleanup_ macros), but that's no big issue, they can always be fixed
later.
2016-10-23 11:43:27 -04:00
Zbigniew Jędrzejewski-Szmek 6b430fdb7c tree-wide: use mfree more 2016-10-16 23:35:39 -04:00
Zbigniew Jędrzejewski-Szmek 481a2b02a3 Always use unicode ellipsis when ellipsizing
We were already unconditionally using the unicode character when the
input string was not pure ASCII, leading to different behaviour in
depending on the input string.

systemd[1]: Starting printit.service.
python3[19962]: foooooooooooooooooooooooooooooooooooo…oooo
python3[19964]: fooąęoooooooooooooooooooooooooooooooo…oooo
python3[19966]: fooąęoooooooooooooooooooooooooooooooo…ąęąę
python3[19968]: fooąęoooooooooooooooooąęąęąęąęąęąęąęą…ąęąę
systemd[1]: Started printit.service.
2016-09-13 20:10:57 -04:00
Michael Biebl b6b609dbc2 string-util: rework memory_erase() to not use GCC optimize attribute (#3812)
"#pragma GCC optimize" is merely a convenience to decorate multiple
functions with attribute optimize. And the manual has this to say about
this attribute:

  This attribute should be used for debugging purposes only. It
  is not suitable in production code.

Some versions of GCC also seem to have a problem with this pragma in
combination with LTO, resulting in ICEs.

So use a different approach (indirect the memset call via a volatile
function pointer) as implemented in openssl's crypto/mem_clr.c.

Closes: #3811
2016-07-26 23:32:37 -04:00
Lennart Poettering 846b8fc30d bootctl: move toupper() implementation to string-util.h
We already have tolower() calls there, hence let's unify this at one place.
Also, update the code to only use ASCII operations, so that we don't end up
being locale dependant.
2016-07-21 11:37:58 +02:00
Vito Caputo 313cefa1d9 tree-wide: make ++/-- usage consistent WRT spacing
Throughout the tree there's spurious use of spaces separating ++ and --
operators from their respective operands.  Make ++ and -- operator
consistent with the majority of existing uses; discard the spaces.
2016-02-22 20:32:04 -08:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Shawn Landden c932fb71cc utf8.[ch] et al: use char32_t and char16_t instead of int, int32_t, int16_t
rework C11 utf8.[ch] to use char32_t instead of uint32_t when referring
to unicode chars, to make things more expressive.

[
 @zonque:
  * rebased to current master
  * use AC_CHECK_DECLS to detect availibility of char{16,32}_t
  * make utf8_encoded_to_unichar() return int
]
2016-01-27 14:10:02 +01:00
Lennart Poettering c174983474 basic: add ascii_strcasecmp_nn() call
In contrast to ascii_strcasecmp_nn() it takes two character buffers with their individual length. It will then compare
the buffers up the smaller size of the two buffers, and finally the length themselves.
2016-01-13 20:22:32 +01:00
Lennart Poettering 522d85ae0a basic: add new ascii_strcasecmp_n() call 2016-01-13 20:21:56 +01:00
Lennart Poettering b577e3d589 basic: introduce generic ascii_strlower_n() call and make use of it everywhere 2016-01-11 19:39:59 +01:00
Thomas Hindoe Paaboel Andersen 11c3a36649 basic: include only what we use
This is a cleaned up result of running iwyu but without forward
declarations on src/basic.
2015-11-30 21:51:03 +01:00
Lennart Poettering b11d6a7bed util-lib: move character class definitions to string-util.h 2015-11-03 17:45:11 +01:00
Lennart Poettering 9fe4ea21be string-util: rework memory_erase() so that it cannot be optimized away
memory_erase() so far just called memset(), which the compiler might
optimize away under certain conditions if it feels there's benefit in
it. C11 knows a new memset_s() call that is like memset(), but may not
be optimized away. Ideally, we'd just use that call, but glibc currently
does not support it. Hence, implement our own simplistic version of it.

We use a GCC pragma to turn off optimization for this call, and also use
the "volatile" keyword on the pointers to ensure that gcc will use the
pointers as-is. According to a variety of internet sources, either one
does the trick. However, there are also reports that at least the
volatile thing isn't fully correct, hence let's add some snake oil and
employ both techniques.

https://news.ycombinator.com/item?id=4711346
2015-11-02 23:07:20 +01:00
Lennart Poettering dcd1262673 Revert "utf8.[ch]: use char32_t and char16_t instead of int, int32_t, int16_t" 2015-11-02 11:21:25 +01:00
Shawn Landden 025b4c4105 utf8.[ch]: use char32_t and char16_t instead of int, int32_t, int16_t
rework C11 utf8.[ch] to use char32_t instead of uint32_t when referring
to unicode chars, to make things more expressive.
2015-10-31 21:00:57 -07:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering f3e2e81d53 util: move string_is_safe() to string-util.[ch] 2015-10-27 13:25:56 +01:00
Lennart Poettering 07630cea1f util-lib: split our string related calls from util.[ch] into its own file string-util.[ch]
There are more than enough calls doing string manipulations to deserve
its own files, hence do something about it.

This patch also sorts the #include blocks of all files that needed to be
updated, according to the sorting suggestions from CODING_STYLE. Since
pretty much every file needs our string manipulation functions this
effectively means that most files have sorted #include blocks now.

Also touches a few unrelated include files.
2015-10-24 23:05:02 +02:00