xatonum.h: add comment
[oweals/busybox.git] / networking / telnet.c
index cd88a9b3da6374871516b0809dc65956de40315c..9085c5848ac55c6ebee914a381561ed6d966783d 100644 (file)
@@ -24,7 +24,7 @@
 #include <termios.h>
 #include <arpa/telnet.h>
 #include <netinet/in.h>
-#include "busybox.h"
+#include "libbb.h"
 
 #ifdef DOTRACE
 #define TRACE(x, y) do { if (x) printf y; } while (0)
@@ -52,7 +52,6 @@ enum {
 
 typedef unsigned char byte;
 
-
 struct globals {
        int     netfd; /* console fd:s are 0 and 1 (and 2) */
        short   iaclen; /* could even use byte */
@@ -78,9 +77,13 @@ struct globals {
        struct termios termios_def;
        struct termios termios_raw;
 };
-
-#define G (*(struct globals*)bb_common_bufsiz1)
-
+#define G (*(struct globals*)&bb_common_bufsiz1)
+void BUG_telnet_globals_too_big(void);
+#define INIT_G() do { \
+       if (sizeof(G) > COMMON_BUFSIZE) \
+               BUG_telnet_globals_too_big(); \
+       /* memset(&G, 0, sizeof G); - already is */ \
+} while (0)
 
 /* Function prototypes */
 static void rawmode(void);
@@ -188,7 +191,7 @@ static void handlenetoutput(int len)
                else if (*p == 0x0d)
                        outbuf[j++] = 0x00;
        }
-       if (j > 0 )
+       if (j > 0)
                write(G.netfd, outbuf, j);
 }
 
@@ -350,7 +353,7 @@ static void putiac_naws(byte c, int x, int y)
 }
 #endif
 
-static char const escapecharis[] = "\r\nEscape character is ";
+static char const escapecharis[] ALIGN1 = "\r\nEscape character is ";
 
 static void setConMode(void)
 {
@@ -547,10 +550,8 @@ static void cookmode(void)
                tcsetattr(0, TCSADRAIN, &G.termios_def);
 }
 
-void BUG_telnet_globals_too_big(void);
-
-int telnet_main(int argc, char** argv);
-int telnet_main(int argc, char** argv)
+int telnet_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int telnet_main(int argc, char **argv)
 {
        char *host;
        int port;
@@ -562,9 +563,7 @@ int telnet_main(int argc, char** argv)
        int maxfd;
 #endif
 
-       if (sizeof(G) > sizeof(bb_common_bufsiz1))
-               BUG_telnet_globals_too_big();
-       /* memset(&G, 0, sizeof G); - already is */
+       INIT_G();
 
 #if ENABLE_FEATURE_AUTOWIDTH
        get_terminal_width_height(0, &G.win_width, &G.win_height);
@@ -584,7 +583,7 @@ int telnet_main(int argc, char** argv)
                bb_show_usage();
 
 #if ENABLE_FEATURE_TELNET_AUTOLOGIN
-       if (1 & getopt32(argc, argv, "al:", &G.autologin))
+       if (1 & getopt32(argv, "al:", &G.autologin))
                G.autologin = getenv("USER");
        argv += optind;
 #else