commit 5a2f3c85b7baf5c5d920b8579ad3178b26592366
parent 8ab8a4cad0dbde39baefd2e6753202110f651671
Author: FRIGN <dev@frign.de>
Date: Thu, 5 Jun 2014 11:28:08 +0100
Bring back some C89/C90 elements
dmesg: don't use VLAs
getty, su: no need to use compound literals
Diffstat:
3 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/dmesg.c b/dmesg.c
@@ -80,12 +80,13 @@ static int
dmesg_show(int fd, const void *buf, size_t n)
{
int last = '\n';
- char newbuf[n], *q = newbuf;
+ char *newbuf, *q;
const char *p = buf;
ssize_t r;
size_t i;
- memset(newbuf, 0, n);
+ newbuf = calloc(n, sizeof(char));
+ q = newbuf;
for (i = 0; i < n; ) {
if (last == '\n' && p[i] == '<') {
i += 2;
@@ -97,6 +98,7 @@ dmesg_show(int fd, const void *buf, size_t n)
last = p[i++];
}
r = write(fd, newbuf, n);
+ free(newbuf);
if(r < 0 || (size_t)r != n)
return -1;
if (last != '\n')
diff --git a/getty.c b/getty.c
@@ -109,5 +109,5 @@ main(int argc, char *argv[])
eprintf("login name cannot start with '-'\n");
if (logname[0] == '\0')
return EXIT_FAILURE;
- return execvp("/bin/login", (char *[]){ "login", "-p", logname, NULL });
+ return execlp("/bin/login", "login", "-p", logname, NULL);
}
diff --git a/su.c b/su.c
@@ -30,9 +30,9 @@ int
main(int argc, char *argv[])
{
char *usr = "root", *pass, *cryptpass;
- char * const *newargv;
struct spwd *spw;
struct passwd *pw;
+ char *newargv[2];
uid_t uid;
ARGBEGIN {
@@ -120,7 +120,8 @@ dosu:
if (lflag) {
return dologin(pw);
} else {
- newargv = (char *const[]){pw->pw_shell, NULL};
+ newargv[0] = pw->pw_shell;
+ newargv[1] = NULL;
if (!pflag) {
setenv("HOME", pw->pw_dir, 1);
setenv("SHELL", pw->pw_shell, 1);