diff options
Diffstat (limited to 'libbb/xfuncs.c')
-rw-r--r-- | libbb/xfuncs.c | 73 |
1 files changed, 2 insertions, 71 deletions
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index d93dd2af9..6200fc600 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -199,15 +199,9 @@ off_t FAST_FUNC fdlength(int fd) | |||
199 | } | 199 | } |
200 | #endif | 200 | #endif |
201 | 201 | ||
202 | char* FAST_FUNC xmalloc_ttyname(int fd) | 202 | int FAST_FUNC bb_putchar_stderr(char ch) |
203 | { | 203 | { |
204 | char *buf = xzalloc(128); | 204 | return write(STDERR_FILENO, &ch, 1); |
205 | int r = ttyname_r(fd, buf, 127); | ||
206 | if (r) { | ||
207 | free(buf); | ||
208 | buf = NULL; | ||
209 | } | ||
210 | return buf; | ||
211 | } | 205 | } |
212 | 206 | ||
213 | static int wh_helper(int value, int def_val, const char *env_name, int *err) | 207 | static int wh_helper(int value, int def_val, const char *env_name, int *err) |
@@ -250,66 +244,3 @@ int FAST_FUNC tcsetattr_stdin_TCSANOW(const struct termios *tp) | |||
250 | { | 244 | { |
251 | return tcsetattr(STDIN_FILENO, TCSANOW, tp); | 245 | return tcsetattr(STDIN_FILENO, TCSANOW, tp); |
252 | } | 246 | } |
253 | |||
254 | void FAST_FUNC generate_uuid(uint8_t *buf) | ||
255 | { | ||
256 | /* http://www.ietf.org/rfc/rfc4122.txt | ||
257 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
258 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
259 | * | time_low | | ||
260 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
261 | * | time_mid | time_hi_and_version | | ||
262 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
263 | * |clk_seq_and_variant | node (0-1) | | ||
264 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
265 | * | node (2-5) | | ||
266 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
267 | * IOW, uuid has this layout: | ||
268 | * uint32_t time_low (big endian) | ||
269 | * uint16_t time_mid (big endian) | ||
270 | * uint16_t time_hi_and_version (big endian) | ||
271 | * version is a 4-bit field: | ||
272 | * 1 Time-based | ||
273 | * 2 DCE Security, with embedded POSIX UIDs | ||
274 | * 3 Name-based (MD5) | ||
275 | * 4 Randomly generated | ||
276 | * 5 Name-based (SHA-1) | ||
277 | * uint16_t clk_seq_and_variant (big endian) | ||
278 | * variant is a 3-bit field: | ||
279 | * 0xx Reserved, NCS backward compatibility | ||
280 | * 10x The variant specified in rfc4122 | ||
281 | * 110 Reserved, Microsoft backward compatibility | ||
282 | * 111 Reserved for future definition | ||
283 | * uint8_t node[6] | ||
284 | * | ||
285 | * For version 4, these bits are set/cleared: | ||
286 | * time_hi_and_version & 0x0fff | 0x4000 | ||
287 | * clk_seq_and_variant & 0x3fff | 0x8000 | ||
288 | */ | ||
289 | pid_t pid; | ||
290 | int i; | ||
291 | |||
292 | i = open("/dev/urandom", O_RDONLY); | ||
293 | if (i >= 0) { | ||
294 | read(i, buf, 16); | ||
295 | close(i); | ||
296 | } | ||
297 | /* Paranoia. /dev/urandom may be missing. | ||
298 | * rand() is guaranteed to generate at least [0, 2^15) range, | ||
299 | * but lowest bits in some libc are not so "random". */ | ||
300 | srand(monotonic_us()); | ||
301 | pid = getpid(); | ||
302 | while (1) { | ||
303 | for (i = 0; i < 16; i++) | ||
304 | buf[i] ^= rand() >> 5; | ||
305 | if (pid == 0) | ||
306 | break; | ||
307 | srand(pid); | ||
308 | pid = 0; | ||
309 | } | ||
310 | |||
311 | /* version = 4 */ | ||
312 | buf[4 + 2 ] = (buf[4 + 2 ] & 0x0f) | 0x40; | ||
313 | /* variant = 10x */ | ||
314 | buf[4 + 2 + 2] = (buf[4 + 2 + 2] & 0x3f) | 0x80; | ||
315 | } | ||