Debian Codegraph @

srtcore/srt_compat.h

raw
1 /*
2 * SRT - Secure, Reliable, Transport
3 * Copyright (c) 2018 Haivision Systems Inc.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 */
10
11
12 /*****************************************************************************
13 written by
14 Haivision Systems Inc.
15 *****************************************************************************/
16
17 #ifndef INC_SRT_COMPAT_H
18 #define INC_SRT_COMPAT_H
19
20 #include <stddef.h>
21 #include <time.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /* Ensures that we store the error in the buffer and return the buffer. */
28 const char * SysStrError(int errnum, char * buf, size_t buflen);
29
30 #ifdef __cplusplus
31 } // extern C
32
33
34 // Extra C++ stuff. Included only in C++ mode.
35
36
37 #include <string>
38 #include <cstring>
39 inline std::string SysStrError(int errnum)
40 {
41 char buf[1024];
42 return SysStrError(errnum, buf, 1024);
43 }
44
45 inline struct tm SysLocalTime(time_t tt)
46 {
47 struct tm tms;
48 memset(&tms, 0, sizeof tms);
49 #ifdef _WIN32
50 errno_t rr = localtime_s(&tms, &tt);
51 if (rr == 0)
52 return tms;
53 #else
54
55 // Ignore the error, state that if something
56 // happened, you simply have a pre-cleared tms.
57 localtime_r(&tt, &tms);
58 #endif
59
60 return tms;
61 }
62
63
64 #endif // defined C++
65
66 #endif // INC_SRT_COMPAT_H