mirror of
https://github.com/sheumann/hush.git
synced 2024-12-21 23:29:34 +00:00
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
This commit is contained in:
parent
03b4c14bd4
commit
542963685c
@ -20,7 +20,7 @@ enum {
|
||||
};
|
||||
|
||||
/* if fn is NULL then input is stdin and output is stdout */
|
||||
static int convert(char *fn, int conv_type)
|
||||
static void convert(char *fn, int conv_type)
|
||||
{
|
||||
FILE *in, *out;
|
||||
int i;
|
||||
@ -37,15 +37,12 @@ static int convert(char *fn, int conv_type)
|
||||
*/
|
||||
snprintf(name_buf, sizeof(name_buf), "%sXXXXXX", fn);
|
||||
i = mkstemp(&name_buf[0]);
|
||||
if (i == -1 || chmod(name_buf, 0600) == -1) {
|
||||
if (i == -1
|
||||
|| fchmod(i, 0600) == -1
|
||||
|| !(out = fdopen(i, "w+"))
|
||||
) {
|
||||
bb_perror_nomsg_and_die();
|
||||
}
|
||||
out = fdopen(i, "w+");
|
||||
if (!out) {
|
||||
close(i);
|
||||
remove(name_buf);
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
while ((i = fgetc(in)) != EOF) {
|
||||
@ -62,20 +59,11 @@ static int convert(char *fn, int conv_type)
|
||||
|
||||
if (fn != NULL) {
|
||||
if (fclose(in) < 0 || fclose(out) < 0) {
|
||||
bb_perror_nomsg();
|
||||
remove(name_buf);
|
||||
return -2;
|
||||
}
|
||||
/* Assume they are both on the same filesystem (which
|
||||
* should be true since we put them into the same directory
|
||||
* so we _should_ be ok, but you never know... */
|
||||
if (rename(name_buf, fn) < 0) {
|
||||
bb_perror_msg("cannot rename '%s' as '%s'", name_buf, fn);
|
||||
return -1;
|
||||
unlink(name_buf);
|
||||
bb_perror_nomsg_and_die();
|
||||
}
|
||||
xrename(name_buf, fn);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dos2unix_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
@ -84,10 +72,9 @@ int dos2unix_main(int argc, char **argv)
|
||||
int o, conv_type;
|
||||
|
||||
/* See if we are supposed to be doing dos2unix or unix2dos */
|
||||
conv_type = CT_UNIX2DOS;
|
||||
if (applet_name[0] == 'd') {
|
||||
conv_type = CT_DOS2UNIX; /* 2 */
|
||||
} else {
|
||||
conv_type = CT_UNIX2DOS; /* 1 */
|
||||
conv_type = CT_DOS2UNIX;
|
||||
}
|
||||
|
||||
/* -u convert to unix, -d convert to dos */
|
||||
@ -101,11 +88,9 @@ int dos2unix_main(int argc, char **argv)
|
||||
|
||||
do {
|
||||
/* might be convert(NULL) if there is no filename given */
|
||||
o = convert(argv[optind], conv_type);
|
||||
if (o < 0)
|
||||
break;
|
||||
convert(argv[optind], conv_type);
|
||||
optind++;
|
||||
} while (optind < argc);
|
||||
|
||||
return o;
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user