int main(void)
{
- write(1, usage_messages, sizeof(usage_messages));
+ write(STDOUT_FILENO, usage_messages, sizeof(usage_messages));
return 0;
}
if (i < 0)
fprintf(stderr,"%s\n", bunzip_errors[-i]);
- else if (read(0, &c, 1))
+ else if (read(STDIN_FILENO, &c, 1))
fprintf(stderr,"Trailing garbage ignored\n");
return -i;
}
}
while (1) {
- bytes_read = safe_read(0, read_buffer, READ_BUFFER_SIZE);
+ bytes_read = safe_read(STDIN_FILENO, read_buffer, READ_BUFFER_SIZE);
if (!bytes_read)
break;
if (bytes_read < 0)
}
}
- xwrite(1, src, to_write);
+ xwrite(STDOUT_FILENO, src, to_write);
bytes_read -= to_write;
src += to_write;
} while (bytes_read);
while (num1 <= num2) {
if (!expandFlag) {
- write(1, lp->data, lp->len);
+ write(STDOUT_FILENO, lp->data, lp->len);
setCurNum(num1++);
lp = lp->next;
continue;
// get input from User- are there already input chars in Q?
if (n <= 0) {
// the Q is empty, wait for a typed char
- n = safe_read(0, readbuffer, sizeof(readbuffer));
+ n = safe_read(STDIN_FILENO, readbuffer, sizeof(readbuffer));
if (n < 0) {
if (errno == EBADF || errno == EFAULT || errno == EINVAL
|| errno == EIO)
&& ((size_t)n <= (sizeof(readbuffer) - 8))
) {
// read the rest of the ESC string
- int r = safe_read(0, readbuffer + n, sizeof(readbuffer) - n);
+ int r = safe_read(STDIN_FILENO, readbuffer + n, sizeof(readbuffer) - n);
if (r > 0)
n += r;
}
printf("\n\n%d: \'%c\' %s\n\n\n%s[Hit return to continue]%s",
totalcmds, last_input_char, msg, SOs, SOn);
fflush(stdout);
- while (safe_read(0, d, 1) > 0) {
+ while (safe_read(STDIN_FILENO, d, 1) > 0) {
if (d[0] == '\n' || d[0] == '\r')
break;
}
if (where & L_CONSOLE) {
/* Send console messages to console so people will see them. */
- full_write(2, msg, l);
+ full_write(STDERR_FILENO, msg, l);
}
}
messageD(L_LOG, "waiting for enter to start '%s'"
"(pid %d, tty '%s')\n",
a->command, getpid(), a->terminal);
- full_write(1, press_enter, sizeof(press_enter) - 1);
- while (safe_read(0, &c, 1) == 1 && c != '\n')
+ full_write(STDOUT_FILENO, press_enter, sizeof(press_enter) - 1);
+ while (safe_read(STDIN_FILENO, &c, 1) == 1 && c != '\n')
continue;
}
static void full_write2_str(const char *str)
{
- full_write(2, str, strlen(str));
+ full_write(STDERR_FILENO, str, strlen(str));
}
void bb_show_usage(void)
if (logmode & LOGMODE_STDIO) {
fflush(stdout);
- full_write(2, msg, used + msgeol_len);
+ full_write(STDERR_FILENO, msg, used + msgeol_len);
}
if (logmode & LOGMODE_SYSLOG) {
syslog(LOG_ERR, "%s", msg + applet_len);
* try to extract the speed of the dial-in call.
*/
sleep(1);
- nread = safe_read(0, buf, size_buf - 1);
+ nread = safe_read(STDIN_FILENO, buf, size_buf - 1);
if (nread > 0) {
buf[nread] = '\0';
for (bp = buf; bp < buf + nread; bp++) {
while (cp->eol == '\0') {
/* Do not report trivial EINTR/EIO errors. */
- if (read(0, &c, 1) < 1) {
+ if (read(STDIN_FILENO, &c, 1) < 1) {
if (errno == EINTR || errno == EIO)
exit(EXIT_SUCCESS);
bb_perror_msg_and_die("%s: read", op->tty);
#endif
cp->erase = ascval; /* set erase character */
if (bp > logname) {
- full_write(1, erase[cp->parity], 3);
+ full_write(STDOUT_FILENO, erase[cp->parity], 3);
bp--;
}
break;
#endif
cp->kill = ascval; /* set kill character */
while (bp > logname) {
- full_write(1, erase[cp->parity], 3);
+ full_write(STDOUT_FILENO, erase[cp->parity], 3);
bp--;
}
break;
} else if ((int)(bp - logname) >= size_logname - 1) {
bb_error_msg_and_die("%s: input overrun", op->tty);
} else {
- full_write(1, &c, 1); /* echo the character */
+ full_write(STDOUT_FILENO, &c, 1); /* echo the character */
*bp++ = ascval; /* and store it */
}
break;
/* Write the modem init string and DON'T flush the buffers */
if (options.flags & F_INITSTRING) {
debug("writing init string\n");
- full_write(1, options.initstring, strlen(options.initstring));
+ full_write(STDOUT_FILENO, options.initstring, strlen(options.initstring));
}
/* Optionally detect the baud rate from the modem status message */
char ch;
debug("waiting for cr-lf\n");
- while (safe_read(0, &ch, 1) == 1) {
+ while (safe_read(STDIN_FILENO, &ch, 1) == 1) {
debug("read %x\n", (unsigned char)ch);
ch &= 0x7f; /* strip "parity bit" */
if (ch == '\n' || ch == '\r')
termios_final(&options, &termios, &chardata);
/* Now the newline character should be properly written. */
- full_write(1, "\n", 1);
+ full_write(STDOUT_FILENO, "\n", 1);
/* Let the login program take care of password validation. */
/* We use PATH because we trust that root doesn't set "bad" PATH,
unsigned char *b = (unsigned char *)buf;
int i;
- xread(0, buf, 1280);
+ xread(STDIN_FILENO, buf, 1280);
// Convert the newline-separated hex data into an identify block.
/* if no unprocessed chars left, eat more */
if (readpos >= readeof) {
ndelay_on(0);
- eof_error = safe_read(0, readbuf, sizeof(readbuf));
+ eof_error = safe_read(STDIN_FILENO, readbuf, sizeof(readbuf));
ndelay_off(0);
readpos = 0;
readeof = eof_error;
/* Why??
(this also messes up stdin when user runs httpd -i from terminal)
ndelay_on(0);
- while (read(0, iobuf, IOBUF_SIZE) > 0)
+ while (read(STDIN_FILENO, iobuf, IOBUF_SIZE) > 0)
continue;
*/
if (DEBUG)
fprintf(stderr, "headers: '%s'\n", iobuf);
- full_write(1, iobuf, len);
+ full_write(STDOUT_FILENO, iobuf, len);
if (DEBUG)
fprintf(stderr, "writing error page: '%s'\n", error_page);
return send_file_and_exit(error_page, SEND_BODY);
}
if (DEBUG)
fprintf(stderr, "headers: '%s'\n", iobuf);
- if (full_write(1, iobuf, len) != len) {
+ if (full_write(STDOUT_FILENO, iobuf, len) != len) {
if (verbose > 1)
bb_perror_msg("error");
log_and_exit();
while (1) {
if (hdr_cnt <= 0) {
- hdr_cnt = safe_read(0, hdr_buf, sizeof(hdr_buf));
+ hdr_cnt = safe_read(STDIN_FILENO, hdr_buf, sizeof(hdr_buf));
if (hdr_cnt <= 0)
break;
hdr_ptr = hdr_buf;
* and there *is* data to read from the peer
* (POSTDATA) */
//count = post_len > (int)sizeof(hdr_buf) ? (int)sizeof(hdr_buf) : post_len;
- //count = safe_read(0, hdr_buf, count);
- count = safe_read(0, hdr_buf, sizeof(hdr_buf));
+ //count = safe_read(STDIN_FILENO, hdr_buf, count);
+ count = safe_read(STDIN_FILENO, hdr_buf, sizeof(hdr_buf));
if (count > 0) {
hdr_cnt = count;
hdr_ptr = hdr_buf;
/* eof (or error) and there was no "HTTP",
* so write it, then write received data */
if (out_cnt) {
- full_write(1, HTTP_200, sizeof(HTTP_200)-1);
- full_write(1, rbuf, out_cnt);
+ full_write(STDOUT_FILENO, HTTP_200, sizeof(HTTP_200)-1);
+ full_write(STDOUT_FILENO, rbuf, out_cnt);
}
break; /* CGI stdout is closed, exiting */
}
/* "Status" header format is: "Status: 302 Redirected\r\n" */
if (out_cnt >= 8 && memcmp(rbuf, "Status: ", 8) == 0) {
/* send "HTTP/1.0 " */
- if (full_write(1, HTTP_200, 9) != 9)
+ if (full_write(STDOUT_FILENO, HTTP_200, 9) != 9)
break;
rbuf += 8; /* skip "Status: " */
count = out_cnt - 8;
/* Did CGI add "HTTP"? */
if (memcmp(rbuf, HTTP_200, 4) != 0) {
/* there is no "HTTP", do it ourself */
- if (full_write(1, HTTP_200, sizeof(HTTP_200)-1) != sizeof(HTTP_200)-1)
+ if (full_write(STDOUT_FILENO, HTTP_200, sizeof(HTTP_200)-1) != sizeof(HTTP_200)-1)
break;
}
/* Commented out:
if (count <= 0)
break; /* eof (or error) */
}
- if (full_write(1, rbuf, count) != count)
+ if (full_write(STDOUT_FILENO, rbuf, count) != count)
break;
if (DEBUG)
fprintf(stderr, "cgi read %d bytes: '%.*s'\n", count, count, rbuf);
while ((count = safe_read(f, iobuf, IOBUF_SIZE)) > 0) {
ssize_t n;
USE_FEATURE_HTTPD_RANGES(if (count > range_len) count = range_len;)
- n = full_write(1, iobuf, count);
+ n = full_write(STDOUT_FILENO, iobuf, count);
if (count != n)
break;
USE_FEATURE_HTTPD_RANGES(range_len -= count;)
{
if (buffer + (BUFFER_SIZE-HEADROOM) - dst >= size)
return;
- write(1, buffer, dst - buffer);
+ write(STDOUT_FILENO, buffer, dst - buffer);
dst = buffer;
}
/* if we have a timeout AND stdin is closed AND we haven't heard anything
from the net during that time, assume it's dead and close it too. */
if (rr == 0) {
- if (!FD_ISSET(0, &ding1))
+ if (!FD_ISSET(STDIN_FILENO, &ding1))
netretry--; /* we actually try a coupla times. */
if (!netretry) {
if (o_verbose > 1) /* normally we don't care */
goto shovel;
/* okay, suck more stdin */
- if (FD_ISSET(0, &ding2)) { /* stdin: ding! */
- rr = read(0, bigbuf_in, BIGSIZ);
+ if (FD_ISSET(STDIN_FILENO, &ding2)) { /* stdin: ding! */
+ rr = read(STDIN_FILENO, bigbuf_in, BIGSIZ);
/* Considered making reads here smaller for UDP mode, but 8192-byte
mobygrams are kinda fun and exercise the reassembler. */
if (rr <= 0) { /* at end, or fukt, or ... */
- FD_CLR(0, &ding1); /* disable and close stdin */
+ FD_CLR(STDIN_FILENO, &ding1); /* disable and close stdin */
close(0);
} else {
rzleft = rr;
return 1;
}
if (rnleft) {
- rr = write(1, np, rnleft);
+ rr = write(STDOUT_FILENO, np, rnleft);
if (rr > 0) {
if (o_ofile) /* log the stdout */
oprint('<', (unsigned char *)np, rr);
}
#endif
- FD_SET(0, &ding1); /* stdin *is* initially open */
+ FD_SET(STDIN_FILENO, &ding1); /* stdin *is* initially open */
if (proggie) {
close(0); /* won't need stdin */
option_mask32 &= ~OPT_o; /* -o with -e is meaningless! */
" z suspend telnet\r\n"
" e exit telnet\r\n");
- if (read(0, &b, 1) <= 0)
+ if (read(STDIN_FILENO, &b, 1) <= 0)
doexit(EXIT_FAILURE);
switch (b) {
}
if (len)
- write(1, G.buf, len);
+ write(STDOUT_FILENO, G.buf, len);
}
static void putiac(int c)
ufds[0].events = ufds[1].events = POLLIN;
#else
FD_ZERO(&readfds);
- FD_SET(0, &readfds);
+ FD_SET(STDIN_FILENO, &readfds);
FD_SET(G.netfd, &readfds);
maxfd = G.netfd + 1;
#endif
#ifdef USE_POLL
if (ufds[0].revents) /* well, should check POLLIN, but ... */
#else
- if (FD_ISSET(0, &rfds))
+ if (FD_ISSET(STDIN_FILENO, &rfds))
#endif
{
- len = read(0, G.buf, DATABUFSIZE);
+ len = read(STDIN_FILENO, G.buf, DATABUFSIZE);
if (len <= 0)
doexit(EXIT_SUCCESS);
TRACE(0, ("Read con: %d\n", len));
{
int sz = cur_outbuf - outbuf;
if (sz > 0) {
- xwrite(1, outbuf, sz);
+ xwrite(STDOUT_FILENO, outbuf, sz);
cur_outbuf = outbuf;
}
}
/* batch mode, or EOF on stdin ("top </dev/null") */
sleep(interval);
else if (safe_poll(pfd, 1, interval * 1000) > 0) {
- if (safe_read(0, &c, 1) != 1) { /* error/EOF? */
+ if (safe_read(STDIN_FILENO, &c, 1) != 1) { /* error/EOF? */
option_mask32 |= OPT_EOF;
continue;
}
poll(&input, 1, i * 1000);
sigprocmask(SIG_BLOCK, &blocked_sigset, NULL);
- i = ndelay_read(0, s, len);
+ i = ndelay_read(STDIN_FILENO, s, len);
if (i >= 0)
break;
if (errno == EINTR)
logmatch(ld);
if (ld->matcherr == 'e') {
/* runit-1.8.0 compat: if timestamping, do it on stderr too */
- ////full_write(2, printptr, printlen);
+ ////full_write(STDERR_FILENO, printptr, printlen);
fwrite(printptr, 1, printlen, stderr);
}
if (ld->match != '+') continue;
for (i = 0; i < dirn; ++i) {
if (dir[i].fddir == -1) continue;
if (dir[i].matcherr == 'e') {
- ////full_write(2, lineptr, linelen);
+ ////full_write(STDERR_FILENO, lineptr, linelen);
fwrite(lineptr, 1, linelen, stderr);
}
if (dir[i].match != '+') continue;
{
#if DEBUG
if (!p || (g_stacknxt < (char *)p) || ((char *)p < g_stackp->space)) {
- write(2, "stunalloc\n", 10);
+ write(STDERR_FILENO, "stunalloc\n", 10);
abort();
}
#endif
static void prs(const char *s)
{
if (*s)
- write(2, s, strlen(s));
+ write(STDERR_FILENO, s, strlen(s));
}
static void prn(unsigned u)
}
for (wp = args + 1; *wp; wp++) {
for (cp = global_env.linep; !nl && cp < elinep - 1; cp++) {
- nb = nonblock_safe_read(0, cp, sizeof(*cp));
+ nb = nonblock_safe_read(STDIN_FILENO, cp, sizeof(*cp));
if (nb != sizeof(*cp))
break;
nl = (*cp == '\n');
static void ioecho(char c)
{
if (FLAG['v'])
- write(2, &c, sizeof c);
+ write(STDERR_FILENO, &c, sizeof c);
}
static void pushio(struct ioarg *argp, int (*fn) (struct ioarg *))
goto restore;
}
if (count > 0) {
- full_write(1, buf, count);
+ full_write(STDOUT_FILENO, buf, count);
full_write(outfd, buf, count);
if (opt & 4) { /* -f */
fsync(outfd);
}
}
if (pfd[1].revents) {
- count = safe_read(0, buf, sizeof(buf));
+ count = safe_read(STDIN_FILENO, buf, sizeof(buf));
if (count <= 0) {
/* err/eof from stdin: don't read stdin anymore */
pfd[1].revents = 0;
loop = 999;
/* pty is in O_NONBLOCK mode, we exit as soon as buffer is empty */
while (--loop && (count = safe_read(pty, buf, sizeof(buf))) > 0) {
- full_write(1, buf, count);
+ full_write(STDOUT_FILENO, buf, count);
full_write(outfd, buf, count);
}
restore: