Skip to content

Conversation

@alejandro-colomar
Copy link
Collaborator

@alejandro-colomar alejandro-colomar commented Jan 1, 2026


Revisions:

v2
  • Move ispfchar() under lib/string/.
  • Document it in lib/string/README.
$ git rd 
1:  247466ab6 ! 1:  85d3d8cb4 lib/ctype/: ispfchar(): Add function
    @@ Metadata
     Author: Alejandro Colomar <alx@kernel.org>
     
      ## Commit message ##
    -    lib/ctype/: ispfchar(): Add function
    +    lib/string/ctype/isascii/: ispfchar(): Add function
     
         This function returns true if the input character is a character from
         the POSIX portable filename character set.
    @@ Commit message
     
      ## lib/Makefile.am ##
     @@ lib/Makefile.am: libshadow_la_SOURCES = \
    -   console.c \
    -   copydir.c \
    -   csrand.c \
    -+  ctype/ispfchar.c \
    -+  ctype/ispfchar.h \
    -   defines.h \
    -   encrypt.c \
    -   env.c \
    +   spawn.c \
    +   sssd.c \
    +   sssd.h \
    ++  string/ctype/isascii/ispfchar.c \
    ++  string/ctype/isascii/ispfchar.h \
    +   string/ctype/strchrisascii/strchriscntrl.c \
    +   string/ctype/strchrisascii/strchriscntrl.h \
    +   string/ctype/strisascii/strisdigit.c \
     
    - ## lib/ctype/ispfchar.c (new) ##
    + ## lib/string/README ##
    +@@ lib/string/README: Specific guidelines:
    + 
    + ctype/ - Character classification and conversion functions
    + 
    ++    isascii/
    ++  The functions defined under this directory
    ++  return true
    ++  is the character
    ++  belongs to the category specified in the function name.
    ++
    +     strchrisascii/
    +   The functions defined under this directory
    +   return true
    +
    + ## lib/string/ctype/isascii/ispfchar.c (new) ##
     @@
    -+// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
    ++// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <alx@kernel.org>
     +// SPDX-License-Identifier: BSD-3-Clause
     +
     +
     +#include <config.h>
     +
    -+#include "ctype/ispfchar.h"
    ++#include "string/ctype/isascii/ispfchar.h"
     +
     +#include <stdbool.h>
     +
     +
     +extern inline bool ispfchar(unsigned char c);
     
    - ## lib/ctype/ispfchar.h (new) ##
    + ## lib/string/ctype/isascii/ispfchar.h (new) ##
     @@
    -+// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
    ++// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <alx@kernel.org>
     +// SPDX-License-Identifier: BSD-3-Clause
     +
     +
    -+#ifndef SHADOW_INCLUDE_LIB_CTYPE_ISPFCHAR_H_
    -+#define SHADOW_INCLUDE_LIB_CTYPE_ISPFCHAR_H_
    ++#ifndef SHADOW_INCLUDE_LIB_STRING_CTYPE_ISASCII_ISPFCHAR_H_
    ++#define SHADOW_INCLUDE_LIB_STRING_CTYPE_ISASCII_ISPFCHAR_H_
     +
     +
     +#include <config.h>
2:  219955397 = 2:  1b917a73d lib/chkname.c: is_valid_name(): Use isalnum(3) instead of its pattern
3:  92332a203 = 3:  e2d77042a lib/chkname.c: is_valid_name(): Split Samba check
4:  1ead5c62f ! 4:  8fd9e48f6 lib/chkname.c: is_valid_name(): Use ispfchar() to simplify
    @@ lib/chkname.c
      
      #include "defines.h"
      #include "chkname.h"
    -+#include "ctype/ispfchar.h"
    ++#include "string/ctype/isascii/ispfchar.h"
      #include "string/ctype/strchrisascii/strchriscntrl.h"
      #include "string/ctype/strisascii/strisdigit.h"
      #include "string/strcmp/streq.h"
v2b
  • tfix
$ git rd 
1:  85d3d8cb4 ! 1:  d339ea77e lib/string/ctype/isascii/: ispfchar(): Add function
    @@ lib/string/README: Specific guidelines:
     +    isascii/
     +  The functions defined under this directory
     +  return true
    -+  is the character
    ++  if the character
     +  belongs to the category specified in the function name.
     +
          strchrisascii/
2:  1b917a73d = 2:  7f83c18fe lib/chkname.c: is_valid_name(): Use isalnum(3) instead of its pattern
3:  e2d77042a = 3:  4c7cee7bc lib/chkname.c: is_valid_name(): Split Samba check
4:  8fd9e48f6 = 4:  d39008cae lib/chkname.c: is_valid_name(): Use ispfchar() to simplify

This function returns true if the input character is a character from
the POSIX portable filename character set.

Link: <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap03.html#tag_03_265>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
In the first case, we can do the transformation because a few lines
above, we explicitly reject a name starting with a '-'.

In the second case, we're obviously using ispfchar() instead of its
pattern.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
inline bool
ispfchar(unsigned char c)
{
return isalnum(c) || c == '.' || c == '_' || c == '-';
Copy link
Contributor

@stoeckmann stoeckmann Jan 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The isalnum function is locale dependent. German umlauts are definitely not portable file characters, but will be as soon as setlocale is called.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the reminder!

I should use variants of these functions that work on the C locale exclusively.

@alejandro-colomar alejandro-colomar marked this pull request as draft January 2, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants