Skip to content

Commit

Permalink
lib/string/strtok/: xastrsep2ls(): Add function
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Colomar <[email protected]>
  • Loading branch information
alejandro-colomar committed Feb 8, 2025
1 parent c3f46d4 commit fcc1d8e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ libshadow_la_SOURCES = \
string/strtok/strsep2arr.h \
string/strtok/strsep2ls.c \
string/strtok/strsep2ls.h \
string/strtok/xastrsep2ls.c \
string/strtok/xastrsep2ls.h \
strtoday.c \
sub.c \
subordinateio.h \
Expand Down
13 changes: 13 additions & 0 deletions lib/string/strtok/xastrsep2ls.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <[email protected]>
// SPDX-License-Identifier: BSD-3-Clause


#include <config.h>

#include "string/strtok/xastrsep2ls.h"

#include <stddef.h>


extern inline char **xastrsep2ls(char *restrict s, const char *restrict delim,
size_t *restrict np);
45 changes: 45 additions & 0 deletions lib/string/strtok/xastrsep2ls.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <[email protected]>
// SPDX-License-Identifier: BSD-3-Clause


#ifndef SHADOW_INCLUDE_LIB_STRING_STRTOK_XASTRSEP2LS_H_
#define SHADOW_INCLUDE_LIB_STRING_STRTOK_XASTRSEP2LS_H_


#include <config.h>

#include <errno.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "attr.h"
#include "shadowlog.h"
#include "string/strtok/astrsep2ls.h"


ATTR_ACCESS(read_write, 1) ATTR_ACCESS(write_only, 3)
ATTR_STRING(1) ATTR_STRING(2)
inline char **xastrsep2ls(char *restrict s, const char *restrict delim,
size_t *restrict np);


inline char **xastrsep2ls(char *s, const char *restrict delim,
size_t *restrict np)
{
char **ls;

ls = astrsep2ls(s, delim, np);
if (ls == NULL)
goto x;

return ls;
x:
fprintf(log_get_logfd(), "%s: %s\n",
log_get_progname(), strerror(errno));
exit(13);
}


#endif // include guard

0 comments on commit fcc1d8e

Please sign in to comment.