Skip to content

Commit

Permalink
lib/, src/, tests/: Rename snprintf() to stprintf()
Browse files Browse the repository at this point in the history
For consistency with strTcpy(), call it sTprintf().

Signed-off-by: Alejandro Colomar <[email protected]>
  • Loading branch information
alejandro-colomar committed Feb 8, 2025
1 parent 62d3f05 commit 0d74116
Show file tree
Hide file tree
Showing 24 changed files with 116 additions and 116 deletions.
4 changes: 2 additions & 2 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ libshadow_la_SOURCES = \
sssd.h \
string/memset/memzero.c \
string/memset/memzero.h \
string/sprintf/snprintf.c \
string/sprintf/snprintf.h \
string/sprintf/stpeprintf.c \
string/sprintf/stpeprintf.h \
string/sprintf/stprintf.c \
string/sprintf/stprintf.h \
string/sprintf/xasprintf.c \
string/sprintf/xasprintf.h \
string/strchr/strchrcnt.c \
Expand Down
12 changes: 6 additions & 6 deletions lib/commonio.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "shadowlog_internal.h"
#include "sssd.h"
#include "string/memset/memzero.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/stprintf.h"
#include "string/strcmp/streq.h"
#include "string/strtok/stpsep.h"

Expand Down Expand Up @@ -146,7 +146,7 @@ static int do_lock_file (const char *file, const char *lock, bool log)
}

