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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/*******************************************************************************
* Copyright (C) ST-Ericsson SA 2011
* License terms: 3-clause BSD license
******************************************************************************/
#ifndef _OS_H
#define _OS_H
#include <sys/time.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include "Types.h"
#include "CWaitableObject.h"
class OS
{
public:
OS();
virtual ~OS();
static void Sleep(DWORD dwMilliseconds);
static time_t GetSystemTimeInMs();
static DWORD GetErrorCode() {
return OS::ErrorCode;
}
static void SetErrorCode(DWORD dwErrorCode) {
OS::ErrorCode = dwErrorCode;
}
static timespec GetAbsoluteTime(DWORD dwTimeout);
private:
static DWORD ErrorCode;
};
#define MAX(a, b) ((a) > (b) ? (a) : (b))
/*
* str manipulation functions used in windows build
*/
char *strcpy_s(char *dst, size_t _Size, const char *src);
char *strncpy_s(char *dst, const char *src, size_t _Size);
int _stricmp(const char *s1, const char *s2);
int sprintf_s(char *dst, size_t _Size, const char *format, ...);
#define _snprintf snprintf
template <size_t _Size>
char *strcpy_s(char(&dst)[_Size], const char src[])
{
return strncpy(dst, src, _Size);
}
template<size_t _Size>
int sprintf_s(char(&dst)[_Size], const char *format, ...)
{
int ReturnValue;
va_list l;
va_start(l, format);
ReturnValue = vsnprintf(dst, _Size, format, l);
va_end(l);
return ReturnValue;
}
template <size_t _Size>
char *strcat_s(char(&dst)[_Size], const char src[])
{
return strncat(dst, src, _Size);
}
template <size_t _Size>
int _ultoa_s(unsigned long value, char(&str)[_Size], int radix)
{
switch (radix) {
case 10:
return sprintf_s(str, "%ul", value);
case 16:
return sprintf_s(str, "%ulX", value);
default:
return -1;
}
}
template<size_t _Size>
int _snprintf_s(char(&dst)[_Size], size_t _MaxCount, const char *format, ...)
{
int ReturnValue;
va_list l;
va_start(l, format);
ReturnValue = vsnprintf(dst, MAX(_MaxCount, _Size), format, l);
va_end(l);
return ReturnValue;
}
template<size_t _Size>
int vsprintf_s(char(&dst)[_Size], const char *format, va_list l)
{
return vsnprintf(dst, _Size, format, l);
}
#endif /* _OS_H */
|