diff options
Diffstat (limited to 'lib-src/movemail.c')
| -rw-r--r-- | lib-src/movemail.c | 97 |
1 files changed, 29 insertions, 68 deletions
diff --git a/lib-src/movemail.c b/lib-src/movemail.c index 9d19df32814..d157aa8c0b9 100644 --- a/lib-src/movemail.c +++ b/lib-src/movemail.c | |||
| @@ -133,16 +133,10 @@ static char *mail_spool_name (char *); | |||
| 133 | #endif | 133 | #endif |
| 134 | #endif | 134 | #endif |
| 135 | 135 | ||
| 136 | #ifndef HAVE_STRERROR | 136 | static _Noreturn void fatal (const char *s1, const char *s2, const char *s3); |
| 137 | char *strerror (int); | ||
| 138 | #endif | ||
| 139 | |||
| 140 | static void fatal (const char *s1, const char *s2, const char *s3) NO_RETURN; | ||
| 141 | static void error (const char *s1, const char *s2, const char *s3); | 137 | static void error (const char *s1, const char *s2, const char *s3); |
| 142 | static void pfatal_with_name (char *name) NO_RETURN; | 138 | static _Noreturn void pfatal_with_name (char *name); |
| 143 | static void pfatal_and_delete (char *name) NO_RETURN; | 139 | static _Noreturn void pfatal_and_delete (char *name); |
| 144 | static char *concat (const char *s1, const char *s2, const char *s3); | ||
| 145 | static long *xmalloc (unsigned int size); | ||
| 146 | #ifdef MAIL_USE_POP | 140 | #ifdef MAIL_USE_POP |
| 147 | static int popmail (char *mailbox, char *outfile, int preserve, char *password, int reverse_order); | 141 | static int popmail (char *mailbox, char *outfile, int preserve, char *password, int reverse_order); |
| 148 | static int pop_retr (popserver server, int msgno, FILE *arg); | 142 | static int pop_retr (popserver server, int msgno, FILE *arg); |
| @@ -151,6 +145,21 @@ static int mbx_delimit_begin (FILE *mbf); | |||
| 151 | static int mbx_delimit_end (FILE *mbf); | 145 | static int mbx_delimit_end (FILE *mbf); |
| 152 | #endif | 146 | #endif |
| 153 | 147 | ||
| 148 | #if (defined MAIL_USE_MAILLOCK \ | ||
| 149 | || (!defined DISABLE_DIRECT_ACCESS && !defined MAIL_USE_MMDF \ | ||
| 150 | && !defined MAIL_USE_SYSTEM_LOCK)) | ||
| 151 | /* Like malloc but get fatal error if memory is exhausted. */ | ||
| 152 | |||
| 153 | static void * | ||
| 154 | xmalloc (size_t size) | ||
| 155 | { | ||
| 156 | void *result = malloc (size); | ||
| 157 | if (!result) | ||
| 158 | fatal ("virtual memory exhausted", 0, 0); | ||
| 159 | return result; | ||
| 160 | } | ||
| 161 | #endif | ||
| 162 | |||
| 154 | /* Nonzero means this is name of a lock file to delete on fatal error. */ | 163 | /* Nonzero means this is name of a lock file to delete on fatal error. */ |
| 155 | static char *delete_lockname; | 164 | static char *delete_lockname; |
| 156 | 165 | ||
| @@ -168,7 +177,7 @@ main (int argc, char **argv) | |||
| 168 | int tem; | 177 | int tem; |
| 169 | char *lockname; | 178 | char *lockname; |
| 170 | char *tempname; | 179 | char *tempname; |
| 171 | size_t inname_dirlen; | 180 | size_t inname_len, inname_dirlen; |
| 172 | int desc; | 181 | int desc; |
| 173 | #endif /* not MAIL_USE_SYSTEM_LOCK */ | 182 | #endif /* not MAIL_USE_SYSTEM_LOCK */ |
| 174 | 183 | ||
| @@ -296,12 +305,15 @@ main (int argc, char **argv) | |||
| 296 | should define MAIL_USE_SYSTEM_LOCK but does not, send a bug report | 305 | should define MAIL_USE_SYSTEM_LOCK but does not, send a bug report |
| 297 | to bug-gnu-emacs@prep.ai.mit.edu so we can fix it. */ | 306 | to bug-gnu-emacs@prep.ai.mit.edu so we can fix it. */ |
| 298 | 307 | ||
| 299 | lockname = concat (inname, ".lock", ""); | 308 | inname_len = strlen (inname); |
| 300 | for (inname_dirlen = strlen (inname); | 309 | lockname = xmalloc (inname_len + sizeof ".lock"); |
| 310 | strcpy (lockname, inname); | ||
| 311 | strcpy (lockname + inname_len, ".lock"); | ||
| 312 | for (inname_dirlen = inname_len; | ||
| 301 | inname_dirlen && !IS_DIRECTORY_SEP (inname[inname_dirlen - 1]); | 313 | inname_dirlen && !IS_DIRECTORY_SEP (inname[inname_dirlen - 1]); |
| 302 | inname_dirlen--) | 314 | inname_dirlen--) |
| 303 | continue; | 315 | continue; |
| 304 | tempname = (char *) xmalloc (inname_dirlen + sizeof "EXXXXXX"); | 316 | tempname = xmalloc (inname_dirlen + sizeof "EXXXXXX"); |
| 305 | 317 | ||
| 306 | while (1) | 318 | while (1) |
| 307 | { | 319 | { |
| @@ -583,8 +595,8 @@ mail_spool_name (char *inname) | |||
| 583 | if (stat (MAILDIR, &stat1) < 0) | 595 | if (stat (MAILDIR, &stat1) < 0) |
| 584 | return NULL; | 596 | return NULL; |
| 585 | 597 | ||
| 586 | indir = (char *) xmalloc (fname - inname + 1); | 598 | indir = xmalloc (fname - inname + 1); |
| 587 | strncpy (indir, inname, fname - inname); | 599 | memcpy (indir, inname, fname - inname); |
| 588 | indir[fname-inname] = '\0'; | 600 | indir[fname-inname] = '\0'; |
| 589 | 601 | ||
| 590 | 602 | ||
| @@ -643,33 +655,6 @@ pfatal_and_delete (char *name) | |||
| 643 | unlink (name); | 655 | unlink (name); |
| 644 | fatal ("%s for %s", s, name); | 656 | fatal ("%s for %s", s, name); |
| 645 | } | 657 | } |
| 646 | |||
| 647 | /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */ | ||
| 648 | |||
| 649 | static char * | ||
| 650 | concat (const char *s1, const char *s2, const char *s3) | ||
| 651 | { | ||
| 652 | size_t len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); | ||
| 653 | char *result = (char *) xmalloc (len1 + len2 + len3 + 1); | ||
| 654 | |||
| 655 | strcpy (result, s1); | ||
| 656 | strcpy (result + len1, s2); | ||
| 657 | strcpy (result + len1 + len2, s3); | ||
| 658 | *(result + len1 + len2 + len3) = 0; | ||
| 659 | |||
| 660 | return result; | ||
| 661 | } | ||
| 662 | |||
| 663 | /* Like malloc but get fatal error if memory is exhausted. */ | ||
| 664 | |||
| 665 | static long * | ||
| 666 | xmalloc (unsigned int size) | ||
| 667 | { | ||
| 668 | long *result = (long *) malloc (size); | ||
| 669 | if (!result) | ||
| 670 | fatal ("virtual memory exhausted", 0, 0); | ||
| 671 | return result; | ||
| 672 | } | ||
| 673 | 658 | ||
| 674 | /* This is the guts of the interface to the Post Office Protocol. */ | 659 | /* This is the guts of the interface to the Post Office Protocol. */ |
| 675 | 660 | ||
| @@ -851,10 +836,7 @@ pop_retr (popserver server, int msgno, FILE *arg) | |||
| 851 | 836 | ||
| 852 | if (pop_retrieve_first (server, msgno, &line)) | 837 | if (pop_retrieve_first (server, msgno, &line)) |
| 853 | { | 838 | { |
| 854 | char *msg = concat ("Error from POP server: ", pop_error, ""); | 839 | snprintf (Errmsg, sizeof Errmsg, "Error from POP server: %s", pop_error); |
| 855 | strncpy (Errmsg, msg, sizeof (Errmsg)); | ||
| 856 | Errmsg[sizeof (Errmsg)-1] = '\0'; | ||
| 857 | free (msg); | ||
| 858 | return (NOTOK); | 840 | return (NOTOK); |
| 859 | } | 841 | } |
| 860 | 842 | ||
| @@ -873,10 +855,7 @@ pop_retr (popserver server, int msgno, FILE *arg) | |||
| 873 | 855 | ||
| 874 | if (ret) | 856 | if (ret) |
| 875 | { | 857 | { |
| 876 | char *msg = concat ("Error from POP server: ", pop_error, ""); | 858 | snprintf (Errmsg, sizeof Errmsg, "Error from POP server: %s", pop_error); |
| 877 | strncpy (Errmsg, msg, sizeof (Errmsg)); | ||
| 878 | Errmsg[sizeof (Errmsg)-1] = '\0'; | ||
| 879 | free (msg); | ||
| 880 | return (NOTOK); | 859 | return (NOTOK); |
| 881 | } | 860 | } |
| 882 | 861 | ||
| @@ -939,21 +918,3 @@ mbx_delimit_end (FILE *mbf) | |||
| 939 | } | 918 | } |
| 940 | 919 | ||
| 941 | #endif /* MAIL_USE_POP */ | 920 | #endif /* MAIL_USE_POP */ |
| 942 | |||
| 943 | #ifndef HAVE_STRERROR | ||
| 944 | char * | ||
| 945 | strerror (errnum) | ||
| 946 | int errnum; | ||
| 947 | { | ||
| 948 | extern char *sys_errlist[]; | ||
| 949 | extern int sys_nerr; | ||
| 950 | |||
| 951 | if (errnum >= 0 && errnum < sys_nerr) | ||
| 952 | return sys_errlist[errnum]; | ||
| 953 | return (char *) "Unknown error"; | ||
| 954 | } | ||
| 955 | |||
| 956 | #endif /* ! HAVE_STRERROR */ | ||
| 957 | |||
| 958 | |||
| 959 | /* movemail.c ends here */ | ||