diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-17 14:31:50 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-17 14:31:50 +0000 |
commit | 542963685c3e25ae4cc7ffa3a80d5f1129e6a0d7 (patch) | |
tree | 3a9fac4689cb1db1ffac9a6361c6e9f293f3517e | |
parent | 03b4c14bd4815f7d0f4b91d90985dfcd8a352025 (diff) | |
download | busybox-w32-542963685c3e25ae4cc7ffa3a80d5f1129e6a0d7.tar.gz busybox-w32-542963685c3e25ae4cc7ffa3a80d5f1129e6a0d7.tar.bz2 busybox-w32-542963685c3e25ae4cc7ffa3a80d5f1129e6a0d7.zip |
dos2unix: shrink
bloatcheck for last four commits:
function old new delta
xrename - 38 +38
md5_hash_block 437 458 +21
sv_main 1237 1254 +17
update_status 569 580 +11
decode_format_string 795 805 +10
doset 317 326 +9
passwd_main 1070 1074 +4
sha1_compile 447 446 -1
rename_or_warn 49 47 -2
fill_bounds 174 172 -2
buffer_fill_and_print 76 73 -3
bb_perror_nomsg 9 - -9
get_next_block 1810 1795 -15
patch_main 1107 1085 -22
write_status_file 1123 1077 -46
remove 52 - -52
__GI_remove 52 - -52
open_as_user 171 111 -60
microcom_main 811 747 -64
dos2unix_main 452 383 -69
------------------------------------------------------------------------------
(add/remove: 1/3 grow/shrink: 6/10 up/down: 110/-397) Total: -287 bytes
-rw-r--r-- | coreutils/dos2unix.c | 39 |
1 files changed, 12 insertions, 27 deletions
diff --git a/coreutils/dos2unix.c b/coreutils/dos2unix.c index 295be2909..7776133f4 100644 --- a/coreutils/dos2unix.c +++ b/coreutils/dos2unix.c | |||
@@ -20,7 +20,7 @@ enum { | |||
20 | }; | 20 | }; |
21 | 21 | ||
22 | /* if fn is NULL then input is stdin and output is stdout */ | 22 | /* if fn is NULL then input is stdin and output is stdout */ |
23 | static int convert(char *fn, int conv_type) | 23 | static void convert(char *fn, int conv_type) |
24 | { | 24 | { |
25 | FILE *in, *out; | 25 | FILE *in, *out; |
26 | int i; | 26 | int i; |
@@ -37,15 +37,12 @@ static int convert(char *fn, int conv_type) | |||
37 | */ | 37 | */ |
38 | snprintf(name_buf, sizeof(name_buf), "%sXXXXXX", fn); | 38 | snprintf(name_buf, sizeof(name_buf), "%sXXXXXX", fn); |
39 | i = mkstemp(&name_buf[0]); | 39 | i = mkstemp(&name_buf[0]); |
40 | if (i == -1 || chmod(name_buf, 0600) == -1) { | 40 | if (i == -1 |
41 | || fchmod(i, 0600) == -1 | ||
42 | || !(out = fdopen(i, "w+")) | ||
43 | ) { | ||
41 | bb_perror_nomsg_and_die(); | 44 | bb_perror_nomsg_and_die(); |
42 | } | 45 | } |
43 | out = fdopen(i, "w+"); | ||
44 | if (!out) { | ||
45 | close(i); | ||
46 | remove(name_buf); | ||
47 | return -2; | ||
48 | } | ||
49 | } | 46 | } |
50 | 47 | ||
51 | while ((i = fgetc(in)) != EOF) { | 48 | while ((i = fgetc(in)) != EOF) { |
@@ -62,20 +59,11 @@ static int convert(char *fn, int conv_type) | |||
62 | 59 | ||
63 | if (fn != NULL) { | 60 | if (fn != NULL) { |
64 | if (fclose(in) < 0 || fclose(out) < 0) { | 61 | if (fclose(in) < 0 || fclose(out) < 0) { |
65 | bb_perror_nomsg(); | 62 | unlink(name_buf); |
66 | remove(name_buf); | 63 | bb_perror_nomsg_and_die(); |
67 | return -2; | ||
68 | } | ||
69 | /* Assume they are both on the same filesystem (which | ||
70 | * should be true since we put them into the same directory | ||
71 | * so we _should_ be ok, but you never know... */ | ||
72 | if (rename(name_buf, fn) < 0) { | ||
73 | bb_perror_msg("cannot rename '%s' as '%s'", name_buf, fn); | ||
74 | return -1; | ||
75 | } | 64 | } |
65 | xrename(name_buf, fn); | ||
76 | } | 66 | } |
77 | |||
78 | return 0; | ||
79 | } | 67 | } |
80 | 68 | ||
81 | int dos2unix_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 69 | int dos2unix_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
@@ -84,10 +72,9 @@ int dos2unix_main(int argc, char **argv) | |||
84 | int o, conv_type; | 72 | int o, conv_type; |
85 | 73 | ||
86 | /* See if we are supposed to be doing dos2unix or unix2dos */ | 74 | /* See if we are supposed to be doing dos2unix or unix2dos */ |
75 | conv_type = CT_UNIX2DOS; | ||
87 | if (applet_name[0] == 'd') { | 76 | if (applet_name[0] == 'd') { |
88 | conv_type = CT_DOS2UNIX; /* 2 */ | 77 | conv_type = CT_DOS2UNIX; |
89 | } else { | ||
90 | conv_type = CT_UNIX2DOS; /* 1 */ | ||
91 | } | 78 | } |
92 | 79 | ||
93 | /* -u convert to unix, -d convert to dos */ | 80 | /* -u convert to unix, -d convert to dos */ |
@@ -101,11 +88,9 @@ int dos2unix_main(int argc, char **argv) | |||
101 | 88 | ||
102 | do { | 89 | do { |
103 | /* might be convert(NULL) if there is no filename given */ | 90 | /* might be convert(NULL) if there is no filename given */ |
104 | o = convert(argv[optind], conv_type); | 91 | convert(argv[optind], conv_type); |
105 | if (o < 0) | ||
106 | break; | ||
107 | optind++; | 92 | optind++; |
108 | } while (optind < argc); | 93 | } while (optind < argc); |
109 | 94 | ||
110 | return o; | 95 | return 0; |
111 | } | 96 | } |