pid = getpid ();
SNPRINTF(buf, "%lu", (unsigned long) pid);
STPRINTF(buf, "%lu", (unsigned long) pid);
len = (ssize_t) strlen (buf) + 1;
if (write_full(fd, buf, len) == -1) {
if (log) {
Expand Down Expand Up @@ -347,7 +347,7 @@ static void free_linked_list (struct commonio_db *db)

int commonio_setname (struct commonio_db *db, const char *name)
{
SNPRINTF(db->filename, "%s", name);
STPRINTF(db->filename, "%s", name);
db->setname = true;
return 1;
}
Expand Down Expand Up @@ -490,7 +490,7 @@ int commonio_unlock (struct commonio_db *db)
* then call ulckpwdf() (if used) on last unlock.
*/
db->locked = false;
SNPRINTF(lock, "%s.lock", db->filename);
STPRINTF(lock, "%s.lock", db->filename);
unlink (lock);
dec_lock_count ();
return 1;
Expand Down Expand Up @@ -924,7 +924,7 @@ int commonio_close (struct commonio_db *db)
/*
* Create backup file.
*/
if (SNPRINTF(buf, "%s-", db->filename) == -1) {
if (STPRINTF(buf, "%s-", db->filename) == -1) {
(void) fclose (db->fp);
db->fp = NULL;
goto fail;
Expand Down Expand Up @@ -961,7 +961,7 @@ int commonio_close (struct commonio_db *db)
sb.st_gid = db->st_gid;
}

if (SNPRINTF(buf, "%s+", db->filename) == -1)
if (STPRINTF(buf, "%s+", db->filename) == -1)
goto fail;

#ifdef WITH_SELINUX
Expand Down
4 changes: 2 additions & 2 deletions lib/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "prototypes.h"
#include "defines.h"
#include "shadowlog.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/stprintf.h"
#include "string/sprintf/xasprintf.h"
#include "string/strdup/xstrdup.h"

Expand Down Expand Up @@ -168,7 +168,7 @@ void set_env (int argc, char *const *argv)

cp = strchr (*argv, '=');
if (NULL == cp) {
assert(SNPRINTF(variable, "L%d", noname) != -1);
assert(STPRINTF(variable, "L%d", noname) != -1);
noname++;
addenv (variable, *argv);
} else {
Expand Down
6 changes: 3 additions & 3 deletions lib/get_pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <fcntl.h>

#include "atoi/getnum.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/stprintf.h"


/*
Expand Down Expand Up @@ -59,8 +59,8 @@ int open_pidfd(const char *pidstr)
return -ENOENT;

/* max string length is 6 + 10 + 1 + 1 = 18, allocate 32 bytes */
if (SNPRINTF(proc_dir_name, "/proc/%u/", target) == -1) {
fprintf(stderr, "snprintf of proc path failed for %u: %s\n",
if (STPRINTF(proc_dir_name, "/proc/%u/", target) == -1) {
fprintf(stderr, "stprintf of proc path failed for %u: %s\n",
target, strerror(errno));
return -EINVAL;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/hushed.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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 Expand Up @@ -60,7 +60,7 @@ bool hushed (const char *username)
*/

if (hushfile[0] != '/') {
SNPRINTF(buf, "%s/%s", pw->pw_dir, hushfile);
STPRINTF(buf, "%s/%s", pw->pw_dir, hushfile);
return (access (buf, F_OK) == 0);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/nss.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "../libsubid/subid.h"
#include "shadowlog_internal.h"
#include "shadowlog.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/stprintf.h"
#include "string/strchr/stpspn.h"
#include "string/strcmp/streq.h"
#include "string/strtok/stpsep.h"
Expand Down Expand Up @@ -107,7 +107,7 @@ nss_init(const char *nsswitch_path) {
fprintf(shadow_logfd, "Using files\n");
goto null_subid;
}
SNPRINTF(libname, "libsubid_%s.so", p);
STPRINTF(libname, "libsubid_%s.so", p);
h = dlopen(libname, RTLD_LAZY);
if (!h) {
fprintf(shadow_logfd, "Error opening %s: %s\n", libname, dlerror());
Expand Down
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -111,7 +111,7 @@ pw_auth(const char *cipher, const char *user)
}
#endif

SNPRINTF(prompt, cp, user);
STPRINTF(prompt, cp, user);
clear = agetpass(prompt);
input = (clear == NULL) ? "" : clear;

Expand Down
6 changes: 3 additions & 3 deletions 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 Expand Up @@ -48,7 +48,7 @@ int shell (const char *file, /*@null@*/const char *arg, char *const envp[])
* don't want to tell us what it is themselves.
*/
if (arg == NULL) {
SNPRINTF(arg0, "-%s", Basename(file));
STPRINTF(arg0, "-%s", Basename(file));
arg = arg0;
}

Expand All @@ -74,7 +74,7 @@ int shell (const char *file, /*@null@*/const char *arg, char *const envp[])
* how to execute this stupid shell, so I might as well give
* up in disgust ...
*/
SNPRINTF(arg0, _("Cannot execute %s"), file);
STPRINTF(arg0, _("Cannot execute %s"), file);
errno = err;
perror (arg0);
return err;
Expand Down
4 changes: 2 additions & 2 deletions lib/string/sprintf/stpeprintf.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <stddef.h>

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


#if !defined(HAVE_STPEPRINTF)
Expand Down Expand Up @@ -98,7 +98,7 @@ vstpeprintf(char *dst, char *end, const char *restrict fmt, va_list ap)
return NULL;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

#include <config.h>

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

#include <stdarg.h>


extern inline int snprintf_(char *restrict s, int size,
extern inline int stprintf(char *restrict s, int size,
const char *restrict fmt, ...);
extern inline int vsnprintf_(char *restrict s, int size,
extern inline int vstprintf(char *restrict s, int size,
const char *restrict fmt, va_list ap);
20 changes: 10 additions & 10 deletions lib/string/sprintf/snprintf.h → lib/string/sprintf/stprintf.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-License-Identifier: BSD-3-Clause


#ifndef SHADOW_INCLUDE_LIB_STRING_SPRINTF_SNPRINTF_H_
#define SHADOW_INCLUDE_LIB_STRING_SPRINTF_SNPRINTF_H_
#ifndef SHADOW_INCLUDE_LIB_STRING_SPRINTF_STPRINTF_H_
#define SHADOW_INCLUDE_LIB_STRING_SPRINTF_STPRINTF_H_


#include <config.h>
Expand All @@ -16,35 +16,35 @@
#include "sizeof.h"


#define SNPRINTF(s, fmt, ...) \
( \
snprintf_(s, NITEMS(s), fmt __VA_OPT__(,) __VA_ARGS__) \
#define STPRINTF(s, fmt, ...) \
( \
stprintf(s, NITEMS(s), fmt __VA_OPT__(,) __VA_ARGS__) \
)


format_attr(printf, 3, 4)
inline int snprintf_(char *restrict s, int size, const char *restrict fmt, ...);
inline int stprintf(char *restrict s, int size, const char *restrict fmt, ...);
format_attr(printf, 3, 0)
inline int vsnprintf_(char *restrict s, int size, const char *restrict fmt,
inline int vstprintf(char *restrict s, int size, const char *restrict fmt,
va_list ap);


inline int
snprintf_(char *restrict s, int size, const char *restrict fmt, ...)
stprintf(char *restrict s, int size, const char *restrict fmt, ...)
{
int len;
va_list ap;

va_start(ap, fmt);
len = vsnprintf_(s, size, fmt, ap);
len = vstprintf(s, size, fmt, ap);
va_end(ap);

return len;
}


inline int
vsnprintf_(char *restrict s, int size, const char *restrict fmt, va_list ap)
vstprintf(char *restrict s, int size, const char *restrict fmt, va_list ap)
{
int len;

Expand Down
8 changes: 4 additions & 4 deletions lib/subordinateio.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "alloc/realloc.h"
#include "alloc/reallocf.h"
#include "atoi/str2i/str2u.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/stprintf.h"
#include "string/strcmp/streq.h"


Expand Down Expand Up @@ -236,7 +236,7 @@ static const struct subordinate_range *find_range(struct commonio_db *db,
return NULL;
}
owner_uid = pwd->pw_uid;
if (SNPRINTF(owner_uid_string, "%lu", (unsigned long) owner_uid) == -1)
if (STPRINTF(owner_uid_string, "%lu", (unsigned long) owner_uid) == -1)
return NULL;

commonio_rewind(db);
Expand Down Expand Up @@ -814,15 +814,15 @@ static bool get_owner_id(const char *owner, enum subid_type id_type, char *id)
if (pw == NULL) {
return false;
}
if (snprintf_(id, ID_SIZE, "%u", pw->pw_uid) == -1)
if (stprintf(id, ID_SIZE, "%u", pw->pw_uid) == -1)
return false;
break;
case ID_TYPE_GID:
gr = getgrnam(owner);
if (gr == NULL) {
return false;
}
if (snprintf_(id, ID_SIZE, "%u", gr->gr_gid) == -1)
if (stprintf(id, ID_SIZE, "%u", gr->gr_gid) == -1)
return false;
break;
default:
Expand Down
10 changes: 5 additions & 5 deletions lib/user_busy.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "subordinateio.h"
#endif /* ENABLE_SUBIDS */
#include "shadowlog.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/stprintf.h"
#include "string/strcmp/streq.h"


Expand Down Expand Up @@ -96,7 +96,7 @@ static int different_namespace (const char *sname)
char path[41];
char buf[512], buf2[512];

SNPRINTF(path, "/proc/%s/ns/user", sname);
STPRINTF(path, "/proc/%s/ns/user", sname);

if (READLINKNUL(path, buf) == -1)
return 0;
Expand All @@ -119,7 +119,7 @@ static int check_status (const char *name, const char *sname, uid_t uid)
char line[1024];
FILE *sfile;

SNPRINTF(status, "/proc/%s/status", sname);
STPRINTF(status, "/proc/%s/status", sname);

sfile = fopen (status, "r");
if (NULL == sfile) {
Expand Down Expand Up @@ -214,7 +214,7 @@ static int user_busy_processes (const char *name, uid_t uid)
}

/* Check if the process is in our chroot */
SNPRINTF(root_path, "/proc/%lu/root", (unsigned long) pid);
STPRINTF(root_path, "/proc/%lu/root", (unsigned long) pid);
if (stat (root_path, &sbroot_process) != 0) {
continue;
}
Expand All @@ -234,7 +234,7 @@ static int user_busy_processes (const char *name, uid_t uid)
return 1;
}

SNPRINTF(task_path, "/proc/%lu/task", (unsigned long) pid);
STPRINTF(task_path, "/proc/%lu/task", (unsigned long) pid);
task_dir = opendir (task_path);
if (task_dir != NULL) {
while ((ent = readdir (task_dir)) != NULL) {
Expand Down
6 changes: 3 additions & 3 deletions src/chage.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "shadowio.h"
#include "shadowlog.h"
#include "string/memset/memzero.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/stprintf.h"
#include "string/strcmp/streq.h"
#include "string/strcpy/strtcpy.h"
#include "string/strdup/xstrdup.h"
Expand Down Expand Up @@ -165,12 +165,12 @@ static int new_fields (void)
(void) puts (_("Enter the new value, or press ENTER for the default"));
(void) puts ("");

SNPRINTF(buf, "%ld", mindays);
STPRINTF(buf, "%ld", mindays);
change_field (buf, sizeof buf, _("Minimum Password Age"));
if (a2sl(&mindays, buf, NULL, 0, -1, LONG_MAX) == -1)
return 0;

SNPRINTF(buf, "%ld", maxdays);
STPRINTF(buf, "%ld", maxdays);
change_field (buf, sizeof buf, _("Maximum Password Age"));
if (a2sl(&maxdays, buf, NULL, 0, -1, LONG_MAX) == -1)
return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/chfn.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "pwio.h"
#include "shadowlog.h"
#include "sssd.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/stprintf.h"
#include "string/strcmp/streq.h"
#include "string/strcpy/strtcpy.h"
#include "string/strdup/xstrdup.h"
Expand Down Expand Up @@ -700,7 +700,7 @@ int main (int argc, char **argv)
fprintf (stderr, _("%s: fields too long\n"), Prog);
fail_exit (E_NOPERM);
}
SNPRINTF(new_gecos, "%s,%s,%s,%s%s%s",
STPRINTF(new_gecos, "%s,%s,%s,%s%s%s",
fullnm, roomno, workph, homeph,
(!streq(slop, "")) ? "," : "", slop);

Expand Down
Loading

0 comments on commit 0d74116

Please sign in to comment.