-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreentrant.h
71 lines (61 loc) · 2.42 KB
/
reentrant.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Provide thread-safe versions or wrappers of some libc functions
// Copyright (C) 2007-2017 Harro Verkouter
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
// PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// Author: Harro Verkouter - verkouter@jive.eu
// Joint Institute for VLBI in Europe
// P.O. Box 2
// 7990 AA Dwingeloo
//
// Example:
// yes there is "strerror_r". But everywhere one uses it, it requires
// some buffer management around it.
// In the etdc namespace we provide simple wrappers that either:
// 1.) do the buffer management for you
// 2.) provide locked access to the resource in case there isn't a
// POSIX "_r" variant
//
// We found that Linux / glibc does implement a lot of "_r" functions but
// that most of them are not POSIX, i.e. not portable.
// Thus we take our losses and make sure the portable systemcalls/libc
// calls are made MT-Safe
//
#ifndef ETDC_REENTRANT_H
#define ETDC_REENTRANT_H
#include <string>
#include <netdb.h>
namespace etdc {
namespace detail {
struct protocol_entry {
int p_proto;
std::string p_name;
protocol_entry();
protocol_entry(struct protoent* pptr);
};
}
// calls strerror_r(3) behind the scenes so we can replace "::strerror()" with
// "etdc::strerror()" everywhere
std::string strerror(int errnum);
// Seed the 48-bit random state
void srand( void );
// Will do srand() first time random() is called inside a thread
long int random( void );
// Will do srand() first time lrand48() is called inside a thread
long int lrand48( void );
// getprotobyname is not marked MT-Safe.
// getprotobyname_r() is not POSIX, apparently. This wrapper returns
// the protocol number, doing it thread-safe.
detail::protocol_entry getprotobyname(char const* name);
}
#endif