Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ AC_CHECK_FUNCS([arc4random_buf \
updwtmpx innetgr \
getspnam_r \
rpmatch \
memset_explicit explicit_bzero stpecpy stpeprintf])
memset_explicit explicit_bzero stpecpy seprintf])
AC_SYS_LARGEFILE

dnl Checks for typedefs, structures, and compiler characteristics.
Expand Down
8 changes: 4 additions & 4 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ libshadow_la_SOURCES = \
string/memset/memzero.h \
string/sprintf/aprintf.c \
string/sprintf/aprintf.h \
string/sprintf/snprintf.c \
string/sprintf/snprintf.h \
string/sprintf/stpeprintf.c \
string/sprintf/stpeprintf.h \
string/sprintf/seprintf.c \
string/sprintf/seprintf.h \
string/sprintf/stprintf.c \
string/sprintf/stprintf.h \
string/strchr/strchrcnt.c \
string/strchr/strchrcnt.h \
string/strchr/strchrscnt.c \
Expand Down
2 changes: 1 addition & 1 deletion lib/audit_help.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "attr.h"
#include "prototypes.h"
#include "shadowlog.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/stprintf.h"

int audit_fd;

Expand Down
2 changes: 1 addition & 1 deletion lib/commonio.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "sssd.h"
#include "string/memset/memzero.h"
#include "string/sprintf/aprintf.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/stprintf.h"
#include "string/strcmp/streq.h"
#include "string/strcmp/strprefix.h"
#include "string/strerrno.h"
Expand Down
3 changes: 1 addition & 2 deletions lib/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
#include "defines.h"
#include "shadowlog.h"
#include "string/sprintf/aprintf.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/aprintf.h"
#include "string/sprintf/stprintf.h"
#include "string/strcmp/strprefix.h"
#include "string/strdup/strdup.h"

Expand Down
2 changes: 1 addition & 1 deletion lib/get_pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "atoi/getnum.h"
#include "defines.h"
#include "prototypes.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/stprintf.h"
#include "string/strerrno.h"


Expand Down
2 changes: 1 addition & 1 deletion lib/hushed.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "defines.h"
#include "getdef.h"
#include "prototypes.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/stprintf.h"
#include "string/strcmp/streq.h"
#include "string/strtok/stpsep.h"

Expand Down
6 changes: 3 additions & 3 deletions lib/idmapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "prototypes.h"
#include "shadowlog.h"
#include "sizeof.h"
#include "string/sprintf/stpeprintf.h"
#include "string/sprintf/seprintf.h"
#include "string/strcmp/streq.h"
#include "string/strerrno.h"

