35 Commits

Author SHA1 Message Date
Tobias Stoeckmann
876e874684 Fix documentation style
Always start a sentence with lowercase letter after 'Note:', 'Warning:',
etc. This unifies all occurrences.

No functional change.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-12-19 16:48:08 +01:00
Alejandro Colomar
cd3a5077b0 */: s/MEMZERO/memzero_a/
This name better reflects that it handles arrays, and doesn't shout.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-11-27 20:50:48 -06:00
Alejandro Colomar
38499ca529 lib/atoi/, */: Move all str2i() macros together with a2i()
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-11-27 20:23:43 -06:00
Alejandro Colomar
f3e67583b4 lib/atoi/, */: Move all a2i() macros to the same file
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-11-27 20:23:43 -06:00
Evgeny Grin (Karlson2k)
eb71706b1c */: Fix including <config.h> as system header
"config.h" is a locally generated header. It must be included as
'#include "config.h"'.
It is already included correctly in some sources files. This commit
unifies the way how "config.h" is included.

Signed-off-by: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
2025-07-16 14:12:40 +02:00
Alejandro Colomar
4fed009495 lib/atoi/str2i/, *: Simplify implementations
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-05-30 15:11:02 -05:00
Alejandro Colomar
d1cbf68f61 lib/, src/: Use strprefix() instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-05-26 11:29:26 -05:00
Alejandro Colomar
68f28eb044 lib/: Use strprefix() instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-05-26 11:29:26 -05:00
Alejandro Colomar
b6140635eb lib/, src/: Use s=strprefix(s,p)?:s instead of its pattern
This skips an optional prefix.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-05-26 11:29:26 -05:00
Alejandro Colomar
872de49dcf lib/string/strspn/, lib/, src/: Move *spn() APIs to separate subdir
This provides a better organization.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-02-16 13:22:51 -06:00
Alejandro Colomar
c39305569b lib/, src/: Use !streq() instead of its pattern
Except for the added (and sorted) includes, the removal of redundant
parentheses, and a few non-string cases that I've left out of the
change, this patch can be approximated with the following semantic
patch:

	$ cat ~/tmp/spatch/strneq.sp
	@@
	expression s;
	@@

	- '\0' != *s
	+ !streq(s, "")

	@@
	expression s;
	@@

	- '\0' != s[0]
	+ !streq(s, "")

	@@
	expression s;
	@@

	- *s != '\0'
	+ !streq(s, "")

	@@
	expression s;
	@@

	- s[0] != '\0'
	+ !streq(s, "")

	$ find contrib/ lib* src/ -type f \
	| xargs spatch --in-place --sp-file ~/tmp/spatch/strneq.sp;

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-09 20:54:42 -06:00
Alejandro Colomar
7182d6402f lib/, src/: Use streq() instead of its pattern
Except for the added (and sorted) includes, the removal of redundant
parentheses, a few cases that have been refactored for readability, and
a couple of non-string cases that I've left out of the change, this
patch can be approximated with the following semantic patch:

	$ cat ~/tmp/spatch/streq.sp
	@@
	expression s;
	@@

	- '\0' == *s
	+ streq(s, "")

	@@
	expression s;
	@@

	- '\0' == s[0]
	+ streq(s, "")

	@@
	expression s;
	@@

	- *s == '\0'
	+ streq(s, "")

	@@
	expression s;
	@@

	- s[0] == '\0'
	+ streq(s, "")

	$ find contrib/ lib* src/ -type f \
	| xargs spatch --in-place --sp-file ~/tmp/spatch/streq.sp;

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-09 20:54:42 -06:00
Alejandro Colomar
5581e74188 contrib/, lib/, src/: Use streq() instead of its pattern
Except for the added (and sorted) includes, and the removal of redundant
parentheses, this patch can be approximated with the following semantic
patch:

	$ cat ~/tmp/spatch/streq.sp;
	@@
	expression a, b;
	@@

	- strcmp(a, b) == 0
	+ streq(a, b)

	@@
	expression a, b;
	@@

	- 0 == strcmp(a, b)
	+ streq(a, b)

	@@
	expression a, b;
	@@

	- !strcmp(a, b)
	+ streq(a, b)

	$ find contrib/ lib* src/ -type f \
	| xargs spatch --sp-file ~/tmp/spatch/streq.sp --in-place;
	$ git restore lib/string/strcmp/streq.h;

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-01 22:23:19 -06:00
Alejandro Colomar
f45adadd28 lib/, src/: Use stpspn() instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-10-13 20:40:02 -05:00
Alejandro Colomar
87a5145719 lib/: Move memzero.[ch] under lib/string/memset/
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-08-30 21:44:07 -05:00
Alejandro Colomar
745281f295 lib/atoi/, *: Split files 2024-07-11 22:42:58 -05:00
Alejandro Colomar
c2ebd210e7 lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE
Fixes: 10396f953613 ("* libmisc/limits.c: Parse the limits, umask, nice, maxlogin, file limit with getlog() / getulong().")
Link: <882cf59459>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-11 22:42:58 -05:00
Alejandro Colomar
03521bccce lib/limits.c: setup_limits(): Simplify, by calling str2i(mode_t, ) instead of str2ul()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 22:52:31 +02:00
Alejandro Colomar
3fd1d62e29 lib/limits.c: setup_limits(): Simplify, by calling str2si() instead of str2sl()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 22:52:31 +02:00
Alejandro Colomar
312c3b1389 lib/limits.c: setup_limits(): Simplify, by calling a2si() instead of str2sl()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 22:52:31 +02:00
Alejandro Colomar
169cbe1f56 lib/limits.c: set_umask(): Simplify, by calling str2i(mode_t, ) instead of str2ul()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 22:52:31 +02:00
Alejandro Colomar
dba5600cef lib/limits.c: set_prio(): Simplify, by calling str2si() instead of str2sl()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 22:52:31 +02:00
Alejandro Colomar
7f3ab84714 lib/limits.c: setrlimit_value(): Reimplement in terms of a2i()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-29 20:00:18 +02:00
Alejandro Colomar
98aefe8772 lib/, src/: Rename some local variables
'endptr' is appropriate internally in strtol(3) because it's a pointer
to 'end', and 'end' itself is a pointer to one-after-the-last character
of the numeric string.  In other words,

	endptr == &end

