diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-06-06 21:53:09 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-06-06 21:53:09 +0200 |
commit | 19ced5c4253bc154aa499a72b6343e01245c92c0 (patch) | |
tree | c1c148612896e748749ce882ed25ad5ffd74418c /libbb/xfuncs_printf.c | |
parent | 5f3303712ef483d270097cae4ba0a559b1056121 (diff) | |
download | busybox-w32-19ced5c4253bc154aa499a72b6343e01245c92c0.tar.gz busybox-w32-19ced5c4253bc154aa499a72b6343e01245c92c0.tar.bz2 busybox-w32-19ced5c4253bc154aa499a72b6343e01245c92c0.zip |
pipe_progress: make it independent of printf machinery
function old new delta
bb_putchar_stderr - 24 +24
ParseField 494 471 -23
progress_meter 212 188 -24
xargs_main 888 842 -46
pipe_progress_main 151 105 -46
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/4 up/down: 24/-139) Total: -115 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/xfuncs_printf.c')
-rw-r--r-- | libbb/xfuncs_printf.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c index 7207ec58a..03aeaaa38 100644 --- a/libbb/xfuncs_printf.c +++ b/libbb/xfuncs_printf.c | |||
@@ -510,3 +510,77 @@ int FAST_FUNC bb_xioctl(int fd, unsigned request, void *argp) | |||
510 | return ret; | 510 | return ret; |
511 | } | 511 | } |
512 | #endif | 512 | #endif |
513 | |||
514 | char* FAST_FUNC xmalloc_ttyname(int fd) | ||
515 | { | ||
516 | char *buf = xzalloc(128); | ||
517 | int r = ttyname_r(fd, buf, 127); | ||
518 | if (r) { | ||
519 | free(buf); | ||
520 | buf = NULL; | ||
521 | } | ||
522 | return buf; | ||
523 | } | ||
524 | |||
525 | void FAST_FUNC generate_uuid(uint8_t *buf) | ||
526 | { | ||
527 | /* http://www.ietf.org/rfc/rfc4122.txt | ||
528 | * 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 | ||
529 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
530 | * | time_low | | ||
531 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
532 | * | time_mid | time_hi_and_version | | ||
533 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
534 | * |clk_seq_and_variant | node (0-1) | | ||
535 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
536 | * | node (2-5) | | ||
537 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
538 | * IOW, uuid has this layout: | ||
539 | * uint32_t time_low (big endian) | ||
540 | * uint16_t time_mid (big endian) | ||
541 | * uint16_t time_hi_and_version (big endian) | ||
542 | * version is a 4-bit field: | ||
543 | * 1 Time-based | ||
544 | * 2 DCE Security, with embedded POSIX UIDs | ||
545 | * 3 Name-based (MD5) | ||
546 | * 4 Randomly generated | ||
547 | * 5 Name-based (SHA-1) | ||
548 | * uint16_t clk_seq_and_variant (big endian) | ||
549 | * variant is a 3-bit field: | ||
550 | * 0xx Reserved, NCS backward compatibility | ||
551 | * 10x The variant specified in rfc4122 | ||
552 | * 110 Reserved, Microsoft backward compatibility | ||
553 | * 111 Reserved for future definition | ||
554 | * uint8_t node[6] | ||
555 | * | ||
556 | * For version 4, these bits are set/cleared: | ||
557 | * time_hi_and_version & 0x0fff | 0x4000 | ||
558 | * clk_seq_and_variant & 0x3fff | 0x8000 | ||
559 | */ | ||
560 | pid_t pid; | ||
561 | int i; | ||
562 | |||
563 | i = open("/dev/urandom", O_RDONLY); | ||
564 | if (i >= 0) { | ||
565 | read(i, buf, 16); | ||
566 | close(i); | ||
567 | } | ||
568 | /* Paranoia. /dev/urandom may be missing. | ||
569 | * rand() is guaranteed to generate at least [0, 2^15) range, | ||
570 | * but lowest bits in some libc are not so "random". */ | ||
571 | srand(monotonic_us()); /* pulls in printf */ | ||
572 | pid = getpid(); | ||
573 | while (1) { | ||
574 | for (i = 0; i < 16; i++) | ||
575 | buf[i] ^= rand() >> 5; | ||
576 | if (pid == 0) | ||
577 | break; | ||
578 | srand(pid); | ||
579 | pid = 0; | ||
580 | } | ||
581 | |||
582 | /* version = 4 */ | ||
583 | buf[4 + 2 ] = (buf[4 + 2 ] & 0x0f) | 0x40; | ||
584 | /* variant = 10x */ | ||
585 | buf[4 + 2 + 2] = (buf[4 + 2 + 2] & 0x3f) | 0x80; | ||
586 | } | ||