Path: blob/main/converters/mpack/files/patch-unixos.c
16151 views
--- unixos.c.orig 2003-07-21 22:54:05.000000000 +02001+++ unixos.c 2012-01-12 19:22:31.000000000 +01002@@ -23,24 +23,30 @@3* SOFTWARE.4*/5#include <stdio.h>6+#include <stdlib.h>7#include <ctype.h>8#include <string.h>9#include <errno.h>10#include <sys/types.h>11+#include <sys/stat.h>12#include <sys/param.h>13+#include <time.h>14#include <netdb.h>15#include <fcntl.h>16+#include <unistd.h>17#include "xmalloc.h"18#include "common.h"19#include "part.h"2021+extern void warn(char *s);22+23#ifndef MAXHOSTNAMELEN24#define MAXHOSTNAMELEN 6425#endif2627+#ifndef errno28extern int errno;29-extern char *malloc();30-extern char *getenv();31+#endif3233int overwrite_files = 0;34int didchat;35@@ -76,7 +82,7 @@36}3738result = malloc(25+strlen(hostname));39- sprintf(result, "%d.%d@%s", pid, curtime++, hostname);40+ sprintf(result, "%d.%lu@%s", pid, (unsigned long) curtime++, hostname);41return result;42}4344@@ -90,7 +96,7 @@45strcpy(buf, getenv("TMPDIR"));46}47else {48- strcpy(buf, "/usr/tmp");49+ strcpy(buf, "/tmp");50}51strcat(buf, "/m-prts-");52p = getenv("USER");53@@ -131,6 +137,20 @@54rmdir(dir);55}5657+FILE *os_createfile(char *fname)58+{59+ int fd;60+ FILE *ret;61+62+ fd=open(fname, O_RDWR|O_CREAT|O_TRUNC, 0600);63+64+ if (fd == -1)65+ return NULL;66+67+ ret=fdopen(fd, "w");68+ return ret;69+}70+71FILE *os_createnewfile(char *fname)72{73int fd;74@@ -194,7 +214,7 @@75do {76if (outfile) fclose(outfile);77sprintf(buf, "part%d", ++filesuffix);78- } while (outfile = fopen(buf, "r"));79+ } while ((outfile = fopen(buf, "r")));80fname = buf;81}82else if (!overwrite_files && (outfile = fopen(fname, "r"))) {83@@ -202,7 +222,7 @@84fclose(outfile);85sprintf(buf, "%s.%d", fname, ++filesuffix);8687- } while (outfile = fopen(buf, "r"));88+ } while ((outfile = fopen(buf, "r")));89fname = buf;90}9192@@ -228,7 +248,7 @@9394p = strchr(descfname, '/');95if (!p) p = descfname;96- if (p = strrchr(p, '.')) *p = '\0';97+ if ((p = strrchr(p, '.'))) *p = '\0';9899strcat(descfname, ".desc");100(void) rename(TEMPFILENAME, descfname);101102103