]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login: simplify name creation
authorTobias Stoeckmann <tobias@stoeckmann.org>
Fri, 29 Dec 2023 17:07:55 +0000 (18:07 +0100)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Fri, 29 Dec 2023 17:07:55 +0000 (18:07 +0100)
The function xasprintf is simpler to handle than calling xstrncpy
and xstrdup for the same task.

Introduced buff variable to make the whole else-block look like the
if-block.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
login-utils/login.c

index 82f0cd9f7f1a7b9fa4224ad7a25868ae92cdd67b..9e9e02988909397024c43d67dfa7595cf8cd87dc 100644 (file)
@@ -1553,14 +1553,13 @@ int main(int argc, char **argv)
                child_argv[child_argc++] = "-c";
                child_argv[child_argc++] = buff;
        } else {
-               char tbuf[PATH_MAX + 2], *p;
-
-               tbuf[0] = '-';
-               xstrncpy(tbuf + 1, ((p = strrchr(pwd->pw_shell, '/')) ?
-                                   p + 1 : pwd->pw_shell), sizeof(tbuf) - 1);
+               char *buff, *p;
 
+               xasprintf(&buff, "-%.*s", PATH_MAX,
+                         ((p = strrchr(pwd->pw_shell, '/')) ?
+                         p + 1 : pwd->pw_shell));
                child_argv[child_argc++] = pwd->pw_shell;
-               child_argv[child_argc++] = xstrdup(tbuf);
+               child_argv[child_argc++] = buff;
        }
 
        child_argv[child_argc++] = NULL;