comparison lib-src/movemail.c @ 604:63a8e7b3c547

*** empty log message ***
author Jim Blandy <jimb@redhat.com>
date Wed, 01 Apr 1992 11:14:15 +0000
parents 3db1540d4b97
children 52d0ff659265
comparison
equal deleted inserted replaced
603:470f556a9453 604:63a8e7b3c547
94 int argc; 94 int argc;
95 char **argv; 95 char **argv;
96 { 96 {
97 char *inname, *outname; 97 char *inname, *outname;
98 int indesc, outdesc; 98 int indesc, outdesc;
99 char buf[1024];
100 int nread; 99 int nread;
101 100
102 #ifndef MAIL_USE_FLOCK 101 #ifndef MAIL_USE_FLOCK
103 struct stat st; 102 struct stat st;
104 long now; 103 long now;
180 and recompile movemail. If the s- file for your system 179 and recompile movemail. If the s- file for your system
181 should define MAIL_USE_FLOCK but does not, send a bug report 180 should define MAIL_USE_FLOCK but does not, send a bug report
182 to bug-gnu-emacs@prep.ai.mit.edu so we can fix it. */ 181 to bug-gnu-emacs@prep.ai.mit.edu so we can fix it. */
183 182
184 lockname = concat (inname, ".lock", ""); 183 lockname = concat (inname, ".lock", "");
185 tempname = (char *) xmalloc (strlen (inname) + 20); 184 tempname = strcpy (xmalloc (strlen (inname)+1), inname);
186 strcpy (tempname, inname);
187 p = tempname + strlen (tempname); 185 p = tempname + strlen (tempname);
188 while (p != tempname && p[-1] != '/') 186 while (p != tempname && p[-1] != '/')
189 p--; 187 p--;
190 *p = 0; 188 *p = 0;
191 strcpy (p, "EXXXXXX"); 189 strcpy (p, "EXXXXXX");
247 #else 245 #else
248 if (flock (indesc, LOCK_EX) < 0) pfatal_with_name (inname); 246 if (flock (indesc, LOCK_EX) < 0) pfatal_with_name (inname);
249 #endif 247 #endif
250 #endif /* MAIL_USE_FLOCK */ 248 #endif /* MAIL_USE_FLOCK */
251 249
252 while (1) 250 {
253 { 251 char buf[1024];
254 nread = read (indesc, buf, sizeof buf); 252
255 if (nread != write (outdesc, buf, nread)) 253 while (1)
256 { 254 {
257 int saved_errno = errno; 255 nread = read (indesc, buf, sizeof buf);
258 unlink (outname); 256 if (nread != write (outdesc, buf, nread))
259 errno = saved_errno; 257 {
260 pfatal_with_name (outname); 258 int saved_errno = errno;
261 } 259 unlink (outname);
262 if (nread < sizeof buf) 260 errno = saved_errno;
263 break; 261 pfatal_with_name (outname);
264 } 262 }
263 if (nread < sizeof buf)
264 break;
265 }
266 }
265 267
266 #ifdef BSD 268 #ifdef BSD
267 if (fsync (outdesc) < 0) 269 if (fsync (outdesc) < 0)
268 pfatal_and_delete (outname); 270 pfatal_and_delete (outname);
269 #endif 271 #endif