Header cleanup on two more networking files (move libbb.h to the top and
[oweals/busybox.git] / miscutils / rx.c
index 2b16f2e220ff22699f4f64fb8c657ef64f94005a..7642094b7855976085a88ad9c12846db1a7d31a5 100644 (file)
@@ -1,37 +1,26 @@
+/* vi: set sw=4 ts=4: */
 /*-------------------------------------------------------------------------
  * Filename:      xmodem.c
- * Version:       $Id: rx.c,v 1.1 2003/12/20 07:30:35 bug1 Exp $
+ * Version:       $Id: rx.c,v 1.2 2004/03/15 08:28:46 andersen Exp $
  * Copyright:     Copyright (C) 2001, Hewlett-Packard Company
  * Author:        Christopher Hoover <ch@hpl.hp.com>
- * Description:   xmodem functionality for uploading of kernels 
+ * Description:   xmodem functionality for uploading of kernels
  *                and the like
  * Created at:    Thu Dec 20 01:58:08 PST 2001
  *-----------------------------------------------------------------------*/
 /*
- * xmodem.c: xmodem functionality for uploading of kernels and 
+ * xmodem.c: xmodem functionality for uploading of kernels and
  *            the like
  *
  * Copyright (C) 2001 Hewlett-Packard Laboratories
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  *
  * This was originally written for blob and then adapted for busybox.
  *
  */
 
+#include "busybox.h"
 #include <stdlib.h>
 #include <stdarg.h>
 #include <stdio.h>
@@ -43,7 +32,6 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <string.h>
-#include "busybox.h"
 
 
 #define SOH 0x01
@@ -69,7 +57,7 @@ Cf:
 #define TIMEOUT_LONG 10
 #define MAXERRORS 10
 
-static inline void write_byte(int fd, char cc) { 
+static inline void write_byte(int fd, char cc) {
        write(fd, &cc, 1);
 }
 
@@ -80,7 +68,7 @@ static inline void write_flush(int fd) {
 static inline void read_flush(int fd) {
        tcflush(fd, TCIFLUSH);
 }
-  
+
 static int read_byte(int fd, unsigned int timeout) {
        char buf[1];
        int n;
@@ -285,7 +273,7 @@ static int receive(char *error_buf, size_t error_buf_size,
 #undef note_error
 }
 
-static void sigalrm_handler(int signum)
+static void sigalrm_handler(int ATTRIBUTE_UNUSED signum)
 {
 }
 
@@ -302,22 +290,17 @@ int rx_main(int argc, char **argv)
                        bb_show_usage();
 
        fn = argv[1];
-       ttyfd = open("/dev/tty", O_RDWR);
-       if (ttyfd < 0)
-                       bb_error_msg_and_die("%s: open on /dev/tty failed: %m\n", argv[0]);
-
-       filefd = open(fn, O_RDWR|O_CREAT|O_TRUNC, 0666);
-       if (filefd < 0)
-                       bb_error_msg_and_die("%s: open on %s failed: %m\n", argv[0], fn);
+       ttyfd = bb_xopen3(CURRENT_TTY, O_RDWR, 0);
+       filefd = bb_xopen3(fn, O_RDWR|O_CREAT|O_TRUNC, 0666);
 
        if (tcgetattr(ttyfd, &tty) < 0)
                        bb_error_msg_and_die("%s: tcgetattr failed: %m\n", argv[0]);
-       
+
        orig_tty = tty;
 
        cfmakeraw(&tty);
        tcsetattr(ttyfd, TCSAFLUSH, &tty);
-       
+
        memset(&act, 0, sizeof(act));
        act.sa_handler = sigalrm_handler;
        sigaction(SIGALRM, &act, 0);
@@ -334,11 +317,3 @@ int rx_main(int argc, char **argv)
 
        bb_fflush_stdout_and_exit(EXIT_SUCCESS);
 }
-
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/