Mercurial > emacs
changeset 15101:f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
(fork, syswait, DISABLE_DIRECT_ACCESS) [WINDOWSNT]: Macros defined.
[WINDOWSNT]: Include locking.h.
(main): Update usage message. Use IS_DIRECTORY_SEP.
(main) [DISABLE_DIRECT_ACCESS]: Don't check access if defined.
(main) [WINDOWSNT]: Invoke locking instead of flock.
(main) [MAIL_USE_SYSTEM_LOCK && WINDOWSNT]: Emulate ftruncate.
(main) [MAIL_USE_POP]: Pass password to popmail if used.
Include winsock.h; don't include unix inet headers.
(popmail): Add password argument and pass it to pop_open.
Open output file in binary mode.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 28 Apr 1996 19:07:35 +0000 |
parents | 85edb1a5281a |
children | ed550d0805ca |
files | lib-src/movemail.c |
diffstat | 1 files changed, 38 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/lib-src/movemail.c Sun Apr 28 19:06:15 1996 +0000 +++ b/lib-src/movemail.c Sun Apr 28 19:07:35 1996 +0000 @@ -1,6 +1,6 @@ /* movemail foo bar -- move file foo to file bar, locking file foo the way /bin/mail respects. - Copyright (C) 1986, 1992, 1993, 1994 Free Software Foundation, Inc. + Copyright (C) 1986, 1992, 1993, 1994, 1996 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -70,6 +70,19 @@ #undef access #endif /* MSDOS */ +#ifdef WINDOWSNT +#undef access +#undef unlink +#define fork() 0 +#define sys_wait(var) (*(var) = 0) +/* Unfortunately, Samba doesn't seem to properly lock Unix files even + though the locking call succeeds (and indeed blocks local access from + other NT programs). If you have direct file access using an NFS + client or something other than Samba, the locking call might work + properly - make sure it does before you enable this! */ +#define DISABLE_DIRECT_ACCESS +#endif /* WINDOWSNT */ + #ifdef USG #include <fcntl.h> #include <unistd.h> @@ -85,7 +98,7 @@ #include <unistd.h> #endif -#ifdef XENIX +#if defined (XENIX) || defined (WINDOWSNT) #include <sys/locking.h> #endif @@ -150,7 +163,7 @@ if (argc < 3) { - fprintf (stderr, "Usage: movemail inbox destfile\n"); + fprintf (stderr, "Usage: movemail inbox destfile [POP-password]\n"); exit(1); } @@ -174,7 +187,7 @@ char *p; strcpy (buf, outname); p = buf + strlen (buf); - while (p > buf && p[-1] != '/') + while (p > buf && !IS_DIRECTORY_SEP (p[-1])) *--p = 0; if (p == buf) *p++ = '.'; @@ -188,13 +201,15 @@ { int status; - status = popmail (inname + 3, outname); + status = popmail (inname + 3, outname, argc > 3 ? argv[3] : NULL); exit (status); } setuid (getuid ()); #endif /* MAIL_USE_POP */ +#ifndef DISABLE_DIRECT_ACCESS + /* Check access to input file. */ if (access (inname, R_OK | W_OK) != 0) pfatal_with_name (inname); @@ -228,7 +243,7 @@ tempname = (char *) xmalloc (strlen (inname) + strlen ("EXXXXXX") + 1); strcpy (tempname, inname); p = tempname + strlen (tempname); - while (p != tempname && p[-1] != '/') + while (p != tempname && !IS_DIRECTORY_SEP (p[-1])) p--; *p = 0; strcpy (p, "EXXXXXX"); @@ -305,8 +320,12 @@ #ifdef XENIX if (locking (indesc, LK_RLCK, 0L) < 0) pfatal_with_name (inname); #else +#ifdef WINDOWSNT + if (locking (indesc, LK_RLCK, -1L) < 0) pfatal_with_name (inname); +#else if (flock (indesc, LOCK_EX) < 0) pfatal_with_name (inname); #endif +#endif #endif /* not MAIL_USE_LOCKF */ #endif /* MAIL_USE_SYSTEM_LOCK */ @@ -338,7 +357,7 @@ pfatal_and_delete (outname); #ifdef MAIL_USE_SYSTEM_LOCK -#if defined (STRIDE) || defined (XENIX) +#if defined (STRIDE) || defined (XENIX) || defined (WINDOWSNT) /* Stride, xenix have file locking, but no ftruncate. This mess will do. */ close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666)); #else @@ -375,6 +394,9 @@ #if !defined (MAIL_USE_MMDF) && !defined (MAIL_USE_SYSTEM_LOCK) unlink (lockname); #endif /* not MAIL_USE_MMDF and not MAIL_USE_SYSTEM_LOCK */ + +#endif /* ! DISABLE_DIRECT_ACCESS */ + return 0; } @@ -451,9 +473,14 @@ #ifdef MAIL_USE_POP +#ifndef WINDOWSNT #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> +#else +#undef _WINSOCKAPI_ +#include <winsock.h> +#endif #include <stdio.h> #include <pwd.h> @@ -477,9 +504,10 @@ char obuffer[BUFSIZ]; char Errmsg[80]; -popmail (user, outfile) +popmail (user, outfile, password) char *user; char *outfile; + char *password; { int nmsgs, nbytes; register int i; @@ -490,7 +518,7 @@ popserver server; extern char *strerror (); - server = pop_open (0, user, 0, POP_NO_GETPASS); + server = pop_open (0, user, password, POP_NO_GETPASS); if (! server) { error (pop_error); @@ -518,7 +546,7 @@ } fchown (mbfi, getuid (), -1); - if ((mbf = fdopen (mbfi, "w")) == NULL) + if ((mbf = fdopen (mbfi, "wb")) == NULL) { pop_close (server); error ("Error in fdopen: %s", strerror (errno));