]> Pileus Git - ~andy/fetchmail/blobdiff - netrc.c
Fix 'make check' build error on -DSTANDALONE mxget.c on some systems.
[~andy/fetchmail] / netrc.c
diff --git a/netrc.c b/netrc.c
index fd28dc86d1c108cf09986092e6ee1b55a7061867..765f5f1d1ac90e434978718e22fac0ce4b67cd35 100644 (file)
--- a/netrc.c
+++ b/netrc.c
@@ -1,11 +1,14 @@
-/* netrc.c -- parse the .netrc file to get hosts, accounts, and passwords
-
+/*
+ * netrc.c -- parse the .netrc file to get hosts, accounts, and passwords
+ *
    Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
    Copyright assigned to Eric S. Raymond, October 2001.
 
    For license terms, see the file COPYING in this directory.
 
-   Compile with -DSTANDALONE to test this module. */
+   Compile with -DSTANDALONE to test this module.
+   (Makefile.am should have a rule so you can just type "make netrc")
+*/
 
 #include <stdio.h>
 #include <ctype.h>
@@ -102,12 +105,12 @@ parse_netrc (file)
     premature_token = NULL;
 
     /* While there are lines in the file... */
-    while (fgets(buf, POPBUFSIZE, fp))
+    while (fgets(buf, sizeof(buf) - 1, fp))
     {
        ln++;
 
        /* Strip trailing CRLF */
-       for (p = buf + strlen(buf) - 1; (p >= buf) && isspace(*p); p--)
+       for (p = buf + strlen(buf) - 1; (p >= buf) && isspace((unsigned char)*p); p--)
            *p = '\0';
 
        /* Parse the line. */
@@ -129,7 +132,7 @@ parse_netrc (file)
            char *pp;
 
            /* Skip any whitespace. */
-           while (*p && isspace (*p))
+           while (*p && isspace ((unsigned char)*p))
                p++;
 
            /* Discard end-of-line comments. */
@@ -139,7 +142,7 @@ parse_netrc (file)
            tok = pp = p;
 
            /* Find the end of the token. */
-           while (*p && (quote_char || !isspace (*p)))
+           while (*p && (quote_char || !isspace ((unsigned char)*p)))
            {
                if (quote_char)
                {
@@ -213,15 +216,9 @@ parse_netrc (file)
 
            if (premature_token)
            {
-#ifdef HAVE_ERROR
-               error_at_line (0, file, ln,
-                              GT_("warning: found \"%s\" before any host names"),
-                              premature_token);
-#else
                fprintf (stderr,
                         GT_("%s:%d: warning: found \"%s\" before any host names\n"),
                         file, ln, premature_token);
-#endif
                premature_token = NULL;
            }
 
@@ -318,12 +315,9 @@ search_netrc (list, host, login)
 #include <sys/types.h>
 #include <sys/stat.h>
 
-extern int errno;
+#include <errno.h>
 
-int
-main (argc, argv)
-     int argc;
-     char **argv;
+int main (int argc, char **argv)
 {
     struct stat sb;
     char *program_name, *file, *host, *login;
@@ -334,6 +328,15 @@ main (argc, argv)
     host = argv[2];
     login = argv[3];
 
+    switch (argc) {
+       case 2:
+       case 4:
+           break;
+       default:
+           fprintf (stderr, "Usage: %s <file> [<host> <login>]\n", argv[0]);
+           exit(EXIT_FAILURE);
+    }
+
     if (stat (file, &sb))
     {
        fprintf (stderr, "%s: cannot stat %s: %s\n", argv[0], file,
@@ -350,8 +353,8 @@ main (argc, argv)
 
     if (host && login)
     {
-       int i, status;
-       status = 0;
+       int status;
+       status = EXIT_SUCCESS;
 
        printf("Host: %s, Login: %s\n", host, login);
            
@@ -361,10 +364,10 @@ main (argc, argv)
            /* Print out the password (if any). */
            if (a->password)
            {
-               fputc (' ', stdout);
-               fputs (a->password, stdout);
+               printf("Password: %s\n", a->password);
            }
-       }
+       } else
+           status = EXIT_FAILURE;
        fputc ('\n', stdout);
 
        exit (status);