aboutsummaryrefslogtreecommitdiff
path: root/coreutils/dos2unix.c
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils/dos2unix.c')
-rw-r--r--coreutils/dos2unix.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/coreutils/dos2unix.c b/coreutils/dos2unix.c
index 7776133f4..2db7e11a1 100644
--- a/coreutils/dos2unix.c
+++ b/coreutils/dos2unix.c
@@ -24,19 +24,19 @@ static void convert(char *fn, int conv_type)
24{ 24{
25 FILE *in, *out; 25 FILE *in, *out;
26 int i; 26 int i;
27#define name_buf bb_common_bufsiz1 27 char *name_buf = name_buf; /* for compiler */
28 28
29 in = stdin; 29 in = stdin;
30 out = stdout; 30 out = stdout;
31 if (fn != NULL) { 31 if (fn != NULL) {
32 in = xfopen(fn, "rw"); 32 in = xfopen(fn, "r");
33 /* 33 /*
34 The file is then created with mode read/write and 34 The file is then created with mode read/write and
35 permissions 0666 for glibc 2.0.6 and earlier or 35 permissions 0666 for glibc 2.0.6 and earlier or
36 0600 for glibc 2.0.7 and later. 36 0600 for glibc 2.0.7 and later.
37 */ 37 */
38 snprintf(name_buf, sizeof(name_buf), "%sXXXXXX", fn); 38 name_buf = xasprintf("%sXXXXXX", fn);
39 i = mkstemp(&name_buf[0]); 39 i = mkstemp(name_buf);
40 if (i == -1 40 if (i == -1
41 || fchmod(i, 0600) == -1 41 || fchmod(i, 0600) == -1
42 || !(out = fdopen(i, "w+")) 42 || !(out = fdopen(i, "w+"))
@@ -48,12 +48,9 @@ static void convert(char *fn, int conv_type)
48 while ((i = fgetc(in)) != EOF) { 48 while ((i = fgetc(in)) != EOF) {
49 if (i == '\r') 49 if (i == '\r')
50 continue; 50 continue;
51 if (i == '\n') { 51 if (i == '\n')
52 if (conv_type == CT_UNIX2DOS) 52 if (conv_type == CT_UNIX2DOS)
53 fputc('\r', out); 53 fputc('\r', out);
54 fputc('\n', out);
55 continue;
56 }
57 fputc(i, out); 54 fputc(i, out);
58 } 55 }
59 56
@@ -62,7 +59,9 @@ static void convert(char *fn, int conv_type)
62 unlink(name_buf); 59 unlink(name_buf);
63 bb_perror_nomsg_and_die(); 60 bb_perror_nomsg_and_die();
64 } 61 }
62// TODO: destroys symlinks. See how passwd handles this
65 xrename(name_buf, fn); 63 xrename(name_buf, fn);
64 free(name_buf);
66 } 65 }
67} 66}
68 67