This provides a safer and more consistent API.
We had the strrspn(3) function as it was for compatibility with Oracle
Solaris, but let's not repeat their mistake. Nevertheless, name our
function strrspn_() with a trailing underscore, to differentiate it from
the one in Solaris, since it's slightly different.
Signed-off-by: Alejandro Colomar <alx@kernel.org>
string/strspn/stpspn.h \
string/strspn/stprcspn.c \
string/strspn/stprcspn.h \
+ string/strspn/stprspn.c \
+ string/strspn/stprspn.h \
string/strspn/strrcspn.c \
string/strspn/strrcspn.h \
string/strspn/strrspn.c \
#include "prototypes.h"
#include "string/strcmp/streq.h"
#include "string/strspn/stpspn.h"
-#include "string/strspn/strrspn.h"
+#include "string/strspn/stprspn.h"
#include "string/strtok/stpsep.h"
* makes it possible to change the field to empty, by
* entering a space. --marekm
*/
- stpcpy(strrspn(newf, " \t"), "");
+ stpcpy(stprspn(newf, " \t"), "");
cp = stpspn(newf, " \t");
strcpy (buf, cp);
}
#include "string/strcmp/strcaseeq.h"
#include "string/strcmp/streq.h"
#include "string/strspn/stpspn.h"
-#include "string/strspn/strrspn.h"
+#include "string/strspn/stprspn.h"
#include "string/strtok/stpsep.h"
/*
* Trim trailing whitespace.
*/
- stpcpy(strrspn(buf, " \t\n"), "");
+ stpcpy(stprspn(buf, " \t\n"), "");
/*
* Break the line into two fields.
--- /dev/null
+// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include <config.h>
+
+#include "string/strspn/stprspn.h"
--- /dev/null
+// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_STRING_STRSPN_STPRSPN_H_
+#define SHADOW_INCLUDE_LIB_STRING_STRSPN_STPRSPN_H_
+
+
+#include <config.h>
+
+#include <string.h>
+
+#include "string/strspn/strrspn.h"
+
+
+// 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); \
+})
+
+
+#endif // include guard
#include "string/strspn/strrspn.h"
+#include <stddef.h>
-extern inline char *strrspn(char *restrict s, const char *restrict accept);
+
+extern inline size_t strrspn_(const char *s, const char *accept);
#include <config.h>
+#include <stddef.h>
#include <string.h>
#include "attr.h"
#include "string/strchr/strnul.h"
+ATTR_STRING(1)
ATTR_STRING(2)
-inline char *strrspn(char *restrict s, const char *restrict accept);
+inline size_t strrspn_(const char *s, const char *accept);
-// Available in Oracle Solaris: strrspn(3GEN).
-// <https://docs.oracle.com/cd/E36784_01/html/E36877/strrspn-3gen.html>
-inline char *
-strrspn(char *restrict s, const char *restrict accept)
+inline size_t
+strrspn_(const char *s, const char *accept)
{
char *p;
while (p > s) {
p--;
if (strchr(accept, *p) == NULL)
- return p + 1;
+ return p + 1 - s;
}
- return s;
+ return 0;
}
#include "sizeof.h"
#include "string/strcmp/strcaseeq.h"
#include "string/strcmp/streq.h"
-#include "string/strspn/strrspn.h"
+#include "string/strspn/stprspn.h"
#include "string/strtok/stpsep.h"
if (line[0] == '#') {
continue; /* comment line */
}
- stpcpy(strrspn(line, " \t"), "");
+ stpcpy(stprspn(line, " \t"), "");
if (streq(line, "")) { /* skip blank lines */
continue;
}
#include "prototypes.h"
#include "string/strcmp/streq.h"
#include "string/strspn/stpspn.h"
-#include "string/strspn/strrspn.h"
+#include "string/strspn/stprspn.h"
#include "string/strtok/stpsep.h"
continue;
}
- stpcpy(strrspn(temp, " \t"), "");
+ stpcpy(stprspn(temp, " \t"), "");
p = stpspn(temp, " \t");
if (*p == '#' || streq(p, ""))