]> git.cworth.org Git - apitrace/blob - common/os.hpp
Merge branch 'master' into d3d10
[apitrace] / common / os.hpp
1 /**************************************************************************
2  *
3  * Copyright 2010 VMware, Inc.
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  *
24  **************************************************************************/
25
26 /*
27  * Simple OS abstraction layer.
28  */
29
30 #ifndef _OS_HPP_
31 #define _OS_HPP_
32
33 #include <stdlib.h>
34 #include <stdarg.h>
35 #include <stdio.h>
36
37 #ifdef _WIN32
38 #ifndef snprintf
39 #define snprintf _snprintf
40 #endif
41 #ifndef vsnprintf
42 #define vsnprintf _vsnprintf
43 #endif
44 #define PATH_SEP '\\'
45 #else /* !_WIN32 */
46 #define PATH_SEP '/'
47 #endif /* !_WIN32 */
48
49 #ifndef PATH_MAX
50 #define PATH_MAX 1024
51 #endif
52
53 namespace OS {
54
55 void AcquireMutex(void);
56
57 void ReleaseMutex(void);
58
59 bool GetProcessName(char *str, size_t size);
60 bool GetCurrentDir(char *str, size_t size);
61
62 void DebugMessage(const char *format, ...)
63 #ifdef __GNUC__
64     __attribute__ ((format (printf, 1, 2)))
65 #endif
66 ;
67
68 #if defined _WIN32 || defined __CYGWIN__
69   /* We always use .def files on windows for now */
70   #if 0
71   #define PUBLIC __declspec(dllexport)
72   #else
73   #define PUBLIC
74   #endif
75   #define PRIVATE
76 #else
77   #if __GNUC__ >= 4
78     #define PUBLIC __attribute__ ((visibility("default")))
79     #define PRIVATE __attribute__ ((visibility("hidden")))
80   #else
81     #define PUBLIC
82     #define PRIVATE
83   #endif
84 #endif
85
86 /**
87  * Get the current time in microseconds from an unknown base.
88  */
89 long long GetTime(void);
90
91 void Abort(void);
92
93 void SetExceptionCallback(void (*callback)(void));
94 void ResetExceptionCallback(void);
95
96 } /* namespace OS */
97
98 #endif /* _OS_HPP_ */