Skip to content
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

Add some wrappers for usual loops around strsep(3) #1155

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

Conversation

alejandro-colomar
Copy link
Collaborator

@alejandro-colomar alejandro-colomar commented Dec 13, 2024

Suggested-by: @hallyn


Revisions:

v2
$ git range-diff master gh/astrsep2ls astrsep2ls 
 1:  ad66293e !  1:  ccee0abc lib/string/strtok/: strsep2arr(), STRSEP2ARR(): Add APIs
    @@ lib/string/strtok/strsep2arr.h (new)
     +)
     +
     +
    -+ATTR_ACCESS(read_write, 1) ATTR_ACCESS(write_only, 4)
    ++ATTR_ACCESS(read_write, 1) ATTR_ACCESS(write_only, 4, 3)
     +ATTR_STRING(1) ATTR_STRING(2)
     +inline ssize_t strsep2arr(char *s, const char *restrict delim,
     +    size_t n, char *a[restrict n]);
 2:  5f98de6e !  2:  95f4a921 lib/string/strtok/: strsep2ls(), STRSEP2LS(): Add APIs
    @@ lib/string/strtok/strsep2ls.h (new)
     +#define STRSEP2LS(s, delim, ls)  strsep2ls(s, delim, NITEMS(ls), ls)
     +
     +
    -+ATTR_ACCESS(read_write, 1) ATTR_ACCESS(write_only, 4)
    ++ATTR_ACCESS(read_write, 1) ATTR_ACCESS(write_only, 4, 3)
     +ATTR_STRING(1) ATTR_STRING(2)
     +inline ssize_t strsep2ls(char *s, const char *restrict delim,
     +    size_t n, char *ls[restrict n]);
 3:  a5390a9c =  3:  ab168394 lib/: Use STRSEP2LS() instead of its pattern
 4:  4f29f5e7 =  4:  411dd0be lib/port.c: getportent(): Use STRSEP2ARR() instead of its pattern
 5:  519fc865 =  5:  dc232372 lib/: Use strsep2arr() instead of its pattern
 6:  57f481b4 =  6:  a2dd29c8 lib/: Use STRSEP2ARR() instead of its pattern
 7:  70f747cc =  7:  884f9611 lib/string/strtok/: astrsep2ls(): Add function
 8:  3b908118 =  8:  abcaf9ed lib/sgetgrent.c: list(): Explicitly free(3) at the start of the function
 9:  28366e31 =  9:  60a02867 lib/string/strtok/: xastrsep2ls(): Add function
10:  8b6cac14 = 10:  040a7acf lib/: Use xastrsep2ls() instead of its pattern
v2b
  • Rebase
$ git range-diff alx/master..gh/astrsep2ls master..astrsep2ls 
 1:  ccee0abc =  1:  060db63c lib/string/strtok/: strsep2arr(), STRSEP2ARR(): Add APIs
 2:  95f4a921 =  2:  2858fb22 lib/string/strtok/: strsep2ls(), STRSEP2LS(): Add APIs
 3:  ab168394 =  3:  e2f2c2ed lib/: Use STRSEP2LS() instead of its pattern
 4:  411dd0be =  4:  a707b113 lib/port.c: getportent(): Use STRSEP2ARR() instead of its pattern
 5:  dc232372 =  5:  d7fdde21 lib/: Use strsep2arr() instead of its pattern
 6:  a2dd29c8 =  6:  b708da45 lib/: Use STRSEP2ARR() instead of its pattern
 7:  884f9611 =  7:  051e32e2 lib/string/strtok/: astrsep2ls(): Add function
 8:  abcaf9ed =  8:  9f3f560f lib/sgetgrent.c: list(): Explicitly free(3) at the start of the function
 9:  60a02867 =  9:  5f22734d lib/string/strtok/: xastrsep2ls(): Add function
10:  040a7acf = 10:  729949bd lib/: Use xastrsep2ls() instead of its pattern

@alejandro-colomar alejandro-colomar force-pushed the astrsep2ls branch 2 times, most recently from 8b6cac1 to 040a7ac Compare December 14, 2024 14:40
This API set implements the usual loop around strsep(3).

This one implements a loop where we are interested in an exact number of
fields.  I'll add another API set, strsep2ls() and STRSEP2LS(), which
will add a NULL terminator, for arbitrary numbers of fields.

Signed-off-by: Alejandro Colomar <[email protected]>
This API set implements another usual loop around strsep(3).

This one implements a loop where we are interested in an arbitrary
number of fields.  For that, a NULL terminator is added at the end.
That is commonly referred to as "list".

Signed-off-by: Alejandro Colomar <[email protected]>
This makes it clear we wipe anything that was in the buffer.

Signed-off-by: Alejandro Colomar <[email protected]>
@alejandro-colomar alejandro-colomar marked this pull request as ready for review January 10, 2025 13:54
@alejandro-colomar alejandro-colomar marked this pull request as draft January 10, 2025 13:55
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