In Bug 78, shortkey points out:
[oweals/busybox.git] / networking / tftp.c
index 10aa63bb97c1e71d44031638f45959ca6f2d1885..3c947318bc89f3def3e51fd7ab706eaf7a87802f 100644 (file)
@@ -76,15 +76,15 @@ const int tftp_cmd_put = 2;
 
 #ifdef CONFIG_FEATURE_TFTP_BLOCKSIZE
 
-static int tftp_blocksize_check(int blocksize, int bufsize)  
+static int tftp_blocksize_check(int blocksize, int bufsize)
 {
-        /* Check if the blocksize is valid: 
+        /* Check if the blocksize is valid:
         * RFC2348 says between 8 and 65464,
         * but our implementation makes it impossible
         * to use blocksizes smaller than 22 octets.
         */
 
-        if ((bufsize && (blocksize > bufsize)) || 
+        if ((bufsize && (blocksize > bufsize)) ||
            (blocksize < 8) || (blocksize > 65464)) {
                bb_error_msg("bad blocksize");
                return 0;
@@ -93,12 +93,12 @@ static int tftp_blocksize_check(int blocksize, int bufsize)
        return blocksize;
 }
 
-static char *tftp_option_get(char *buf, int len, char *option)  
+static char *tftp_option_get(char *buf, int len, char *option)
 {
         int opt_val = 0;
        int opt_found = 0;
        int k;
-  
+
        while (len > 0) {
 
                /* Make sure the options are terminated correctly */
@@ -117,21 +117,21 @@ static char *tftp_option_get(char *buf, int len, char *option)
                        if (strcasecmp(buf, option) == 0) {
                                opt_found = 1;
                        }
-               }      
+               }
                else {
                        if (opt_found) {
                                return buf;
                        }
                }
-    
+
                k++;
-               
+
                buf += k;
                len -= k;
-               
+
                opt_val ^= 1;
        }
-       
+
        return NULL;
 }
 
@@ -207,7 +207,7 @@ static inline int tftp(const int cmd, const struct hostent *host,
 
                if ((cmd_get && (opcode == TFTP_RRQ)) ||
                        (cmd_put && (opcode == TFTP_WRQ))) {
-                        int too_long = 0; 
+                        int too_long = 0;
 
                        /* see if the filename fits into buf */
                        /* and fill in packet                */
@@ -267,7 +267,7 @@ static inline int tftp(const int cmd, const struct hostent *host,
                        block_nr++;
 
                        if (cmd_put && (opcode == TFTP_DATA)) {
-                               len = read(localfd, cp, tftp_bufsize - 4);
+                               len = bb_full_read(localfd, cp, tftp_bufsize - 4);
 
                                if (len < 0) {
                                        bb_perror_msg("read");
@@ -380,7 +380,7 @@ static inline int tftp(const int cmd, const struct hostent *host,
                        if (buf[4] != '\0') {
                                msg = &buf[4];
                                buf[tftp_bufsize - 1] = '\0';
-                       } else if (tmp < (sizeof(tftp_bb_error_msg) 
+                       } else if (tmp < (sizeof(tftp_bb_error_msg)
                                          / sizeof(char *))) {
 
                                msg = (char *) tftp_bb_error_msg[tmp];
@@ -404,12 +404,12 @@ static inline int tftp(const int cmd, const struct hostent *host,
 
                                 char *res;
 
-                                res = tftp_option_get(&buf[2], len-2, 
+                                res = tftp_option_get(&buf[2], len-2,
                                                       "blksize");
 
                                 if (res) {
                                         int blksize = atoi(res);
-                            
+                       
                                         if (tftp_blocksize_check(blksize,
                                                           tftp_bufsize - 4)) {
 
@@ -443,8 +443,8 @@ static inline int tftp(const int cmd, const struct hostent *host,
                if (cmd_get && (opcode == TFTP_DATA)) {
 
                        if (tmp == block_nr) {
-                           
-                               len = write(localfd, &buf[4], len - 4);
+                       
+                               len = bb_full_write(localfd, &buf[4], len - 4);
 
                                if (len < 0) {
                                        bb_perror_msg("write");
@@ -485,8 +485,8 @@ static inline int tftp(const int cmd, const struct hostent *host,
 int tftp_main(int argc, char **argv)
 {
        struct hostent *host = NULL;
-       char *localfile = NULL;
-       char *remotefile = NULL;
+       const char *localfile = NULL;
+       const char *remotefile = NULL;
        int port;
        int cmd = 0;
        int fd = -1;
@@ -506,13 +506,13 @@ int tftp_main(int argc, char **argv)
 #ifdef CONFIG_FEATURE_TFTP_GET
 #define GET "g"
 #else
-#define GET 
+#define GET
 #endif
 
 #ifdef CONFIG_FEATURE_TFTP_PUT
 #define PUT "p"
 #else
-#define PUT 
+#define PUT
 #endif
 
        while ((opt = getopt(argc, argv, BS GET PUT "l:r:")) != -1) {
@@ -537,11 +537,11 @@ int tftp_main(int argc, char **argv)
                        flags = O_RDONLY;
                        break;
 #endif
-               case 'l': 
-                       localfile = bb_xstrdup(optarg);
+               case 'l':
+                       localfile = optarg;
                        break;
                case 'r':
-                       remotefile = bb_xstrdup(optarg);
+                       remotefile = optarg;
                        break;
                }
        }
@@ -576,7 +576,7 @@ int tftp_main(int argc, char **argv)
        result = tftp(cmd, host, remotefile, fd, port, blocksize);
 
 #ifdef CONFIG_FEATURE_CLEAN_UP
-       if (!(fd == fileno(stdout) || fd == fileno(stdin))) {
+       if (!(fd == STDOUT_FILENO || fd == STDIN_FILENO)) {
            close(fd);
        }
 #endif