sedna 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/{CHANGES → CHANGES.rdoc} +9 -0
  2. data/{README → README.rdoc} +23 -25
  3. data/Rakefile +32 -9
  4. data/ext/{extconf.rb → sedna/extconf.rb} +33 -21
  5. data/ext/{sedna.c → sedna/sedna.c} +48 -40
  6. data/test/sedna_test.rb +9 -9
  7. data/vendor/sedna/AUTHORS +18 -0
  8. data/vendor/sedna/COPYRIGHT +90 -0
  9. data/vendor/sedna/LICENSE +202 -0
  10. data/vendor/sedna/Makefile.include +423 -0
  11. data/vendor/sedna/Makefile.platform +31 -0
  12. data/vendor/sedna/depend.sed +48 -0
  13. data/vendor/sedna/driver/c/Makefile +98 -0
  14. data/vendor/sedna/driver/c/libsedna.c +1998 -0
  15. data/vendor/sedna/driver/c/libsedna.h +199 -0
  16. data/vendor/sedna/driver/c/sednamt.def +21 -0
  17. data/vendor/sedna/driver/c/sp_defs.h +186 -0
  18. data/vendor/sedna/kernel/common/FastXptrHash.cpp +101 -0
  19. data/vendor/sedna/kernel/common/IntHash.h +314 -0
  20. data/vendor/sedna/kernel/common/IntList.h +224 -0
  21. data/vendor/sedna/kernel/common/Makefile +30 -0
  22. data/vendor/sedna/kernel/common/SSMMsg.cpp +459 -0
  23. data/vendor/sedna/kernel/common/SSMMsg.h +142 -0
  24. data/vendor/sedna/kernel/common/XptrHash.h +435 -0
  25. data/vendor/sedna/kernel/common/argtable.c +972 -0
  26. data/vendor/sedna/kernel/common/argtable.h +896 -0
  27. data/vendor/sedna/kernel/common/base.cpp +339 -0
  28. data/vendor/sedna/kernel/common/base.h +226 -0
  29. data/vendor/sedna/kernel/common/bit_set.cpp +157 -0
  30. data/vendor/sedna/kernel/common/bit_set.h +55 -0
  31. data/vendor/sedna/kernel/common/commutil.h +67 -0
  32. data/vendor/sedna/kernel/common/config.h +62 -0
  33. data/vendor/sedna/kernel/common/counted_ptr.h +74 -0
  34. data/vendor/sedna/kernel/common/errdbg/ErrorCodes.java +1056 -0
  35. data/vendor/sedna/kernel/common/errdbg/Makefile +34 -0
  36. data/vendor/sedna/kernel/common/errdbg/assert.c +133 -0
  37. data/vendor/sedna/kernel/common/errdbg/d_printf.c +150 -0
  38. data/vendor/sedna/kernel/common/errdbg/d_printf.h +91 -0
  39. data/vendor/sedna/kernel/common/errdbg/error.codes +1743 -0
  40. data/vendor/sedna/kernel/common/errdbg/error_codes.c +531 -0
  41. data/vendor/sedna/kernel/common/errdbg/error_codes.h +549 -0
  42. data/vendor/sedna/kernel/common/errdbg/error_codes_scm.scm +527 -0
  43. data/vendor/sedna/kernel/common/errdbg/event_log.c +956 -0
  44. data/vendor/sedna/kernel/common/errdbg/event_log.h +226 -0
  45. data/vendor/sedna/kernel/common/errdbg/exceptions.cpp +155 -0
  46. data/vendor/sedna/kernel/common/errdbg/exceptions.h +559 -0
  47. data/vendor/sedna/kernel/common/errdbg/gen_error_codes +0 -0
  48. data/vendor/sedna/kernel/common/errdbg/gen_error_codes.c +345 -0
  49. data/vendor/sedna/kernel/common/gmm.cpp +192 -0
  50. data/vendor/sedna/kernel/common/gmm.h +29 -0
  51. data/vendor/sedna/kernel/common/ipc_ops.cpp +435 -0
  52. data/vendor/sedna/kernel/common/ipc_ops.h +51 -0
  53. data/vendor/sedna/kernel/common/lfsGlobals.h +12 -0
  54. data/vendor/sedna/kernel/common/lm_base.h +90 -0
  55. data/vendor/sedna/kernel/common/mmgr/Makefile +11 -0
  56. data/vendor/sedna/kernel/common/mmgr/aset.c +1185 -0
  57. data/vendor/sedna/kernel/common/mmgr/mcxt.c +741 -0
  58. data/vendor/sedna/kernel/common/mmgr/memnodes.h +70 -0
  59. data/vendor/sedna/kernel/common/mmgr/memutils.h +145 -0
  60. data/vendor/sedna/kernel/common/mmgr/se_alloc.h +321 -0
  61. data/vendor/sedna/kernel/common/mmgr/track.c +214 -0
  62. data/vendor/sedna/kernel/common/pping.cpp +672 -0
  63. data/vendor/sedna/kernel/common/pping.h +119 -0
  64. data/vendor/sedna/kernel/common/rcv_test.cpp +273 -0
  65. data/vendor/sedna/kernel/common/rcv_test.h +19 -0
  66. data/vendor/sedna/kernel/common/sedna.c +128 -0
  67. data/vendor/sedna/kernel/common/sedna.h +49 -0
  68. data/vendor/sedna/kernel/common/sedna_ef.h +52 -0
  69. data/vendor/sedna/kernel/common/sm_vmm_data.h +144 -0
  70. data/vendor/sedna/kernel/common/sp.c +93 -0
  71. data/vendor/sedna/kernel/common/sp.h +36 -0
  72. data/vendor/sedna/kernel/common/st/Makefile +20 -0
  73. data/vendor/sedna/kernel/common/st/os_linux/stacktrace.c +213 -0
  74. data/vendor/sedna/kernel/common/st/os_nt/stacktrace.c +338 -0
  75. data/vendor/sedna/kernel/common/st/os_other/stacktrace.c +39 -0
  76. data/vendor/sedna/kernel/common/st/stacktrace.h +72 -0
  77. data/vendor/sedna/kernel/common/st/stacktrfmt.c +64 -0
  78. data/vendor/sedna/kernel/common/tr_debug.cpp +112 -0
  79. data/vendor/sedna/kernel/common/tr_debug.h +22 -0
  80. data/vendor/sedna/kernel/common/u/Makefile +14 -0
  81. data/vendor/sedna/kernel/common/u/u.c +268 -0
  82. data/vendor/sedna/kernel/common/u/u.h +715 -0
  83. data/vendor/sedna/kernel/common/u/uatomic.h +12 -0
  84. data/vendor/sedna/kernel/common/u/udl.h +31 -0
  85. data/vendor/sedna/kernel/common/u/uevent.c +406 -0
  86. data/vendor/sedna/kernel/common/u/uevent.h +71 -0
  87. data/vendor/sedna/kernel/common/u/ugnames.cpp +330 -0
  88. data/vendor/sedna/kernel/common/u/ugnames.h +134 -0
  89. data/vendor/sedna/kernel/common/u/uhash_map.h +77 -0
  90. data/vendor/sedna/kernel/common/u/uhdd.c +1018 -0
  91. data/vendor/sedna/kernel/common/u/uhdd.h +206 -0
  92. data/vendor/sedna/kernel/common/u/ummap.cpp +268 -0
  93. data/vendor/sedna/kernel/common/u/ummap.h +60 -0
  94. data/vendor/sedna/kernel/common/u/umutex.c +145 -0
  95. data/vendor/sedna/kernel/common/u/umutex.h +65 -0
  96. data/vendor/sedna/kernel/common/u/upipe.cpp +244 -0
  97. data/vendor/sedna/kernel/common/u/upipe.h +74 -0
  98. data/vendor/sedna/kernel/common/u/uprocess.c +767 -0
  99. data/vendor/sedna/kernel/common/u/uprocess.h +91 -0
  100. data/vendor/sedna/kernel/common/u/usafesync.h +41 -0
  101. data/vendor/sedna/kernel/common/u/usecurity.c +150 -0
  102. data/vendor/sedna/kernel/common/u/usecurity.h +55 -0
  103. data/vendor/sedna/kernel/common/u/usem.c +891 -0
  104. data/vendor/sedna/kernel/common/u/usem.h +83 -0
  105. data/vendor/sedna/kernel/common/u/ushm.c +222 -0
  106. data/vendor/sedna/kernel/common/u/ushm.h +46 -0
  107. data/vendor/sedna/kernel/common/u/usocket.c +541 -0
  108. data/vendor/sedna/kernel/common/u/usocket.h +118 -0
  109. data/vendor/sedna/kernel/common/u/usystem.c +57 -0
  110. data/vendor/sedna/kernel/common/u/usystem.h +46 -0
  111. data/vendor/sedna/kernel/common/u/uthread.c +259 -0
  112. data/vendor/sedna/kernel/common/u/uthread.h +95 -0
  113. data/vendor/sedna/kernel/common/u/utime.c +65 -0
  114. data/vendor/sedna/kernel/common/u/utime.h +40 -0
  115. data/vendor/sedna/kernel/common/u/uutils.c +142 -0
  116. data/vendor/sedna/kernel/common/u/uutils.h +65 -0
  117. data/vendor/sedna/kernel/common/ugc.cpp +156 -0
  118. data/vendor/sedna/kernel/common/ugc.h +15 -0
  119. data/vendor/sedna/kernel/common/utils.cpp +156 -0
  120. data/vendor/sedna/kernel/common/utils.h +133 -0
  121. data/vendor/sedna/kernel/common/version.c +16 -0
  122. data/vendor/sedna/kernel/common/version.h +21 -0
  123. data/vendor/sedna/kernel/common/wustructures.h +18 -0
  124. data/vendor/sedna/kernel/common/wutypes.h +34 -0
  125. data/vendor/sedna/kernel/common/xptr.cpp +17 -0
  126. data/vendor/sedna/kernel/common/xptr.h +211 -0
  127. data/vendor/sedna/ver +1 -0
  128. metadata +142 -14
