YAZ  5.23.1
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 
32 void yaz_thread_id_cstr(char *buf, size_t buf_max)
33 {
34 #ifdef WIN32
35  *buf = '\0';
36 #elif YAZ_POSIX_THREADS
37  pthread_t t = pthread_self();
38  size_t i;
39  *buf = '\0';
40  for (i = 0; i < sizeof(t); i++)
41  {
42  if (strlen(buf) >= buf_max-2)
43  break;
44  sprintf(buf + strlen(buf), "%02x", ((const unsigned char *) &t)[i]);
45  }
46 #else
47  *buf = '\0';
48 #endif
49 }
50 
51 /*
52  * Local variables:
53  * c-basic-offset: 4
54  * c-file-style: "Stroustrup"
55  * indent-tabs-mode: nil
56  * End:
57  * vim: shiftwidth=4 tabstop=8 expandtab
58  */
59 
Header for Mutex functions.
void yaz_thread_id_cstr(char *buf, size_t buf_max)
format current thread as printable C-string
Definition: thread_id.c:32