Skip to content

Move nonstring and memory APIs from lib/string/ to a new lib/memory/ - #1727

Open
alejandro-colomar wants to merge 10 commits into
shadow-maint:masterfrom
alejandro-colomar:m
Open

Move nonstring and memory APIs from lib/string/ to a new lib/memory/#1727
alejandro-colomar wants to merge 10 commits into
shadow-maint:masterfrom
alejandro-colomar:m

Conversation

@alejandro-colomar

@alejandro-colomar alejandro-colomar commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

@ikerexxe It turns out it was less work than I thought, so we can do the movement already. Here it is.

See also memory.h(3head): https://www.kernel.org/pub/linux/docs/man-pages/book/man-pages-6.19.pdf#memory.h.3head.


Revisions:

v1b
  • Update paragraph in the README. [@ikerexxe ]
$ git rd 
 1:  f65d2fe1b947 =  1:  f65d2fe1b947 lib/memory/README: Add symlink to the string README
 2:  a686e1b76ef7 !  2:  81219686b3fb lib/string/README: Reorganize the library in memory/ and string/
    @@ Commit message
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/string/README ##
    -@@ lib/string/README: Specific guidelines:
    -   strings, separated in subdirectories by utility type.  In this
    -   section, we provide a broad overview.
    +@@ lib/string/README: Don't use some libc functions without Really Good Reasons:
    + 
    + Specific guidelines:
    + ====================
    ++  Under lib/memory/ we provide a set of functions to manipulate
    ++  bytes --mem*()-- and nonstrings --strn*()--.
    +   Under lib/string/ we provide a set of functions to manipulate
    +-  strings, separated in subdirectories by utility type.  In this
    +-  section, we provide a broad overview.
    ++  strings.
    ++  All of these functions are separated in subdirectories
    ++  by utility type.
    ++  In this section, we provide a broad overview of all of them.
      
     -ctype/ - Character classification and conversion functions
     +memory/ - memory operations
 3:  c3612a7db1b8 =  3:  8cdf0ce71aae lib/string/README: Remove strndup_a()
 4:  6757c8c928a5 =  4:  0943230b4d4f lib/string/README: Rename MEMCPY() => memcpy_a()
 5:  1249699267a0 =  5:  cb653ae17c53 lib/string/README: Document strncmp(3) and strncat(3) as being from <memory.h>
 6:  51efa2ddff9d =  6:  2312c3889cf0 lib/, src/: Move memzero() to under lib/memory/
 7:  d421d1236e18 =  7:  0ded15960a1c lib/, src/: Move strzero() to under lib/string/strzero/
 8:  99bf4380d941 =  8:  886f51695d59 lib/: Move memdup() and strndup() under lib/memory/
 9:  77990d3a2ab2 =  9:  5c627cb5a4c1 lib/, src/: Move strneq() to under lib/memory/
10:  8db526f99e40 = 10:  459e7d946156 lib/: Move strncpy/cat() to under lib/memory/
v1c
  • Rebase
