diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-08-22 05:06:29 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-08-22 05:06:29 +0000 |
commit | 59443965ad359f3c72e2ea3a15c77140d938d930 (patch) | |
tree | 188fd6bea557dd4340932189dd49487c4ba97b03 | |
parent | d36cdd25a56db0c9b8ea41ce717c2440009d5ce0 (diff) | |
download | busybox-w32-59443965ad359f3c72e2ea3a15c77140d938d930.tar.gz busybox-w32-59443965ad359f3c72e2ea3a15c77140d938d930.tar.bz2 busybox-w32-59443965ad359f3c72e2ea3a15c77140d938d930.zip |
Scrub things and ditch uint64_t and use a custom type name
to avoid C lib compatibility problems.
-rw-r--r-- | coreutils/dos2unix.c | 20 | ||||
-rw-r--r-- | dos2unix.c | 20 |
2 files changed, 26 insertions, 14 deletions
diff --git a/coreutils/dos2unix.c b/coreutils/dos2unix.c index e110680c3..8b65d05de 100644 --- a/coreutils/dos2unix.c +++ b/coreutils/dos2unix.c | |||
@@ -30,14 +30,18 @@ | |||
30 | #include <string.h> | 30 | #include <string.h> |
31 | #include <getopt.h> | 31 | #include <getopt.h> |
32 | #include <unistd.h> | 32 | #include <unistd.h> |
33 | #include <stdint.h> | ||
33 | #include <fcntl.h> | 34 | #include <fcntl.h> |
34 | #include <sys/time.h> | 35 | #include <sys/time.h> |
35 | #include "busybox.h" | 36 | #include "busybox.h" |
36 | 37 | ||
37 | /* Teach older glibc and libc5 what a uint64_t is */ | 38 | /* We are making a lame pseudo-random string generator here. in |
38 | #if (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 3) | 39 | * convert(), each pass through the while loop will add more and more |
39 | typedef unsigned long int uint64_t; | 40 | * stuff into value, which is _supposed_ to wrap. We don't care about |
40 | #endif | 41 | * it being accurate. We care about it being messy, since we then mod |
42 | * it by the sizeof(letters) and then use that as an index into letters | ||
43 | * to pick a random letter to add to out temporary file. */ | ||
44 | typedef unsigned long int bb_uint64_t; | ||
41 | 45 | ||
42 | static const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | 46 | static const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
43 | 47 | ||
@@ -47,7 +51,7 @@ static int convert(char *fn, int ConvType) | |||
47 | int c, fd; | 51 | int c, fd; |
48 | struct timeval tv; | 52 | struct timeval tv; |
49 | char tempFn[BUFSIZ]; | 53 | char tempFn[BUFSIZ]; |
50 | static uint64_t value=0; | 54 | static bb_uint64_t value=0; |
51 | FILE *in = stdin, *out = stdout; | 55 | FILE *in = stdin, *out = stdout; |
52 | 56 | ||
53 | if (fn != NULL) { | 57 | if (fn != NULL) { |
@@ -64,7 +68,7 @@ static int convert(char *fn, int ConvType) | |||
64 | * random filename based (and in the same dir as) | 68 | * random filename based (and in the same dir as) |
65 | * the input file... */ | 69 | * the input file... */ |
66 | gettimeofday (&tv, NULL); | 70 | gettimeofday (&tv, NULL); |
67 | value += ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid (); | 71 | value += ((bb_uint64_t) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid (); |
68 | tempFn[++c] = letters[value % 62]; | 72 | tempFn[++c] = letters[value % 62]; |
69 | tempFn[c+1] = '\0'; | 73 | tempFn[c+1] = '\0'; |
70 | value /= 62; | 74 | value /= 62; |
@@ -138,7 +142,9 @@ static int convert(char *fn, int ConvType) | |||
138 | return -2; | 142 | return -2; |
139 | } | 143 | } |
140 | 144 | ||
141 | /* Assume they are both on the same filesystem */ | 145 | /* Assume they are both on the same filesystem (which |
146 | * should be true since we put them into the same directory | ||
147 | * so we _should_ be ok, but you never know... */ | ||
142 | if (rename(tempFn, fn) < 0) { | 148 | if (rename(tempFn, fn) < 0) { |
143 | perror_msg("unable to rename '%s' as '%s'", tempFn, fn); | 149 | perror_msg("unable to rename '%s' as '%s'", tempFn, fn); |
144 | return -1; | 150 | return -1; |
diff --git a/dos2unix.c b/dos2unix.c index e110680c3..8b65d05de 100644 --- a/dos2unix.c +++ b/dos2unix.c | |||
@@ -30,14 +30,18 @@ | |||
30 | #include <string.h> | 30 | #include <string.h> |
31 | #include <getopt.h> | 31 | #include <getopt.h> |
32 | #include <unistd.h> | 32 | #include <unistd.h> |
33 | #include <stdint.h> | ||
33 | #include <fcntl.h> | 34 | #include <fcntl.h> |
34 | #include <sys/time.h> | 35 | #include <sys/time.h> |
35 | #include "busybox.h" | 36 | #include "busybox.h" |
36 | 37 | ||
37 | /* Teach older glibc and libc5 what a uint64_t is */ | 38 | /* We are making a lame pseudo-random string generator here. in |
38 | #if (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 3) | 39 | * convert(), each pass through the while loop will add more and more |
39 | typedef unsigned long int uint64_t; | 40 | * stuff into value, which is _supposed_ to wrap. We don't care about |
40 | #endif | 41 | * it being accurate. We care about it being messy, since we then mod |
42 | * it by the sizeof(letters) and then use that as an index into letters | ||
43 | * to pick a random letter to add to out temporary file. */ | ||
44 | typedef unsigned long int bb_uint64_t; | ||
41 | 45 | ||
42 | static const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | 46 | static const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
43 | 47 | ||
@@ -47,7 +51,7 @@ static int convert(char *fn, int ConvType) | |||
47 | int c, fd; | 51 | int c, fd; |
48 | struct timeval tv; | 52 | struct timeval tv; |
49 | char tempFn[BUFSIZ]; | 53 | char tempFn[BUFSIZ]; |
50 | static uint64_t value=0; | 54 | static bb_uint64_t value=0; |
51 | FILE *in = stdin, *out = stdout; | 55 | FILE *in = stdin, *out = stdout; |
52 | 56 | ||
53 | if (fn != NULL) { | 57 | if (fn != NULL) { |
@@ -64,7 +68,7 @@ static int convert(char *fn, int ConvType) | |||
64 | * random filename based (and in the same dir as) | 68 | * random filename based (and in the same dir as) |
65 | * the input file... */ | 69 | * the input file... */ |
66 | gettimeofday (&tv, NULL); | 70 | gettimeofday (&tv, NULL); |
67 | value += ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid (); | 71 | value += ((bb_uint64_t) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid (); |
68 | tempFn[++c] = letters[value % 62]; | 72 | tempFn[++c] = letters[value % 62]; |
69 | tempFn[c+1] = '\0'; | 73 | tempFn[c+1] = '\0'; |
70 | value /= 62; | 74 | value /= 62; |
@@ -138,7 +142,9 @@ static int convert(char *fn, int ConvType) | |||
138 | return -2; | 142 | return -2; |
139 | } | 143 | } |
140 | 144 | ||
141 | /* Assume they are both on the same filesystem */ | 145 | /* Assume they are both on the same filesystem (which |
146 | * should be true since we put them into the same directory | ||
147 | * so we _should_ be ok, but you never know... */ | ||
142 | if (rename(tempFn, fn) < 0) { | 148 | if (rename(tempFn, fn) < 0) { |
143 | perror_msg("unable to rename '%s' as '%s'", tempFn, fn); | 149 | perror_msg("unable to rename '%s' as '%s'", tempFn, fn); |
144 | return -1; | 150 | return -1; |