However, naming the pointer whose address we pass to strtol(3)'s
'endptr' feels wrong, and causes me trouble while parsing the code; I
need to double check the number of dereferences, because something feels
wrong in my head.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-04 17:22:57 -05:00
Alejandro Colomar
f39ac101ff lib/, src/: str2*(): Rename functions and reorder parameters
This makes them compatible with liba2i's functions.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-29 14:29:13 -05:00
Alejandro Colomar
27e236ca79 lib/, src/, po/: get[u]long(): Move functions to lib/atoi/str2i.h
And make them inline.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-29 14:29:13 -05:00
Alejandro Colomar
2a9b6d80e7 lib/, src/: getulong(): Use the usual -1 as an error code
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-05 16:54:55 -06:00
Alejandro Colomar
2d581cb337 lib/, src/: getlong(): Use the usual -1 as an error code
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-05 16:54:55 -06:00
Alejandro Colomar
1c464d9a2d lib/, src/: Fix error handling after strto[u]l[l](3)
-  Set errno = 0 before the call.  Otherwise, it may contain anything.
-  ERANGE is not the only possible errno value of these functions.  They
   can also set it to EINVAL.
-  Any errno value after these calls is bad; just compare against 0.
-  Don't check for the return value; just errno.  This function is
   guaranteed to not modify errno on success (POSIX).
-  Check endptr == str, which may or may not set EINVAL.

Suggested-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-04 12:21:55 +01:00
Alejandro Colomar
5e0c61cce3 lib/limits.c: Check for overflow without invoking UB
The multiplication was already invoking UB.  The test was flawed.
Use __builtin_mul_overflow() instead.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-04 11:45:09 +01:00
Alejandro Colomar
9b798b584a lib/limits.c: Fix wrong error check
strtol(3) doesn't specify a return value if (value == endptr).
It is always an error, if (value==endptr).

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-04 11:45:09 +01:00
Alejandro Colomar
4f16458b6c lib/, src/: Say 'long' instead of 'long int'
We were using 'long' in most places, so be consistent and use it
everywhere.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-03 09:58:19 -06:00
Alejandro Colomar
f3ee47fe3f Use MEMZERO() instead of its pattern
This patch implicitly adds the safety of SIZEOF_ARRAY(), since the calls
were using sizeof() instead.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
6b11077f09 memzero.h: Move memzero() and strzero() to their own header
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
093fb605f9 lib: Merge libmisc into libshadow
The separation was unnecessary, and caused build problems.  Let's go
wild and obliterate the library.  The files are moved to libshadow.

Scripted change:

$ find libmisc/ -type f \
| grep '\.[chy]$' \
| xargs mv -t lib;

Plus updating the Makefile and other references.  While at it, I've
sorted the sources lists.

Link: <https://github.com/shadow-maint/shadow/pull/792>
Reported-by: David Seifert <soap@gentoo.org>
Cc: Sam James <sam@gentoo.org>
Cc: Christian Bricart <christian@bricart.de>
Cc: Michael Vetter <jubalh@iodoru.org>
Cc: Robert Förster <Dessa@gmake.de>
[ soap tested the Gentoo package ]
Tested-by: David Seifert <soap@gentoo.org>
Acked-by: David Seifert <soap@gentoo.org>
Acked-by: Serge Hallyn <serge@hallyn.com>
Acked-by: Iker Pedrosa <ipedrosa@redhat.com>
Acked-by: <lslebodn@fedoraproject.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-08-31 08:55:26 +02:00