1 --- dos2unix-3.1/dos2unix.c
2 +++ dos2unix-3.1/dos2unix.c
4 * RetVal: NULL if failure
5 * file stream otherwise
7 -FILE* OpenOutFile(char *ipFN)
8 +FILE* OpenOutFile(int fd)
10 - return (fopen(ipFN, W_CNTRL));
11 + return (fdopen(fd, W_CNTRL));
18 struct utimbuf UTimeBuf;
21 /* retrieve ipInFN file date stamp */
22 if ((ipFlag->KeepDate) && stat(ipInFN, &StatBuf))
25 - strcpy (TempPath, "./d2utmp");
26 - strcat (TempPath, "XXXXXX");
28 + strcpy (TempPath, "./d2utmpXXXXXX");
29 + if((fd=mkstemp (TempPath))<0) {
30 + perror("Failed to open output temp file");
35 fprintf(stderr, "dos2unix: using %s as temp file\n", TempPath);
39 /* can open out file? */
40 - if ((!RetVal) && (InF) && ((TempF=OpenOutFile(TempPath)) == NULL))
41 + if ((!RetVal) && (InF) && ((TempF=OpenOutFile(fd)) == NULL))
46 /* can close out file? */
47 if ((TempF) && (fclose(TempF) == EOF))
52 if ((!RetVal) && (ipFlag->KeepDate))
57 struct utimbuf UTimeBuf;
60 /* retrieve ipInFN file date stamp */
61 if ((ipFlag->KeepDate) && stat(ipInFN, &StatBuf))
64 - strcpy (TempPath, "./u2dtmp");
65 - strcat (TempPath, "XXXXXX");
67 + strcpy (TempPath, "./u2dtmpXXXXXX");
68 + if((fd=mkstemp (TempPath))<0) {
69 + perror("Failed to open output temp file");
74 fprintf(stderr, "dos2unix: using %s as temp file\n", TempPath);
78 /* can open out file? */
79 - if ((!RetVal) && (InF) && ((TempF=OpenOutFile(TempPath)) == NULL))
80 + if ((!RetVal) && (InF) && ((TempF=OpenOutFile(fd)) == NULL))
85 if ((TempF) && (fclose(TempF) == EOF))
91 if ((!RetVal) && (ipFlag->KeepDate))
93 UTimeBuf.actime = StatBuf.st_atime;