diff options
author | Ondřej Surý <ondrej@sury.org> | 2013-06-28 12:59:40 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2013-06-28 12:59:40 +0200 |
commit | 124965832295a277b9ca6ae9fac4f45a74a36b2a (patch) | |
tree | f299e2335863f74e0be0707f84b85211baaf2d03 /src/libknot/util/utils.c | |
parent | 3d2d198c71a6b844b60fa9ef68801b66bba93361 (diff) | |
download | knot-upstream/1.3.0_rc3.tar.gz |
New upstream version 1.3.0~rc3upstream/1.3.0_rc3
Diffstat (limited to 'src/libknot/util/utils.c')
-rw-r--r-- | src/libknot/util/utils.c | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/src/libknot/util/utils.c b/src/libknot/util/utils.c index 04e12c5..e64e297 100644 --- a/src/libknot/util/utils.c +++ b/src/libknot/util/utils.c @@ -56,59 +56,6 @@ knot_lookup_table_t *knot_lookup_by_id(knot_lookup_table_t *table, /*----------------------------------------------------------------------------*/ -size_t knot_strlcpy(char *dst, const char *src, size_t size) -{ - char *d = dst; - const char *s = src; - size_t n = size; - - /* Copy as many bytes as will fit */ - if (n != 0 && --n != 0) { - do { - if ((*d++ = *s++) == 0) { - break; - } - } while (--n != 0); - } - - /* Not enough room in dst, add NUL and traverse rest of src */ - if (n == 0) { - if (size != 0) { - *d = '\0'; /* NUL-terminate dst */ - } - while (*s++) - ; - } - - return(s - src - 1); /* count does not include NUL */ -} - -/*! \brief TLS key for rand seed. */ -static pthread_key_t _qr_key; -static pthread_once_t _qr_once = PTHREAD_ONCE_INIT; - -/*! \brief TLS key initializer. */ -static void _qr_init() -{ - (void) pthread_key_create(&_qr_key, NULL); - (void) pthread_setspecific(_qr_key, (void*)time(0)); -} - -size_t knot_quick_rand() -{ - (void) pthread_once(&_qr_once, _qr_init); - size_t x = (size_t)pthread_getspecific(_qr_key); - - /* Numerical Recipes in C. - * The Art of Scientific Computing, 2nd Edition, - * 1992, ISBN 0-521-43108-5. - * Page 284. - */ - x = 1664525L * x + 1013904223L; - (void) pthread_setspecific(_qr_key, (void*)x); - return x; -} - uint16_t knot_random_id() { return (uint16_t)(tls_rand() * ((uint16_t)~0)); @@ -124,4 +71,3 @@ struct flock* knot_file_lock(short type, short whence) ret.l_pid = getpid(); return &ret; } - |