Skip to content

ls #1272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 23 commits into
base: master
Choose a base branch
from
Draft

ls #1272

wants to merge 23 commits into from

Conversation

alejandro-colomar
Copy link
Collaborator

@alejandro-colomar alejandro-colomar commented Jun 10, 2025

I've managed to remove one of the static, but most of them seem necessary, since these shadow APIs are either libc APIs or similar to libc APIs, and they're specified as using static memory.

I've also done a lot of simplification and de-duplication work in surrounding code, especially in code transforming CSVs to lists.

This is queued after #1197

…on and rename it

Rename it for consistency with the file name itself, and with the FILE*
variable that holds the handle to the open file.

Also, we don't need to wrap it in conditionals.  Just define it
unconditionally, and let it be unused if we don't need it.

Signed-off-by: Alejandro Colomar <[email protected]>
And with it, the file that defines it, which does nothing else.

Signed-off-by: Alejandro Colomar <[email protected]>
This is for consistency with how this is done in sgetsgent().

Now we need to make sure that the list is NULL before the first call,
which means that the 'grent' structure must be cleared.  Since it's
a static object, it's already true, but let's be explicit about it.

Since we remember the address of the list in grent.gr_mem (which is
static), we don't need to keep 'members' being static too, so we get rid
of one static thing.

Signed-off-by: Alejandro Colomar <[email protected]>
Imitate how this is done in sgetgrent().

BE CAREFUL:  The NULL check needs to be performed after *both*
build_list() calls, since we need to make sure that either a NULL or a
valid pointer is stored in both .sg_adm and .sg_mem, since we'll call
free(3) next time sgetsgent() is called.

Signed-off-by: Alejandro Colomar <[email protected]>
Move build_list() to "lib/list.c", where we can reuse it.

Signed-off-by: Alejandro Colomar <[email protected]>
In some places we call comma_to_list(), and in others build_list(), and
they're essentially the same thing: they transform a comma-separated
list into an array of strings.

Both of them consider an empty list to have 0 members instead of one.
However, they differ in how they treat trailing commas:

-  comma_to_list() interprets that as an empty field.
-  build_list() ignores the trailing comma.

The behavior of build_list() seems more appropriate, since it allows
tools to generate the CSVs more easily.  Also, these lists are used to
represent user names or group names, so an empty user name makes no
sense.

This patch makes both functions be more consistent, which will
eventually allow us to de-duplicate code.

Signed-off-by: Alejandro Colomar <[email protected]>
get_gid() will fail to parse a number if the field is empty.

Signed-off-by: Alejandro Colomar <[email protected]>
This name tells better what this API does.

Signed-off-by: Alejandro Colomar <[email protected]>
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.

1 participant