aboutsummaryrefslogtreecommitdiff
path: root/coreutils/dos2unix.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2016-02-22 10:00:45 +0000
committerRon Yorston <rmy@pobox.com>2016-02-22 10:00:45 +0000
commit371c20c008254a36e7157df6c13dc2e4cf87d6fd (patch)
treea214c03f6617dffa60df2192b312a46c93b7c19f /coreutils/dos2unix.c
parentab879a41ab674129ef1593cda181cc8b64d0dadf (diff)
parent3a5cc989025eefe03fda0552b253a4a8f015a761 (diff)
downloadbusybox-w32-371c20c008254a36e7157df6c13dc2e4cf87d6fd.tar.gz
busybox-w32-371c20c008254a36e7157df6c13dc2e4cf87d6fd.tar.bz2
busybox-w32-371c20c008254a36e7157df6c13dc2e4cf87d6fd.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'coreutils/dos2unix.c')
-rw-r--r--coreutils/dos2unix.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/coreutils/dos2unix.c b/coreutils/dos2unix.c
index 07398bdfa..ccb74a113 100644
--- a/coreutils/dos2unix.c
+++ b/coreutils/dos2unix.c
@@ -41,7 +41,7 @@ enum {
41static void convert(char *fn, int conv_type) 41static void convert(char *fn, int conv_type)
42{ 42{
43 FILE *in, *out; 43 FILE *in, *out;
44 int i; 44 int ch;
45 char *temp_fn = temp_fn; /* for compiler */ 45 char *temp_fn = temp_fn; /* for compiler */
46 char *resolved_fn = resolved_fn; 46 char *resolved_fn = resolved_fn;
47 47
@@ -49,28 +49,30 @@ static void convert(char *fn, int conv_type)
49 out = stdout; 49 out = stdout;
50 if (fn != NULL) { 50 if (fn != NULL) {
51 struct stat st; 51 struct stat st;
52 int fd;
52 53
53 resolved_fn = xmalloc_follow_symlinks(fn); 54 resolved_fn = xmalloc_follow_symlinks(fn);
54 if (resolved_fn == NULL) 55 if (resolved_fn == NULL)
55 bb_simple_perror_msg_and_die(fn); 56 bb_simple_perror_msg_and_die(fn);
56 in = xfopen_for_read(resolved_fn); 57 in = xfopen_for_read(resolved_fn);
57 fstat(fileno(in), &st); 58 xfstat(fileno(in), &st, resolved_fn);
58 59
59 temp_fn = xasprintf("%sXXXXXX", resolved_fn); 60 temp_fn = xasprintf("%sXXXXXX", resolved_fn);
60 i = xmkstemp(temp_fn); 61 fd = xmkstemp(temp_fn);
61 if (fchmod(i, st.st_mode) == -1) 62 if (fchmod(fd, st.st_mode) == -1)
62 bb_simple_perror_msg_and_die(temp_fn); 63 bb_simple_perror_msg_and_die(temp_fn);
64 fchown(fd, st.st_uid, st.st_gid);
63 65
64 out = xfdopen_for_write(i); 66 out = xfdopen_for_write(fd);
65 } 67 }
66 68
67 while ((i = fgetc(in)) != EOF) { 69 while ((ch = fgetc(in)) != EOF) {
68 if (i == '\r') 70 if (ch == '\r')
69 continue; 71 continue;
70 if (i == '\n') 72 if (ch == '\n')
71 if (conv_type == CT_UNIX2DOS) 73 if (conv_type == CT_UNIX2DOS)
72 fputc('\r', out); 74 fputc('\r', out);
73 fputc(i, out); 75 fputc(ch, out);
74 } 76 }
75 77
76 if (fn != NULL) { 78 if (fn != NULL) {