Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-gnome
Path: blob/main/converters/mpack/files/patch-unixos.c
16151 views
1
--- unixos.c.orig 2003-07-21 22:54:05.000000000 +0200
2
+++ unixos.c 2012-01-12 19:22:31.000000000 +0100
3
@@ -23,24 +23,30 @@
4
* SOFTWARE.
5
*/
6
#include <stdio.h>
7
+#include <stdlib.h>
8
#include <ctype.h>
9
#include <string.h>
10
#include <errno.h>
11
#include <sys/types.h>
12
+#include <sys/stat.h>
13
#include <sys/param.h>
14
+#include <time.h>
15
#include <netdb.h>
16
#include <fcntl.h>
17
+#include <unistd.h>
18
#include "xmalloc.h"
19
#include "common.h"
20
#include "part.h"
21
22
+extern void warn(char *s);
23
+
24
#ifndef MAXHOSTNAMELEN
25
#define MAXHOSTNAMELEN 64
26
#endif
27
28
+#ifndef errno
29
extern int errno;
30
-extern char *malloc();
31
-extern char *getenv();
32
+#endif
33
34
int overwrite_files = 0;
35
int didchat;
36
@@ -76,7 +82,7 @@
37
}
38
39
result = malloc(25+strlen(hostname));
40
- sprintf(result, "%d.%d@%s", pid, curtime++, hostname);
41
+ sprintf(result, "%d.%lu@%s", pid, (unsigned long) curtime++, hostname);
42
return result;
43
}
44
45
@@ -90,7 +96,7 @@
46
strcpy(buf, getenv("TMPDIR"));
47
}
48
else {
49
- strcpy(buf, "/usr/tmp");
50
+ strcpy(buf, "/tmp");
51
}
52
strcat(buf, "/m-prts-");
53
p = getenv("USER");
54
@@ -131,6 +137,20 @@
55
rmdir(dir);
56
}
57
58
+FILE *os_createfile(char *fname)
59
+{
60
+ int fd;
61
+ FILE *ret;
62
+
63
+ fd=open(fname, O_RDWR|O_CREAT|O_TRUNC, 0600);
64
+
65
+ if (fd == -1)
66
+ return NULL;
67
+
68
+ ret=fdopen(fd, "w");
69
+ return ret;
70
+}
71
+
72
FILE *os_createnewfile(char *fname)
73
{
74
int fd;
75
@@ -194,7 +214,7 @@
76
do {
77
if (outfile) fclose(outfile);
78
sprintf(buf, "part%d", ++filesuffix);
79
- } while (outfile = fopen(buf, "r"));
80
+ } while ((outfile = fopen(buf, "r")));
81
fname = buf;
82
}
83
else if (!overwrite_files && (outfile = fopen(fname, "r"))) {
84
@@ -202,7 +222,7 @@
85
fclose(outfile);
86
sprintf(buf, "%s.%d", fname, ++filesuffix);
87
88
- } while (outfile = fopen(buf, "r"));
89
+ } while ((outfile = fopen(buf, "r")));
90
fname = buf;
91
}
92
93
@@ -228,7 +248,7 @@
94
95
p = strchr(descfname, '/');
96
if (!p) p = descfname;
97
- if (p = strrchr(p, '.')) *p = '\0';
98
+ if ((p = strrchr(p, '.'))) *p = '\0';
99
100
strcat(descfname, ".desc");
101
(void) rename(TEMPFILENAME, descfname);
102
103