mirror of git://git.suckless.org/ubase
Stop using *_FILENO
This commit is contained in:
parent
2d45a04b92
commit
10d6bf2f4d
2
dmesg.c
2
dmesg.c
|
@ -60,7 +60,7 @@ main(int argc, char *argv[])
|
|||
if (n < 0)
|
||||
eprintf("klogctl:");
|
||||
|
||||
dmesg_show(STDOUT_FILENO, buf, n);
|
||||
dmesg_show(1, buf, n);
|
||||
|
||||
if (cflag && klogctl(SYSLOG_ACTION_CLEAR, NULL, 0) < 0)
|
||||
eprintf("klogctl:");
|
||||
|
|
10
getty.c
10
getty.c
|
@ -73,9 +73,9 @@ main(int argc, char *argv[])
|
|||
fd = open(tty, O_RDWR);
|
||||
if (fd < 0)
|
||||
eprintf("open %s:", tty);
|
||||
dup2(fd, STDIN_FILENO);
|
||||
dup2(fd, STDOUT_FILENO);
|
||||
dup2(fd, STDERR_FILENO);
|
||||
dup2(fd, 0);
|
||||
dup2(fd, 1);
|
||||
dup2(fd, 2);
|
||||
if (fchown(fd, 0, 0) < 0)
|
||||
weprintf("fchown %s:", tty);
|
||||
if (fchmod(fd, 0600) < 0)
|
||||
|
@ -118,10 +118,10 @@ main(int argc, char *argv[])
|
|||
fflush(stdout);
|
||||
|
||||
/* Flush pending input */
|
||||
ioctl(STDIN_FILENO, TCFLSH, (void *)0);
|
||||
ioctl(0, TCFLSH, (void *)0);
|
||||
memset(logname, 0, sizeof(logname));
|
||||
while (1) {
|
||||
n = read(STDIN_FILENO, &c, 1);
|
||||
n = read(0, &c, 1);
|
||||
if (n < 0)
|
||||
eprintf("read:");
|
||||
if (n == 0)
|
||||
|
|
4
login.c
4
login.c
|
@ -88,7 +88,7 @@ main(int argc, char *argv[])
|
|||
gid = pw->pw_gid;
|
||||
|
||||
/* Flush pending input */
|
||||
ioctl(STDIN_FILENO, TCFLSH, (void *)0);
|
||||
ioctl(0, TCFLSH, (void *)0);
|
||||
|
||||
pass = getpass("Password: ");
|
||||
if (!pass)
|
||||
|
@ -96,7 +96,7 @@ main(int argc, char *argv[])
|
|||
if (pw_check(pw, pass) <= 0)
|
||||
exit(1);
|
||||
|
||||
tty = ttyname(STDIN_FILENO);
|
||||
tty = ttyname(0);
|
||||
if (!tty)
|
||||
eprintf("ttyname:");
|
||||
|
||||
|
|
6
mesg.c
6
mesg.c
|
@ -28,10 +28,10 @@ main(int argc, char *argv[])
|
|||
if (argc > 1)
|
||||
usage();
|
||||
|
||||
if (isatty(STDERR_FILENO) == 0)
|
||||
if (isatty(2) == 0)
|
||||
eprintf("stderr: not a tty\n");
|
||||
|
||||
if (fstat(STDERR_FILENO, &sb) < 0)
|
||||
if (fstat(2, &sb) < 0)
|
||||
eprintf("fstat stderr:");
|
||||
|
||||
if (argc == 0) {
|
||||
|
@ -46,7 +46,7 @@ main(int argc, char *argv[])
|
|||
else
|
||||
usage();
|
||||
|
||||
if (fchmod(STDERR_FILENO, mode) < 0)
|
||||
if (fchmod(2, mode) < 0)
|
||||
eprintf("fchmod stderr:");
|
||||
|
||||
return 0;
|
||||
|
|
4
passwd.c
4
passwd.c
|
@ -176,7 +176,7 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
/* Flush pending input */
|
||||
ioctl(STDIN_FILENO, TCFLSH, (void *)0);
|
||||
ioctl(0, TCFLSH, (void *)0);
|
||||
|
||||
if (getuid() == 0) {
|
||||
goto newpass;
|
||||
|
@ -220,7 +220,7 @@ newpass:
|
|||
eprintf("password left unchanged\n");
|
||||
|
||||
/* Flush pending input */
|
||||
ioctl(STDIN_FILENO, TCFLSH, (void *)0);
|
||||
ioctl(0, TCFLSH, (void *)0);
|
||||
|
||||
inpass = getpass("Retype new password: ");
|
||||
if (!inpass)
|
||||
|
|
4
ps.c
4
ps.c
|
@ -104,7 +104,7 @@ psout(struct procstat *ps)
|
|||
* the same controlling terminal as the invoker and the same
|
||||
* euid as the current user */
|
||||
if (!(flags & (PS_aflag | PS_Aflag | PS_dflag))) {
|
||||
myttystr = ttyname(STDIN_FILENO);
|
||||
myttystr = ttyname(0);
|
||||
if (myttystr) {
|
||||
if (strcmp(myttystr + strlen("/dev/"), ttystr)) {
|
||||
free(ttystr);
|
||||
|
@ -125,7 +125,7 @@ psout(struct procstat *ps)
|
|||
|
||||
sutime = (ps->stime + ps->utime) / sysconf(_SC_CLK_TCK);
|
||||
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
||||
ioctl(1, TIOCGWINSZ, &w);
|
||||
if (!(flags & PS_fflag)) {
|
||||
snprintf(buf, sizeof(buf), "%5d %-6s %02u:%02u:%02u %s", ps->pid, ttystr,
|
||||
sutime / 3600, (sutime % 3600) / 60, sutime % 60,
|
||||
|
|
2
stat.c
2
stat.c
|
@ -41,7 +41,7 @@ main(int argc, char *argv[])
|
|||
} ARGEND;
|
||||
|
||||
if (argc == 0) {
|
||||
if (fstat(STDIN_FILENO, &st) < 0)
|
||||
if (fstat(0, &st) < 0)
|
||||
eprintf("stat <stdin>:");
|
||||
show_stat("<stdin>", &st);
|
||||
}
|
||||
|
|
|
@ -117,13 +117,11 @@ main(int argc, char *argv[])
|
|||
|
||||
/* if -c is set, redirect stdin/stdout/stderr to console */
|
||||
if (console) {
|
||||
close(STDIN_FILENO);
|
||||
close(0);
|
||||
if (open(console, O_RDWR) == -1)
|
||||
eprintf("open %s:", console);
|
||||
if (dup2(STDIN_FILENO, STDOUT_FILENO) != STDOUT_FILENO)
|
||||
eprintf("dup2 %s:", "stdin,stdout");
|
||||
if (dup2(STDIN_FILENO, STDERR_FILENO) != STDERR_FILENO)
|
||||
eprintf("dup2 %s:", "stdin,stderr");
|
||||
dup2(0, 1);
|
||||
dup2(0, 2);
|
||||
}
|
||||
|
||||
/* execute init */
|
||||
|
|
Loading…
Reference in New Issue