diff lib-src/movemail.c @ 173:8eaf7971accc r20-3b13

Import from CVS: tag r20-3b13
author cvs
date Mon, 13 Aug 2007 09:49:09 +0200
parents 0132846995bd
children 2d532a89d707
line wrap: on
line diff
--- a/lib-src/movemail.c	Mon Aug 13 09:47:55 2007 +0200
+++ b/lib-src/movemail.c	Mon Aug 13 09:49:09 2007 +0200
@@ -129,30 +129,25 @@
 #undef write
 #undef close
 
-#ifndef errno
-extern int errno;
+static void fatal (char *, char*);
+static void error (char *, char *, char *);
+static void pfatal_with_name (char *);
+static void pfatal_and_delete (char *);
+static char *concat (char *, char *, char *);
+static long *xmalloc (unsigned int);
+static int popmail (char *, char *, char *);
+#ifdef MAIL_USE_POP
+static int pop_retr (popserver server, int msgno, int (*action)(), int arg);
 #endif
-char *strerror ();
-
-void fatal (char *, char*);
-void error ();
-void pfatal_with_name ();
-void pfatal_and_delete ();
-char *concat ();
-long *xmalloc ();
-int popmail ();
-int pop_retr ();
-int mbx_write ();
-int mbx_delimit_begin ();
-int mbx_delimit_end ();
+static int mbx_write (char *, FILE *);
+static int mbx_delimit_begin (FILE *);
+static int mbx_delimit_end (FILE *);
 
 /* Nonzero means this is name of a lock file to delete on fatal error.  */
 char *delete_lockname;
 
 int
