From: Richard M. Stallman Date: Sun, 28 Apr 1996 19:07:35 +0000 (+0000) Subject: (access, unlink) [WINDOWSNT]: Macros undefined. X-Git-Tag: emacs-19.34~760 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=7f75d5c619a6498b8d92816f1c1e5852e147a5fb;p=emacs.git (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. --- diff --git a/lib-src/movemail.c b/lib-src/movemail.c index 4ac1343fa9b..295b006911b 100644 --- a/lib-src/movemail.c +++ b/lib-src/movemail.c @@ -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 @@ Boston, MA 02111-1307, USA. */ #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 #include @@ -85,7 +98,7 @@ Boston, MA 02111-1307, USA. */ #include #endif -#ifdef XENIX +#if defined (XENIX) || defined (WINDOWSNT) #include #endif @@ -150,7 +163,7 @@ main (argc, argv) 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 @@ main (argc, argv) 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 @@ main (argc, argv) { 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 @@ main (argc, argv) 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"); @@ -304,9 +319,13 @@ main (argc, argv) #else /* not MAIL_USE_LOCKF */ #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 @@ main (argc, argv) 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 @@ main (argc, argv) #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 @@ xmalloc (size) #ifdef MAIL_USE_POP +#ifndef WINDOWSNT #include #include #include +#else +#undef _WINSOCKAPI_ +#include +#endif #include #include @@ -477,9 +504,10 @@ char ibuffer[BUFSIZ]; 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 @@ popmail (user, outfile) 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 @@ popmail (user, outfile) } 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));