Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions lib/string/strspn/stprcspn.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
// SPDX-FileCopyrightText: 2024-2026, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause


Expand All @@ -10,15 +10,16 @@

#include <string.h>

#include "string/strchr/strnul.h"
#include "string/strspn/strrcspn.h"


// string returns-pointer rear complement substring prefix length
#define stprcspn(s, reject) \
({ \
__auto_type s_ = (s); \
\
s_ + strrcspn(s_, reject); \
// stprcspn - string returns-pointer rear complement span
#define stprcspn(s, reject) \
({ \
__auto_type s_ = (s); \
\
strnul(s_) - strrcspn(s_, reject); \
})


Expand Down
17 changes: 8 additions & 9 deletions lib/string/strspn/stprspn.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
// SPDX-FileCopyrightText: 2024-2026, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause


Expand All @@ -10,17 +10,16 @@

#include <string.h>

#include "string/strchr/strnul.h"
#include "string/strspn/strrspn.h"


// string returns-pointer rear substring prefix length
// Available in Oracle Solaris as strrspn(3GEN).
// <https://docs.oracle.com/cd/E36784_01/html/E36877/strrspn-3gen.html>
#define stprspn(s, accept) \
({ \
__auto_type s_ = (s); \
\
s_ + strrspn_(s_, accept); \
// stprspn - string returns-pointer rear span
#define stprspn(s, accept) \
({ \
__auto_type s_ = (s); \
\
strnul(s_) - strrspn_(s_, accept); \
})


Expand Down
11 changes: 6 additions & 5 deletions lib/string/strspn/strrcspn.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
// SPDX-FileCopyrightText: 2024-2026, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause


Expand All @@ -20,19 +20,20 @@ ATTR_STRING(2)
inline size_t strrcspn(const char *s, const char *reject);


// string rear complement substring prefix length
// strrcspn - string rear complement span
inline size_t
strrcspn(const char *s, const char *reject)
{
size_t spn;
const char *p;

p = strnul(s);
while (p > s) {
for (spn = 0; p > s; spn++) {
p--;
if (strchr(reject, *p) != NULL)
return p + 1 - s;
return spn;
}
return 0;
return spn;
}


Expand Down
11 changes: 6 additions & 5 deletions lib/string/strspn/strrspn.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
// SPDX-FileCopyrightText: 2024-2026, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause


Expand All @@ -20,19 +20,20 @@ ATTR_STRING(2)
inline size_t strrspn_(const char *s, const char *accept);


// string rear substring prefix length
// strrspn_ - string rear span
inline size_t
strrspn_(const char *s, const char *accept)
{
size_t spn;
const char *p;

p = strnul(s);
while (p > s) {
for (spn = 0; p > s; spn++) {
p--;
if (strchr(accept, *p) == NULL)
return p + 1 - s;
return spn;
}
return 0;
return spn;
}


Expand Down
3 changes: 2 additions & 1 deletion src/login_nopam.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include "string/strcmp/strcaseeq.h"
#include "string/strcmp/streq.h"
#include "string/strcmp/strprefix.h"
#include "string/strspn/strrspn.h"
#include "string/strspn/stprspn.h"
#include "string/strtok/stpsep.h"

Expand Down Expand Up @@ -315,7 +316,7 @@ static bool from_match (char *tok, const char *string)
} else if (strcaseeq(tok, "LOCAL")) { /* LOCAL: no dots */
if (!strchr(string, '.'))
return true;
} else if ( (!streq(tok, "") && tok[strlen(tok) - 1] == '.') /* network */
} else if ( strrspn_(tok, ".") /* network */
&& strprefix(resolve_hostname(string), tok)) {
return true;
}
Expand Down
Loading