]> git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia2/utilsunx.cpp
8e68bef6bcb1dcd90529db6991e4e1baac71caf7
[wxWidgets.git] / utils / wxMMedia2 / utilsunx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: utilsunx.cpp
3 // Purpose: generic Unix implementation of many wx functions
4 // Author: Vadim Zeitlin
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 // ============================================================================
11 // declarations
12 // ============================================================================
13
14 // ----------------------------------------------------------------------------
15 // headers
16 // ----------------------------------------------------------------------------
17
18 #include "wx/defs.h"
19 #include "wx/string.h"
20
21 #include "wx/intl.h"
22 #include "wx/log.h"
23
24 #include "wx/utils.h"
25 #include "wx/process.h"
26 #include "wx/thread.h"
27
28 #include "wx/stream.h"
29
30 #if wxUSE_GUI
31 #include "wx/unix/execute.h"
32 #endif
33
34 #include <stdarg.h>
35 #include <dirent.h>
36 #include <string.h>
37 #include <sys/stat.h>
38 #include <sys/types.h>
39 #include <unistd.h>
40 #include <sys/wait.h>
41 #include <pwd.h>
42 #include <errno.h>
43 #include <netdb.h>
44 #include <signal.h>
45 #include <fcntl.h> // for O_WRONLY and friends
46 #include <time.h> // nanosleep() and/or usleep()
47 #include <ctype.h> // isspace()
48 #include <sys/time.h> // needed for FD_SETSIZE
49
50 #ifdef HAVE_UNAME
51 #include <sys/utsname.h> // for uname()
52 #endif // HAVE_UNAME
53
54 // ----------------------------------------------------------------------------
55 // conditional compilation
56 // ----------------------------------------------------------------------------
57
58 // many versions of Unices have this function, but it is not defined in system
59 // headers - please add your system here if it is the case for your OS.
60 // SunOS < 5.6 (i.e. Solaris < 2.6) and DG-UX are like this.
61 #if !defined(HAVE_USLEEP) && \
62 (defined(__SUN__) && !defined(__SunOs_5_6) && \
63 !defined(__SunOs_5_7) && !defined(__SUNPRO_CC)) || \
64 defined(__osf__) || defined(__EMX__)
65 extern "C"
66 {
67 #ifdef __SUN__
68 int usleep(unsigned int usec);
69 #else // !Sun
70 #ifdef __EMX__
71 /* I copied this from the XFree86 diffs. AV. */
72 #define INCL_DOSPROCESS
73 #include <os2.h>
74 inline void usleep(unsigned long delay)
75 {
76 DosSleep(delay ? (delay/1000l) : 1l);
77 }
78 #else // !Sun && !EMX
79 void usleep(unsigned long usec);
80 #endif
81 #endif // Sun/EMX/Something else
82 };
83
84 #define HAVE_USLEEP 1
85 #endif // Unices without usleep()
86
87 // ============================================================================
88 // implementation
89 // ============================================================================
90
91 // ----------------------------------------------------------------------------
92 // sleeping
93 // ----------------------------------------------------------------------------
94
95 void wxSleep(int nSecs)
96 {
97 sleep(nSecs);
98 }
99
100 void wxUsleep(unsigned long milliseconds)
101 {
102 #if defined(HAVE_NANOSLEEP)
103 timespec tmReq;
104 tmReq.tv_sec = (time_t)(milliseconds / 1000);
105 tmReq.tv_nsec = (milliseconds % 1000) * 1000 * 1000;
106
107 // we're not interested in remaining time nor in return value
108 (void)nanosleep(&tmReq, (timespec *)NULL);
109 #elif defined(HAVE_USLEEP)
110 // uncomment this if you feel brave or if you are sure that your version
111 // of Solaris has a safe usleep() function but please notice that usleep()
112 // is known to lead to crashes in MT programs in Solaris 2.[67] and is not
113 // documented as MT-Safe
114 #if defined(__SUN__) && wxUSE_THREADS
115 #error "usleep() cannot be used in MT programs under Solaris."
116 #endif // Sun
117
118 usleep(milliseconds * 1000); // usleep(3) wants microseconds
119 #elif defined(HAVE_SLEEP)
120 // under BeOS sleep() takes seconds (what about other platforms, if any?)
121 sleep(milliseconds * 1000);
122 #else // !sleep function
123 #error "usleep() or nanosleep() function required for wxUsleep"
124 #endif // sleep function
125 }
126
127 // ----------------------------------------------------------------------------
128 // process management
129 // ----------------------------------------------------------------------------
130
131 int wxKill(long pid, wxSignal sig)
132 {
133 return kill((pid_t)pid, (int)sig);
134 }
135
136 #define WXEXECUTE_NARGS 127
137
138 long wxExecute( const wxString& command, bool sync, wxProcess *process )
139 {
140 wxCHECK_MSG( !command.IsEmpty(), 0, wxT("can't exec empty command") );
141
142 int argc = 0;
143 wxChar *argv[WXEXECUTE_NARGS];
144 wxString argument;
145 const wxChar *cptr = command.c_str();
146 wxChar quotechar = wxT('\0'); // is arg quoted?
147 bool escaped = FALSE;
148
149 // split the command line in arguments
150 do
151 {
152 argument=wxT("");
153 quotechar = wxT('\0');
154
155 // eat leading whitespace:
156 while ( wxIsspace(*cptr) )
157 cptr++;
158
159 if ( *cptr == wxT('\'') || *cptr == wxT('"') )
160 quotechar = *cptr++;
161
162 do
163 {
164 if ( *cptr == wxT('\\') && ! escaped )
165 {
166 escaped = TRUE;
167 cptr++;
168 continue;
169 }
170
171 // all other characters:
172 argument += *cptr++;
173 escaped = FALSE;
174
175 // have we reached the end of the argument?
176 if ( (*cptr == quotechar && ! escaped)
177 || (quotechar == wxT('\0') && wxIsspace(*cptr))
178 || *cptr == wxT('\0') )
179 {
180 wxASSERT_MSG( argc < WXEXECUTE_NARGS,
181 wxT("too many arguments in wxExecute") );
182
183 argv[argc] = new wxChar[argument.length() + 1];
184 wxStrcpy(argv[argc], argument.c_str());
185 argc++;
186
187 // if not at end of buffer, swallow last character:
188 if(*cptr)
189 cptr++;
190
191 break; // done with this one, start over
192 }
193 } while(*cptr);
194 } while(*cptr);
195 argv[argc] = NULL;
196
197 // do execute the command
198 long lRc = wxExecute(argv, sync, process);
199
200 // clean up
201 argc = 0;
202 while( argv[argc] )
203 delete [] argv[argc++];
204
205 return lRc;
206 }
207
208 bool wxShell(const wxString& command)
209 {
210 wxString cmd;
211 if ( !!command )
212 cmd.Printf(wxT("xterm -e %s"), command.c_str());
213 else
214 cmd = command;
215
216 return wxExecute(cmd) != 0;
217 }
218
219 #if wxUSE_GUI
220
221 void wxHandleProcessTermination(wxEndProcessData *proc_data)
222 {
223 int pid = (proc_data->pid > 0) ? proc_data->pid : -(proc_data->pid);
224
225 // waitpid is POSIX so should be available everywhere, however on older
226 // systems wait() might be used instead in a loop (until the right pid
227 // terminates)
228 int status = 0;
229 int rc;
230
231 // wait for child termination and if waitpid() was interrupted, try again
232 do
233 {
234 rc = waitpid(pid, &status, 0);
235 }
236 while ( rc == -1 && errno == EINTR );
237
238
239 if( rc == -1 || ! (WIFEXITED(status) || WIFSIGNALED(status)) )
240 {
241 wxLogSysError(_("Waiting for subprocess termination failed"));
242 /* AFAIK, this can only happen if something went wrong within
243 wxGTK, i.e. due to a race condition or some serious bug.
244 After having fixed the order of statements in
245 GTK_EndProcessDetector(). (KB)
246 */
247 }
248 else
249 {
250 // notify user about termination if required
251 if (proc_data->process)
252 {
253 proc_data->process->OnTerminate(proc_data->pid,
254 WEXITSTATUS(status));
255 }
256 // clean up
257 if ( proc_data->pid > 0 )
258 {
259 delete proc_data;
260 }
261 else
262 {
263 // wxExecute() will know about it
264 proc_data->exitcode = status;
265
266 proc_data->pid = 0;
267 }
268 }
269 }
270
271 #endif // wxUSE_GUI
272
273 #if wxUSE_GUI
274 #define WXUNUSED_UNLESS_GUI(p) p
275 #else
276 #define WXUNUSED_UNLESS_GUI(p)
277 #endif
278
279 // New wxStream classes to clean up the data when the process terminates
280
281 #if wxUSE_GUI
282 class wxProcessFileInputStream: public wxInputStream {
283 public:
284 wxProcessFileInputStream(int fd);
285 ~wxProcessFileInputStream();
286
287 protected:
288 size_t OnSysRead(void *buffer, size_t bufsize);
289 off_t OnSysSeek(off_t seek, wxSeekMode mode);
290 off_t OnSysTell() const;
291
292 protected:
293 int m_fd;
294 };
295
296 class wxProcessFileOutputStream: public wxOutputStream {
297 public:
298 wxProcessFileOutputStream(int fd);
299 ~wxProcessFileOutputStream();
300
301 protected:
302 size_t OnSysWrite(const void *buffer, size_t bufsize);
303 off_t OnSysSeek(off_t seek, wxSeekMode mode);
304 off_t OnSysTell() const;
305
306 protected:
307 int m_fd;
308 };
309
310 wxProcessFileInputStream::wxProcessFileInputStream(int fd)
311 {
312 m_fd = fd;
313 }
314
315 wxProcessFileInputStream::~wxProcessFileInputStream()
316 {
317 close(m_fd);
318 }
319
320 size_t wxProcessFileInputStream::OnSysRead(void *buffer, size_t bufsize)
321 {
322 int ret;
323
324 ret = read(m_fd, buffer, bufsize);
325 m_lasterror = wxSTREAM_NOERROR;
326 if (ret == 0)
327 m_lasterror = wxSTREAM_EOF;
328 if (ret == -1) {
329 m_lasterror = wxSTREAM_READ_ERROR;
330 ret = 0;
331 }
332 return ret;
333 }
334
335 off_t wxProcessFileInputStream::OnSysSeek(off_t WXUNUSED(seek),
336 wxSeekMode WXUNUSED(mode))
337 {
338 return wxInvalidOffset;
339 }
340
341 off_t wxProcessFileInputStream::OnSysTell() const
342 {
343 return wxInvalidOffset;
344 }
345
346
347 wxProcessFileOutputStream::wxProcessFileOutputStream(int fd)
348 {
349 m_fd = fd;
350 }
351
352 wxProcessFileOutputStream::~wxProcessFileOutputStream()
353 {
354 close(m_fd);
355 }
356
357 size_t wxProcessFileOutputStream::OnSysWrite(const void *buffer, size_t bufsize)
358 {
359 int ret;
360
361 ret = write(m_fd, buffer, bufsize);
362 m_lasterror = wxSTREAM_NOERROR;
363 if (ret == -1) {
364 m_lasterror = wxSTREAM_WRITE_ERROR;
365 ret = 0;
366 }
367 return ret;
368 }
369
370 off_t wxProcessFileOutputStream::OnSysSeek(off_t WXUNUSED(seek),
371 wxSeekMode WXUNUSED(mode))
372 {
373 return wxInvalidOffset;
374 }
375
376 off_t wxProcessFileOutputStream::OnSysTell() const
377 {
378 return wxInvalidOffset;
379 }
380
381 #endif
382
383 long wxExecute(wxChar **argv,
384 bool sync,
385 wxProcess * WXUNUSED_UNLESS_GUI(process))
386 {
387 wxCHECK_MSG( *argv, 0, wxT("can't exec empty command") );
388
389 #if wxUSE_UNICODE
390 int mb_argc = 0;
391 char *mb_argv[WXEXECUTE_NARGS];
392
393 while (argv[mb_argc])
394 {
395 wxWX2MBbuf mb_arg = wxConvertWX2MB(argv[mb_argc]);
396 mb_argv[mb_argc] = strdup(mb_arg);
397 mb_argc++;
398 }
399 mb_argv[mb_argc] = (char *) NULL;
400
401 // this macro will free memory we used above
402 #define ARGS_CLEANUP \
403 for ( mb_argc = 0; mb_argv[mb_argc]; mb_argc++ ) \
404 free(mb_argv[mb_argc])
405 #else // ANSI
406 // no need for cleanup
407 #define ARGS_CLEANUP
408
409 wxChar **mb_argv = argv;
410 #endif // Unicode/ANSI
411
412 #if wxUSE_GUI
413 // create pipes
414 int end_proc_detect[2];
415 if (pipe(end_proc_detect) == -1)
416 {
417 wxLogSysError( _("Pipe creation failed") );
418
419 ARGS_CLEANUP;
420
421 return 0;
422 }
423 #endif // wxUSE_GUI
424
425 #if wxUSE_GUI
426 int in_pipe[2] = { -1, -1 };
427 int out_pipe[2] = { -1, -1 };
428 // Only asynchronous mode is interresting
429 if (!sync && process && process->NeedPipe())
430 {
431 if (pipe(in_pipe) == -1 || pipe(out_pipe) == -1)
432 {
433 /* Free fds */
434 close(end_proc_detect[0]);
435 close(end_proc_detect[1]);
436 wxLogSysError( _("Pipe creation failed (Console pipes)") );
437
438 ARGS_CLEANUP;
439
440 return 0;
441 }
442 }
443 #endif // wxUSE_GUI
444
445 // fork the process
446 #ifdef HAVE_VFORK
447 pid_t pid = vfork();
448 #else
449 pid_t pid = fork();
450 #endif
451 if (pid == -1)
452 {
453 #if wxUSE_GUI
454 close(end_proc_detect[0]);
455 close(end_proc_detect[1]);
456 close(in_pipe[0]);
457 close(in_pipe[1]);
458 close(out_pipe[0]);
459 close(out_pipe[1]);
460 #endif
461 wxLogSysError( _("Fork failed") );
462
463 ARGS_CLEANUP;
464
465 return 0;
466 }
467 else if (pid == 0)
468 {
469 #if wxUSE_GUI
470 // we're in child
471 close(end_proc_detect[0]); // close reading side
472 #endif // wxUSE_GUI
473
474 // These three lines close the open file descriptors to to avoid any
475 // input/output which might block the process or irritate the user. If
476 // one wants proper IO for the subprocess, the right thing to do is
477 // to start an xterm executing it.
478 if (sync == 0)
479 {
480 // leave stderr opened, it won't do any hurm
481 for ( int fd = 0; fd < FD_SETSIZE; fd++ )
482 {
483 #if wxUSE_GUI
484 if ( fd == end_proc_detect[1] || fd == in_pipe[0] || fd == out_pipe[1] )
485 continue;
486 #endif // wxUSE_GUI
487
488 if ( fd != STDERR_FILENO )
489 close(fd);
490 }
491 }
492
493 // Fake a console by duplicating pipes
494 #if wxUSE_GUI
495 if (in_pipe[0] != -1) {
496 dup2(in_pipe[0], STDIN_FILENO);
497 dup2(out_pipe[1], STDOUT_FILENO);
498 close(in_pipe[0]);
499 close(out_pipe[1]);
500 }
501 #endif // wxUSE_GUI
502
503 #if 0
504 close(STDERR_FILENO);
505
506 // some programs complain about stderr not being open, so redirect
507 // them:
508 open("/dev/null", O_RDONLY); // stdin
509 open("/dev/null", O_WRONLY); // stdout
510 open("/dev/null", O_WRONLY); // stderr
511 #endif
512
513 execvp (*mb_argv, mb_argv);
514
515 // there is no return after successful exec()
516 wxFprintf(stderr, _("Can't execute '%s'\n"), *argv);
517
518 _exit(-1);
519 }
520 else
521 {
522 #if wxUSE_GUI
523 wxEndProcessData *data = new wxEndProcessData;
524
525 ARGS_CLEANUP;
526
527 if ( sync )
528 {
529 wxASSERT_MSG( !process, wxT("wxProcess param ignored for sync exec") );
530 data->process = NULL;
531
532 // sync execution: indicate it by negating the pid
533 data->pid = -pid;
534 data->tag = wxAddProcessCallback(data, end_proc_detect[0]);
535 // we're in parent
536 close(end_proc_detect[1]); // close writing side
537
538 // it will be set to 0 from GTK_EndProcessDetector
539 while (data->pid != 0)
540 wxYield();
541
542 int exitcode = data->exitcode;
543
544 delete data;
545
546 return exitcode;
547 }
548 else
549 {
550 // pipe initialization: construction of the wxStreams
551 if (process && process->NeedPipe()) {
552 // These two streams are relative to this process.
553 wxOutputStream *my_output_stream;
554 wxInputStream *my_input_stream;
555
556 my_output_stream = new wxProcessFileOutputStream(in_pipe[1]);
557 my_input_stream = new wxProcessFileInputStream(out_pipe[0]);
558 close(in_pipe[0]); // close reading side
559 close(out_pipe[1]); // close writing side
560
561 process->SetPipeStreams(my_input_stream, my_output_stream);
562 }
563
564 // async execution, nothing special to do - caller will be
565 // notified about the process termination if process != NULL, data
566 // will be deleted in GTK_EndProcessDetector
567 data->process = process;
568 data->pid = pid;
569 data->tag = wxAddProcessCallback(data, end_proc_detect[0]);
570 // we're in parent
571 close(end_proc_detect[1]); // close writing side
572
573 return pid;
574 }
575 #else // !wxUSE_GUI
576 wxASSERT_MSG( sync, wxT("async execution not supported yet") );
577
578 int exitcode = 0;
579 if ( waitpid(pid, &exitcode, 0) == -1 || !WIFEXITED(exitcode) )
580 {
581 wxLogSysError(_("Waiting for subprocess termination failed"));
582 }
583
584 return exitcode;
585 #endif // wxUSE_GUI
586 }
587 return 0;
588
589 #undef ARGS_CLEANUP
590 }
591
592 // ----------------------------------------------------------------------------
593 // file and directory functions
594 // ----------------------------------------------------------------------------
595
596 const wxChar* wxGetHomeDir( wxString *home )
597 {
598 *home = wxGetUserHome( wxString() );
599 if ( home->IsEmpty() )
600 *home = wxT("/");
601
602 return home->c_str();
603 }
604
605 #if wxUSE_UNICODE
606 const wxMB2WXbuf wxGetUserHome( const wxString &user )
607 #else // just for binary compatibility -- there is no 'const' here
608 char *wxGetUserHome( const wxString &user )
609 #endif
610 {
611 struct passwd *who = (struct passwd *) NULL;
612
613 if ( !user )
614 {
615 wxChar *ptr;
616
617 if ((ptr = wxGetenv(wxT("HOME"))) != NULL)
618 {
619 return ptr;
620 }
621 if ((ptr = wxGetenv(wxT("USER"))) != NULL || (ptr = wxGetenv(wxT("LOGNAME"))) != NULL)
622 {
623 who = getpwnam(wxConvertWX2MB(ptr));
624 }
625
626 // We now make sure the the user exists!
627 if (who == NULL)
628 {
629 who = getpwuid(getuid());
630 }
631 }
632 else
633 {
634 who = getpwnam (user.mb_str());
635 }
636
637 return wxConvertMB2WX(who ? who->pw_dir : 0);
638 }
639
640 // ----------------------------------------------------------------------------
641 // network and user id routines
642 // ----------------------------------------------------------------------------
643
644 // retrieve either the hostname or FQDN depending on platform (caller must
645 // check whether it's one or the other, this is why this function is for
646 // private use only)
647 static bool wxGetHostNameInternal(wxChar *buf, int sz)
648 {
649 wxCHECK_MSG( buf, FALSE, wxT("NULL pointer in wxGetHostNameInternal") );
650
651 *buf = wxT('\0');
652
653 // we're using uname() which is POSIX instead of less standard sysinfo()
654 #if defined(HAVE_UNAME)
655 struct utsname uts;
656 bool ok = uname(&uts) != -1;
657 if ( ok )
658 {
659 wxStrncpy(buf, wxConvertMB2WX(uts.nodename), sz - 1);
660 buf[sz] = wxT('\0');
661 }
662 #elif defined(HAVE_GETHOSTNAME)
663 bool ok = gethostname(buf, sz) != -1;
664 #else // no uname, no gethostname
665 wxFAIL_MSG(wxT("don't know host name for this machine"));
666
667 bool ok = FALSE;
668 #endif // uname/gethostname
669
670 if ( !ok )
671 {
672 wxLogSysError(_("Cannot get the hostname"));
673 }
674
675 return ok;
676 }
677
678 bool wxGetHostName(wxChar *buf, int sz)
679 {
680 bool ok = wxGetHostNameInternal(buf, sz);
681
682 if ( ok )
683 {
684 // BSD systems return the FQDN, we only want the hostname, so extract
685 // it (we consider that dots are domain separators)
686 wxChar *dot = wxStrchr(buf, wxT('.'));
687 if ( dot )
688 {
689 // nuke it
690 *dot = wxT('\0');
691 }
692 }
693
694 return ok;
695 }
696
697 bool wxGetFullHostName(wxChar *buf, int sz)
698 {
699 bool ok = wxGetHostNameInternal(buf, sz);
700
701 if ( ok )
702 {
703 if ( !wxStrchr(buf, wxT('.')) )
704 {
705 struct hostent *host = gethostbyname(wxConvertWX2MB(buf));
706 if ( !host )
707 {
708 wxLogSysError(_("Cannot get the official hostname"));
709
710 ok = FALSE;
711 }
712 else
713 {
714 // the canonical name
715 wxStrncpy(buf, wxConvertMB2WX(host->h_name), sz);
716 }
717 }
718 //else: it's already a FQDN (BSD behaves this way)
719 }
720
721 return ok;
722 }
723
724 bool wxGetUserId(wxChar *buf, int sz)
725 {
726 struct passwd *who;
727
728 *buf = wxT('\0');
729 if ((who = getpwuid(getuid ())) != NULL)
730 {
731 wxStrncpy (buf, wxConvertMB2WX(who->pw_name), sz - 1);
732 return TRUE;
733 }
734
735 return FALSE;
736 }
737
738 bool wxGetUserName(wxChar *buf, int sz)
739 {
740 struct passwd *who;
741
742 *buf = wxT('\0');
743 if ((who = getpwuid (getuid ())) != NULL)
744 {
745 // pw_gecos field in struct passwd is not standard
746 #if HAVE_PW_GECOS
747 char *comma = strchr(who->pw_gecos, ',');
748 if (comma)
749 *comma = '\0'; // cut off non-name comment fields
750 wxStrncpy (buf, wxConvertMB2WX(who->pw_gecos), sz - 1);
751 #else // !HAVE_PW_GECOS
752 wxStrncpy (buf, wxConvertMB2WX(who->pw_name), sz - 1);
753 #endif // HAVE_PW_GECOS/!HAVE_PW_GECOS
754 return TRUE;
755 }
756
757 return FALSE;
758 }
759
760 wxString wxGetOsDescription()
761 {
762 #ifndef WXWIN_OS_DESCRIPTION
763 #error WXWIN_OS_DESCRIPTION should be defined in config.h by configure
764 #else
765 return WXWIN_OS_DESCRIPTION;
766 #endif
767 }
768
769 // ----------------------------------------------------------------------------
770 // error and debug output routines (deprecated, use wxLog)
771 // ----------------------------------------------------------------------------
772
773 void wxDebugMsg( const char *format, ... )
774 {
775 va_list ap;
776 va_start( ap, format );
777 vfprintf( stderr, format, ap );
778 fflush( stderr );
779 va_end(ap);
780 }
781
782 void wxError( const wxString &msg, const wxString &title )
783 {
784 wxFprintf( stderr, _("Error ") );
785 if (!title.IsNull()) wxFprintf( stderr, wxT("%s "), WXSTRINGCAST(title) );
786 if (!msg.IsNull()) wxFprintf( stderr, wxT(": %s"), WXSTRINGCAST(msg) );
787 wxFprintf( stderr, wxT(".\n") );
788 }
789
790 void wxFatalError( const wxString &msg, const wxString &title )
791 {
792 wxFprintf( stderr, _("Error ") );
793 if (!title.IsNull()) wxFprintf( stderr, wxT("%s "), WXSTRINGCAST(title) );
794 if (!msg.IsNull()) wxFprintf( stderr, wxT(": %s"), WXSTRINGCAST(msg) );
795 wxFprintf( stderr, wxT(".\n") );
796 exit(3); // the same exit code as for abort()
797 }
798