shadow-maint / shadow

Upstream shadow tree
Other
287 stars 227 forks source link

Simplify string handling, and add some new APIs for that #1035

Closed alejandro-colomar closed 1 week ago

alejandro-colomar commented 1 week ago

Revisions:

v1b - Fix includes ``` $ git range-diff shadow/master gh/string string 1: 3adb0ad0 = 1: 3adb0ad0 lib/string/strchr/: stp[rc]spn(), strnul(): Add macros and functions 2: d91463be = 2: d91463be lib/getdef.c: def_load(): Use stp[c]spn() instead of their patterns 3: 5670297a = 3: 5670297a src/login_nopam.c: login_access(): Simplify, calling strchr(3) 4: 9627b8e5 = 4: 9627b8e5 lib/sssd.c: Style fixes 5: 3e5fde30 ! 5: 66c757bb lib/, src/: Use stprspn() instead of its pattern @@ lib/fields.c #include + #include "prototypes.h" -+#include "string/stpspn.h" ++#include "string/strchr/stprspn.h" + /* @@ lib/fields.c: void change_field (char *buf, size_t maxsize, const char *prompt) while (isspace (*cp)) { ## lib/getdef.c ## +@@ + #include "string/sprintf/xasprintf.h" + #include "string/strchr/stpcspn.h" + #include "string/strchr/stpspn.h" ++#include "string/strchr/stprspn.h" + + + /* @@ lib/getdef.c: static void def_load (void) #else /* USE_ECONF */ static void def_load (void) @@ src/login_nopam.c #include /* for inet_ntoa() */ #include "sizeof.h" -+#include "string/stpspn.h" ++#include "string/string/stprspn.h" #if !defined(MAXHOSTNAMELEN) || (MAXHOSTNAMELEN < 64) #undef MAXHOSTNAMELEN @@ src/suauth.c + #include "defines.h" #include "prototypes.h" -+#include "string/stpspn.h" ++#include "string/strchr/stprspn.h" + #ifndef SUAUTHFILE 6: 49fc8f79 = 6: 837f6557 contrib, lib/, src/, tests/: Use stpcpy(3) instead of its pattern 7: 9695c71b = 7: 13c5a064 contrib/adduser.c: main(): Use strcpy/cat(3) instead of their pattern ```
v1c - Add missing include ``` $ git range-diff shadow/master gh/string string 1: 3adb0ad0 ! 1: 9b33f7d0 lib/string/strchr/: stp[rc]spn(), strnul(): Add macros and functions @@ lib/string/strchr/stprspn.h (new) +#include + +#include "attr.h" ++#include "string/strchr/strnul.h" + + +// Similar to strspn(3), but start from the end, and return a pointer. 2: d91463be = 2: e9b74af9 lib/getdef.c: def_load(): Use stp[c]spn() instead of their patterns 3: 5670297a = 3: ecc4ba88 src/login_nopam.c: login_access(): Simplify, calling strchr(3) 4: 9627b8e5 = 4: 1a7abdcf lib/sssd.c: Style fixes 5: 66c757bb = 5: 7b7baa54 lib/, src/: Use stprspn() instead of its pattern 6: 837f6557 = 6: c2642082 contrib, lib/, src/, tests/: Use stpcpy(3) instead of its pattern 7: 13c5a064 = 7: a90be944 contrib/adduser.c: main(): Use strcpy/cat(3) instead of their pattern ```
v1d - Fix include ``` $ git range-diff shadow/master gh/string string 1: 9b33f7d0 = 1: 9b33f7d0 lib/string/strchr/: stp[rc]spn(), strnul(): Add macros and functions 2: e9b74af9 = 2: e9b74af9 lib/getdef.c: def_load(): Use stp[c]spn() instead of their patterns 3: ecc4ba88 = 3: ecc4ba88 src/login_nopam.c: login_access(): Simplify, calling strchr(3) 4: 1a7abdcf = 4: 1a7abdcf lib/sssd.c: Style fixes 5: 7b7baa54 ! 5: 9b00f777 lib/, src/: Use stprspn() instead of its pattern @@ src/login_nopam.c #include /* for inet_ntoa() */ #include "sizeof.h" -+#include "string/string/stprspn.h" ++#include "string/strchr/stprspn.h" #if !defined(MAXHOSTNAMELEN) || (MAXHOSTNAMELEN < 64) #undef MAXHOSTNAMELEN 6: c2642082 = 6: 743030f7 contrib, lib/, src/, tests/: Use stpcpy(3) instead of its pattern 7: a90be944 = 7: 00e6458f contrib/adduser.c: main(): Use strcpy/cat(3) instead of their pattern ```
v2 - Add missing parameters (I had accidentally removed them while transforming some APIs from functions to macros), ``` $ git range-diff shadow/master gh/string string 1: 9b33f7d0 ! 1: f3b843ca lib/string/strchr/: stp[rc]spn(), strnul(): Add macros and functions @@ lib/string/strchr/stpcspn.h (new) + + +// Similar to strcspn(3), but return a pointer. -+#define stpcspn(s) \ ++#define stpcspn(s, reject) \ +({ \ + __auto_type s_ = s; \ + \ -+ s_ + strcspn(s_); \ ++ s_ + strcspn(s_, reject); \ +}) + + @@ lib/string/strchr/stpspn.h (new) +({ \ + __auto_type s_ = s; \ + \ -+ s_ + strspn(s_); \ ++ s_ + strspn(s_, accept); \ +}) + + 2: e9b74af9 = 2: b7eee949 lib/getdef.c: def_load(): Use stp[c]spn() instead of their patterns 3: ecc4ba88 = 3: 0a5349d6 src/login_nopam.c: login_access(): Simplify, calling strchr(3) 4: 1a7abdcf = 4: 2801e87f lib/sssd.c: Style fixes 5: 9b00f777 = 5: c033ab93 lib/, src/: Use stprspn() instead of its pattern 6: 743030f7 = 6: 1f1afc35 contrib, lib/, src/, tests/: Use stpcpy(3) instead of its pattern 7: 00e6458f = 7: 88c6cf98 contrib/adduser.c: main(): Use strcpy/cat(3) instead of their pattern ```
v2b - Add a few more cases ``` $ git range-diff shadow/master gh/string string 1: f3b843ca = 1: f3b843ca lib/string/strchr/: stp[rc]spn(), strnul(): Add macros and functions 2: b7eee949 = 2: b7eee949 lib/getdef.c: def_load(): Use stp[c]spn() instead of their patterns 3: 0a5349d6 = 3: 0a5349d6 src/login_nopam.c: login_access(): Simplify, calling strchr(3) 4: 2801e87f = 4: 2801e87f lib/sssd.c: Style fixes 5: c033ab93 = 5: c033ab93 lib/, src/: Use stprspn() instead of its pattern 6: 1f1afc35 ! 6: dcca5be5 contrib, lib/, src/, tests/: Use stpcpy(3) instead of its pattern @@ lib/getdate.y: static int LookupWord (char *buff) } else abbrev = false; +@@ lib/getdate.y: static int LookupWord (char *buff) + i = strlen (buff) - 1; + if (buff[i] == 's') + { +- buff[i] = '\0'; ++ stpcpy(&buf[i], ""); + for (tp = UnitsTable; tp->name; tp++) + if (strcmp (buff, tp->name) == 0) + { @@ lib/getdate.y: static int LookupWord (char *buff) *p++ = *q; else @@ lib/obscure.c: static /*@observer@*//*@null@*/const char *obscure_msg ( ## lib/port.c ## +@@ lib/port.c: again: + * TTY devices. + */ + +- *strchrnul(buf, '\n') = '\0'; ++ stpcpy(strchrnul(buf, '\n'), ""); + + port.pt_names = ttys; + for (cp = buf, j = 0; j < PORT_TTY; j++) { @@ lib/port.c: again: break; } @@ lib/tcbfuncs.c: static /*@null@*/ char *shadowtcb_path_rel_existing (const char rval = strdup (link); if (NULL == rval) { OUT_OF_MEMORY; +@@ lib/tcbfuncs.c: static shadowtcb_status mkdir_leading (const char *name, uid_t uid) + goto out_free_path; + } + while ((ind = strchr (ptr, '/'))) { +- *ind = '\0'; ++ stpcpy(ind, ""); + if (asprintf (&dir, TCB_DIR "/%s", path) == -1) { + OUT_OF_MEMORY; + return SHADOWTCB_FAILURE; @@ lib/tcbfuncs.c: static shadowtcb_status rmdir_leading (char *path) char *ind, *dir; shadowtcb_status ret = SHADOWTCB_SUCCESS; 7: 88c6cf98 = 7: 28c2e770 contrib/adduser.c: main(): Use strcpy/cat(3) instead of their pattern ```
v2c - Fix typo introduced in v2b. ``` $ git range-diff shadow/master gh/string string 1: f3b843ca = 1: f3b843ca lib/string/strchr/: stp[rc]spn(), strnul(): Add macros and functions 2: b7eee949 = 2: b7eee949 lib/getdef.c: def_load(): Use stp[c]spn() instead of their patterns 3: 0a5349d6 = 3: 0a5349d6 src/login_nopam.c: login_access(): Simplify, calling strchr(3) 4: 2801e87f = 4: 2801e87f lib/sssd.c: Style fixes 5: c033ab93 = 5: c033ab93 lib/, src/: Use stprspn() instead of its pattern 6: dcca5be5 ! 6: 1b2e08d0 contrib, lib/, src/, tests/: Use stpcpy(3) instead of its pattern @@ lib/getdate.y: static int LookupWord (char *buff) if (buff[i] == 's') { - buff[i] = '\0'; -+ stpcpy(&buf[i], ""); ++ stpcpy(&buff[i], ""); for (tp = UnitsTable; tp->name; tp++) if (strcmp (buff, tp->name) == 0) { 7: 28c2e770 = 7: 470a9de3 contrib/adduser.c: main(): Use strcpy/cat(3) instead of their pattern ```
v2d - Rebase ``` $ git range-diff master..gh/string shadow/master..string 1: f3b843ca = 1: eeff3e63 lib/string/strchr/: stp[rc]spn(), strnul(): Add macros and functions 2: b7eee949 = 2: 460cae37 lib/getdef.c: def_load(): Use stp[c]spn() instead of their patterns 3: 0a5349d6 = 3: 33f5eed8 src/login_nopam.c: login_access(): Simplify, calling strchr(3) 4: 2801e87f = 4: 0866dd74 lib/sssd.c: Style fixes 5: c033ab93 = 5: f5930587 lib/, src/: Use stprspn() instead of its pattern 6: 1b2e08d0 = 6: 896d8843 contrib, lib/, src/, tests/: Use stpcpy(3) instead of its pattern 7: 470a9de3 = 7: d6bfd265 contrib/adduser.c: main(): Use strcpy/cat(3) instead of their pattern ```
v2e - Describe the added functions and macros further by comparing them to well-known functions. ``` $ git range-diff master gh/string string 1: eeff3e63 ! 1: d7cd8b88 lib/string/strchr/: stp[rc]spn(), strnul(): Add macros and functions @@ lib/string/strchr/stpcspn.h (new) + + +// Similar to strcspn(3), but return a pointer. ++// Similar to strchrnul(3), but search for several delimiters. ++// Similar to strpbrk(3), but return 's + strlen(s)' if not found. +#define stpcspn(s, reject) \ +({ \ + __auto_type s_ = s; \ @@ lib/string/strchr/stprspn.h (new) +#include "string/strchr/strnul.h" + + -+// Similar to strspn(3), but start from the end, and return a pointer. ++// Similar to strspn(3), ++// but start from the end, and return a pointer. ++// Similar to strrchr(3), ++// but search for several delimiters, and return 's' if not found. ++// Identical to Solaris strrspn(3GEN), ++// but I didn't like their choice of a name. +ATTR_STRING(2) +inline char *stprspn(char *restrict s, const char *restrict accept); + @@ lib/string/strchr/stpspn.h (new) + + +// Similar to strspn(3), but return a pointer. ++// Similar to strchrnul(3), but search for all bytes not in 'accept'. +#define stpspn(s, accept) \ +({ \ + __auto_type s_ = s; \ 2: 460cae37 = 2: 36a95b16 lib/getdef.c: def_load(): Use stp[c]spn() instead of their patterns 3: 33f5eed8 = 3: f9c7504f src/login_nopam.c: login_access(): Simplify, calling strchr(3) 4: 0866dd74 = 4: 3294c812 lib/sssd.c: Style fixes 5: f5930587 = 5: 025353a6 lib/, src/: Use stprspn() instead of its pattern 6: 896d8843 = 6: 1963586f contrib, lib/, src/, tests/: Use stpcpy(3) instead of its pattern 7: d6bfd265 = 7: c39d3337 contrib/adduser.c: main(): Use strcpy/cat(3) instead of their pattern ```
v2f - Add link to Oracle Solaris documentation for strrspn(3GEN) in commit message. - wfix. ``` $ git range-diff master gh/string string 1: d7cd8b88 ! 1: b0adba05 lib/string/strchr/: stp[rc]spn(), strnul(): Add macros and functions @@ Commit message Ofter, a pointer is more useful than a length when calling these. + Link: Signed-off-by: Alejandro Colomar ## lib/Makefile.am ## @@ lib/string/strchr/stpspn.h (new) + + +// Similar to strspn(3), but return a pointer. -+// Similar to strchrnul(3), but search for all bytes not in 'accept'. ++// Similar to strchrnul(3), but search for any bytes not in 'accept'. +#define stpspn(s, accept) \ +({ \ + __auto_type s_ = s; \ 2: 36a95b16 = 2: 732aa367 lib/getdef.c: def_load(): Use stp[c]spn() instead of their patterns 3: f9c7504f = 3: 31a538e4 src/login_nopam.c: login_access(): Simplify, calling strchr(3) 4: 3294c812 = 4: 434a08aa lib/sssd.c: Style fixes 5: 025353a6 = 5: 36b9d865 lib/, src/: Use stprspn() instead of its pattern 6: 1963586f = 6: bc99c740 contrib, lib/, src/, tests/: Use stpcpy(3) instead of its pattern 7: c39d3337 = 7: e15fd51a contrib/adduser.c: main(): Use strcpy/cat(3) instead of their pattern ```
v2g - s/Ofter/Often/ @hallyn ``` $ git range-diff master gh/string string 1: b0adba05 ! 1: 2683f6c2 lib/string/strchr/: stp[rc]spn(), strnul(): Add macros and functions @@ Metadata ## Commit message ## lib/string/strchr/: stp[rc]spn(), strnul(): Add macros and functions - Ofter, a pointer is more useful than a length when calling these. + Often, a pointer is more useful than a length when calling these. Link: Signed-off-by: Alejandro Colomar 2: 732aa367 = 2: 77174000 lib/getdef.c: def_load(): Use stp[c]spn() instead of their patterns 3: 31a538e4 = 3: ce484b83 src/login_nopam.c: login_access(): Simplify, calling strchr(3) 4: 434a08aa = 4: 3c6330b4 lib/sssd.c: Style fixes 5: 36b9d865 = 5: 8fb49c71 lib/, src/: Use stprspn() instead of its pattern 6: bc99c740 = 6: be17255e contrib, lib/, src/, tests/: Use stpcpy(3) instead of its pattern 7: e15fd51a = 7: d019faf8 contrib/adduser.c: main(): Use strcpy/cat(3) instead of their pattern ```
v2h - Move comments to function definition. ``` $ git range-diff master gh/string string 1: 2683f6c2 ! 1: 96cffb93 lib/string/strchr/: stp[rc]spn(), strnul(): Add macros and functions @@ lib/string/strchr/stprspn.h (new) +#include "string/strchr/strnul.h" + + ++ATTR_STRING(2) ++inline char *stprspn(char *restrict s, const char *restrict accept); ++ ++ +// Similar to strspn(3), +// but start from the end, and return a pointer. +// Similar to strrchr(3), +// but search for several delimiters, and return 's' if not found. +// Identical to Solaris strrspn(3GEN), +// but I didn't like their choice of a name. -+ATTR_STRING(2) -+inline char *stprspn(char *restrict s, const char *restrict accept); -+ -+ +inline char * +stprspn(char *restrict s, const char *restrict accept) +{ 2: 77174000 = 2: a8ef68a0 lib/getdef.c: def_load(): Use stp[c]spn() instead of their patterns 3: ce484b83 = 3: 032bbbcb src/login_nopam.c: login_access(): Simplify, calling strchr(3) 4: 3c6330b4 = 4: 387d7330 lib/sssd.c: Style fixes 5: 8fb49c71 = 5: 7e97fc64 lib/, src/: Use stprspn() instead of its pattern 6: be17255e = 6: e25437bd contrib, lib/, src/, tests/: Use stpcpy(3) instead of its pattern 7: d019faf8 = 7: 26867ae4 contrib/adduser.c: main(): Use strcpy/cat(3) instead of their pattern ```
v2i - wfix ``` $ git range-diff master gh/string string 1: 96cffb93 ! 1: bf20ab2e lib/string/strchr/: stp[rc]spn(), strnul(): Add macros and functions @@ lib/string/strchr/stprspn.h (new) + + +// Similar to strspn(3), -+// but start from the end, and return a pointer. ++// but start from the end and search backwards, ++// and return a pointer. +// Similar to strrchr(3), -+// but search for several delimiters, and return 's' if not found. ++// but search for any bytes not in 'accept', ++// and return a pointer to one after that, or 's' if not found. +// Identical to Solaris strrspn(3GEN), +// but I didn't like their choice of a name. +inline char * 2: a8ef68a0 = 2: 3c86bfca lib/getdef.c: def_load(): Use stp[c]spn() instead of their patterns 3: 032bbbcb = 3: bb73e951 src/login_nopam.c: login_access(): Simplify, calling strchr(3) 4: 387d7330 = 4: ca39eacd lib/sssd.c: Style fixes 5: 7e97fc64 = 5: f9bc7177 lib/, src/: Use stprspn() instead of its pattern 6: e25437bd = 6: 2bca8c14 contrib, lib/, src/, tests/: Use stpcpy(3) instead of its pattern 7: 26867ae4 = 7: 5e6666af contrib/adduser.c: main(): Use strcpy/cat(3) instead of their pattern ```
v3 - Use Oracle Solaris name: strrspn(3GEN). It's actually how these *spn() functions should have been designed from the start, since a length is useless. That makes it easier to refer to them for documentation. ``` $ git range-diff master gh/string string 1: bf20ab2e ! 1: 303300ad lib/string/strchr/: stp[rc]spn(), strnul(): Add macros and functions @@ Metadata Author: Alejandro Colomar ## Commit message ## - lib/string/strchr/: stp[rc]spn(), strnul(): Add macros and functions + lib/string/strchr/: stp[c]spn(), strrspn(), strnul(): Add macros and functions Often, a pointer is more useful than a length when calling these. @@ lib/Makefile.am: libshadow_la_SOURCES = \ string/sprintf/xasprintf.h \ + string/strchr/stpcspn.c \ + string/strchr/stpcspn.h \ -+ string/strchr/stprspn.c \ -+ string/strchr/stprspn.h \ + string/strchr/stpspn.c \ + string/strchr/stpspn.h \ + string/strchr/strnul.c \ + string/strchr/strnul.h \ ++ string/strchr/strrspn.c \ ++ string/strchr/strrspn.h \ string/strcpy/stpecpy.c \ string/strcpy/stpecpy.h \ string/strcpy/strncat.c \ @@ lib/string/strchr/stpcspn.h (new) +}) + + -+#endif // include guard - - ## lib/string/strchr/stprspn.c (new) ## -@@ -+// SPDX-FileCopyrightText: 2024, Alejandro Colomar -+// SPDX-License-Identifier: BSD-3-Clause -+ -+ -+#include -+ -+#include "string/strchr/stpspn.h" -+ -+ -+extern inline char *stprspn(char *restrict s, const char *restrict accept); - - ## lib/string/strchr/stprspn.h (new) ## -@@ -+// SPDX-FileCopyrightText: 2024, Alejandro Colomar -+// SPDX-License-Identifier: BSD-3-Clause -+ -+ -+#ifndef SHADOW_INCLUDE_LIB_STRING_STRCHR_STPRSPN_H_ -+#define SHADOW_INCLUDE_LIB_STRING_STRCHR_STPRSPN_H_ -+ -+ -+#include -+ -+#include -+ -+#include "attr.h" -+#include "string/strchr/strnul.h" -+ -+ -+ATTR_STRING(2) -+inline char *stprspn(char *restrict s, const char *restrict accept); -+ -+ -+// Similar to strspn(3), -+// but start from the end and search backwards, -+// and return a pointer. -+// Similar to strrchr(3), -+// but search for any bytes not in 'accept', -+// and return a pointer to one after that, or 's' if not found. -+// Identical to Solaris strrspn(3GEN), -+// but I didn't like their choice of a name. -+inline char * -+stprspn(char *restrict s, const char *restrict accept) -+{ -+ char *p; -+ -+ p = strnul(s); -+ while (p > s) { -+ p--; -+ if (strchr(accept, *p) == NULL) -+ return p + 1; -+ } -+ return s; -+} -+ -+ +#endif // include guard ## lib/string/strchr/stpspn.c (new) ## @@ lib/string/strchr/strnul.h (new) + + +#endif // include guard + + ## lib/string/strchr/strrspn.c (new) ## +@@ ++// SPDX-FileCopyrightText: 2024, Alejandro Colomar ++// SPDX-License-Identifier: BSD-3-Clause ++ ++ ++#include ++ ++#include "string/strchr/strrspn.h" ++ ++ ++extern inline char *strrspn(char *restrict s, const char *restrict accept); + + ## lib/string/strchr/strrspn.h (new) ## +@@ ++// SPDX-FileCopyrightText: 2024, Alejandro Colomar ++// SPDX-License-Identifier: BSD-3-Clause ++ ++ ++#ifndef SHADOW_INCLUDE_LIB_STRING_STRCHR_STRRSPN_H_ ++#define SHADOW_INCLUDE_LIB_STRING_STRCHR_STRRSPN_H_ ++ ++ ++#include ++ ++#include ++ ++#include "attr.h" ++#include "string/strchr/strnul.h" ++ ++ ++ATTR_STRING(2) ++inline char *strrspn(char *restrict s, const char *restrict accept); ++ ++ ++// Available in Oracle Solaris: strrspn(3GEN). ++// ++inline char * ++strrspn(char *restrict s, const char *restrict accept) ++{ ++ char *p; ++ ++ p = strnul(s); ++ while (p > s) { ++ p--; ++ if (strchr(accept, *p) == NULL) ++ return p + 1; ++ } ++ return s; ++} ++ ++ ++#endif // include guard 2: 3c86bfca = 2: b83b6904 lib/getdef.c: def_load(): Use stp[c]spn() instead of their patterns 3: bb73e951 = 3: 88bf401a src/login_nopam.c: login_access(): Simplify, calling strchr(3) 4: ca39eacd = 4: 97506539 lib/sssd.c: Style fixes 5: f9bc7177 ! 5: a30a2609 lib/, src/: Use stprspn() instead of its pattern @@ Metadata Author: Alejandro Colomar ## Commit message ## - lib/, src/: Use stprspn() instead of its pattern + lib/, src/: Use strrspn() instead of its pattern This requires changing isspace(3) calls to an explicit accept string, and I chose " \t\n" for it (as is done in other parts of this project), @@ lib/fields.c #include + #include "prototypes.h" -+#include "string/strchr/stprspn.h" ++#include "string/strchr/strrspn.h" + /* @@ lib/fields.c: void change_field (char *buf, size_t maxsize, const char *prompt) - cp--; - } - *cp = '\0'; -+ *stprspn(newf, " \t\n") = '\0'; ++ *strrspn(newf, " \t\n") = '\0'; cp = newf; while (isspace (*cp)) { @@ lib/getdef.c #include "string/sprintf/xasprintf.h" #include "string/strchr/stpcspn.h" #include "string/strchr/stpspn.h" -+#include "string/strchr/stprspn.h" ++#include "string/strchr/strrspn.h" /* @@ lib/getdef.c: static void def_load (void) - } - i++; - buf[i] = '\0'; -+ *stprspn(buf, " \t\n") = '\0'; ++ *strrspn(buf, " \t\n") = '\0'; /* * Break the line into two fields. @@ src/login_nopam.c #include /* for inet_ntoa() */ #include "sizeof.h" -+#include "string/strchr/stprspn.h" ++#include "string/strchr/strrspn.h" #if !defined(MAXHOSTNAMELEN) || (MAXHOSTNAMELEN < 64) #undef MAXHOSTNAMELEN @@ src/login_nopam.c: int login_access (const char *user, const char *from) - end--; - } - line[end] = '\0'; /* strip trailing whitespace */ -+ *stprspn(line, " \t\n") = '\0'; ++ *strrspn(line, " \t\n") = '\0'; if (line[0] == '\0') { /* skip blank lines */ continue; } @@ src/suauth.c + #include "defines.h" #include "prototypes.h" -+#include "string/strchr/stprspn.h" ++#include "string/strchr/strrspn.h" + #ifndef SUAUTHFILE @@ src/suauth.c: int check_su_auth (const char *actual_id, - || temp[endline - 1] == '\n')) - endline--; - temp[endline] = '\0'; -+ *stprspn(temp, " \t\n") = '\0'; ++ *strrspn(temp, " \t\n") = '\0'; posn = 0; while (temp[posn] == ' ' || temp[posn] == '\t') 6: 2bca8c14 ! 6: 6831dbdf contrib, lib/, src/, tests/: Use stpcpy(3) instead of its pattern @@ lib/fields.c: void change_field (char *buf, size_t maxsize, const char *prompt) * makes it possible to change the field to empty, by * entering a space. --marekm */ -- *stprspn(newf, " \t\n") = '\0'; -+ stpcpy(stprspn(newf, " \t\n"), ""); +- *strrspn(newf, " \t\n") = '\0'; ++ stpcpy(strrspn(newf, " \t\n"), ""); cp = newf; while (isspace (*cp)) { @@ lib/getdef.c: static void def_load (void) /* * Trim trailing whitespace. */ -- *stprspn(buf, " \t\n") = '\0'; -+ stpcpy(stprspn(buf, " \t\n"), ""); +- *strrspn(buf, " \t\n") = '\0'; ++ stpcpy(strrspn(buf, " \t\n"), ""); /* * Break the line into two fields. @@ src/login_nopam.c: int login_access (const char *user, const char *from) if (line[0] == '#') { continue; /* comment line */ } -- *stprspn(line, " \t\n") = '\0'; -+ stpcpy(stprspn(line, " \t\n"), ""); +- *strrspn(line, " \t\n") = '\0'; ++ stpcpy(strrspn(line, " \t\n"), ""); if (line[0] == '\0') { /* skip blank lines */ continue; } @@ src/suauth.c: int check_su_auth (const char *actual_id, continue; } -- *stprspn(temp, " \t\n") = '\0'; -+ stpcpy(stprspn(temp, " \t\n"), ""); +- *strrspn(temp, " \t\n") = '\0'; ++ stpcpy(strrspn(temp, " \t\n"), ""); posn = 0; while (temp[posn] == ' ' || temp[posn] == '\t') 7: 5e6666af = 7: bcc04a5d contrib/adduser.c: main(): Use strcpy/cat(3) instead of their pattern ```
v3b - wfix ``` $ git range-diff master gh/string string 1: 303300ad ! 1: 53780f68 lib/string/strchr/: stp[c]spn(), strrspn(), strnul(): Add macros and functions @@ lib/string/strchr/stpcspn.h (new) +#include "attr.h" + + -+// Similar to strcspn(3), but return a pointer. ++// Similar to strcspn(3), but return a pointer instead of an offset. +// Similar to strchrnul(3), but search for several delimiters. +// Similar to strpbrk(3), but return 's + strlen(s)' if not found. +#define stpcspn(s, reject) \ @@ lib/string/strchr/stpspn.h (new) +#include "attr.h" + + -+// Similar to strspn(3), but return a pointer. ++// Similar to strspn(3), but return a pointer instead of an offset. +// Similar to strchrnul(3), but search for any bytes not in 'accept'. +#define stpspn(s, accept) \ +({ \ @@ lib/string/strchr/strnul.h (new) +#include "attr.h" + + -+// Similar to strlen(3), but return a pointer. ++// Similar to strlen(3), but return a pointer instead of an offset. +#define strnul(s) \ +({ \ + __auto_type s_ = s; \ 2: b83b6904 = 2: 30951171 lib/getdef.c: def_load(): Use stp[c]spn() instead of their patterns 3: 88bf401a = 3: 2c6c6b32 src/login_nopam.c: login_access(): Simplify, calling strchr(3) 4: 97506539 = 4: 9f107526 lib/sssd.c: Style fixes 5: a30a2609 = 5: d65d9b98 lib/, src/: Use strrspn() instead of its pattern 6: 6831dbdf = 6: 5fe33f9e contrib, lib/, src/, tests/: Use stpcpy(3) instead of its pattern 7: bcc04a5d = 7: d35731a4 contrib/adduser.c: main(): Use strcpy/cat(3) instead of their pattern ```