YAZ 5.37.0
thread_id.c
Go to the documentation of this file.
1/* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
4 */
5
11#if HAVE_CONFIG_H
12#include <config.h>
13#endif
14
15#include <string.h>
16#include <stdio.h>
17
18#ifdef WIN32
19#include <windows.h>
20#endif
21
22#if HAVE_SYS_TIME_H
23#include <sys/time.h>
24#endif
25
26#if YAZ_POSIX_THREADS
27#include <pthread.h>
28#endif
29
30#include <yaz/thread_id.h>
31#include <yaz/snprintf.h>
32
33void yaz_thread_id_cstr(char *buf, size_t buf_max)
34{
35#ifdef WIN32
36 *buf = '\0';
37#elif YAZ_POSIX_THREADS
38 pthread_t t = pthread_self();
39 size_t i;
40 *buf = '\0';
41 for (i = 0; i < sizeof(t); i++)
42 {
43 if (strlen(buf) >= buf_max-2)
44 break;
45 yaz_snprintf(buf + strlen(buf), 3, "%02x", ((const unsigned char *) &t)[i]);
46 }
47#else
48 *buf = '\0';
49#endif
50}
51
52/*
53 * Local variables:
54 * c-basic-offset: 4
55 * c-file-style: "Stroustrup"
56 * indent-tabs-mode: nil
57 * End:
58 * vim: shiftwidth=4 tabstop=8 expandtab
59 */
60
void yaz_snprintf(char *buf, size_t size, const char *fmt,...)
Definition snprintf.c:31
Header for config file reading utilities.
void yaz_thread_id_cstr(char *buf, size_t buf_max)
format current thread as printable C-string
Definition thread_id.c:33
Header for Mutex functions.