Add defines, enums and headers for MSVC
[cascardo/ovs.git] / include / windows / unistd.h
1 /*
2  * Copyright (c) 2014 Nicira, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef _UNISTD_H
17 #define _UNISTD_H   1
18
19 #define WIN32_LEAN_AND_MEAN
20 #include <windows.h>
21
22 #define fsync _commit
23
24 /* Standard file descriptors.  */
25 #define STDIN_FILENO    0   /* Standard input.  */
26 #define STDOUT_FILENO   1   /* Standard output.  */
27 #define STDERR_FILENO   2   /* Standard error output.  */
28
29 #define _SC_UIO_MAXIOV                  2
30 #define _XOPEN_IOV_MAX                 16
31
32 #define _SC_PAGESIZE                    0x1
33 #define _SC_NPROCESSORS_ONLN            0x2
34 #define _SC_PHYS_PAGES                  0x4
35
36 __inline int GetNumLogicalProcessors(void)
37 {
38     SYSTEM_INFO info_temp;
39     GetSystemInfo(&info_temp);
40     long int n_cores = info_temp.dwNumberOfProcessors;
41     return n_cores;
42 }
43
44 __inline long sysconf(int type)
45 {
46     long value = -1;
47     long page_size = -1;
48     SYSTEM_INFO sys_info;
49     MEMORYSTATUSEX status;
50
51     switch (type) {
52     case _SC_NPROCESSORS_ONLN:
53         value = GetNumLogicalProcessors();
54         break;
55
56     case _SC_PAGESIZE:
57         GetSystemInfo(&sys_info);
58         value = sys_info.dwPageSize;
59         break;
60
61     case _SC_PHYS_PAGES:
62         status.dwLength = sizeof(status);
63         page_size = sysconf(_SC_PAGESIZE);
64         if (GlobalMemoryStatusEx(&status) && page_size != -1) {
65             value = status.ullTotalPhys / page_size;
66         }
67         break;
68
69     default:
70         break;
71     }
72
73     return value;
74 }
75
76 #endif /* unistd.h  */