diff options
Diffstat (limited to 'coreutils/dos2unix.c')
| -rw-r--r-- | coreutils/dos2unix.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/coreutils/dos2unix.c b/coreutils/dos2unix.c index b1d0a9d70..c28e6a8b9 100644 --- a/coreutils/dos2unix.c +++ b/coreutils/dos2unix.c | |||
| @@ -35,6 +35,10 @@ | |||
| 35 | #include <sys/time.h> | 35 | #include <sys/time.h> |
| 36 | #include "busybox.h" | 36 | #include "busybox.h" |
| 37 | 37 | ||
| 38 | #define CT_AUTO 0 | ||
| 39 | #define CT_UNIX2DOS 1 | ||
| 40 | #define CT_DOS2UNIX 2 | ||
| 41 | |||
| 38 | /* We are making a lame pseudo-random string generator here. in | 42 | /* We are making a lame pseudo-random string generator here. in |
| 39 | * convert(), each pass through the while loop will add more and more | 43 | * convert(), each pass through the while loop will add more and more |
| 40 | * stuff into value, which is _supposed_ to wrap. We don't care about | 44 | * stuff into value, which is _supposed_ to wrap. We don't care about |
| @@ -55,15 +59,13 @@ static int convert(char *fn, int ConvType) | |||
| 55 | FILE *in = stdin, *out = stdout; | 59 | FILE *in = stdin, *out = stdout; |
| 56 | 60 | ||
| 57 | if (fn != NULL) { | 61 | if (fn != NULL) { |
| 58 | if ((in = wfopen(fn, "rw")) == NULL) { | 62 | in = bb_xfopen(fn, "rw"); |
| 59 | return -1; | ||
| 60 | } | ||
| 61 | safe_strncpy(tempFn, fn, sizeof(tempFn)); | 63 | safe_strncpy(tempFn, fn, sizeof(tempFn)); |
| 62 | c = strlen(tempFn); | 64 | c = strlen(tempFn); |
| 63 | tempFn[c] = '.'; | 65 | tempFn[c] = '.'; |
| 64 | while(1) { | 66 | while(1) { |
| 65 | if (c >=BUFSIZ) | 67 | if (c >=BUFSIZ) |
| 66 | error_msg_and_die("unique name not found"); | 68 | bb_error_msg_and_die("unique name not found"); |
| 67 | /* Get some semi random stuff to try and make a | 69 | /* Get some semi random stuff to try and make a |
| 68 | * random filename based (and in the same dir as) | 70 | * random filename based (and in the same dir as) |
| 69 | * the input file... */ | 71 | * the input file... */ |
| @@ -92,7 +94,7 @@ static int convert(char *fn, int ConvType) | |||
| 92 | // file is alredy in DOS format so it is not necessery to touch it | 94 | // file is alredy in DOS format so it is not necessery to touch it |
| 93 | remove(tempFn); | 95 | remove(tempFn); |
| 94 | if (fclose(in) < 0 || fclose(out) < 0) { | 96 | if (fclose(in) < 0 || fclose(out) < 0) { |
| 95 | perror_msg(NULL); | 97 | bb_perror_nomsg(); |
| 96 | return -2; | 98 | return -2; |
| 97 | } | 99 | } |
| 98 | return 0; | 100 | return 0; |
| @@ -106,7 +108,7 @@ static int convert(char *fn, int ConvType) | |||
| 106 | // file is alredy in UNIX format so it is not necessery to touch it | 108 | // file is alredy in UNIX format so it is not necessery to touch it |
| 107 | remove(tempFn); | 109 | remove(tempFn); |
| 108 | if ((fclose(in) < 0) || (fclose(out) < 0)) { | 110 | if ((fclose(in) < 0) || (fclose(out) < 0)) { |
| 109 | perror_msg(NULL); | 111 | bb_perror_nomsg(); |
| 110 | return -2; | 112 | return -2; |
| 111 | } | 113 | } |
| 112 | return 0; | 114 | return 0; |
| @@ -137,7 +139,7 @@ static int convert(char *fn, int ConvType) | |||
| 137 | 139 | ||
| 138 | if (fn != NULL) { | 140 | if (fn != NULL) { |
| 139 | if (fclose(in) < 0 || fclose(out) < 0) { | 141 | if (fclose(in) < 0 || fclose(out) < 0) { |
| 140 | perror_msg(NULL); | 142 | bb_perror_nomsg(); |
| 141 | remove(tempFn); | 143 | remove(tempFn); |
| 142 | return -2; | 144 | return -2; |
| 143 | } | 145 | } |
| @@ -146,7 +148,7 @@ static int convert(char *fn, int ConvType) | |||
| 146 | * should be true since we put them into the same directory | 148 | * should be true since we put them into the same directory |
| 147 | * so we _should_ be ok, but you never know... */ | 149 | * so we _should_ be ok, but you never know... */ |
| 148 | if (rename(tempFn, fn) < 0) { | 150 | if (rename(tempFn, fn) < 0) { |
| 149 | perror_msg("unable to rename '%s' as '%s'", tempFn, fn); | 151 | bb_perror_msg("unable to rename '%s' as '%s'", tempFn, fn); |
| 150 | return -1; | 152 | return -1; |
| 151 | } | 153 | } |
| 152 | } | 154 | } |
| @@ -177,7 +179,7 @@ int dos2unix_main(int argc, char *argv[]) | |||
| 177 | ConvType = CT_DOS2UNIX; | 179 | ConvType = CT_DOS2UNIX; |
| 178 | break; | 180 | break; |
| 179 | default: | 181 | default: |
| 180 | show_usage(); | 182 | bb_show_usage(); |
| 181 | } | 183 | } |
| 182 | } | 184 | } |
| 183 | 185 | ||
