This source file includes following definitions.
- getenv
- setenv
- sleep
- sysconf
- fcntl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #ifndef OPAL_MISC_H
20 #define OPAL_MISC_H
21
22 #include <stdio.h>
23 #include <stdlib.h>
24
25 #define _SC_PAGESIZE 0
26 #define _SC_OPEN_MAX 1
27
28 #if 0
29
30 static __inline char* getenv (const char *name)
31 {
32 int ret;
33 char *buffer;
34 DWORD length = GetEnvironmentVariable( (LPCSTR)name, NULL, 0 );
35
36 if( 0 == length ) return NULL;
37 buffer = (char *)malloc(sizeof(char) * length);
38 ret = GetEnvironmentVariable((LPCSTR)name, (LPSTR)buffer, length);
39 return (ret > 0) ? buffer: NULL;
40 }
41
42
43 static __inline int setenv (const char *name, const char *value, int rewrite)
44 {
45 int ret;
46 if( 0 == rewrite ) {
47 DWORD length = 0;
48 if( 0 == (length = GetEnvironmentVariable( (LPCSTR)name, NULL, length )) ) {
49 if( ERROR_ENVVAR_NOT_FOUND == GetLastError() ) {
50 return 0;
51 }
52 }
53 }
54
55 ret = SetEnvironmentVariable ((LPCSTR)name, (LPCSTR)value);
56 return (0 != ret)? 1: 0;
57 }
58 #endif
59
60 static __inline unsigned int sleep(unsigned int seconds) {
61
62
63 SleepEx(seconds * 1000, TRUE);
64 return 0;
65 }
66
67
68
69 static __inline size_t sysconf(int option) {
70
71 SYSTEM_INFO sys_info;
72
73 if( _SC_OPEN_MAX == option ) {
74 return _getmaxstdio();
75 }
76
77 GetSystemInfo(&sys_info);
78 if (_SC_PAGESIZE == option){
79 return (size_t)sys_info.dwPageSize;
80 }
81 printf( "This functionality is not supported: line: %d\tfile: %s\n",
82 __LINE__, __FILE__ );
83 abort();
84 return 0;
85 }
86
87 #define F_GETFL 0
88 #define F_SETFL 1
89 #define O_NONBLOCK 0
90
91
92
93
94
95 static __inline int fcntl (int fildes, int cmd, ...) {
96 int ret;
97 int mode;
98
99 switch (cmd) {
100 case F_SETFL: mode = 1; ret = ioctlsocket ((SOCKET)fildes, FIONBIO, (u_long FAR*) &mode);
101 break;
102 case F_GETFL: ret = 0;
103 break;
104 default: printf("Option not supported: %d %s\n", __LINE__, __FILE__);
105 abort();
106 };
107
108 return ret;
109 }
110
111 #endif