Expand Down Expand Up @@ -184,13 +184,13 @@ void write_mapping(int proc_dir_fd, int ranges, const struct map_range *mappings
mapping = mappings;
for (idx = 0; idx < ranges; idx++, mapping++) {
/* Append this range to the string that will be written */
pos = stpeprintf(pos, end, "%lu %lu %lu\n",
pos = seprintf(pos, end, "%lu %lu %lu\n",
mapping->upper,
mapping->lower,
mapping->count);
}
if (pos == end || pos == NULL) {
fprintf(log_get_logfd(), _("%s: stpeprintf failed!\n"), log_get_progname());
fprintf(log_get_logfd(), _("%s: seprintf failed!\n"), log_get_progname());
exit(EXIT_FAILURE);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/nss.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "prototypes.h"
#include "../libsubid/subid.h"
#include "shadowlog.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/stprintf.h"
#include "string/strcmp/strcaseprefix.h"
#include "string/strcmp/streq.h"
#include "string/strcmp/strprefix.h"
Expand Down
2 changes: 1 addition & 1 deletion lib/pwauth.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "pwauth.h"
#include "getdef.h"
#include "string/memset/memzero.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/stprintf.h"
#include "string/strcmp/streq.h"

#ifdef SKEY
Expand Down
5 changes: 3 additions & 2 deletions lib/salt.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "getdef.h"
#include "prototypes.h"
#include "shadowlog.h"
#include "string/sprintf/stprintf.h"
#include "string/strcmp/streq.h"


Expand Down Expand Up @@ -172,7 +173,7 @@ static /*@observer@*/void SHA_salt_rounds_to_buf (char *buf, unsigned long round
*/
assert (GENSALT_SETTING_SIZE > buf_begin + 17);

(void) snprintf (buf + buf_begin, 18, "rounds=%lu$", rounds);
stprintf(buf + buf_begin, 18, "rounds=%lu$", rounds);
}

#ifdef USE_BCRYPT
Expand Down Expand Up @@ -250,7 +251,7 @@ static /*@observer@*/void BCRYPT_salt_rounds_to_buf (char *buf, unsigned long ro
*/
assert (GENSALT_SETTING_SIZE > buf_begin + 3);

(void) snprintf (buf + buf_begin, 4, "%2.2lu$", rounds);
stprintf(buf + buf_begin, 4, "%2.2lu$", rounds);
}
#endif /* USE_BCRYPT */

Expand Down
2 changes: 1 addition & 1 deletion lib/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <errno.h>
#include "prototypes.h"
#include "defines.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/stprintf.h"


extern char **newenvp;
Expand Down
4 changes: 2 additions & 2 deletions lib/string/README
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,14 @@ sprintf/ - Formatted string creation
sprintf(3) variant that allocates.
It has better interface than asprintf(3).

stprintf() // Current name: snprintf_()
stprintf()
snprintf(3) wrapper that reports truncation with -1.
If you need more than one call to form a string,
use seprintf() instead.
stprintf_a()
Like stprintf(), but takes an array.

seprintf() // Current name: stpeprintf())
seprintf()
Similar to stprintf(), but takes a pointer to the end instead of
a size. This makes it safer for chaining several calls.

Expand Down
17 changes: 17 additions & 0 deletions lib/string/sprintf/seprintf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2022-2025, Alejandro Colomar <[email protected]>
// SPDX-License-Identifier: BSD-3-Clause


#include "config.h"

#include "string/sprintf/seprintf.h"

#include <stdarg.h>


#if !defined(HAVE_SEPRINTF)
extern inline char *seprintf(char *dst, const char end[0],
const char *restrict fmt, ...);
extern inline char *vseprintf(char *dst, const char end[0],
const char *restrict fmt, va_list ap);
#endif
66 changes: 66 additions & 0 deletions lib/string/sprintf/seprintf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// SPDX-FileCopyrightText: 2022-2025, Alejandro Colomar <[email protected]>
// SPDX-License-Identifier: BSD-3-Clause


#ifndef SHADOW_INCLUDE_LIB_STRING_SPRINTF_SEPRINTF_H_
#define SHADOW_INCLUDE_LIB_STRING_SPRINTF_SEPRINTF_H_


#include "config.h"

#include <stdarg.h>
#include <stddef.h>

#include "attr.h"
#include "string/sprintf/stprintf.h"


#if !defined(HAVE_SEPRINTF)
// seprintf - string end-pointer print formatted
format_attr(printf, 3, 4)
inline char *seprintf(char *dst, const char end[0], const char *restrict fmt,
...);
// vseprintf - va_list string end-pointer print formatted
format_attr(printf, 3, 0)
inline char *vseprintf(char *dst, const char end[0], const char *restrict fmt,
va_list ap);
#endif


#if !defined(HAVE_SEPRINTF)
inline char *
seprintf(char *dst, const char end[0], const char *restrict fmt, ...)
{
char *p;
va_list ap;

va_start(ap, fmt);
p = vseprintf(dst, end, fmt, ap);
va_end(ap);

return p;
}
#endif


#if !defined(HAVE_SEPRINTF)
inline char *
vseprintf(char *dst, const char end[0], const char *restrict fmt, va_list ap)
{
int len;
ptrdiff_t size;

if (dst == NULL)
return NULL;

size = end - dst;
len = vstprintf(dst, size, fmt, ap);
if (len == -1)
return NULL;

return dst + len;
}
#endif


#endif // include guard
16 changes: 0 additions & 16 deletions lib/string/sprintf/snprintf.c

This file was deleted.

63 changes: 0 additions & 63 deletions lib/string/sprintf/snprintf.h

This file was deleted.

17 changes: 0 additions & 17 deletions lib/string/sprintf/stpeprintf.c

This file was deleted.

Loading
Loading