@@ -0,0 +1,60 @@
1
+ /*
2
+ * File: ummap.h
3
+ * Copyright (C) 2004 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
4
+ */
5
+
6
+
7
+ #ifndef _UMMAP_H
8
+ #define _UMMAP_H
9
+
10
+ #include "common/u/uhdd.h"
11
+ #include "common/u/usecurity.h"
12
+
13
+ #ifdef _WIN32
14
+
15
+ #define U_INVALID_FILEMAPPING(m) ((m).map == NULL)
16
+
17
+ typedef struct {
18
+ HANDLE map;
19
+ UFile fd;
20
+ } UMMap;
21
+
22
+ #else
23
+
24
+ #include <sys/mman.h>
25
+
26
+ #define U_INVALID_FILEMAPPING(m) ((m).map == -1)
27
+
28
+ typedef struct {
29
+ int map;
30
+ int size;
31
+ int to_file;
32
+ } UMMap;
33
+
34
+ #endif
35
+
36
+
37
+ // check the result by U_INVALID_FILEMAPPING macros
38
+ // pass U_INVALID_FD as fd if you want to create object in swap file
39
+ UMMap uCreateFileMapping(UFile fd, int size, const char* name, USECURITY_ATTRIBUTES* sa, sys_call_error_fun fun);
40
+ UMMap uOpenFileMapping(UFile fd, int size, const char *name, sys_call_error_fun fun);
41
+ /*
42
+ UMMap uCreateFileMapping(const char* file_name, UShareMode share, UFlag attr, global_name g_name);
43
+ UMMap uOpenFileMapping(const char* file_name, UShareMode share, UFlag attr, global_name g_name);
44
+ */
45
+ // returns -1 in case of error
46
+ int uReleaseFileMapping(UMMap m, const char *name, sys_call_error_fun fun);
47
+ int uCloseFileMapping(UMMap m, sys_call_error_fun fun);
48
+
49
+ // returns 0 in case of error
50
+ void *uMapViewOfFile(UMMap m, void *addr, int size, int offs, sys_call_error_fun fun);
51
+
52
+ // returns -1 in case of error
53
+ int uUnmapViewOfFile(UMMap m, void *addr, int size, sys_call_error_fun fun);
54
+ int uFlushViewOfFile(UMMap m, void *addr, int size, sys_call_error_fun fun);
55
+
56
+ int uMemLock(void *addr, size_t size, sys_call_error_fun fun);
57
+ int uMemUnlock(void *addr, size_t size, sys_call_error_fun fun);
58
+
59
+ #endif
60
+
@@ -0,0 +1,145 @@
1
+ /*
2
+ * File: umutex.c
3
+ * Copyright (C) 2004 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
4
+ */
5
+
6
+ #ifndef _WIN32
7
+ /* need this to enable UNIX98 features like pthread_mutexattr_settype from pthread.h */
8
+ #define _GNU_SOURCE
9
+ #endif
10
+ #include "common/u/umutex.h"
11
+
12
+ int uMutexInit(uMutexType *mutex, sys_call_error_fun fun)
13
+ {
14
+ #ifdef _WIN32
15
+ InitializeCriticalSection(mutex);
16
+ return 0;
17
+ #else
18
+ pthread_mutexattr_t attr;
19
+ int res = pthread_mutexattr_init(&attr);
20
+ if (res != 0)
21
+ {
22
+ sys_call_error("pthread_mutexattr_init");
23
+ return res;
24
+ }
25
+
26
+ if (res = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE), res!=0)
27
+ {
28
+ sys_call_error("pthread_mutexattr_settype");
29
+ return res;
30
+ }
31
+
32
+ if ((res = pthread_mutex_init(mutex, &attr)) != 0)
33
+ sys_call_error("pthread_mutex_init");
34
+ return res;
35
+ #endif
36
+ }
37
+
38
+ int uMutexLock(uMutexType *mutex, sys_call_error_fun fun)
39
+ {
40
+ #ifdef _WIN32
41
+ EnterCriticalSection(mutex);
42
+ return 0;
43
+ #else
44
+ int res;
45
+ if ((res = pthread_mutex_lock(mutex)) != 0)
46
+ sys_call_error("pthread_mutex_lock");
47
+ return res;
48
+ #endif
49
+ }
50
+
51
+ int uMutexUnlock(uMutexType *mutex, sys_call_error_fun fun)
52
+ {
53
+ #ifdef _WIN32
54
+ LeaveCriticalSection(mutex);
55
+ return 0;
56
+ #else
57
+ int res;
58
+ if ((res = pthread_mutex_unlock(mutex)) != 0)
59
+ sys_call_error("pthread_mutex_unlock");
60
+
61
+ return res;
62
+ #endif
63
+ }
64
+
65
+ int uMutexDestroy(uMutexType *mutex, sys_call_error_fun fun)
66
+ {
67
+ #ifdef _WIN32
68
+ DeleteCriticalSection(mutex);
69
+ return 0;
70
+ #else
71
+ int res;
72
+ if ((res = pthread_mutex_destroy(mutex)) != 0)
73
+ sys_call_error("pthread_mutex_destroy");
74
+
75
+ return res;
76
+ #endif
77
+ }
78
+
79
+
80
+
81
+
82
+
83
+ /*
84
+ int uMutex2Create(uMutex2Type *mutex, int inheritable, sys_call_error_fun fun)
85
+ {
86
+ #ifdef _WIN32
87
+ SECURITY_ATTRIBUTES sa;
88
+ sa.nLength = sizeof(SECURITY_ATTRIBUTES);
89
+ sa.lpSecurityDescriptor = NULL;
90
+ sa.bInheritHandle = inheritable ? TRUE : FALSE;
91
+ *mutex = CreateMutex(
92
+ &sa,
93
+ TRUE, // initial owner
94
+ NULL // object name
95
+ );
96
+ if (*mutex == NULL) return 1;
97
+ return 0;
98
+ #else
99
+ #error The platform is unsupported now
100
+ #endif
101
+ }
102
+
103
+ int uMutex2Lock(uMutex2Type *mutex, sys_call_error_fun fun)
104
+ {
105
+ #ifdef _WIN32
106
+ DWORD res = WaitForSingleObject(
107
+ *mutex, // handle to object
108
+ INFINITE // time-out interval
109
+ );
110
+
111
+ if (res == WAIT_FAILED) return 1;
112
+ return 0;
113
+ #else
114
+ #error The platform is unsupported now
115
+ #endif
116
+ }
117
+
118
+ int uMutex2Unlock(uMutex2Type *mutex, sys_call_error_fun fun)
119
+ {
120
+ #ifdef _WIN32
121
+ BOOL res = ReleaseMutex(
122
+ *mutex // handle to mutex
123
+ );
124
+
125
+ if (res == 0) return 1;
126
+ return 0;
127
+ #else
128
+ #error The platform is unsupported now
129
+ #endif
130
+ }
131
+
132
+ int uMutex2Destroy(uMutex2Type *mutex, sys_call_error_fun fun)
133
+ {
134
+ #ifdef _WIN32
135
+ BOOL res = CloseHandle(
136
+ *mutex // handle to mutex
137
+ );
138
+
139
+ if (res == 0) return 1;
140
+ return 0;
141
+ #else
142
+ #error The platform is unsupported now
143
+ #endif
144
+ }
145
+ */
@@ -0,0 +1,65 @@
1
+ /*
2
+ * File: umutex.h
3
+ * Copyright (C) 2004 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
4
+ */
5
+
6
+
7
+ #ifndef UMUTEX_H
8
+ #define UMUTEX_H
9
+
10
+ #include "common/u/u.h"
11
+
12
+ #ifdef __cplusplus
13
+ extern "C" {
14
+ #endif
15
+
16
+ //#if defined _WIN32
17
+ // WIN32 defined
18
+ //#elif defined POSIX
19
+ // POSIX defined
20
+ //#else
21
+ //#error Unknown platform, unknown threads...
22
+ //#endif
23
+
24
+
25
+ #ifdef _WIN32
26
+ typedef CRITICAL_SECTION uMutexType;
27
+ #else
28
+ #include <pthread.h>
29
+
30
+ typedef pthread_mutex_t uMutexType;
31
+ #endif
32
+
33
+ /*
34
+ #ifdef _WIN32
35
+ typedef HANDLE uMutex2Type;
36
+ #else
37
+ typedef pthread_mutex_t uMutex2Type;
38
+ #endif
39
+ */
40
+
41
+ int uMutexInit(uMutexType *mutex, sys_call_error_fun fun);
42
+
43
+ int uMutexLock(uMutexType *mutex, sys_call_error_fun fun);
44
+
45
+ int uMutexUnlock(uMutexType *mutex, sys_call_error_fun fun);
46
+
47
+ int uMutexDestroy(uMutexType *mutex, sys_call_error_fun fun);
48
+
49
+
50
+ /*
51
+ int uMutex2Create(uMutex2Type *mutex, int inheritable, sys_call_error_fun fun);
52
+
53
+ int uMutex2Lock(uMutex2Type *mutex, sys_call_error_fun fun);
54
+
55
+ int uMutex2Unlock(uMutex2Type *mutex, sys_call_error_fun fun);
56
+
57
+ int uMutex2Destroy(uMutex2Type *mutex, sys_call_error_fun fun);
58
+ */
59
+ #ifdef __cplusplus
60
+ }
61
+ #endif
62
+
63
+
64
+ #endif
65
+
@@ -0,0 +1,244 @@
1
+ /*
2
+ * File: upipe.cpp
3
+ * Copyright (C) 2004 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
4
+ */
5
+
6
+
7
+ #include "common/errdbg/d_printf.h"
8
+ #include "common/u/upipe.h"
9
+
10
+ int uPipe(UPIPE* rpipe, /*read pipe*/
11
+ UPIPE* wpipe, /*write pipe*/
12
+ int inheritable,
13
+ sys_call_error_fun fun)
14
+ {
15
+ #ifdef _WIN32
16
+ SECURITY_ATTRIBUTES sa;
17
+ sa.nLength = sizeof(SECURITY_ATTRIBUTES);
18
+ sa.lpSecurityDescriptor = NULL;
19
+ sa.bInheritHandle = inheritable ? TRUE : FALSE;
20
+
21
+ BOOL res = CreatePipe(
22
+ rpipe, // read handle
23
+ wpipe, // write handle
24
+ &sa, // security attributes
25
+ 0 // pipe size
26
+ );
27
+
28
+ if (res != 0) return 0;
29
+ else
30
+ {
31
+ sys_call_error("CreatePipe");
32
+ return -1;
33
+ }
34
+ #else
35
+ int fildes[2];
36
+ int res = pipe(fildes);
37
+ if (res == -1) sys_call_error("pipe");
38
+
39
+ *rpipe = fildes[0];
40
+ *wpipe = fildes[1];
41
+ return res;
42
+ #endif
43
+ }
44
+
45
+ int uReadPipe(UPIPE rpipe, /*read pipe*/
46
+ void *buf, /*buffer for data*/
47
+ int nbyte, /*size of the buffer*/
48
+ sys_call_error_fun fun
49
+ )
50
+ {
51
+ #ifdef _WIN32
52
+ DWORD bytes_read = 0;
53
+ BOOL res = ReadFile(
54
+ rpipe, // handle to file
55
+ buf, // data buffer
56
+ nbyte, // number of bytes to read
57
+ &bytes_read, // number of bytes read
58
+ NULL // overlapped buffer
59
+ );
60
+
61
+ if (res == 0)
62
+ {
63
+ if (GetLastError() == 109) return bytes_read;
64
+ else
65
+ {
66
+ sys_call_error("ReadFile");
67
+ return -1;
68
+ }
69
+ }
70
+ else return bytes_read;
71
+ #else
72
+ int res;
73
+ if ((res = read(rpipe, buf, nbyte)) == -1)
74
+ sys_call_error("read");
75
+
76
+ return res;
77
+ #endif
78
+ }
79
+
80
+ //return the number of bytes read
81
+ // -1 indicates failure
82
+ int uReadPipeAll(UPIPE rpipe, // read pipe
83
+ void* buf, // buffer for data
84
+ int nbyte, // size of the buffer
85
+ sys_call_error_fun fun
86
+ )
87
+ {
88
+ int res = 0;
89
+ int bytes_read = 0;
90
+ while (true)
91
+ {
92
+ res = uReadPipe(rpipe, (char*)buf + bytes_read, nbyte - bytes_read, __sys_call_error);
93
+ if (res == -1) return -1;
94
+
95
+ if (res == 0 ) return bytes_read;
96
+ else bytes_read += res;
97
+
98
+ if (bytes_read == nbyte) return bytes_read;
99
+
100
+ }
101
+ }
102
+
103
+
104
+ /*
105
+ int uReadPipeMsg(UPIPE rpipe,
106
+ std::string &str, sys_call_error_fun fun)
107
+ {
108
+ char buf[2];
109
+ DWORD bytes_read;
110
+ str = "";
111
+ for (;;)
112
+ {
113
+ memset(buf, (char)0, 1);
114
+ BOOL res = ReadFile(
115
+ rpipe, // handle to file
116
+ buf, // data buffer
117
+ 1, // number of bytes to read
118
+ &bytes_read, // number of bytes read
119
+ NULL // overlapped buffer
120
+ );
121
+ if (bytes_read < 0) return -1;
122
+ if (buf[0] == '\0') break;
123
+
124
+ buf[1]='\0';
125
+ str += std::string(buf);
126
+ }
127
+
128
+ return 0;
129
+ }
130
+ */
131
+
132
+ int uWritePipe(UPIPE wpipe, /*write pipe*/
133
+ const void *buf, /*pointer to data*/
134
+ int nbyte, /*size of the data*/
135
+ sys_call_error_fun fun
136
+ )
137
+ {
138
+ #ifdef _WIN32
139
+ DWORD bytes_written = 0;
140
+ BOOL res = WriteFile(
141
+ wpipe, // handle to file
142
+ buf, // data buffer
143
+ nbyte, // number of bytes to write
144
+ &bytes_written, // number of bytes written
145
+ NULL // overlapped buffer
146
+ );
147
+
148
+ if (res == 0)
149
+ {
150
+ sys_call_error("WriteFile");
151
+ return -1;
152
+ }
153
+ else return bytes_written;
154
+ #else
155
+ int res;
156
+ if ((res = write(wpipe, buf, nbyte)) == -1)
157
+ sys_call_error("write");
158
+
159
+ return res;
160
+ #endif
161
+ }
162
+
163
+ // return value 0 indicates success
164
+ int uWritePipeAll(UPIPE wpipe, /*write pipe*/
165
+ const void *buf, /*pointer to data*/
166
+ int nbyte, /*size of the data*/
167
+ sys_call_error_fun fun
168
+ )
169
+ {
170
+ int res = 0;
171
+ int bytes_written = 0;
172
+ while (true)
173
+ {
174
+ res = uWritePipe(wpipe, (char*)buf + bytes_written, nbyte - bytes_written, __sys_call_error);
175
+ if (res == -1) return -1;
176
+ else bytes_written += res;
177
+
178
+ if (bytes_written == nbyte) return 0;
179
+ }
180
+ }
181
+
182
+ int uClosePipe(UPIPE upipe, sys_call_error_fun fun)
183
+ {
184
+ #ifdef _WIN32
185
+ BOOL res = CloseHandle(
186
+ upipe // handle to object
187
+ );
188
+
189
+
190
+ if (res == 0)
191
+ {
192
+ sys_call_error("CloseHandle");
193
+ return -1;
194
+ }
195
+ else return 0;
196
+ #else
197
+ int res;
198
+ if ((res = close(upipe)) == -1)
199
+ sys_call_error("close");
200
+
201
+ return res;
202
+ #endif
203
+ }
204
+
205
+ #define BUFSIZE 1024
206
+
207
+ int uReadPipeAll(UPIPE rpipe, std::string &str, sys_call_error_fun fun)
208
+ {
209
+ char buf[BUFSIZE + 1];
210
+ int bytes_read;
211
+ for (;;)
212
+ {
213
+ memset(buf, (char)0, BUFSIZE + 1);
214
+ bytes_read = uReadPipe(rpipe, buf, BUFSIZE, __sys_call_error);
215
+ if (bytes_read < 0) return -1;
216
+ if (bytes_read == 0) break;
217
+ str += std::string(buf);
218
+ }
219
+ return 0;
220
+ }
221
+
222
+ /*
223
+ int uPipeDoNotInherit(UPIPE *upipe, sys_call_error_fun fun)
224
+ {
225
+ #ifdef _WIN32
226
+ HANDLE tmp = *upipe;
227
+ BOOL res = DuplicateHandle(
228
+ GetCurrentProcess(),
229
+ tmp,
230
+ GetCurrentProcess(),
231
+ upipe,
232
+ 0,
233
+ FALSE,
234
+ DUPLICATE_SAME_ACCESS);
235
+
236
+ CloseHandle(tmp);
237
+
238
+ if (res == 0) return -1;
239
+ else return 0;
240
+ #else
241
+ return 0;
242
+ #endif
243
+ }
244
+ */