78
79 MessageResponse PosixPlatform::ShowResponseMessage(TString title,
80 TString description) {
81 MessageResponse result = mrCancel;
82
83 printf("%s %s (Y/N)\n", PlatformString(title).toPlatformString(),
84 PlatformString(description).toPlatformString());
85 fflush(stdout);
86
87 std::string input;
88 std::cin >> input;
89
90 if (input == "Y") {
91 result = mrOK;
92 }
93
94 return result;
95 }
96
97 void PosixPlatform::SetCurrentDirectory(TString Value) {
98 chdir(StringToFileSystemString(Value));
99 }
100
101 Module PosixPlatform::LoadLibrary(TString FileName) {
102 return dlopen(StringToFileSystemString(FileName), RTLD_LAZY);
103 }
104
105 void PosixPlatform::FreeLibrary(Module AModule) {
106 dlclose(AModule);
107 }
108
109 Procedure PosixPlatform::GetProcAddress(Module AModule,
110 std::string MethodName) {
111 return dlsym(AModule, PlatformString(MethodName));
112 }
113
114 Process* PosixPlatform::CreateProcess() {
115 return new PosixProcess();
116 }
117
118 void PosixPlatform::addPlatformDependencies(JavaLibrary *pJavaLibrary) {
195 }
196
197 bool PosixProcess::ReadOutput() {
198 bool result = false;
199
200 if (FOutputHandle != 0 && IsRunning() == true) {
201 char buffer[4096] = {0};
202
203 ssize_t count = read(FOutputHandle, buffer, sizeof (buffer));
204
205 if (count == -1) {
206 if (errno == EINTR) {
207 // continue;
208 } else {
209 perror("read");
210 exit(1);
211 }
212 } else if (count == 0) {
213 // break;
214 } else {
215 if (buffer[count - 1] == EOF) {
216 buffer[count - 1] = '\0';
217 }
218
219 std::list<TString> output = Helpers::StringToArray(buffer);
220 FOutput.splice(FOutput.end(), output, output.begin(), output.end());
221 result = true;
222 }
223 }
224
225 return false;
226 }
227
228 bool PosixProcess::IsRunning() {
229 bool result = false;
230
231 if (kill(FChildPID, 0) == 0) {
232 result = true;
233 }
234
235 return result;
236 }
237
293 printf("child continued\n");
294 #endif // WIFCONTINUED
295 } else { // Non-standard case -- may never happen
296 printf("Unexpected status (0x%x)\n", status);
297 }
298 #endif // DEBUG
299
300 if (wpid != -1) {
301 result = true;
302 }
303
304 return result;
305 }
306
307 TProcessID PosixProcess::GetProcessID() {
308 return FChildPID;
309 }
310
311 void PosixProcess::SetInput(TString Value) {
312 if (FInputHandle != 0) {
313 write(FInputHandle, Value.data(), Value.size());
314 }
315 }
316
317 std::list<TString> PosixProcess::GetOutput() {
318 ReadOutput();
319 return Process::GetOutput();
320 }
|
78
79 MessageResponse PosixPlatform::ShowResponseMessage(TString title,
80 TString description) {
81 MessageResponse result = mrCancel;
82
83 printf("%s %s (Y/N)\n", PlatformString(title).toPlatformString(),
84 PlatformString(description).toPlatformString());
85 fflush(stdout);
86
87 std::string input;
88 std::cin >> input;
89
90 if (input == "Y") {
91 result = mrOK;
92 }
93
94 return result;
95 }
96
97 void PosixPlatform::SetCurrentDirectory(TString Value) {
98 int ignored = chdir(StringToFileSystemString(Value));
99 }
100
101 Module PosixPlatform::LoadLibrary(TString FileName) {
102 return dlopen(StringToFileSystemString(FileName), RTLD_LAZY);
103 }
104
105 void PosixPlatform::FreeLibrary(Module AModule) {
106 dlclose(AModule);
107 }
108
109 Procedure PosixPlatform::GetProcAddress(Module AModule,
110 std::string MethodName) {
111 return dlsym(AModule, PlatformString(MethodName));
112 }
113
114 Process* PosixPlatform::CreateProcess() {
115 return new PosixProcess();
116 }
117
118 void PosixPlatform::addPlatformDependencies(JavaLibrary *pJavaLibrary) {
195 }
196
197 bool PosixProcess::ReadOutput() {
198 bool result = false;
199
200 if (FOutputHandle != 0 && IsRunning() == true) {
201 char buffer[4096] = {0};
202
203 ssize_t count = read(FOutputHandle, buffer, sizeof (buffer));
204
205 if (count == -1) {
206 if (errno == EINTR) {
207 // continue;
208 } else {
209 perror("read");
210 exit(1);
211 }
212 } else if (count == 0) {
213 // break;
214 } else {
215 /*
216 if (buffer[count - 1] == EOF) {
217 buffer[count - 1] = '\0';
218 }
219 */
220
221 std::list<TString> output = Helpers::StringToArray(buffer);
222 FOutput.splice(FOutput.end(), output, output.begin(), output.end());
223 result = true;
224 }
225 }
226
227 return false;
228 }
229
230 bool PosixProcess::IsRunning() {
231 bool result = false;
232
233 if (kill(FChildPID, 0) == 0) {
234 result = true;
235 }
236
237 return result;
238 }
239
295 printf("child continued\n");
296 #endif // WIFCONTINUED
297 } else { // Non-standard case -- may never happen
298 printf("Unexpected status (0x%x)\n", status);
299 }
300 #endif // DEBUG
301
302 if (wpid != -1) {
303 result = true;
304 }
305
306 return result;
307 }
308
309 TProcessID PosixProcess::GetProcessID() {
310 return FChildPID;
311 }
312
313 void PosixProcess::SetInput(TString Value) {
314 if (FInputHandle != 0) {
315 ssize_t ignored = write(FInputHandle, Value.data(), Value.size());
316 }
317 }
318
319 std::list<TString> PosixProcess::GetOutput() {
320 ReadOutput();
321 return Process::GetOutput();
322 }
|