$ git rd
 1:  f65d2fe1b947 =  1:  8a9eff5e33f8 lib/memory/README: Add symlink to the string README
 2:  81219686b3fb !  2:  b2540e74c515 lib/string/README: Reorganize the library in memory/ and string/
    @@ lib/string/README: Don't use some libc functions without Really Good Reasons:
     +    strncpytail()
     +  Like strncpy(), but when truncating, the tail of the string is
     +  kept instead of the beginning.  This is useful for ut_id.
    -+    STRNCPYTAIL()
    ++    strncpytail_a()
     +  Like strncpytail, but takes an array.
     +
     +    strncat_a()  // To be removed
    @@ lib/string/README: strcmp/ - String comparison
     -    strncpytail()
     -  Like strncpy(), but when truncating, the tail of the string is
     -  kept instead of the beginning.  This is useful for ut_id.
    --    STRNCPYTAIL()
    +-    strncpytail_a()
     -  Like strncpytail, but takes an array.
     -
     -    strncat_a()  // To be removed
 3:  8cdf0ce71aae =  3:  8606ae5ef083 lib/string/README: Remove strndup_a()
 4:  0943230b4d4f =  4:  be3363dfd009 lib/string/README: Rename MEMCPY() => memcpy_a()
 5:  cb653ae17c53 =  5:  23c4eb8b7dc0 lib/string/README: Document strncmp(3) and strncat(3) as being from <memory.h>
 6:  2312c3889cf0 !  6:  c6a51f909e3a lib/, src/: Move memzero() to under lib/memory/
    @@ Commit message
     
      ## lib/Makefile.am ##
     @@ lib/Makefile.am: libshadow_la_SOURCES = \
    -   lockpw.c \
    -   loginprompt.c \
        mail.c \
    +   memory/memcpy/strncpytail.c \
    +   memory/memcpy/strncpytail.h \
     +  memory/memset/memzero.c \
     +  memory/memset/memzero.h \
        motd.c \
 7:  0ded15960a1c =  7:  9ca51df949ea lib/, src/: Move strzero() to under lib/string/strzero/
 8:  886f51695d59 !  8:  34e4a93bf36c lib/: Move memdup() and strndup() under lib/memory/
    @@ Commit message
     
      ## lib/Makefile.am ##
     @@ lib/Makefile.am: libshadow_la_SOURCES = \
    -   lockpw.c \
    -   loginprompt.c \
        mail.c \
    +   memory/memcpy/strncpytail.c \
    +   memory/memcpy/strncpytail.h \
     +  memory/memdup/memdup.c \
     +  memory/memdup/memdup.h \
     +  memory/memdup/strndup.c \
    @@ lib/string/strdup/strndup.c (deleted)
     
      ## lib/utmp.c ##
     @@
    - #include "alloc/malloc.h"
      #include "attr.h"
      #include "io/syslog.h"
    + #include "memory/memcpy/strncpytail.h"
     +#include "memory/memdup/memdup.h"
     +#include "memory/memdup/strndup.h"
      #include "sizeof.h"
 9:  5c627cb5a4c1 !  9:  75ced5207be8 lib/, src/: Move strneq() to under lib/memory/
    @@ lib/user_busy.c
     
      ## lib/utmp.c ##
     @@
    - #include "io/syslog.h"
    + #include "memory/memcpy/strncpytail.h"
      #include "memory/memdup/memdup.h"
      #include "memory/memdup/strndup.h"
     +#include "memory/strncmp/strneq.h"
10:  459e7d946156 ! 10:  0f1bf7265307 lib/: Move strncpy/cat() to under lib/memory/
    @@ lib/Makefile.am: libshadow_la_SOURCES = \
     +  memory/memcpy/strncat.h \
     +  memory/memcpy/strncpy.c \
     +  memory/memcpy/strncpy.h \
    +   memory/memcpy/strncpytail.c \
    +   memory/memcpy/strncpytail.h \
        memory/memdup/memdup.c \
    -   memory/memdup/memdup.h \
    -   memory/memdup/strndup.c \
     @@ lib/Makefile.am: libshadow_la_SOURCES = \
        string/strcmp/strprefix.h \
        string/strcpy/stpecpy.c \
    @@ lib/utmp.c
      #include "attr.h"
      #include "io/syslog.h"
     +#include "memory/memcpy/strncpy.h"
    + #include "memory/memcpy/strncpytail.h"
      #include "memory/memdup/memdup.h"
      #include "memory/memdup/strndup.h"
    - #include "memory/strncmp/strneq.h"
     @@
      #include "string/strchr/strnul.h"
      #include "string/strcmp/streq.h"

@ikerexxe ikerexxe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One minor comment inline, apart from that this looks good

I'd also like to hear @hallyn's opinion before merging

Comment thread lib/string/README Outdated
@alejandro-colomar

alejandro-colomar commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator Author

Cc: @ikerexxe , @hallyn

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Future commits will do the actual move of functions.
This change to the README serves as an overview of those changes.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Fixes: cb0d47b (2026-08-18; "lib/string/: strndupa(3): Remove unused macro")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
For consistency with the other _a() macros.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
…memory.h>

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants