23 |
* SOFTWARE. |
* SOFTWARE. |
24 |
*/ |
*/ |
25 |
#include <stdio.h> |
#include <stdio.h> |
|
#include <stdlib.h> |
|
26 |
#include <ctype.h> |
#include <ctype.h> |
27 |
#include <string.h> |
#include <string.h> |
28 |
#include <errno.h> |
#include <errno.h> |
29 |
#include <sys/types.h> |
#include <sys/types.h> |
|
#include <sys/stat.h> |
|
30 |
#include <sys/param.h> |
#include <sys/param.h> |
|
#include <time.h> |
|
31 |
#include <netdb.h> |
#include <netdb.h> |
32 |
#include <fcntl.h> |
#include <fcntl.h> |
|
#include <unistd.h> |
|
33 |
#include "xmalloc.h" |
#include "xmalloc.h" |
34 |
#include "common.h" |
#include "common.h" |
35 |
#include "part.h" |
#include "part.h" |
36 |
|
|
|
extern void warn(char *s); |
|
|
|
|
37 |
#ifndef MAXHOSTNAMELEN |
#ifndef MAXHOSTNAMELEN |
38 |
#define MAXHOSTNAMELEN 64 |
#define MAXHOSTNAMELEN 64 |
39 |
#endif |
#endif |
40 |
|
|
|
#ifndef errno |
|
41 |
extern int errno; |
extern int errno; |
42 |
#endif |
/* extern char *malloc(); */ |
43 |
|
extern char *getenv(); |
44 |
|
|
45 |
int overwrite_files = 0; |
int overwrite_files = 0; |
46 |
int didchat; |
int didchat; |
75 |
} |
} |
76 |
} |
} |
77 |
|
|
78 |
result = malloc(25+strlen(hostname)); |
result = (char *)malloc(25+strlen(hostname)); |
79 |
sprintf(result, "%d.%lu@%s", pid, (unsigned long) curtime++, hostname); |
sprintf(result, "%d.%d@%s", pid, curtime++, hostname); |
80 |
return result; |
return result; |
81 |
} |
} |
82 |
|
|
90 |
strcpy(buf, getenv("TMPDIR")); |
strcpy(buf, getenv("TMPDIR")); |
91 |
} |
} |
92 |
else { |
else { |
93 |
strcpy(buf, "/var/tmp"); |
strcpy(buf, "/usr/tmp"); |
94 |
} |
} |
95 |
strcat(buf, "/m-prts-"); |
strcat(buf, "/m-prts-"); |
96 |
p = getenv("USER"); |
p = getenv("USER"); |
137 |
FILE *ret; |
FILE *ret; |
138 |
|
|
139 |
#ifdef O_EXCL |
#ifdef O_EXCL |
140 |
struct stat statbuf; |
fd=open(fname, O_RDWR|O_CREAT|O_EXCL, 0644); |
|
|
|
|
if ((stat(fname, &statbuf) == 0) && (S_ISCHR(statbuf.st_mode))) { |
|
|
fd=open(fname, O_RDWR); |
|
|
} |
|
|
else { |
|
|
fd=open(fname, O_RDWR|O_CREAT|O_EXCL, 0644); |
|
|
} |
|
141 |
#else |
#else |
142 |
fd=open(fname, O_RDWR|O_CREAT|O_TRUNC, 0644); |
fd=open(fname, O_RDWR|O_CREAT|O_TRUNC, 0644); |
143 |
#endif |
#endif |
194 |
do { |
do { |
195 |
if (outfile) fclose(outfile); |
if (outfile) fclose(outfile); |
196 |
sprintf(buf, "part%d", ++filesuffix); |
sprintf(buf, "part%d", ++filesuffix); |
197 |
} while ((outfile = fopen(buf, "r"))); |
} while (outfile = fopen(buf, "r")); |
198 |
fname = buf; |
fname = buf; |
199 |
} |
} |
200 |
else if (!overwrite_files && (outfile = fopen(fname, "r"))) { |
else if (!overwrite_files && (outfile = fopen(fname, "r"))) { |
202 |
fclose(outfile); |
fclose(outfile); |
203 |
sprintf(buf, "%s.%d", fname, ++filesuffix); |
sprintf(buf, "%s.%d", fname, ++filesuffix); |
204 |
|
|
205 |
} while ((outfile = fopen(buf, "r"))); |
} while (outfile = fopen(buf, "r")); |
206 |
fname = buf; |
fname = buf; |
207 |
} |
} |
208 |
|
|
228 |
|
|
229 |
p = strchr(descfname, '/'); |
p = strchr(descfname, '/'); |
230 |
if (!p) p = descfname; |
if (!p) p = descfname; |
231 |
if ((p = strrchr(p, '.'))) *p = '\0'; |
if (p = strrchr(p, '.')) *p = '\0'; |
232 |
|
|
233 |
strcat(descfname, ".desc"); |
strcat(descfname, ".desc"); |
234 |
(void) rename(TEMPFILENAME, descfname); |
(void) rename(TEMPFILENAME, descfname); |