Bring back some C89/C90 elements
dmesg: don't use VLAs getty, su: no need to use compound literals
This commit is contained in:
parent
8ab8a4cad0
commit
5a2f3c85b7
6
dmesg.c
6
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')
|
||||
|
2
getty.c
2
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);
|
||||
}
|
||||
|
5
su.c
5
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);
|
||||
|
Loading…
Reference in New Issue
Block a user