1
0
mirror of git://git.suckless.org/ubase synced 2024-12-17 20:24:45 +00:00

Stop using *_FILENO

This commit is contained in:
sin 2014-11-30 13:12:15 +00:00
parent 2d45a04b92
commit 10d6bf2f4d
9 changed files with 20 additions and 22 deletions

View File

@ -60,7 +60,7 @@ main(int argc, char *argv[])
if (n < 0) if (n < 0)
eprintf("klogctl:"); eprintf("klogctl:");
dmesg_show(STDOUT_FILENO, buf, n); dmesg_show(1, buf, n);
if (cflag && klogctl(SYSLOG_ACTION_CLEAR, NULL, 0) < 0) if (cflag && klogctl(SYSLOG_ACTION_CLEAR, NULL, 0) < 0)
eprintf("klogctl:"); eprintf("klogctl:");

10
getty.c
View File

@ -73,9 +73,9 @@ main(int argc, char *argv[])
fd = open(tty, O_RDWR); fd = open(tty, O_RDWR);
if (fd < 0) if (fd < 0)
eprintf("open %s:", tty); eprintf("open %s:", tty);
dup2(fd, STDIN_FILENO); dup2(fd, 0);
dup2(fd, STDOUT_FILENO); dup2(fd, 1);
dup2(fd, STDERR_FILENO); dup2(fd, 2);
if (fchown(fd, 0, 0) < 0) if (fchown(fd, 0, 0) < 0)
weprintf("fchown %s:", tty); weprintf("fchown %s:", tty);
if (fchmod(fd, 0600) < 0) if (fchmod(fd, 0600) < 0)
@ -118,10 +118,10 @@ main(int argc, char *argv[])
fflush(stdout); fflush(stdout);
/* Flush pending input */ /* Flush pending input */
ioctl(STDIN_FILENO, TCFLSH, (void *)0); ioctl(0, TCFLSH, (void *)0);
memset(logname, 0, sizeof(logname)); memset(logname, 0, sizeof(logname));
while (1) { while (1) {
n = read(STDIN_FILENO, &c, 1); n = read(0, &c, 1);
if (n < 0) if (n < 0)
eprintf("read:"); eprintf("read:");
if (n == 0) if (n == 0)

View File

@ -88,7 +88,7 @@ main(int argc, char *argv[])
gid = pw->pw_gid; gid = pw->pw_gid;
/* Flush pending input */ /* Flush pending input */
ioctl(STDIN_FILENO, TCFLSH, (void *)0); ioctl(0, TCFLSH, (void *)0);
pass = getpass("Password: "); pass = getpass("Password: ");
if (!pass) if (!pass)
@ -96,7 +96,7 @@ main(int argc, char *argv[])
if (pw_check(pw, pass) <= 0) if (pw_check(pw, pass) <= 0)
exit(1); exit(1);
tty = ttyname(STDIN_FILENO); tty = ttyname(0);
if (!tty) if (!tty)
eprintf("ttyname:"); eprintf("ttyname:");

6
mesg.c
View File

@ -28,10 +28,10 @@ main(int argc, char *argv[])
if (argc > 1) if (argc > 1)
usage(); usage();
if (isatty(STDERR_FILENO) == 0) if (isatty(2) == 0)
eprintf("stderr: not a tty\n"); eprintf("stderr: not a tty\n");
if (fstat(STDERR_FILENO, &sb) < 0) if (fstat(2, &sb) < 0)
eprintf("fstat stderr:"); eprintf("fstat stderr:");
if (argc == 0) { if (argc == 0) {
@ -46,7 +46,7 @@ main(int argc, char *argv[])
else else
usage(); usage();
if (fchmod(STDERR_FILENO, mode) < 0) if (fchmod(2, mode) < 0)
eprintf("fchmod stderr:"); eprintf("fchmod stderr:");
return 0; return 0;

View File

@ -176,7 +176,7 @@ main(int argc, char *argv[])
} }
/* Flush pending input */ /* Flush pending input */
ioctl(STDIN_FILENO, TCFLSH, (void *)0); ioctl(0, TCFLSH, (void *)0);
if (getuid() == 0) { if (getuid() == 0) {
goto newpass; goto newpass;
@ -220,7 +220,7 @@ newpass:
eprintf("password left unchanged\n"); eprintf("password left unchanged\n");
/* Flush pending input */ /* Flush pending input */
ioctl(STDIN_FILENO, TCFLSH, (void *)0); ioctl(0, TCFLSH, (void *)0);
inpass = getpass("Retype new password: "); inpass = getpass("Retype new password: ");
if (!inpass) if (!inpass)

4
ps.c
View File

@ -104,7 +104,7 @@ psout(struct procstat *ps)
* the same controlling terminal as the invoker and the same * the same controlling terminal as the invoker and the same
* euid as the current user */ * euid as the current user */
if (!(flags & (PS_aflag | PS_Aflag | PS_dflag))) { if (!(flags & (PS_aflag | PS_Aflag | PS_dflag))) {
myttystr = ttyname(STDIN_FILENO); myttystr = ttyname(0);
if (myttystr) { if (myttystr) {
if (strcmp(myttystr + strlen("/dev/"), ttystr)) { if (strcmp(myttystr + strlen("/dev/"), ttystr)) {
free(ttystr); free(ttystr);
@ -125,7 +125,7 @@ psout(struct procstat *ps)
sutime = (ps->stime + ps->utime) / sysconf(_SC_CLK_TCK); sutime = (ps->stime + ps->utime) / sysconf(_SC_CLK_TCK);
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); ioctl(1, TIOCGWINSZ, &w);
if (!(flags & PS_fflag)) { if (!(flags & PS_fflag)) {
snprintf(buf, sizeof(buf), "%5d %-6s %02u:%02u:%02u %s", ps->pid, ttystr, snprintf(buf, sizeof(buf), "%5d %-6s %02u:%02u:%02u %s", ps->pid, ttystr,
sutime / 3600, (sutime % 3600) / 60, sutime % 60, sutime / 3600, (sutime % 3600) / 60, sutime % 60,

2
stat.c
View File

@ -41,7 +41,7 @@ main(int argc, char *argv[])
} ARGEND; } ARGEND;
if (argc == 0) { if (argc == 0) {
if (fstat(STDIN_FILENO, &st) < 0) if (fstat(0, &st) < 0)
eprintf("stat <stdin>:"); eprintf("stat <stdin>:");
show_stat("<stdin>", &st); show_stat("<stdin>", &st);
} }

View File

@ -117,13 +117,11 @@ main(int argc, char *argv[])
/* if -c is set, redirect stdin/stdout/stderr to console */ /* if -c is set, redirect stdin/stdout/stderr to console */
if (console) { if (console) {
close(STDIN_FILENO); close(0);
if (open(console, O_RDWR) == -1) if (open(console, O_RDWR) == -1)
eprintf("open %s:", console); eprintf("open %s:", console);
if (dup2(STDIN_FILENO, STDOUT_FILENO) != STDOUT_FILENO) dup2(0, 1);
eprintf("dup2 %s:", "stdin,stdout"); dup2(0, 2);
if (dup2(STDIN_FILENO, STDERR_FILENO) != STDERR_FILENO)
eprintf("dup2 %s:", "stdin,stderr");
} }
/* execute init */ /* execute init */

2
who.c
View File

@ -28,7 +28,7 @@ main(int argc, char *argv[])
ARGBEGIN { ARGBEGIN {
case 'm': case 'm':
mflag = 1; mflag = 1;
tty = ttyname(STDIN_FILENO); tty = ttyname(0);
if (!tty) if (!tty)
eprintf("ttyname: stdin:"); eprintf("ttyname: stdin:");
if ((ttmp = strrchr(tty, '/'))) if ((ttmp = strrchr(tty, '/')))