mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-27 22:03:54 +03:00
dos2unix and unix2dos provided by griswold
svn path=/nixpkgs/trunk/; revision=19409
This commit is contained in:
parent
0407211253
commit
a6cd7eb8a1
41
pkgs/tools/text/dos2unix/default.nix
Normal file
41
pkgs/tools/text/dos2unix/default.nix
Normal file
@ -0,0 +1,41 @@
|
||||
{stdenv, fetchurl}:
|
||||
|
||||
stdenv.mkDerivation {
|
||||
name = "dos2unix-2.2";
|
||||
|
||||
src = fetchurl {
|
||||
url = http://cvs.fedoraproject.org/repo/pkgs/dos2unix/dos2unix-3.1.tar.bz2/f90026a397cf787083ec2e4892c6dcdd/dos2unix-3.1.tar.bz2;
|
||||
md5 = "f90026a397cf787083ec2e4892c6dcdd";
|
||||
};
|
||||
|
||||
patches = [
|
||||
./dos2unix-3.1.patch
|
||||
./dos2unix-3.1-segfault.patch
|
||||
./dos2unix-3.1-safeconv.patch
|
||||
./dos2unix-3.1-manpage-update-57507.patch
|
||||
./dos2unix-3.1-preserve-file-modes.patch
|
||||
./dos2unix-3.1-tmppath.patch
|
||||
./dos2unix-c-missing-arg.patch
|
||||
./dos2unix-missing-proto.patch
|
||||
./dos2unix-manpage.patch
|
||||
./dos2unix-preserve-file-modes.patch
|
||||
];
|
||||
|
||||
installPhase = ''
|
||||
ensureDir $out/bin
|
||||
ensureDir $out/share/man/man1
|
||||
install -p -m755 dos2unix $out/bin
|
||||
install -p -m644 dos2unix.1 $out/share/man/man1
|
||||
ln -s dos2unix $out/bin/mac2unix
|
||||
'';
|
||||
|
||||
buildPhase = ''
|
||||
rm -f dos2unix
|
||||
make dos2unix
|
||||
'';
|
||||
|
||||
meta = {
|
||||
homepage = http://unknown/;
|
||||
description = "dos2unix tool";
|
||||
};
|
||||
}
|
238
pkgs/tools/text/dos2unix/dos2unix-3.1-manpage-update-57507.patch
Normal file
238
pkgs/tools/text/dos2unix/dos2unix-3.1-manpage-update-57507.patch
Normal file
@ -0,0 +1,238 @@
|
||||
Patch by Bill Anderson, to fix bug:
|
||||
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=57507
|
||||
|
||||
|
||||
|
||||
Description of Problem:
|
||||
|
||||
The dos2unix man page examples are confusing.
|
||||
For instance, one piece of text mentions "c.txt", but that file
|
||||
isn't used in the following example.
|
||||
|
||||
|
||||
|
||||
--- dos2unix-3.1/dos2unix.1 2004-09-28 03:17:29.000000000 -0600
|
||||
+++ dos2unix-3.1/dos2unix.1-new 2004-09-28 03:16:32.000000000 -0600
|
||||
@@ -1,123 +1,126 @@
|
||||
.\" $$Id: dos2unix.1 2.2 1995/03/31 01:50:45 blin Exp blin $$
|
||||
-.TH dos2unix 1 "dos2unix v3.0" "1995.03.31"
|
||||
-
|
||||
-.SH NAME
|
||||
-
|
||||
+.\"
|
||||
+.TH "dos2unix" "1" "dos2unix v3.0" "1995.03.31" ""
|
||||
+.SH "NAME"
|
||||
dos2unix \- DOS/MAC to UNIX text file format converter
|
||||
|
||||
-.SH SYNOPSYS
|
||||
-
|
||||
-dos2unix [options] [-c convmode] [-o file ...] [-n infile outfile ...]
|
||||
-.PP
|
||||
+.SH "SYNOPSYS"
|
||||
+dos2unix [options] [\-c convmode] [\-o file ...] [\-n infile outfile ...]
|
||||
+.PP
|
||||
Options:
|
||||
-.PP
|
||||
-[-hkqV] [--help] [--keepdate] [--quiet] [--version]
|
||||
-
|
||||
-.SH DESCRIPTION
|
||||
+.PP
|
||||
+[\-hkqV] [\-\-help] [\-\-keepdate] [\-\-quiet] [\-\-version]
|
||||
|
||||
-.PP
|
||||
+.SH "DESCRIPTION"
|
||||
+.PP
|
||||
This manual page documents dos2unix, the program that converts plain text
|
||||
files in DOS/MAC format to UNIX format.
|
||||
|
||||
-.SH OPTIONS
|
||||
-
|
||||
+.SH "OPTIONS"
|
||||
The following options are available:
|
||||
-.TP
|
||||
-.B \-h --help
|
||||
+.TP
|
||||
+.B \-h \-\-help
|
||||
Print online help.
|
||||
|
||||
-.TP
|
||||
-.B \-k --keepdate
|
||||
+.TP
|
||||
+.B \-k \-\-keepdate
|
||||
Keep the date stamp of output file same as input file.
|
||||
|
||||
-.TP
|
||||
-.B \-q --quiet
|
||||
+.TP
|
||||
+.B \-q \-\-quiet
|
||||
Quiet mode. Suppress all warning and messages.
|
||||
|
||||
-.TP
|
||||
-.B \-V --version
|
||||
+.TP
|
||||
+.B \-V \-\-version
|
||||
Prints version information.
|
||||
|
||||
-.TP
|
||||
-.B \-c --convmode convmode
|
||||
-Sets conversion mode. Simulates dos2unix under SunOS.
|
||||
+.TP
|
||||
+.B \-c \-\-convmode convmode
|
||||
+Sets conversion mode. Where convmode is one of:
|
||||
+.B ASCII, 7bit, ISO, Mac
|
||||
+with ASCII being the default.
|
||||
+Simulates dos2unix under SunOS.
|
||||
+
|
||||
+
|
||||
|
||||
-.TP
|
||||
-.B \-o --oldfile file ...
|
||||
+.TP
|
||||
+.B \-o \-\-oldfile file ...
|
||||
Old file mode. Convert the file and write output to it. The program
|
||||
default to run in this mode. Wildcard names may be used.
|
||||
|
||||
-.TP
|
||||
-.B \-n --newfile infile outfile ...
|
||||
+.TP
|
||||
+.B \-n \-\-newfile infile outfile ...
|
||||
New file mode. Convert the infile and write output to outfile. File names
|
||||
must be given in pairs and wildcard names should NOT be used or you WILL
|
||||
lost your files.
|
||||
|
||||
-.SH EXAMPLES
|
||||
-
|
||||
-.LP
|
||||
+.SH "EXAMPLES"
|
||||
+.LP
|
||||
Get input from stdin and write output to stdout.
|
||||
-.IP
|
||||
+.IP
|
||||
.B dos2unix
|
||||
|
||||
-.LP
|
||||
+.LP
|
||||
Convert and replace a.txt. Convert and replace b.txt.
|
||||
-.IP
|
||||
+.IP
|
||||
.B dos2unix a.txt b.txt
|
||||
-.IP
|
||||
-.B dos2unix -o a.txt b.txt
|
||||
+.IP
|
||||
+.B dos2unix \-o a.txt b.txt
|
||||
|
||||
-.LP
|
||||
+.LP
|
||||
Convert and replace a.txt in ASCII conversion mode.
|
||||
+.IP
|
||||
+.B dos2unix a.txt \-c iso b.txt
|
||||
+
|
||||
+.LP
|
||||
Convert and replace b.txt in ISO conversion mode.
|
||||
+.IP
|
||||
+.B dos2unix \-c ascii a.txt \-c iso b.txt
|
||||
+
|
||||
+.LP
|
||||
Convert c.txt from Mac to Unix ascii format.
|
||||
-.IP
|
||||
-.B dos2unix a.txt -c iso b.txt
|
||||
-.IP
|
||||
-.B dos2unix -c ascii a.txt -c iso b.txt
|
||||
-.IP
|
||||
-.B dos2unix -c mac a.txt b.txt
|
||||
|
||||
-.LP
|
||||
+.IP
|
||||
+.B dos2unix \-c mac c.txt b.txt
|
||||
+
|
||||
+.LP
|
||||
Convert and replace a.txt while keeping original date stamp.
|
||||
-.IP
|
||||
-.B dos2unix -k a.txt
|
||||
-.IP
|
||||
-.B dos2unix -k -o a.txt
|
||||
+.IP
|
||||
+.B dos2unix \-k a.txt
|
||||
+.IP
|
||||
+.B dos2unix \-k \-o a.txt
|
||||
|
||||
-.LP
|
||||
+.LP
|
||||
Convert a.txt and write to e.txt.
|
||||
-.IP
|
||||
-.B dos2unix -n a.txt e.txt
|
||||
+.IP
|
||||
+.B dos2unix \-n a.txt e.txt
|
||||
|
||||
-.LP
|
||||
+.LP
|
||||
Convert a.txt and write to e.txt, keep date stamp of e.txt same as a.txt.
|
||||
-.IP
|
||||
-.B dos2unix -k -n a.txt e.txt
|
||||
+.IP
|
||||
+.B dos2unix \-k \-n a.txt e.txt
|
||||
|
||||
-.LP
|
||||
+.LP
|
||||
Convert and replace a.txt. Convert b.txt and write to e.txt.
|
||||
-.IP
|
||||
-.B dos2unix a.txt -n b.txt e.txt
|
||||
-.IP
|
||||
-.B dos2unix -o a.txt -n b.txt e.txt
|
||||
+.IP
|
||||
+.B dos2unix a.txt \-n b.txt e.txt
|
||||
+.IP
|
||||
+.B dos2unix \-o a.txt \-n b.txt e.txt
|
||||
|
||||
-.LP
|
||||
+.LP
|
||||
Convert c.txt and write to e.txt. Convert and replace a.txt.
|
||||
Convert and replace b.txt. Convert d.txt and write to f.txt.
|
||||
-.IP
|
||||
-.B dos2unix -n c.txt e.txt -o a.txt b.txt -n d.txt f.txt
|
||||
+.IP
|
||||
+.B dos2unix \-n c.txt e.txt \-o a.txt b.txt \-n d.txt f.txt
|
||||
|
||||
-.SH DIAGNOSTICS
|
||||
-
|
||||
-.SH BUGS
|
||||
+.SH "DIAGNOSTICS"
|
||||
|
||||
+.SH "BUGS"
|
||||
The program does not work properly under MSDOS in stdio processing mode.
|
||||
If you know why is that so, please tell me.
|
||||
|
||||
-.SH AUTHORS
|
||||
-
|
||||
-Benjamin Lin -
|
||||
+.SH "AUTHORS"
|
||||
+Benjamin Lin \-
|
||||
.B <blin@socs.uts.edu.au>
|
||||
|
||||
|
||||
@@ -125,18 +128,17 @@
|
||||
.B <wuebben@kde.org>
|
||||
|
||||
|
||||
-.SH MISCELLANY
|
||||
-
|
||||
+.SH "MISCELLANY"
|
||||
Tested environment:
|
||||
-.IP
|
||||
+.IP
|
||||
Linux 1.2.0 with GNU C 2.5.8
|
||||
-.IP
|
||||
+.IP
|
||||
SunOS 4.1.3 with GNU C 2.6.3
|
||||
-.IP
|
||||
-MS-DOS 6.20 with Borland C++ 4.02
|
||||
-.PP
|
||||
+.IP
|
||||
+MS\-DOS 6.20 with Borland C++ 4.02
|
||||
+.PP
|
||||
Suggestions and bug reports are welcome.
|
||||
|
||||
-.SH SEE ALSO
|
||||
+.SH "SEE ALSO"
|
||||
unix2dos(1) mac2unix(1)
|
||||
|
@ -0,0 +1,28 @@
|
||||
--- dos2unix-3.1/dos2unix.c.mode 2003-05-21 08:09:08.000000000 -0700
|
||||
+++ dos2unix-3.1/dos2unix.c 2003-05-21 08:09:56.000000000 -0700
|
||||
@@ -345,11 +345,14 @@ int ConvertDosToUnixOldFile(char* ipInFN
|
||||
char TempPath[16];
|
||||
struct stat StatBuf;
|
||||
struct utimbuf UTimeBuf;
|
||||
+ mode_t mode = S_IRUSR | S_IWUSR;
|
||||
int fd;
|
||||
|
||||
/* retrieve ipInFN file date stamp */
|
||||
- if ((ipFlag->KeepDate) && stat(ipInFN, &StatBuf))
|
||||
+ if (stat(ipInFN, &StatBuf))
|
||||
RetVal = -1;
|
||||
+ else
|
||||
+ mode = StatBuf.st_mode;
|
||||
|
||||
strcpy (TempPath, "./u2dtmpXXXXXX");
|
||||
if((fd=mkstemp (TempPath))<0) {
|
||||
@@ -357,6 +360,9 @@ int ConvertDosToUnixOldFile(char* ipInFN
|
||||
RetVal = -1;
|
||||
}
|
||||
|
||||
+ if (!RetVal && fchmod (fd, mode) && fchmod (fd, S_IRUSR | S_IWUSR))
|
||||
+ RetVal = -1;
|
||||
+
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "dos2unix: using %s as temp file\n", TempPath);
|
||||
#endif DEBUG
|
88
pkgs/tools/text/dos2unix/dos2unix-3.1-safeconv.patch
Normal file
88
pkgs/tools/text/dos2unix/dos2unix-3.1-safeconv.patch
Normal file
@ -0,0 +1,88 @@
|
||||
* Fix http://bugzilla.redhat.com/57508 (make dos2unix not modify Mac
|
||||
files unless in mac2unix mode)
|
||||
* Make mac2unix mode not create duplicate Unix line delimiters when
|
||||
run on a DOS file. (mschwendt@users.sf.net)
|
||||
|
||||
diff -Nur dos2unix-3.1-orig/dos2unix.c dos2unix-3.1/dos2unix.c
|
||||
--- dos2unix-3.1-orig/dos2unix.c 1998-11-19 13:19:25.000000000 +0100
|
||||
+++ dos2unix-3.1/dos2unix.c 2004-09-26 20:57:41.606587616 +0200
|
||||
@@ -153,6 +153,24 @@
|
||||
}
|
||||
|
||||
|
||||
+void StripDelimiter(FILE* ipInF, FILE* ipOutF, CFlag *ipFlag, int CurChar)
|
||||
+{
|
||||
+ int TempNextChar;
|
||||
+ /* Don't modify Mac files when in dos2unix mode. */
|
||||
+ if ( (TempNextChar = getc(ipInF)) != EOF) {
|
||||
+ ungetc( TempNextChar, ipInF ); /* put back peek char */
|
||||
+ if ( TempNextChar != '\x0a' ) {
|
||||
+ putc( CurChar, ipOutF ); /* Mac line, put back CR */
|
||||
+ }
|
||||
+ }
|
||||
+ else if ( CurChar == '\x0d' ) { /* EOF: last Mac line delimiter (CR)? */
|
||||
+ putc( CurChar, ipOutF );
|
||||
+ }
|
||||
+ if (ipFlag->NewLine) { /* add additional LF? */
|
||||
+ putc('\n', ipOutF);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
/* converts stream ipInF to UNIX format text and write to stream ipOutF
|
||||
* RetVal: 0 if success
|
||||
* -1 otherwise
|
||||
@@ -161,6 +179,7 @@
|
||||
{
|
||||
int RetVal = 0;
|
||||
int TempChar;
|
||||
+ int TempNextChar;
|
||||
|
||||
if ( macmode )
|
||||
ipFlag->ConvMode = 3;
|
||||
@@ -177,9 +196,7 @@
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
- if (ipFlag->NewLine) {
|
||||
- putc('\n', ipOutF);
|
||||
- }
|
||||
+ StripDelimiter( ipInF, ipOutF, ipFlag, TempChar );
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -193,9 +210,7 @@
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
- if (ipFlag->NewLine) {
|
||||
- putc('\n', ipOutF);
|
||||
- }
|
||||
+ StripDelimiter( ipInF, ipOutF, ipFlag, TempChar );
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -209,9 +224,7 @@
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
- if (ipFlag->NewLine) {
|
||||
- putc('\n', ipOutF);
|
||||
- }
|
||||
+ StripDelimiter( ipInF, ipOutF, ipFlag, TempChar );
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -227,6 +240,13 @@
|
||||
}
|
||||
}
|
||||
else{
|
||||
+ if ( (TempNextChar = getc(ipInF)) != EOF) {
|
||||
+ ungetc( TempNextChar, ipInF ); /* put back peek char */
|
||||
+ /* Don't touch this delimiter if it's a CR,LF pair. */
|
||||
+ if ( TempNextChar == '\x0a' ) {
|
||||
+ continue;
|
||||
+ }
|
||||
+ }
|
||||
if (putc('\x0a', ipOutF) == EOF)
|
||||
{
|
||||
RetVal = -1;
|
93
pkgs/tools/text/dos2unix/dos2unix-3.1-segfault.patch
Normal file
93
pkgs/tools/text/dos2unix/dos2unix-3.1-segfault.patch
Normal file
@ -0,0 +1,93 @@
|
||||
--- dos2unix-3.1/dos2unix.c.segf Thu Jan 17 17:27:42 2002
|
||||
+++ dos2unix-3.1/dos2unix.c Thu Jan 17 17:28:07 2002
|
||||
@@ -147,9 +147,9 @@
|
||||
* RetVal: NULL if failure
|
||||
* file stream otherwise
|
||||
*/
|
||||
-FILE* OpenOutFile(char *ipFN)
|
||||
+FILE* OpenOutFile(int fd)
|
||||
{
|
||||
- return (fopen(ipFN, W_CNTRL));
|
||||
+ return (fdopen(fd, W_CNTRL));
|
||||
}
|
||||
|
||||
|
||||
@@ -260,14 +260,17 @@
|
||||
char TempPath[16];
|
||||
struct stat StatBuf;
|
||||
struct utimbuf UTimeBuf;
|
||||
+ int fd;
|
||||
|
||||
/* retrieve ipInFN file date stamp */
|
||||
if ((ipFlag->KeepDate) && stat(ipInFN, &StatBuf))
|
||||
RetVal = -1;
|
||||
|
||||
- strcpy (TempPath, "./d2utmp");
|
||||
- strcat (TempPath, "XXXXXX");
|
||||
- mkstemp (TempPath);
|
||||
+ strcpy (TempPath, "./d2utmpXXXXXX");
|
||||
+ if((fd=mkstemp (TempPath))<0) {
|
||||
+ perror("Failed to open output temp file");
|
||||
+ RetVal = -1;
|
||||
+ }
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "dos2unix: using %s as temp file\n", TempPath);
|
||||
@@ -278,7 +281,7 @@
|
||||
RetVal = -1;
|
||||
|
||||
/* can open out file? */
|
||||
- if ((!RetVal) && (InF) && ((TempF=OpenOutFile(TempPath)) == NULL))
|
||||
+ if ((!RetVal) && (InF) && ((TempF=OpenOutFile(fd)) == NULL))
|
||||
{
|
||||
fclose (InF);
|
||||
RetVal = -1;
|
||||
@@ -295,6 +298,8 @@
|
||||
/* can close out file? */
|
||||
if ((TempF) && (fclose(TempF) == EOF))
|
||||
RetVal = -1;
|
||||
+ if(fd>=0)
|
||||
+ close(fd);
|
||||
|
||||
if ((!RetVal) && (ipFlag->KeepDate))
|
||||
{
|
||||
@@ -340,14 +345,17 @@
|
||||
char TempPath[16];
|
||||
struct stat StatBuf;
|
||||
struct utimbuf UTimeBuf;
|
||||
+ int fd;
|
||||
|
||||
/* retrieve ipInFN file date stamp */
|
||||
if ((ipFlag->KeepDate) && stat(ipInFN, &StatBuf))
|
||||
RetVal = -1;
|
||||
|
||||
- strcpy (TempPath, "./u2dtmp");
|
||||
- strcat (TempPath, "XXXXXX");
|
||||
- mkstemp (TempPath);
|
||||
+ strcpy (TempPath, "./u2dtmpXXXXXX");
|
||||
+ if((fd=mkstemp (TempPath))<0) {
|
||||
+ perror("Failed to open output temp file");
|
||||
+ RetVal = -1;
|
||||
+ }
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "dos2unix: using %s as temp file\n", TempPath);
|
||||
@@ -358,7 +366,7 @@
|
||||
RetVal = -1;
|
||||
|
||||
/* can open out file? */
|
||||
- if ((!RetVal) && (InF) && ((TempF=OpenOutFile(TempPath)) == NULL))
|
||||
+ if ((!RetVal) && (InF) && ((TempF=OpenOutFile(fd)) == NULL))
|
||||
{
|
||||
fclose (InF);
|
||||
RetVal = -1;
|
||||
@@ -376,6 +384,9 @@
|
||||
if ((TempF) && (fclose(TempF) == EOF))
|
||||
RetVal = -1;
|
||||
|
||||
+ if(fd>=0)
|
||||
+ close(fd);
|
||||
+
|
||||
if ((!RetVal) && (ipFlag->KeepDate))
|
||||
{
|
||||
UTimeBuf.actime = StatBuf.st_atime;
|
141
pkgs/tools/text/dos2unix/dos2unix-3.1-tmppath.patch
Normal file
141
pkgs/tools/text/dos2unix/dos2unix-3.1-tmppath.patch
Normal file
@ -0,0 +1,141 @@
|
||||
--- dos2unix-3.1/dos2unix.c.tmppath 2004-10-20 16:00:00.342561008 +0200
|
||||
+++ dos2unix-3.1/dos2unix.c 2004-10-20 16:01:42.210074792 +0200
|
||||
@@ -69,6 +69,7 @@
|
||||
#ifdef __MSDOS__
|
||||
# include <dir.h>
|
||||
#endif __MSDOS__
|
||||
+#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -267,6 +268,39 @@
|
||||
return RetVal;
|
||||
}
|
||||
|
||||
+static int MakeTempFileFrom(const char *OutFN, char **fname_ret)
|
||||
+{
|
||||
+ char *cpy = strdup(OutFN);
|
||||
+ char *dir = NULL;
|
||||
+ size_t fname_len = 0;
|
||||
+ char *fname_str = NULL;
|
||||
+ int fd = -1;
|
||||
+
|
||||
+ *fname_ret = NULL;
|
||||
+
|
||||
+ if (!cpy)
|
||||
+ goto make_failed;
|
||||
+
|
||||
+ dir = dirname(cpy);
|
||||
+
|
||||
+ fname_len = strlen(dir) + strlen("/d2utmpXXXXXX") + sizeof (char);
|
||||
+ if (!(fname_str = malloc(fname_len)))
|
||||
+ goto make_failed;
|
||||
+ sprintf(fname_str, "%s%s", dir, "/d2utmpXXXXXX");
|
||||
+ *fname_ret = fname_str;
|
||||
+
|
||||
+ free(cpy);
|
||||
+
|
||||
+ if ((fd = mkstemp(fname_str)) == -1)
|
||||
+ goto make_failed;
|
||||
+
|
||||
+ return (fd);
|
||||
+
|
||||
+ make_failed:
|
||||
+ free(*fname_ret);
|
||||
+ *fname_ret = NULL;
|
||||
+ return (-1);
|
||||
+}
|
||||
|
||||
/* convert file ipInFN to UNIX format text and write to file ipOutFN
|
||||
* RetVal: 0 if success
|
||||
@@ -277,7 +311,7 @@
|
||||
int RetVal = 0;
|
||||
FILE *InF = NULL;
|
||||
FILE *TempF = NULL;
|
||||
- char TempPath[16];
|
||||
+ char *TempPath;
|
||||
struct stat StatBuf;
|
||||
struct utimbuf UTimeBuf;
|
||||
int fd;
|
||||
@@ -286,8 +320,7 @@
|
||||
if ((ipFlag->KeepDate) && stat(ipInFN, &StatBuf))
|
||||
RetVal = -1;
|
||||
|
||||
- strcpy (TempPath, "./d2utmpXXXXXX");
|
||||
- if((fd=mkstemp (TempPath))<0) {
|
||||
+ if((fd = MakeTempFileFrom(ipOutFN, &TempPath))<0) {
|
||||
perror("Failed to open output temp file");
|
||||
RetVal = -1;
|
||||
}
|
||||
@@ -304,6 +337,7 @@
|
||||
if ((!RetVal) && (InF) && ((TempF=OpenOutFile(fd)) == NULL))
|
||||
{
|
||||
fclose (InF);
|
||||
+ InF = NULL;
|
||||
RetVal = -1;
|
||||
}
|
||||
|
||||
@@ -337,9 +371,6 @@
|
||||
/* can rename temp file to out file? */
|
||||
if (!RetVal)
|
||||
{
|
||||
- if (stat(ipOutFN, &StatBuf) == 0)
|
||||
- unlink(ipOutFN);
|
||||
-
|
||||
if ((rename(TempPath, ipOutFN) == -1) && (!ipFlag->Quiet))
|
||||
{
|
||||
fprintf(stderr, "dos2unix: problems renaming '%s' to '%s'\n", TempPath, ipOutFN);
|
||||
@@ -347,6 +378,7 @@
|
||||
RetVal = -1;
|
||||
}
|
||||
}
|
||||
+ free(TempPath);
|
||||
return RetVal;
|
||||
}
|
||||
|
||||
@@ -362,7 +394,7 @@
|
||||
int RetVal = 0;
|
||||
FILE *InF = NULL;
|
||||
FILE *TempF = NULL;
|
||||
- char TempPath[16];
|
||||
+ char *TempPath;
|
||||
struct stat StatBuf;
|
||||
struct utimbuf UTimeBuf;
|
||||
mode_t mode = S_IRUSR | S_IWUSR;
|
||||
@@ -374,8 +406,7 @@
|
||||
else
|
||||
mode = StatBuf.st_mode;
|
||||
|
||||
- strcpy (TempPath, "./u2dtmpXXXXXX");
|
||||
- if((fd=mkstemp (TempPath))<0) {
|
||||
+ if((fd = MakeTempFileFrom(ipInFN, &TempPath))<0) {
|
||||
perror("Failed to open output temp file");
|
||||
RetVal = -1;
|
||||
}
|
||||
@@ -395,6 +426,7 @@
|
||||
if ((!RetVal) && (InF) && ((TempF=OpenOutFile(fd)) == NULL))
|
||||
{
|
||||
fclose (InF);
|
||||
+ InF = NULL;
|
||||
RetVal = -1;
|
||||
}
|
||||
|
||||
@@ -422,10 +454,6 @@
|
||||
RetVal = -1;
|
||||
}
|
||||
|
||||
- /* can delete in file? */
|
||||
- if ((!RetVal) && (unlink(ipInFN) == -1))
|
||||
- RetVal = -1;
|
||||
-
|
||||
/* any error? */
|
||||
if ((RetVal) && (unlink(TempPath)))
|
||||
RetVal = -1;
|
||||
@@ -440,6 +468,7 @@
|
||||
}
|
||||
RetVal = -1;
|
||||
}
|
||||
+ free(TempPath);
|
||||
return RetVal;
|
||||
}
|
||||
|
49
pkgs/tools/text/dos2unix/dos2unix-3.1.patch
Normal file
49
pkgs/tools/text/dos2unix/dos2unix-3.1.patch
Normal file
@ -0,0 +1,49 @@
|
||||
--- dos2unix-3.1/Makefile.orig Thu Nov 19 07:09:38 1998
|
||||
+++ dos2unix-3.1/Makefile Fri Nov 17 13:25:35 2000
|
||||
@@ -1,10 +1,12 @@
|
||||
+CFLAGS=
|
||||
+
|
||||
default: dos2unix
|
||||
|
||||
all: dos2unix link install
|
||||
|
||||
|
||||
dos2unix:
|
||||
- gcc -O dos2unix.c -o dos2unix
|
||||
+ gcc $(CFLAGS) dos2unix.c -o dos2unix
|
||||
|
||||
|
||||
link:
|
||||
@@ -12,11 +14,10 @@
|
||||
ln -s dos2unix.1 mac2unix.1
|
||||
|
||||
clean:
|
||||
- rm dos2unix
|
||||
+ rm -f dos2unix mac2unix mac2unix.1 *~ *.orig core
|
||||
|
||||
install:
|
||||
install -m 755 dos2unix /usr/local/bin
|
||||
install -m 644 dos2unix.1 /usr/local/man/man1
|
||||
install -m 755 mac2unix /usr/local/bin
|
||||
install -m 644 mac2unix.1 /usr/local/man/man1
|
||||
-
|
||||
--- dos2unix-3.1/dos2unix.c.orig Thu Nov 19 07:19:25 1998
|
||||
+++ dos2unix-3.1/dos2unix.c Fri Nov 17 13:25:25 2000
|
||||
@@ -267,7 +267,7 @@
|
||||
|
||||
strcpy (TempPath, "./d2utmp");
|
||||
strcat (TempPath, "XXXXXX");
|
||||
- mktemp (TempPath);
|
||||
+ mkstemp (TempPath);
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "dos2unix: using %s as temp file\n", TempPath);
|
||||
@@ -347,7 +347,7 @@
|
||||
|
||||
strcpy (TempPath, "./u2dtmp");
|
||||
strcat (TempPath, "XXXXXX");
|
||||
- mktemp (TempPath);
|
||||
+ mkstemp (TempPath);
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "dos2unix: using %s as temp file\n", TempPath);
|
42
pkgs/tools/text/dos2unix/dos2unix-c-missing-arg.patch
Normal file
42
pkgs/tools/text/dos2unix/dos2unix-c-missing-arg.patch
Normal file
@ -0,0 +1,42 @@
|
||||
diff -up dos2unix-3.1/dos2unix.c.c-missing-arg dos2unix-3.1/dos2unix.c
|
||||
--- dos2unix-3.1/dos2unix.c.c-missing-arg 2008-01-18 09:24:21.000000000 +0000
|
||||
+++ dos2unix-3.1/dos2unix.c 2008-01-18 09:25:43.000000000 +0000
|
||||
@@ -533,19 +533,28 @@ int main (int argc, char *argv[])
|
||||
|
||||
if ((strcmp(argv[ArgIdx],"-c") == 0) || (strcmp(argv[ArgIdx],"--convmode") == 0))
|
||||
{
|
||||
- ArgIdx++;
|
||||
- if (strcmpi(argv[ArgIdx],"ASCII") == 0)
|
||||
- pFlag->ConvMode = 0;
|
||||
- else if (strcmpi(argv[ArgIdx], "7Bit") == 0)
|
||||
- pFlag->ConvMode = 1;
|
||||
- else if (strcmpi(argv[ArgIdx], "ISO") == 0)
|
||||
- pFlag->ConvMode = 2;
|
||||
- else if (strcmpi(argv[ArgIdx], "Mac") == 0)
|
||||
- pFlag->ConvMode = 3;
|
||||
+ if (++ArgIdx < argc)
|
||||
+ {
|
||||
+ if (strcmpi(argv[ArgIdx],"ASCII") == 0)
|
||||
+ pFlag->ConvMode = 0;
|
||||
+ else if (strcmpi(argv[ArgIdx], "7Bit") == 0)
|
||||
+ pFlag->ConvMode = 1;
|
||||
+ else if (strcmpi(argv[ArgIdx], "ISO") == 0)
|
||||
+ pFlag->ConvMode = 2;
|
||||
+ else if (strcmpi(argv[ArgIdx], "Mac") == 0)
|
||||
+ pFlag->ConvMode = 3;
|
||||
+ else
|
||||
+ {
|
||||
+ if (!pFlag->Quiet)
|
||||
+ fprintf(stderr, "dos2unix: invalid %s conversion mode specified\n",argv[ArgIdx]);
|
||||
+ ShouldExit = 1;
|
||||
+ }
|
||||
+ }
|
||||
else
|
||||
{
|
||||
+ ArgIdx--;
|
||||
if (!pFlag->Quiet)
|
||||
- fprintf(stderr, "dos2unix: invalid %s conversion mode specified\n",argv[ArgIdx]);
|
||||
+ fprintf(stderr,"dos2unix: option `%s' requires an argument\n",argv[ArgIdx]);
|
||||
ShouldExit = 1;
|
||||
}
|
||||
}
|
12
pkgs/tools/text/dos2unix/dos2unix-manpage.patch
Normal file
12
pkgs/tools/text/dos2unix/dos2unix-manpage.patch
Normal file
@ -0,0 +1,12 @@
|
||||
diff -up dos2unix-3.1/dos2unix.1.manpage dos2unix-3.1/dos2unix.1
|
||||
--- dos2unix-3.1/dos2unix.1.manpage 2008-09-08 09:58:46.000000000 +0100
|
||||
+++ dos2unix-3.1/dos2unix.1 2008-09-08 09:58:56.000000000 +0100
|
||||
@@ -52,7 +52,7 @@ default to run in this mode. Wildcard na
|
||||
.B \-n \-\-newfile infile outfile ...
|
||||
New file mode. Convert the infile and write output to outfile. File names
|
||||
must be given in pairs and wildcard names should NOT be used or you WILL
|
||||
-lost your files.
|
||||
+lose your files.
|
||||
|
||||
.SH "EXAMPLES"
|
||||
.LP
|
15
pkgs/tools/text/dos2unix/dos2unix-missing-proto.patch
Normal file
15
pkgs/tools/text/dos2unix/dos2unix-missing-proto.patch
Normal file
@ -0,0 +1,15 @@
|
||||
diff -up dos2unix-3.1/dos2unix.c.missing-proto dos2unix-3.1/dos2unix.c
|
||||
--- dos2unix-3.1/dos2unix.c.missing-proto 2008-04-14 17:11:58.000000000 +0100
|
||||
+++ dos2unix-3.1/dos2unix.c 2008-04-14 17:12:42.000000000 +0100
|
||||
@@ -75,6 +75,11 @@ static int macmode = 0;
|
||||
#include <string.h>
|
||||
#include <utime.h>
|
||||
#include <sys/stat.h>
|
||||
+#if defined(__MSDOS__) || defined(__WIN32__) || defined(_WIN32)
|
||||
+# include <io.h>
|
||||
+#else
|
||||
+# include <unistd.h>
|
||||
+#endif
|
||||
#include "dos2unix.h"
|
||||
|
||||
|
28
pkgs/tools/text/dos2unix/dos2unix-preserve-file-modes.patch
Normal file
28
pkgs/tools/text/dos2unix/dos2unix-preserve-file-modes.patch
Normal file
@ -0,0 +1,28 @@
|
||||
diff -up dos2unix-3.1/dos2unix.c.preserve-file-modes dos2unix-3.1/dos2unix.c
|
||||
--- dos2unix-3.1/dos2unix.c.preserve-file-modes 2008-09-08 09:58:05.000000000 +0100
|
||||
+++ dos2unix-3.1/dos2unix.c 2008-09-08 10:16:04.000000000 +0100
|
||||
@@ -320,9 +320,10 @@ int ConvertDosToUnixNewFile(char *ipInFN
|
||||
struct stat StatBuf;
|
||||
struct utimbuf UTimeBuf;
|
||||
int fd;
|
||||
+ mode_t mask;
|
||||
|
||||
/* retrieve ipInFN file date stamp */
|
||||
- if ((ipFlag->KeepDate) && stat(ipInFN, &StatBuf))
|
||||
+ if (stat(ipInFN, &StatBuf))
|
||||
RetVal = -1;
|
||||
|
||||
if((fd = MakeTempFileFrom(ipOutFN, &TempPath))<0) {
|
||||
@@ -346,6 +347,12 @@ int ConvertDosToUnixNewFile(char *ipInFN
|
||||
RetVal = -1;
|
||||
}
|
||||
|
||||
+ /* preserve original mode as modified by umask */
|
||||
+ mask = umask(0);
|
||||
+ umask(mask);
|
||||
+ if (!RetVal && fchmod(fd, StatBuf.st_mode & ~mask))
|
||||
+ RetVal = -1;
|
||||
+
|
||||
/* conversion sucessful? */
|
||||
if ((!RetVal) && (ConvertDosToUnix(InF, TempF, ipFlag)))
|
||||
RetVal = -1;
|
37
pkgs/tools/text/unix2dos/default.nix
Normal file
37
pkgs/tools/text/unix2dos/default.nix
Normal file
@ -0,0 +1,37 @@
|
||||
{stdenv, fetchurl}:
|
||||
|
||||
stdenv.mkDerivation {
|
||||
name = "unix2dos-2.2";
|
||||
|
||||
src = fetchurl {
|
||||
url = http://cvs.fedoraproject.org/repo/pkgs/unix2dos/unix2dos-2.2.src.tar.gz/e4488c241fa9067a48a7534a21d4babb/unix2dos-2.2.src.tar.gz;
|
||||
md5 = "e4488c241fa9067a48a7534a21d4babb";
|
||||
};
|
||||
|
||||
patches = [
|
||||
./unix2dos-mkstemp.patch
|
||||
./unix2dos-2.2-segfault.patch
|
||||
./unix2dos-2.2-manpage.patch
|
||||
./unix2dos-2.2-mode.patch
|
||||
./unix2dos-2.2-tmppath.patch
|
||||
./unix2dos-preserve-file-modes.patch
|
||||
];
|
||||
|
||||
sourceRoot = ".";
|
||||
|
||||
buildPhase = ''
|
||||
cc -o unix2dos unix2dos.c
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
ensureDir $out/bin
|
||||
ensureDir $out/share/man
|
||||
install -p -m755 unix2dos $out/bin
|
||||
install -p -m444 unix2dos.1 $out/share/man
|
||||
'';
|
||||
|
||||
meta = {
|
||||
homepage = http://unknown/;
|
||||
description = "unix2dos tool";
|
||||
};
|
||||
}
|
42
pkgs/tools/text/unix2dos/unix2dos-2.2-manpage.patch
Normal file
42
pkgs/tools/text/unix2dos/unix2dos-2.2-manpage.patch
Normal file
@ -0,0 +1,42 @@
|
||||
diff -up unix2dos-2.2/unix2dos.1.man unix2dos-2.2/unix2dos.1
|
||||
--- unix2dos-2.2/unix2dos.1.man 1995-03-30 17:03:22.000000000 +0100
|
||||
+++ unix2dos-2.2/unix2dos.1 2008-09-08 09:49:19.000000000 +0100
|
||||
@@ -16,7 +16,7 @@ Options:
|
||||
.SH DESCRIPTION
|
||||
|
||||
.PP
|
||||
-This manual page documents dos2unix, the program that converts text
|
||||
+This manual page documents unix2dos, the program that converts text
|
||||
files in UNIX format to DOS format.
|
||||
|
||||
.SH OPTIONS
|
||||
@@ -40,7 +40,7 @@ Prints version information.
|
||||
|
||||
.TP
|
||||
.B \-c --convmode convmode
|
||||
-Sets conversion mode. Simulates dos2unix under SunOS.
|
||||
+Sets conversion mode. Simulates unix2dos under SunOS.
|
||||
|
||||
.TP
|
||||
.B \-o --oldfile file ...
|
||||
@@ -51,7 +51,7 @@ default to run in this mode. Wildcard na
|
||||
.B \-n --newfile infile outfile ...
|
||||
New file mode. Convert the infile and write output to outfile. File names
|
||||
must be given in pairs and wildcard names should NOT be used or you WILL
|
||||
-lost your files.
|
||||
+lose your files.
|
||||
|
||||
.SH EXAMPLES
|
||||
|
||||
@@ -71,9 +71,9 @@ Convert and replace a.txt. Convert and r
|
||||
Convert and replace a.txt in ASCII conversion mode.
|
||||
Convert and replace b.txt in ISO conversion mode.
|
||||
.IP
|
||||
-.B dos2unix a.txt -c iso b.txt
|
||||
+.B unix2dos a.txt -c iso b.txt
|
||||
.IP
|
||||
-.B dos2unix -c ascii a.txt -c iso b.txt
|
||||
+.B unix2dos -c ascii a.txt -c iso b.txt
|
||||
|
||||
.LP
|
||||
Convert and replace a.txt while keeping original date stamp.
|
29
pkgs/tools/text/unix2dos/unix2dos-2.2-mode.patch
Normal file
29
pkgs/tools/text/unix2dos/unix2dos-2.2-mode.patch
Normal file
@ -0,0 +1,29 @@
|
||||
diff -up unix2dos-2.2/unix2dos.c.mode unix2dos-2.2/unix2dos.c
|
||||
--- unix2dos-2.2/unix2dos.c.mode 2008-09-08 10:13:39.000000000 +0100
|
||||
+++ unix2dos-2.2/unix2dos.c 2008-09-08 10:13:39.000000000 +0100
|
||||
@@ -292,11 +292,14 @@ int ConvertUnixToDosOldFile(char* ipInFN
|
||||
char TempPath[16];
|
||||
struct stat StatBuf;
|
||||
struct utimbuf UTimeBuf;
|
||||
+ mode_t mode = S_IRUSR | S_IWUSR;
|
||||
int fd;
|
||||
|
||||
/* retrieve ipInFN file date stamp */
|
||||
- if ((ipFlag->KeepDate) && stat(ipInFN, &StatBuf))
|
||||
+ if (stat(ipInFN, &StatBuf))
|
||||
RetVal = -1;
|
||||
+ else
|
||||
+ mode = StatBuf.st_mode;
|
||||
|
||||
strcpy (TempPath, "./u2dtmpXXXXXX");
|
||||
if((fd=mkstemp (TempPath)) < 0) {
|
||||
@@ -304,6 +307,9 @@ int ConvertUnixToDosOldFile(char* ipInFN
|
||||
RetVal = -1;
|
||||
}
|
||||
|
||||
+ if (!RetVal && fchmod (fd, mode) && fchmod (fd, S_IRUSR | S_IWUSR))
|
||||
+ RetVal = -1;
|
||||
+
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "unix2dos: using %s as temp file\n", TempPath);
|
||||
#endif DEBUG
|
94
pkgs/tools/text/unix2dos/unix2dos-2.2-segfault.patch
Normal file
94
pkgs/tools/text/unix2dos/unix2dos-2.2-segfault.patch
Normal file
@ -0,0 +1,94 @@
|
||||
--- unix2dos-2.2/unix2dos.c.segf Thu Jan 17 17:09:49 2002
|
||||
+++ unix2dos-2.2/unix2dos.c Thu Jan 17 17:12:47 2002
|
||||
@@ -131,9 +131,9 @@
|
||||
* RetVal: NULL if failure
|
||||
* file stream otherwise
|
||||
*/
|
||||
-FILE* OpenOutFile(char *ipFN)
|
||||
+FILE* OpenOutFile(int fd)
|
||||
{
|
||||
- return (fopen(ipFN, W_CNTRL));
|
||||
+ return (fdopen(fd, W_CNTRL));
|
||||
}
|
||||
|
||||
|
||||
@@ -207,14 +207,17 @@
|
||||
char TempPath[16];
|
||||
struct stat StatBuf;
|
||||
struct utimbuf UTimeBuf;
|
||||
+ int fd;
|
||||
|
||||
/* retrieve ipInFN file date stamp */
|
||||
if ((ipFlag->KeepDate) && stat(ipInFN, &StatBuf))
|
||||
RetVal = -1;
|
||||
|
||||
- strcpy (TempPath, "./u2dtmp");
|
||||
- strcat (TempPath, "XXXXXX");
|
||||
- mkstemp (TempPath);
|
||||
+ strcpy (TempPath, "./u2dtmpXXXXXX");
|
||||
+ if((fd=mkstemp (TempPath)) < 0) {
|
||||
+ perror("Can't open output temp file");
|
||||
+ RetVal = -1;
|
||||
+ }
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "unix2dos: using %s as temp file\n", TempPath);
|
||||
@@ -225,7 +228,7 @@
|
||||
RetVal = -1;
|
||||
|
||||
/* can open out file? */
|
||||
- if ((!RetVal) && (InF) && ((TempF=OpenOutFile(TempPath)) == NULL))
|
||||
+ if ((!RetVal) && (InF) && ((TempF=OpenOutFile(fd)) == NULL))
|
||||
{
|
||||
fclose (InF);
|
||||
RetVal = -1;
|
||||
@@ -243,6 +246,9 @@
|
||||
if ((TempF) && (fclose(TempF) == EOF))
|
||||
RetVal = -1;
|
||||
|
||||
+ if(fd>=0)
|
||||
+ close(fd);
|
||||
+
|
||||
if ((!RetVal) && (ipFlag->KeepDate))
|
||||
{
|
||||
UTimeBuf.actime = StatBuf.st_atime;
|
||||
@@ -286,14 +292,17 @@
|
||||
char TempPath[16];
|
||||
struct stat StatBuf;
|
||||
struct utimbuf UTimeBuf;
|
||||
+ int fd;
|
||||
|
||||
/* retrieve ipInFN file date stamp */
|
||||
if ((ipFlag->KeepDate) && stat(ipInFN, &StatBuf))
|
||||
RetVal = -1;
|
||||
|
||||
- strcpy (TempPath, "./u2dtmp");
|
||||
- strcat (TempPath, "XXXXXX");
|
||||
- mkstemp (TempPath);
|
||||
+ strcpy (TempPath, "./u2dtmpXXXXXX");
|
||||
+ if((fd=mkstemp (TempPath)) < 0) {
|
||||
+ perror("Can't open output temp file");
|
||||
+ RetVal = -1;
|
||||
+ }
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "unix2dos: using %s as temp file\n", TempPath);
|
||||
@@ -304,7 +313,7 @@
|
||||
RetVal = -1;
|
||||
|
||||
/* can open out file? */
|
||||
- if ((!RetVal) && (InF) && ((TempF=OpenOutFile(TempPath)) == NULL))
|
||||
+ if ((!RetVal) && (InF) && ((TempF=OpenOutFile(fd)) == NULL))
|
||||
{
|
||||
fclose (InF);
|
||||
RetVal = -1;
|
||||
@@ -322,6 +331,9 @@
|
||||
if ((TempF) && (fclose(TempF) == EOF))
|
||||
RetVal = -1;
|
||||
|
||||
+ if(fd>=0)
|
||||
+ close(fd);
|
||||
+
|
||||
if ((!RetVal) && (ipFlag->KeepDate))
|
||||
{
|
||||
UTimeBuf.actime = StatBuf.st_atime;
|
146
pkgs/tools/text/unix2dos/unix2dos-2.2-tmppath.patch
Normal file
146
pkgs/tools/text/unix2dos/unix2dos-2.2-tmppath.patch
Normal file
@ -0,0 +1,146 @@
|
||||
diff -up unix2dos-2.2/unix2dos.c.tmppath unix2dos-2.2/unix2dos.c
|
||||
--- unix2dos-2.2/unix2dos.c.tmppath 2008-09-08 10:14:30.000000000 +0100
|
||||
+++ unix2dos-2.2/unix2dos.c 2008-09-08 10:14:30.000000000 +0100
|
||||
@@ -57,7 +57,10 @@
|
||||
|
||||
#ifdef __MSDOS__
|
||||
# include <dir.h>
|
||||
+#else
|
||||
+# include <unistd.h>
|
||||
#endif __MSDOS
|
||||
+#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -195,6 +198,40 @@ int ConvertUnixToDos(FILE* ipInF, FILE*
|
||||
}
|
||||
|
||||
|
||||
+static int MakeTempFileFrom(const char *OutFN, char **fname_ret)
|
||||
+{
|
||||
+ char *cpy = strdup(OutFN);
|
||||
+ char *dir = NULL;
|
||||
+ size_t fname_len = 0;
|
||||
+ char *fname_str = NULL;
|
||||
+ int fd = -1;
|
||||
+
|
||||
+ *fname_ret = NULL;
|
||||
+
|
||||
+ if (!cpy)
|
||||
+ goto make_failed;
|
||||
+
|
||||
+ dir = dirname(cpy);
|
||||
+
|
||||
+ fname_len = strlen(dir) + strlen("/u2dtmpXXXXXX") + sizeof (char);
|
||||
+ if (!(fname_str = malloc(fname_len)))
|
||||
+ goto make_failed;
|
||||
+ sprintf(fname_str, "%s%s", dir, "/u2dtmpXXXXXX");
|
||||
+ *fname_ret = fname_str;
|
||||
+
|
||||
+ free(cpy);
|
||||
+
|
||||
+ if ((fd = mkstemp(fname_str)) == -1)
|
||||
+ goto make_failed;
|
||||
+
|
||||
+ return (fd);
|
||||
+
|
||||
+ make_failed:
|
||||
+ free(*fname_ret);
|
||||
+ *fname_ret = NULL;
|
||||
+ return (-1);
|
||||
+}
|
||||
+
|
||||
/* convert file ipInFN to DOS format text and write to file ipOutFN
|
||||
* RetVal: 0 if success
|
||||
* -1 otherwise
|
||||
@@ -204,7 +241,7 @@ int ConvertUnixToDosNewFile(char *ipInFN
|
||||
int RetVal = 0;
|
||||
FILE *InF = NULL;
|
||||
FILE *TempF = NULL;
|
||||
- char TempPath[16];
|
||||
+ char *TempPath;
|
||||
struct stat StatBuf;
|
||||
struct utimbuf UTimeBuf;
|
||||
int fd;
|
||||
@@ -213,8 +250,7 @@ int ConvertUnixToDosNewFile(char *ipInFN
|
||||
if ((ipFlag->KeepDate) && stat(ipInFN, &StatBuf))
|
||||
RetVal = -1;
|
||||
|
||||
- strcpy (TempPath, "./u2dtmpXXXXXX");
|
||||
- if((fd=mkstemp (TempPath)) < 0) {
|
||||
+ if((fd = MakeTempFileFrom (ipOutFN, &TempPath)) < 0) {
|
||||
perror("Can't open output temp file");
|
||||
RetVal = -1;
|
||||
}
|
||||
@@ -231,6 +267,7 @@ int ConvertUnixToDosNewFile(char *ipInFN
|
||||
if ((!RetVal) && (InF) && ((TempF=OpenOutFile(fd)) == NULL))
|
||||
{
|
||||
fclose (InF);
|
||||
+ InF = NULL;
|
||||
RetVal = -1;
|
||||
}
|
||||
|
||||
@@ -265,9 +302,6 @@ int ConvertUnixToDosNewFile(char *ipInFN
|
||||
/* can rename temp file to out file? */
|
||||
if (!RetVal)
|
||||
{
|
||||
- if (stat(ipOutFN, &StatBuf) == 0)
|
||||
- unlink(ipOutFN);
|
||||
-
|
||||
if ((rename(TempPath, ipOutFN) == -1) && (!ipFlag->Quiet))
|
||||
{
|
||||
fprintf(stderr, "unix2dos: problems renaming '%s' to '%s'\n", TempPath, ipOutFN);
|
||||
@@ -275,6 +309,7 @@ int ConvertUnixToDosNewFile(char *ipInFN
|
||||
RetVal = -1;
|
||||
}
|
||||
}
|
||||
+ free(TempPath);
|
||||
|
||||
return RetVal;
|
||||
}
|
||||
@@ -289,7 +324,7 @@ int ConvertUnixToDosOldFile(char* ipInFN
|
||||
int RetVal = 0;
|
||||
FILE *InF = NULL;
|
||||
FILE *TempF = NULL;
|
||||
- char TempPath[16];
|
||||
+ char *TempPath;
|
||||
struct stat StatBuf;
|
||||
struct utimbuf UTimeBuf;
|
||||
mode_t mode = S_IRUSR | S_IWUSR;
|
||||
@@ -301,8 +336,7 @@ int ConvertUnixToDosOldFile(char* ipInFN
|
||||
else
|
||||
mode = StatBuf.st_mode;
|
||||
|
||||
- strcpy (TempPath, "./u2dtmpXXXXXX");
|
||||
- if((fd=mkstemp (TempPath)) < 0) {
|
||||
+ if((fd = MakeTempFileFrom(ipInFN, &TempPath)) < 0) {
|
||||
perror("Can't open output temp file");
|
||||
RetVal = -1;
|
||||
}
|
||||
@@ -322,6 +356,7 @@ int ConvertUnixToDosOldFile(char* ipInFN
|
||||
if ((!RetVal) && (InF) && ((TempF=OpenOutFile(fd)) == NULL))
|
||||
{
|
||||
fclose (InF);
|
||||
+ InF = NULL;
|
||||
RetVal = -1;
|
||||
}
|
||||
|
||||
@@ -349,10 +384,6 @@ int ConvertUnixToDosOldFile(char* ipInFN
|
||||
RetVal = -1;
|
||||
}
|
||||
|
||||
- /* can delete in file? */
|
||||
- if ((!RetVal) && (unlink(ipInFN) == -1))
|
||||
- RetVal = -1;
|
||||
-
|
||||
/* any error? */
|
||||
if ((RetVal) && (unlink(TempPath)))
|
||||
RetVal = -1;
|
||||
@@ -367,6 +398,7 @@ int ConvertUnixToDosOldFile(char* ipInFN
|
||||
}
|
||||
RetVal = -1;
|
||||
}
|
||||
+ free(TempPath);
|
||||
return RetVal;
|
||||
}
|
||||
|
20
pkgs/tools/text/unix2dos/unix2dos-mkstemp.patch
Normal file
20
pkgs/tools/text/unix2dos/unix2dos-mkstemp.patch
Normal file
@ -0,0 +1,20 @@
|
||||
--- unix2dos-2.2/unix2dos.c.orig Fri Nov 17 13:29:24 2000
|
||||
+++ unix2dos-2.2/unix2dos.c Fri Nov 17 13:30:16 2000
|
||||
@@ -214,7 +214,7 @@
|
||||
|
||||
strcpy (TempPath, "./u2dtmp");
|
||||
strcat (TempPath, "XXXXXX");
|
||||
- mktemp (TempPath);
|
||||
+ mkstemp (TempPath);
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "unix2dos: using %s as temp file\n", TempPath);
|
||||
@@ -293,7 +293,7 @@
|
||||
|
||||
strcpy (TempPath, "./u2dtmp");
|
||||
strcat (TempPath, "XXXXXX");
|
||||
- mktemp (TempPath);
|
||||
+ mkstemp (TempPath);
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "unix2dos: using %s as temp file\n", TempPath);
|
29
pkgs/tools/text/unix2dos/unix2dos-preserve-file-modes.patch
Normal file
29
pkgs/tools/text/unix2dos/unix2dos-preserve-file-modes.patch
Normal file
@ -0,0 +1,29 @@
|
||||
diff -up unix2dos-2.2/unix2dos.c~ unix2dos-2.2/unix2dos.c
|
||||
--- unix2dos-2.2/unix2dos.c~ 2008-03-03 13:16:34.000000000 +0000
|
||||
+++ unix2dos-2.2/unix2dos.c 2008-03-03 13:22:10.000000000 +0000
|
||||
@@ -244,10 +244,11 @@ int ConvertUnixToDosNewFile(char *ipInFN
|
||||
char *TempPath;
|
||||
struct stat StatBuf;
|
||||
struct utimbuf UTimeBuf;
|
||||
+ mode_t mask;
|
||||
int fd;
|
||||
|
||||
/* retrieve ipInFN file date stamp */
|
||||
- if ((ipFlag->KeepDate) && stat(ipInFN, &StatBuf))
|
||||
+ if (stat(ipInFN, &StatBuf))
|
||||
RetVal = -1;
|
||||
|
||||
if((fd = MakeTempFileFrom (ipOutFN, &TempPath)) < 0) {
|
||||
@@ -271,6 +272,12 @@ int ConvertUnixToDosNewFile(char *ipInFN
|
||||
RetVal = -1;
|
||||
}
|
||||
|
||||
+ /* preserve original mode as modified by umask */
|
||||
+ mask = umask(0);
|
||||
+ umask(mask);
|
||||
+ if (!RetVal && fchmod(fd, StatBuf.st_mode & ~mask))
|
||||
+ RetVal = -1;
|
||||
+
|
||||
/* conversion sucessful? */
|
||||
if ((!RetVal) && (ConvertUnixToDos(InF, TempF, ipFlag)))
|
||||
RetVal = -1;
|
@ -693,6 +693,14 @@ let
|
||||
inherit (xlibs) libX11 xproto libXt;
|
||||
};
|
||||
|
||||
dos2unix = import ../tools/text/dos2unix {
|
||||
inherit fetchurl stdenv;
|
||||
};
|
||||
|
||||
unix2dos = import ../tools/text/unix2dos {
|
||||
inherit fetchurl stdenv;
|
||||
};
|
||||
|
||||
gawk = useFromStdenv "gawk"
|
||||
(import ../tools/text/gawk {
|
||||
inherit fetchurl stdenv;
|
||||
|
Loading…
Reference in New Issue
Block a user