23 |
* SOFTWARE. |
* SOFTWARE. |
24 |
*/ |
*/ |
25 |
#include <stdio.h> |
#include <stdio.h> |
26 |
|
#include <stdlib.h> |
27 |
#include <ctype.h> |
#include <ctype.h> |
28 |
#include <string.h> |
#include <string.h> |
29 |
#include <errno.h> |
#include <errno.h> |
30 |
#include <sys/types.h> |
#include <sys/types.h> |
31 |
|
#include <sys/stat.h> |
32 |
#include <sys/param.h> |
#include <sys/param.h> |
33 |
|
#include <time.h> |
34 |
#include <netdb.h> |
#include <netdb.h> |
35 |
#include <fcntl.h> |
#include <fcntl.h> |
36 |
|
#include <unistd.h> |
37 |
#include "xmalloc.h" |
#include "xmalloc.h" |
38 |
#include "common.h" |
#include "common.h" |
39 |
#include "part.h" |
#include "part.h" |
40 |
|
|
41 |
|
extern void warn(char *s); |
42 |
|
|
43 |
#ifndef MAXHOSTNAMELEN |
#ifndef MAXHOSTNAMELEN |
44 |
#define MAXHOSTNAMELEN 64 |
#define MAXHOSTNAMELEN 64 |
45 |
#endif |
#endif |
46 |
|
|
47 |
|
#ifndef errno |
48 |
extern int errno; |
extern int errno; |
49 |
/* extern char *malloc(); */ |
#endif |
|
extern char *getenv(); |
|
50 |
|
|
51 |
int overwrite_files = 0; |
int overwrite_files = 0; |
52 |
int didchat; |
int didchat; |
81 |
} |
} |
82 |
} |
} |
83 |
|
|
84 |
result = (char *)malloc(25+strlen(hostname)); |
result = malloc(25+strlen(hostname)); |
85 |
sprintf(result, "%d.%d@%s", pid, curtime++, hostname); |
sprintf(result, "%d.%lu@%s", pid, (unsigned long) curtime++, hostname); |
86 |
return result; |
return result; |
87 |
} |
} |
88 |
|
|
96 |
strcpy(buf, getenv("TMPDIR")); |
strcpy(buf, getenv("TMPDIR")); |
97 |
} |
} |
98 |
else { |
else { |
99 |
strcpy(buf, "/usr/tmp"); |
strcpy(buf, "/var/tmp"); |
100 |
} |
} |
101 |
strcat(buf, "/m-prts-"); |
strcat(buf, "/m-prts-"); |
102 |
p = getenv("USER"); |
p = getenv("USER"); |
143 |
FILE *ret; |
FILE *ret; |
144 |
|
|
145 |
#ifdef O_EXCL |
#ifdef O_EXCL |
146 |
fd=open(fname, O_RDWR|O_CREAT|O_EXCL, 0644); |
struct stat statbuf; |
147 |
|
|
148 |
|
if ((stat(fname, &statbuf) == 0) && (S_ISCHR(statbuf.st_mode))) { |
149 |
|
fd=open(fname, O_RDWR); |
150 |
|
} |
151 |
|
else { |
152 |
|
fd=open(fname, O_RDWR|O_CREAT|O_EXCL, 0644); |
153 |
|
} |
154 |
#else |
#else |
155 |
fd=open(fname, O_RDWR|O_CREAT|O_TRUNC, 0644); |
fd=open(fname, O_RDWR|O_CREAT|O_TRUNC, 0644); |
156 |
#endif |
#endif |
207 |
do { |
do { |
208 |
if (outfile) fclose(outfile); |
if (outfile) fclose(outfile); |
209 |
sprintf(buf, "part%d", ++filesuffix); |
sprintf(buf, "part%d", ++filesuffix); |
210 |
} while (outfile = fopen(buf, "r")); |
} while ((outfile = fopen(buf, "r"))); |
211 |
fname = buf; |
fname = buf; |
212 |
} |
} |
213 |
else if (!overwrite_files && (outfile = fopen(fname, "r"))) { |
else if (!overwrite_files && (outfile = fopen(fname, "r"))) { |
215 |
fclose(outfile); |
fclose(outfile); |
216 |
sprintf(buf, "%s.%d", fname, ++filesuffix); |
sprintf(buf, "%s.%d", fname, ++filesuffix); |
217 |
|
|
218 |
} while (outfile = fopen(buf, "r")); |
} while ((outfile = fopen(buf, "r"))); |
219 |
fname = buf; |
fname = buf; |
220 |
} |
} |
221 |
|
|
241 |
|
|
242 |
p = strchr(descfname, '/'); |
p = strchr(descfname, '/'); |
243 |
if (!p) p = descfname; |
if (!p) p = descfname; |
244 |
if (p = strrchr(p, '.')) *p = '\0'; |
if ((p = strrchr(p, '.'))) *p = '\0'; |
245 |
|
|
246 |
strcat(descfname, ".desc"); |
strcat(descfname, ".desc"); |
247 |
(void) rename(TEMPFILENAME, descfname); |
(void) rename(TEMPFILENAME, descfname); |