Skip to content

Commit

Permalink
lib/, src/: Use xaprintf() instead of xasprintf()
Browse files Browse the repository at this point in the history
This makes some temporary variables unnecessary.  They'll be removed in
the next commit.

Signed-off-by: Alejandro Colomar <[email protected]>
  • Loading branch information
alejandro-colomar committed Jan 2, 2025
1 parent af803c8 commit 14b995b
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 51 deletions.
4 changes: 2 additions & 2 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ libshadow_la_SOURCES = \
string/sprintf/snprintf.h \
string/sprintf/stpeprintf.c \
string/sprintf/stpeprintf.h \
string/sprintf/xasprintf.c \
string/sprintf/xasprintf.h \
string/sprintf/xaprintf.c \
string/sprintf/xaprintf.h \
string/strchr/strchrcnt.c \
string/strchr/strchrcnt.h \
string/strchr/stpspn.c \
Expand Down
6 changes: 3 additions & 3 deletions lib/copydir.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#endif /* WITH_ATTR */
#include "shadowlog.h"
#include "string/sprintf/aprintf.h"
#include "string/sprintf/xasprintf.h"
#include "string/sprintf/xaprintf.h"
#include "string/strcmp/streq.h"


Expand Down Expand Up @@ -233,7 +233,7 @@ static /*@exposed@*/ /*@null@*/struct link_name *check_link (const char *name, c
lp->ln_dev = sb->st_dev;
lp->ln_ino = sb->st_ino;
lp->ln_count = sb->st_nlink;
xasprintf(&lp->ln_name, "%s%s", dst_orig, name + strlen(src_orig));
lp->ln_name = xaprintf("%s%s", dst_orig, name + strlen(src_orig));
lp->ln_next = links;
links = lp;

Expand Down Expand Up @@ -580,7 +580,7 @@ static int copy_symlink (const struct path_info *src, const struct path_info *ds
if (strncmp(oldlink, src_orig, strlen(src_orig)) == 0) {
char *dummy;

xasprintf(&dummy, "%s%s", dst_orig, oldlink + strlen(src_orig));
dummy = xaprintf("%s%s", dst_orig, oldlink + strlen(src_orig));
free(oldlink);
oldlink = dummy;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "defines.h"
#include "shadowlog.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/xasprintf.h"
#include "string/sprintf/xaprintf.h"
#include "string/strdup/xstrdup.h"


Expand Down Expand Up @@ -77,7 +77,7 @@ void addenv (const char *string, /*@null@*/const char *value)
size_t i, n;

if (NULL != value) {
xasprintf(&newstring, "%s=%s", string, value);
newstring = xaprintf("%s=%s", string, value);
} else {
newstring = xstrdup (string);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/getdef.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "getdef.h"
#include "prototypes.h"
#include "shadowlog_internal.h"
#include "string/sprintf/xasprintf.h"
#include "string/sprintf/xaprintf.h"
#include "string/strchr/stpspn.h"
#include "string/strchr/strrspn.h"
#include "string/strcmp/streq.h"
Expand Down Expand Up @@ -455,10 +455,10 @@ void setdef_config_file (const char* file)
#ifdef USE_ECONF
char *cp;

xasprintf(&cp, "%s/%s", file, sysconfdir);
cp = xaprintf("%s/%s", file, sysconfdir);
sysconfdir = cp;
#ifdef VENDORDIR
xasprintf(&cp, "%s/%s", file, vendordir);
cp = xaprintf("%s/%s", file, vendordir);
vendordir = cp;
#endif
#else
Expand Down
4 changes: 2 additions & 2 deletions lib/mail.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <string.h>

#include "getdef.h"
#include "string/sprintf/xasprintf.h"
#include "string/sprintf/xaprintf.h"

#ident "$Id$"

Expand All @@ -37,7 +37,7 @@ void mailcheck (void)
if (NULL != mailbox) {
char *newmail;

xasprintf(&newmail, "%s/new", mailbox);
newmail = xaprintf("%s/new", mailbox);

if (stat (newmail, &statbuf) != -1 && statbuf.st_size != 0) {
if (statbuf.st_mtime > statbuf.st_atime) {
Expand Down
4 changes: 2 additions & 2 deletions lib/obscure.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "defines.h"
#include "getdef.h"
#include "string/memset/memzero.h"
#include "string/sprintf/xasprintf.h"
#include "string/sprintf/xaprintf.h"
#include "string/strcmp/streq.h"
#include "string/strdup/xstrdup.h"

Expand Down Expand Up @@ -102,7 +102,7 @@ static /*@observer@*//*@null@*/const char *password_check (

newmono = str_lower (xstrdup (new));
oldmono = str_lower (xstrdup (old));
xasprintf(&wrapped, "%s%s", oldmono, oldmono);
wrapped = xaprintf("%s%s", oldmono, oldmono);

if (palindrome (oldmono, newmono)) {
msg = _("a palindrome");
Expand Down
16 changes: 8 additions & 8 deletions lib/prefix_flag.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#endif /* ENABLE_SUBIDS */
#include "getdef.h"
#include "shadowlog.h"
#include "string/sprintf/xasprintf.h"
#include "string/sprintf/xaprintf.h"
#include "string/strcmp/streq.h"


Expand Down Expand Up @@ -109,32 +109,32 @@ extern const char* process_prefix_flag (const char* short_opt, int argc, char **
exit (E_BAD_ARG);
}

xasprintf(&passwd_db_file, "%s/%s", prefix, PASSWD_FILE);
passwd_db_file = xaprintf("%s/%s", prefix, PASSWD_FILE);
pw_setdbname(passwd_db_file);

xasprintf(&group_db_file, "%s/%s", prefix, GROUP_FILE);
group_db_file = xaprintf("%s/%s", prefix, GROUP_FILE);
gr_setdbname(group_db_file);

#ifdef SHADOWGRP
xasprintf(&sgroup_db_file, "%s/%s", prefix, SGROUP_FILE);
sgroup_db_file = xaprintf("%s/%s", prefix, SGROUP_FILE);
sgr_setdbname(sgroup_db_file);
#endif

xasprintf(&spw_db_file, "%s/%s", prefix, SHADOW_FILE);
spw_db_file = xaprintf("%s/%s", prefix, SHADOW_FILE);
spw_setdbname(spw_db_file);

#ifdef ENABLE_SUBIDS
xasprintf(&suid_db_file, "%s/%s", prefix, SUBUID_FILE);
suid_db_file = xaprintf("%s/%s", prefix, SUBUID_FILE);
sub_uid_setdbname(suid_db_file);

xasprintf(&sgid_db_file, "%s/%s", prefix, SUBGID_FILE);
sgid_db_file = xaprintf("%s/%s", prefix, SUBGID_FILE);
sub_gid_setdbname(sgid_db_file);
#endif

#ifdef USE_ECONF
setdef_config_file(prefix);
#else
xasprintf(&def_conf_file, "%s/%s", prefix, "/etc/login.defs");
def_conf_file = xaprintf("%s/%s", prefix, "/etc/login.defs");
setdef_config_file(def_conf_file);
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions lib/setupenv.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <pwd.h>
#include "getdef.h"
#include "shadowlog.h"
#include "string/sprintf/xasprintf.h"
#include "string/sprintf/xaprintf.h"
#include "string/strchr/stpspn.h"
#include "string/strcmp/streq.h"
#include "string/strdup/xstrdup.h"
Expand All @@ -39,7 +39,7 @@ addenv_path(const char *varname, const char *dirname, const char *filename)
{
char *buf;

xasprintf(&buf, "%s/%s", dirname, filename);
buf = xaprintf("%s/%s", dirname, filename);
addenv(varname, buf);
free(buf);
}
Expand Down
4 changes: 2 additions & 2 deletions src/passwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "shadowlog.h"
#include "sssd.h"
#include "string/memset/memzero.h"
#include "string/sprintf/xasprintf.h"
#include "string/sprintf/xaprintf.h"
#include "string/strcmp/streq.h"
#include "string/strcpy/strtcpy.h"
#include "string/strdup/xstrdup.h"
Expand Down Expand Up @@ -534,7 +534,7 @@ static char *update_crypt_pw (char *cp)
if (lflg && *cp != '!') {
char *newpw;

xasprintf(&newpw, "!%s", cp);
newpw = xaprintf("!%s", cp);
if (!use_pam)
{
if (do_update_pwd) {
Expand Down
4 changes: 2 additions & 2 deletions src/su.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
#include "prototypes.h"
#include "shadowlog.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/xasprintf.h"
#include "string/sprintf/xaprintf.h"
#include "string/strcmp/streq.h"
#include "string/strcpy/strtcpy.h"
#include "string/strdup/xstrdup.h"
Expand Down Expand Up @@ -1211,7 +1211,7 @@ int main (int argc, char **argv)
cp = Basename (shellstr);
}

xasprintf(&arg0, "-%s", cp);
arg0 = xaprintf("-%s", cp);
cp = arg0;
} else {
cp = Basename (shellstr);
Expand Down
14 changes: 7 additions & 7 deletions src/useradd.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
#include "string/memset/memzero.h"
#include "string/sprintf/aprintf.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/xasprintf.h"
#include "string/sprintf/xaprintf.h"
#include "string/strcmp/streq.h"
#include "string/strdup/xstrdup.h"
#include "string/strtok/stpsep.h"
Expand Down Expand Up @@ -447,7 +447,7 @@ get_defaults(void)
if (prefix[0]) {
char *dt;

xasprintf(&dt, "%s/%s", prefix, ccp);
dt = xaprintf("%s/%s", prefix, ccp);
def_template = dt;
} else {
def_template = xstrdup(ccp);
Expand All @@ -464,7 +464,7 @@ get_defaults(void)
if (prefix[0]) {
char *dut;

xasprintf(&dut, "%s/%s", prefix, ccp);
dut = xaprintf("%s/%s", prefix, ccp);
def_usrtemplate = dut;
} else {
def_usrtemplate = xstrdup(ccp);
Expand Down Expand Up @@ -1556,13 +1556,13 @@ static void process_flags (int argc, char **argv)
if (!dflg) {
char *uh;

xasprintf(&uh, "%s/%s", def_home, user_name);
uh = xaprintf("%s/%s", def_home, user_name);
user_home = uh;
}
if (prefix[0]) {
char *puh; /* to avoid const warning */

xasprintf(&puh, "%s/%s", prefix, user_home);
puh = xaprintf("%s/%s", prefix, user_home);
prefix_user_home = puh;
} else {
prefix_user_home = user_home;
Expand Down Expand Up @@ -2375,9 +2375,9 @@ static void create_mail (void)
return;
}
if (prefix[0])
xasprintf(&file, "%s/%s/%s", prefix, spool, user_name);
file = xaprintf("%s/%s/%s", prefix, spool, user_name);
else
xasprintf(&file, "%s/%s", spool, user_name);
file = xaprintf("%s/%s", spool, user_name);

#ifdef WITH_SELINUX
if (set_selinux_file_context(file, S_IFREG) != 0) {
Expand Down
8 changes: 4 additions & 4 deletions src/userdel.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#endif /* ENABLE_SUBIDS */
#include "shadowlog.h"
#include "string/sprintf/aprintf.h"
#include "string/sprintf/xasprintf.h"
#include "string/sprintf/xaprintf.h"
#include "string/strcmp/streq.h"
#include "string/strdup/xstrdup.h"

Expand Down Expand Up @@ -807,9 +807,9 @@ static int remove_mailbox (void)
}

if (prefix[0]) {
xasprintf(&mailfile, "%s/%s/%s", prefix, maildir, user_name);
mailfile = xaprintf("%s/%s/%s", prefix, maildir, user_name);
} else {
xasprintf(&mailfile, "%s/%s", maildir, user_name);
mailfile = xaprintf("%s/%s", maildir, user_name);
}

if (access (mailfile, F_OK) != 0) {
Expand Down Expand Up @@ -1117,7 +1117,7 @@ int main (int argc, char **argv)
user_gid = pwd->pw_gid;

if (prefix[0]) {
xasprintf(&user_home, "%s/%s", prefix, pwd->pw_dir);
user_home = xaprintf("%s/%s", prefix, pwd->pw_dir);
} else {
user_home = xstrdup(pwd->pw_dir);
}
Expand Down
20 changes: 10 additions & 10 deletions src/usermod.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
#include "shadowlog.h"
#include "sssd.h"
#include "string/memset/memzero.h"
#include "string/sprintf/xasprintf.h"
#include "string/sprintf/xaprintf.h"
#include "string/strcmp/streq.h"
#include "string/strdup/xstrdup.h"
#include "time/day_to_str.h"
Expand Down Expand Up @@ -434,7 +434,7 @@ static char *new_pw_passwd (char *pw_pass)
"updating passwd", user_newname, user_newid, 0);
#endif
SYSLOG ((LOG_INFO, "lock user '%s' password", user_newname));
xasprintf(&buf, "!%s", pw_pass);
buf = xaprintf("!%s", pw_pass);
pw_pass = buf;
} else if (Uflg && pw_pass[0] == '!') {
if (pw_pass[1] == '\0') {
Expand Down Expand Up @@ -1291,10 +1291,10 @@ process_flags(int argc, char **argv)
user_newgid = user_gid;
}
if (prefix[0]) {
xasprintf(&prefix_user_home, "%s/%s", prefix, user_home);
prefix_user_home = xaprintf("%s/%s", prefix, user_home);
if (user_newhome) {
xasprintf(&prefix_user_newhome, "%s/%s",
prefix, user_newhome);
prefix_user_newhome = xaprintf("%s/%s",
prefix, user_newhome);
}
} else {
prefix_user_home = user_home;
Expand Down Expand Up @@ -2068,9 +2068,9 @@ static void move_mailbox (void)
* between stat and chown). --marekm
*/
if (prefix[0]) {
xasprintf(&mailfile, "%s/%s/%s", prefix, maildir, user_name);
mailfile = xaprintf("%s/%s/%s", prefix, maildir, user_name);
} else {
xasprintf(&mailfile, "%s/%s", maildir, user_name);
mailfile = xaprintf("%s/%s", maildir, user_name);
}

fd = open (mailfile, O_RDONLY | O_NONBLOCK, 0);
Expand Down Expand Up @@ -2115,10 +2115,10 @@ static void move_mailbox (void)
char *newmailfile;

if (prefix[0]) {
xasprintf(&newmailfile, "%s/%s/%s",
prefix, maildir, user_newname);
newmailfile = xaprintf("%s/%s/%s",
prefix, maildir, user_newname);
} else {
xasprintf(&newmailfile, "%s/%s", maildir, user_newname);
newmailfile = xaprintf("%s/%s", maildir, user_newname);
}
if ( (link (mailfile, newmailfile) != 0)
|| (unlink (mailfile) != 0)) {
Expand Down
4 changes: 2 additions & 2 deletions src/vipw.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#include "sssd.h"
#include "string/sprintf/aprintf.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/xasprintf.h"
#include "string/sprintf/xaprintf.h"
#include "string/strcmp/streq.h"


Expand Down Expand Up @@ -308,7 +308,7 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (void))
continue;
}

xasprintf(&buf, "%s %s", editor, fileedit);
buf = xaprintf("%s %s", editor, fileedit);

status = system (buf);
if (-1 == status) {
Expand Down

0 comments on commit 14b995b

Please sign in to comment.