-main (argc, argv)
-     int argc;
-     char **argv;
+main (int argc, char *argv[])
 {
   char *inname, *outname;
   int indesc, outdesc;
@@ -193,13 +188,13 @@
   /* Also check that outname's directory is writable to the real uid.  */
   {
     char *buf = (char *) xmalloc (strlen (outname) + 1);
-    char *p;
+    char *cp;
     strcpy (buf, outname);
-    p = buf + strlen (buf);
-    while (p > buf && !IS_DIRECTORY_SEP (p[-1]))
-      *--p = 0;
-    if (p == buf)
-      *p++ = '.';
+    cp = buf + strlen (buf);
+    while (cp > buf && !IS_DIRECTORY_SEP (cp[-1]))
+      *--cp = 0;
+    if (cp == buf)
+      *cp++ = '.';
     if (access (buf, W_OK) != 0)
       pfatal_with_name (buf);
     free (buf);
@@ -411,38 +406,34 @@
 
 /* Print error message and exit.  */
 
-void
-fatal (s1, s2)
-     char *s1, *s2;
+static void
+fatal (char *s1, char *s2)
 {
   if (delete_lockname)
     unlink (delete_lockname);
-  error (s1, s2);
+  error (s1, s2, NULL);
   exit (1);
 }
 
 /* Print error message.  `s1' is printf control string, `s2' is arg for it. */
 
-void
-error (s1, s2, s3)
-     char *s1, *s2, *s3;
+static void
+error (char *s1, char *s2, char *s3)
 {
   fprintf (stderr, "movemail: ");
   fprintf (stderr, s1, s2, s3);
   fprintf (stderr, "\n");
 }
 
-void
-pfatal_with_name (name)
-     char *name;
+static void
+pfatal_with_name (char *name)
 {
   char *s = concat ("", strerror (errno), " for %s");
   fatal (s, name);
 }
 
-void
-pfatal_and_delete (name)
-     char *name;
+static void
+pfatal_and_delete (char *name)
 {
   char *s = concat ("", strerror (errno), " for %s");
   unlink (name);
@@ -451,9 +442,8 @@
 
 /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3.  */
 
-char *
-concat (s1, s2, s3)
-     char *s1, *s2, *s3;
+static char *
+concat (char *s1, char *s2, char *s3)
 {
   int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
   char *result = (char *) xmalloc (len1 + len2 + len3 + 1);
@@ -468,9 +458,8 @@
 
 /* Like malloc but get fatal error if memory is exhausted.  */
 
-long *
-xmalloc (size)
-     unsigned size;
+static long *
+xmalloc (unsigned int size)
 {
   long *result = (long *) malloc (size);
   if (!result)
@@ -504,10 +493,8 @@
 char obuffer[BUFSIZ];
 char Errmsg[80];
 
-popmail (user, outfile, password)
-     char *user;
-     char *outfile;
-     char *password;
+static int
+popmail (char *user, char *outfile, char *password)
 {
   int nmsgs, nbytes;
   register int i;
@@ -521,13 +508,13 @@
   server = pop_open (0, user, password, POP_NO_GETPASS);
   if (! server)
     {
-      error (pop_error);
+      error (pop_error, NULL, NULL);
       return (1);
     }
 
   if (pop_stat (server, &nmsgs, &nbytes))
     {
-      error (pop_error);
+      error (pop_error, NULL, NULL);
       return (1);
     }
 
@@ -549,7 +536,7 @@
   if ((mbf = fdopen (mbfi, "wb")) == NULL)
     {
       pop_close (server);
-      error ("Error in fdopen: %s", strerror (errno));
+      error ("Error in fdopen: %s", strerror (errno), NULL);
       close (mbfi);
       unlink (outfile);
       return (1);
@@ -560,7 +547,7 @@
       mbx_delimit_begin (mbf);
       if (pop_retr (server, i, mbx_write, mbf) != OK)
 	{
-	  error (Errmsg);
+	  error (Errmsg, NULL, NULL);
 	  close (mbfi);
 	  return (1);
 	}
@@ -568,7 +555,7 @@
       fflush (mbf);
       if (ferror (mbf))
 	{
-	  error ("Error in fflush: %s", strerror (errno));
+	  error ("Error in fflush: %s", strerror (errno), NULL);
 	  pop_close (server);
 	  close (mbfi);
 	  return (1);
@@ -584,14 +571,14 @@
 #ifdef BSD
   if (fsync (mbfi) < 0)
     {
-      error ("Error in fsync: %s", strerror (errno));
+      error ("Error in fsync: %s", strerror (errno), NULL);
       return (1);
     }
 #endif
 
   if (close (mbfi) == -1)
     {
-      error ("Error in close: %s", strerror (errno));
+      error ("Error in close: %s", strerror (errno), NULL);
       return (1);
     }
 
@@ -599,7 +586,7 @@
     {
       if (pop_delete (server, i))
 	{
-	  error (pop_error);
+	  error (pop_error, NULL, NULL);
 	  pop_close (server);
 	  return (1);
 	}
@@ -607,16 +594,15 @@
 
   if (pop_quit (server))
     {
-      error (pop_error);
+      error (pop_error, NULL, NULL);
       return (1);
     }
     
   return (0);
 }
 
-pop_retr (server, msgno, action, arg)
-     popserver server;
-     int (*action)();
+static int
+pop_retr (popserver server, int msgno, int (*action)(), int arg)
 {
   extern char *strerror ();
   char *line;
@@ -659,10 +645,8 @@
 			 && (a[3] == 'm') \
 			 && (a[4] == ' '))
 
-int
-mbx_write (line, mbf)
-     char *line;
-     FILE *mbf;
+static int
+mbx_write (char *line, FILE *mbf)
 {
   if (IS_FROM_LINE (line))
     {
@@ -676,17 +660,16 @@
   return (OK);
 }
 
-int
-mbx_delimit_begin (mbf)
-     FILE *mbf;
+static int
+mbx_delimit_begin (FILE *mbf)
 {
   if (fputs ("\f\n0, unseen,,\n", mbf) == EOF)
     return (NOTOK);
   return (OK);
 }
 
-mbx_delimit_end (mbf)
-     FILE *mbf;
+static int
+mbx_delimit_end (FILE *mbf)
 {
   if (putc ('\037', mbf) == EOF)
     return (NOTOK);
@@ -696,9 +679,8 @@
 #endif /* MAIL_USE_POP */
 
 #ifndef HAVE_STRERROR
-char *
-strerror (errnum)
-     int errnum;
+static char *
+strerror (int errnum)
 {
   extern char *sys_errlist[];
   extern int sys_nerr;