1 /////////////////////////////////////////////////////////////////////////////
2 // Name: unix/utilsunx.cpp
3 // Purpose: generic Unix implementation of many wx functions
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // ============================================================================
12 // ============================================================================
14 // ----------------------------------------------------------------------------
16 // ----------------------------------------------------------------------------
19 #include "wx/string.h"
26 #include "wx/process.h"
27 #include "wx/thread.h"
29 #include "wx/wfstream.h"
33 # include <sys/param.h>
34 # include <sys/mount.h>
40 // not only the statfs syscall is called differently depending on platform, but
41 // we also can't use "struct statvfs" under Solaris because it breaks down if
42 // HAVE_LARGEFILE_SUPPORT == 1 and we must use statvfs_t instead
44 #include <sys/statvfs.h>
46 #define statfs statvfs
47 #define wxStatFs statvfs_t
49 #define wxStatFs struct statfs
50 #endif // HAVE_STAT[V]FS
53 #include "wx/unix/execute.h"
56 // SGI signal.h defines signal handler arguments differently depending on
57 // whether _LANGUAGE_C_PLUS_PLUS is set or not - do set it
58 #if defined(__SGI__) && !defined(_LANGUAGE_C_PLUS_PLUS)
59 #define _LANGUAGE_C_PLUS_PLUS 1
66 #include <sys/types.h>
73 #include <fcntl.h> // for O_WRONLY and friends
74 #include <time.h> // nanosleep() and/or usleep()
75 #include <ctype.h> // isspace()
76 #include <sys/time.h> // needed for FD_SETSIZE
79 #include <sys/utsname.h> // for uname()
82 // ----------------------------------------------------------------------------
83 // conditional compilation
84 // ----------------------------------------------------------------------------
86 // many versions of Unices have this function, but it is not defined in system
87 // headers - please add your system here if it is the case for your OS.
88 // SunOS < 5.6 (i.e. Solaris < 2.6) and DG-UX are like this.
89 #if !defined(HAVE_USLEEP) && \
90 (defined(__SUN__) && !defined(__SunOs_5_6) && \
91 !defined(__SunOs_5_7) && !defined(__SUNPRO_CC)) || \
92 defined(__osf__) || defined(__EMX__)
96 int usleep(unsigned int usec
);
99 /* I copied this from the XFree86 diffs. AV. */
100 #define INCL_DOSPROCESS
102 inline void usleep(unsigned long delay
)
104 DosSleep(delay
? (delay
/1000l) : 1l);
106 #else // !Sun && !EMX
107 void usleep(unsigned long usec
);
109 #endif // Sun/EMX/Something else
112 #define HAVE_USLEEP 1
113 #endif // Unices without usleep()
115 // ============================================================================
117 // ============================================================================
119 // ----------------------------------------------------------------------------
121 // ----------------------------------------------------------------------------
123 void wxSleep(int nSecs
)
128 void wxUsleep(unsigned long milliseconds
)
130 #if defined(HAVE_NANOSLEEP)
132 tmReq
.tv_sec
= (time_t)(milliseconds
/ 1000);
133 tmReq
.tv_nsec
= (milliseconds
% 1000) * 1000 * 1000;
135 // we're not interested in remaining time nor in return value
136 (void)nanosleep(&tmReq
, (timespec
*)NULL
);
137 #elif defined(HAVE_USLEEP)
138 // uncomment this if you feel brave or if you are sure that your version
139 // of Solaris has a safe usleep() function but please notice that usleep()
140 // is known to lead to crashes in MT programs in Solaris 2.[67] and is not
141 // documented as MT-Safe
142 #if defined(__SUN__) && wxUSE_THREADS
143 #error "usleep() cannot be used in MT programs under Solaris."
146 usleep(milliseconds
* 1000); // usleep(3) wants microseconds
147 #elif defined(HAVE_SLEEP)
148 // under BeOS sleep() takes seconds (what about other platforms, if any?)
149 sleep(milliseconds
* 1000);
150 #else // !sleep function
151 #error "usleep() or nanosleep() function required for wxUsleep"
152 #endif // sleep function
155 // ----------------------------------------------------------------------------
156 // process management
157 // ----------------------------------------------------------------------------
159 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
)
161 int err
= kill((pid_t
)pid
, (int)sig
);
171 *rc
= wxKILL_BAD_SIGNAL
;
175 *rc
= wxKILL_ACCESS_DENIED
;
179 *rc
= wxKILL_NO_PROCESS
;
183 // this goes against Unix98 docs so log it
184 wxLogDebug(_T("unexpected kill(2) return value %d"), err
);
194 #define WXEXECUTE_NARGS 127
196 long wxExecute( const wxString
& command
, int flags
, wxProcess
*process
)
198 wxCHECK_MSG( !command
.IsEmpty(), 0, wxT("can't exec empty command") );
201 wxChar
*argv
[WXEXECUTE_NARGS
];
203 const wxChar
*cptr
= command
.c_str();
204 wxChar quotechar
= wxT('\0'); // is arg quoted?
205 bool escaped
= FALSE
;
207 // split the command line in arguments
211 quotechar
= wxT('\0');
213 // eat leading whitespace:
214 while ( wxIsspace(*cptr
) )
217 if ( *cptr
== wxT('\'') || *cptr
== wxT('"') )
222 if ( *cptr
== wxT('\\') && ! escaped
)
229 // all other characters:
233 // have we reached the end of the argument?
234 if ( (*cptr
== quotechar
&& ! escaped
)
235 || (quotechar
== wxT('\0') && wxIsspace(*cptr
))
236 || *cptr
== wxT('\0') )
238 wxASSERT_MSG( argc
< WXEXECUTE_NARGS
,
239 wxT("too many arguments in wxExecute") );
241 argv
[argc
] = new wxChar
[argument
.length() + 1];
242 wxStrcpy(argv
[argc
], argument
.c_str());
245 // if not at end of buffer, swallow last character:
249 break; // done with this one, start over
255 // do execute the command
259 long lRc
= wxExecute(argv
, flags
, process
);
265 delete [] argv
[argc
++];
270 // ----------------------------------------------------------------------------
272 // ----------------------------------------------------------------------------
274 static wxString
wxMakeShellCommand(const wxString
& command
)
279 // just an interactive shell
284 // execute command in a shell
285 cmd
<< _T("/bin/sh -c '") << command
<< _T('\'');
291 bool wxShell(const wxString
& command
)
293 return wxExecute(wxMakeShellCommand(command
), wxEXEC_SYNC
) == 0;
296 bool wxShell(const wxString
& command
, wxArrayString
& output
)
298 wxCHECK_MSG( !!command
, FALSE
, _T("can't exec shell non interactively") );
300 return wxExecute(wxMakeShellCommand(command
), output
);
303 // Shutdown or reboot the PC
304 bool wxShutdown(wxShutdownFlags wFlags
)
309 case wxSHUTDOWN_POWEROFF
:
313 case wxSHUTDOWN_REBOOT
:
318 wxFAIL_MSG( _T("unknown wxShutdown() flag") );
322 return system(wxString::Format(_T("init %c"), level
).mb_str()) == 0;
328 void wxHandleProcessTermination(wxEndProcessData
*proc_data
)
330 // notify user about termination if required
331 if ( proc_data
->process
)
333 proc_data
->process
->OnTerminate(proc_data
->pid
, proc_data
->exitcode
);
337 if ( proc_data
->pid
> 0 )
343 // let wxExecute() know that the process has terminated
350 // ----------------------------------------------------------------------------
351 // wxStream classes to support IO redirection in wxExecute
352 // ----------------------------------------------------------------------------
356 // ----------------------------------------------------------------------------
357 // wxPipeInputStream: stream for reading from a pipe
358 // ----------------------------------------------------------------------------
360 class wxPipeInputStream
: public wxFileInputStream
363 wxPipeInputStream(int fd
) : wxFileInputStream(fd
) { }
365 // return TRUE if the pipe is still opened
366 bool IsOpened() const { return !Eof(); }
368 // return TRUE if we have anything to read, don't block
369 bool IsAvailable() const;
372 bool wxPipeInputStream::IsAvailable() const
374 if ( m_lasterror
== wxSTREAM_EOF
)
377 // check if there is any input available
382 const int fd
= m_file
->fd();
386 FD_SET(fd
, &readfds
);
387 switch ( select(fd
+ 1, &readfds
, NULL
, NULL
, &tv
) )
390 wxLogSysError(_("Impossible to get child process input"));
397 wxFAIL_MSG(_T("unexpected select() return value"));
398 // still fall through
401 // input available -- or maybe not, as select() returns 1 when a
402 // read() will complete without delay, but it could still not read
408 // define this to let wxexec.cpp know that we know what we're doing
409 #define _WX_USED_BY_WXEXECUTE_
410 #include "../common/execcmn.cpp"
412 #endif // wxUSE_STREAMS
414 // ----------------------------------------------------------------------------
415 // wxPipe: this encapsulates pipe() system call
416 // ----------------------------------------------------------------------------
421 // the symbolic names for the pipe ends
433 // default ctor doesn't do anything
434 wxPipe() { m_fds
[Read
] = m_fds
[Write
] = INVALID_FD
; }
436 // create the pipe, return TRUE if ok, FALSE on error
439 if ( pipe(m_fds
) == -1 )
441 wxLogSysError(_("Pipe creation failed"));
449 // return TRUE if we were created successfully
450 bool IsOk() const { return m_fds
[Read
] != INVALID_FD
; }
452 // return the descriptor for one of the pipe ends
453 int operator[](Direction which
) const
455 wxASSERT_MSG( which
>= 0 && (size_t)which
< WXSIZEOF(m_fds
),
456 _T("invalid pipe index") );
461 // detach a descriptor, meaning that the pipe dtor won't close it, and
463 int Detach(Direction which
)
465 wxASSERT_MSG( which
>= 0 && (size_t)which
< WXSIZEOF(m_fds
),
466 _T("invalid pipe index") );
468 int fd
= m_fds
[which
];
469 m_fds
[which
] = INVALID_FD
;
474 // close the pipe descriptors
477 for ( size_t n
= 0; n
< WXSIZEOF(m_fds
); n
++ )
479 if ( m_fds
[n
] != INVALID_FD
)
484 // dtor closes the pipe descriptors
485 ~wxPipe() { Close(); }
491 // ----------------------------------------------------------------------------
492 // wxExecute: the real worker function
493 // ----------------------------------------------------------------------------
496 #pragma message disable codeunreachable
499 long wxExecute(wxChar
**argv
,
503 // for the sync execution, we return -1 to indicate failure, but for async
504 // case we return 0 which is never a valid PID
506 // we define this as a macro, not a variable, to avoid compiler warnings
507 // about "ERROR_RETURN_CODE value may be clobbered by fork()"
508 #define ERROR_RETURN_CODE ((flags & wxEXEC_SYNC) ? -1 : 0)
510 wxCHECK_MSG( *argv
, ERROR_RETURN_CODE
, wxT("can't exec empty command") );
514 char *mb_argv
[WXEXECUTE_NARGS
];
516 while (argv
[mb_argc
])
518 wxWX2MBbuf mb_arg
= wxConvertWX2MB(argv
[mb_argc
]);
519 mb_argv
[mb_argc
] = strdup(mb_arg
);
522 mb_argv
[mb_argc
] = (char *) NULL
;
524 // this macro will free memory we used above
525 #define ARGS_CLEANUP \
526 for ( mb_argc = 0; mb_argv[mb_argc]; mb_argc++ ) \
527 free(mb_argv[mb_argc])
529 // no need for cleanup
532 wxChar
**mb_argv
= argv
;
533 #endif // Unicode/ANSI
537 wxPipe pipeEndProcDetect
;
538 if ( !pipeEndProcDetect
.Create() )
540 wxLogError( _("Failed to execute '%s'\n"), *argv
);
544 return ERROR_RETURN_CODE
;
548 // pipes for inter process communication
549 wxPipe pipeIn
, // stdin
553 if ( process
&& process
->IsRedirected() )
555 if ( !pipeIn
.Create() || !pipeOut
.Create() || !pipeErr
.Create() )
557 wxLogError( _("Failed to execute '%s'\n"), *argv
);
561 return ERROR_RETURN_CODE
;
567 // NB: do *not* use vfork() here, it completely breaks this code for some
568 // reason under Solaris (and maybe others, although not under Linux)
570 if ( pid
== -1 ) // error?
572 wxLogSysError( _("Fork failed") );
576 return ERROR_RETURN_CODE
;
578 else if ( pid
== 0 ) // we're in child
580 // These lines close the open file descriptors to to avoid any
581 // input/output which might block the process or irritate the user. If
582 // one wants proper IO for the subprocess, the right thing to do is to
583 // start an xterm executing it.
584 if ( !(flags
& wxEXEC_SYNC
) )
586 for ( int fd
= 0; fd
< FD_SETSIZE
; fd
++ )
588 if ( fd
== pipeIn
[wxPipe::Read
]
589 || fd
== pipeOut
[wxPipe::Write
]
590 || fd
== pipeErr
[wxPipe::Write
]
592 || fd
== pipeEndProcDetect
[wxPipe::Write
]
596 // don't close this one, we still need it
600 // leave stderr opened too, it won't do any harm
601 if ( fd
!= STDERR_FILENO
)
606 #if !defined(__VMS) && !defined(__EMX__)
607 if ( flags
& wxEXEC_MAKE_GROUP_LEADER
)
609 // Set process group to child process' pid. Then killing -pid
610 // of the parent will kill the process and all of its children.
616 // reading side can be safely closed but we should keep the write one
618 pipeEndProcDetect
.Detach(wxPipe::Write
);
619 pipeEndProcDetect
.Close();
622 // redirect stdin, stdout and stderr
625 if ( dup2(pipeIn
[wxPipe::Read
], STDIN_FILENO
) == -1 ||
626 dup2(pipeOut
[wxPipe::Write
], STDOUT_FILENO
) == -1 ||
627 dup2(pipeErr
[wxPipe::Write
], STDERR_FILENO
) == -1 )
629 wxLogSysError(_("Failed to redirect child process input/output"));
637 execvp (*mb_argv
, mb_argv
);
639 // there is no return after successful exec()
642 // some compilers complain about missing return - of course, they
643 // should know that exit() doesn't return but what else can we do if
646 // and, sure enough, other compilers complain about unreachable code
647 // after exit() call, so we can just always have return here...
648 #if defined(__VMS) || defined(__INTEL_COMPILER)
652 else // we're in parent
656 // prepare for IO redirection
659 // the input buffer bufOut is connected to stdout, this is why it is
660 // called bufOut and not bufIn
661 wxStreamTempInputBuffer bufOut
,
663 #endif // wxUSE_STREAMS
665 if ( process
&& process
->IsRedirected() )
668 wxOutputStream
*inStream
=
669 new wxFileOutputStream(pipeIn
.Detach(wxPipe::Write
));
671 wxPipeInputStream
*outStream
=
672 new wxPipeInputStream(pipeOut
.Detach(wxPipe::Read
));
674 wxPipeInputStream
*errStream
=
675 new wxPipeInputStream(pipeErr
.Detach(wxPipe::Read
));
677 process
->SetPipeStreams(outStream
, inStream
, errStream
);
679 bufOut
.Init(outStream
);
680 bufErr
.Init(errStream
);
681 #endif // wxUSE_STREAMS
691 #if wxUSE_GUI && !defined(__WXMICROWIN__)
692 wxEndProcessData
*data
= new wxEndProcessData
;
694 data
->tag
= wxAddProcessCallback
697 pipeEndProcDetect
.Detach(wxPipe::Read
)
700 pipeEndProcDetect
.Close();
702 if ( flags
& wxEXEC_SYNC
)
704 // we may have process for capturing the program output, but it's
705 // not used in wxEndProcessData in the case of sync execution
706 data
->process
= NULL
;
708 // sync execution: indicate it by negating the pid
714 // data->pid will be set to 0 from GTK_EndProcessDetector when the
715 // process terminates
716 while ( data
->pid
!= 0 )
721 #endif // wxUSE_STREAMS
723 // give GTK+ a chance to call GTK_EndProcessDetector here and
724 // also repaint the GUI
728 int exitcode
= data
->exitcode
;
734 else // async execution
736 // async execution, nothing special to do - caller will be
737 // notified about the process termination if process != NULL, data
738 // will be deleted in GTK_EndProcessDetector
739 data
->process
= process
;
746 wxASSERT_MSG( flags
& wxEXEC_SYNC
,
747 wxT("async execution not supported yet") );
750 if ( waitpid(pid
, &exitcode
, 0) == -1 || !WIFEXITED(exitcode
) )
752 wxLogSysError(_("Waiting for subprocess termination failed"));
759 return ERROR_RETURN_CODE
;
763 #pragma message enable codeunreachable
766 #undef ERROR_RETURN_CODE
769 // ----------------------------------------------------------------------------
770 // file and directory functions
771 // ----------------------------------------------------------------------------
773 const wxChar
* wxGetHomeDir( wxString
*home
)
775 *home
= wxGetUserHome( wxString() );
777 if ( home
->IsEmpty() )
781 if ( tmp
.Last() != wxT(']'))
782 if ( tmp
.Last() != wxT('/')) *home
<< wxT('/');
784 return home
->c_str();
788 const wxMB2WXbuf
wxGetUserHome( const wxString
&user
)
789 #else // just for binary compatibility -- there is no 'const' here
790 char *wxGetUserHome( const wxString
&user
)
793 struct passwd
*who
= (struct passwd
*) NULL
;
799 if ((ptr
= wxGetenv(wxT("HOME"))) != NULL
)
803 if ((ptr
= wxGetenv(wxT("USER"))) != NULL
|| (ptr
= wxGetenv(wxT("LOGNAME"))) != NULL
)
805 who
= getpwnam(wxConvertWX2MB(ptr
));
808 // We now make sure the the user exists!
811 who
= getpwuid(getuid());
816 who
= getpwnam (user
.mb_str());
819 return wxConvertMB2WX(who
? who
->pw_dir
: 0);
822 // ----------------------------------------------------------------------------
823 // network and user id routines
824 // ----------------------------------------------------------------------------
826 // retrieve either the hostname or FQDN depending on platform (caller must
827 // check whether it's one or the other, this is why this function is for
829 static bool wxGetHostNameInternal(wxChar
*buf
, int sz
)
831 wxCHECK_MSG( buf
, FALSE
, wxT("NULL pointer in wxGetHostNameInternal") );
835 // we're using uname() which is POSIX instead of less standard sysinfo()
836 #if defined(HAVE_UNAME)
838 bool ok
= uname(&uts
) != -1;
841 wxStrncpy(buf
, wxConvertMB2WX(uts
.nodename
), sz
- 1);
844 #elif defined(HAVE_GETHOSTNAME)
845 bool ok
= gethostname(buf
, sz
) != -1;
846 #else // no uname, no gethostname
847 wxFAIL_MSG(wxT("don't know host name for this machine"));
850 #endif // uname/gethostname
854 wxLogSysError(_("Cannot get the hostname"));
860 bool wxGetHostName(wxChar
*buf
, int sz
)
862 bool ok
= wxGetHostNameInternal(buf
, sz
);
866 // BSD systems return the FQDN, we only want the hostname, so extract
867 // it (we consider that dots are domain separators)
868 wxChar
*dot
= wxStrchr(buf
, wxT('.'));
879 bool wxGetFullHostName(wxChar
*buf
, int sz
)
881 bool ok
= wxGetHostNameInternal(buf
, sz
);
885 if ( !wxStrchr(buf
, wxT('.')) )
887 struct hostent
*host
= gethostbyname(wxConvertWX2MB(buf
));
890 wxLogSysError(_("Cannot get the official hostname"));
896 // the canonical name
897 wxStrncpy(buf
, wxConvertMB2WX(host
->h_name
), sz
);
900 //else: it's already a FQDN (BSD behaves this way)
906 bool wxGetUserId(wxChar
*buf
, int sz
)
911 if ((who
= getpwuid(getuid ())) != NULL
)
913 wxStrncpy (buf
, wxConvertMB2WX(who
->pw_name
), sz
- 1);
920 bool wxGetUserName(wxChar
*buf
, int sz
)
925 if ((who
= getpwuid (getuid ())) != NULL
)
927 // pw_gecos field in struct passwd is not standard
929 char *comma
= strchr(who
->pw_gecos
, ',');
931 *comma
= '\0'; // cut off non-name comment fields
932 wxStrncpy (buf
, wxConvertMB2WX(who
->pw_gecos
), sz
- 1);
933 #else // !HAVE_PW_GECOS
934 wxStrncpy (buf
, wxConvertMB2WX(who
->pw_name
), sz
- 1);
935 #endif // HAVE_PW_GECOS/!HAVE_PW_GECOS
943 wxString
wxGetOsDescription()
945 #ifndef WXWIN_OS_DESCRIPTION
946 #error WXWIN_OS_DESCRIPTION should be defined in config.h by configure
948 return WXWIN_OS_DESCRIPTION
;
953 // this function returns the GUI toolkit version in GUI programs, but OS
954 // version in non-GUI ones
957 int wxGetOsVersion(int *majorVsn
, int *minorVsn
)
962 if ( sscanf(WXWIN_OS_DESCRIPTION
, "%s %d.%d", name
, &major
, &minor
) != 3 )
964 // unreckognized uname string format
978 unsigned long wxGetProcessId()
980 return (unsigned long)getpid();
983 long wxGetFreeMemory()
985 #if defined(__LINUX__)
986 // get it from /proc/meminfo
987 FILE *fp
= fopen("/proc/meminfo", "r");
993 if ( fgets(buf
, WXSIZEOF(buf
), fp
) && fgets(buf
, WXSIZEOF(buf
), fp
) )
995 long memTotal
, memUsed
;
996 sscanf(buf
, "Mem: %ld %ld %ld", &memTotal
, &memUsed
, &memFree
);
1003 #elif defined(__SUN__) && defined(_SC_AVPHYS_PAGES)
1004 return sysconf(_SC_AVPHYS_PAGES
)*sysconf(_SC_PAGESIZE
);
1005 //#elif defined(__FREEBSD__) -- might use sysctl() to find it out, probably
1008 // can't find it out
1012 bool wxGetDiskSpace(const wxString
& path
, wxLongLong
*pTotal
, wxLongLong
*pFree
)
1014 #if defined(HAVE_STATFS) || defined(HAVE_STATVFS)
1015 // the case to "char *" is needed for AIX 4.3
1017 if ( statfs((char *)(const char*)path
.fn_str(), &fs
) != 0 )
1019 wxLogSysError( wxT("Failed to get file system statistics") );
1024 // under Solaris we also have to use f_frsize field instead of f_bsize
1025 // which is in general a multiple of f_frsize
1027 wxLongLong blockSize
= fs
.f_frsize
;
1028 #else // HAVE_STATFS
1029 wxLongLong blockSize
= fs
.f_bsize
;
1030 #endif // HAVE_STATVFS/HAVE_STATFS
1034 *pTotal
= wxLongLong(fs
.f_blocks
) * blockSize
;
1039 *pFree
= wxLongLong(fs
.f_bavail
) * blockSize
;
1043 #else // !HAVE_STATFS && !HAVE_STATVFS
1045 #endif // HAVE_STATFS
1048 // ----------------------------------------------------------------------------
1050 // ----------------------------------------------------------------------------
1052 bool wxGetEnv(const wxString
& var
, wxString
*value
)
1054 // wxGetenv is defined as getenv()
1055 wxChar
*p
= wxGetenv(var
);
1067 bool wxSetEnv(const wxString
& variable
, const wxChar
*value
)
1069 #if defined(HAVE_SETENV)
1070 return setenv(variable
.mb_str(),
1071 value
? (const char *)wxString(value
).mb_str()
1073 1 /* overwrite */) == 0;
1074 #elif defined(HAVE_PUTENV)
1075 wxString s
= variable
;
1077 s
<< _T('=') << value
;
1079 // transform to ANSI
1080 const char *p
= s
.mb_str();
1082 // the string will be free()d by libc
1083 char *buf
= (char *)malloc(strlen(p
) + 1);
1086 return putenv(buf
) == 0;
1087 #else // no way to set an env var
1092 // ----------------------------------------------------------------------------
1094 // ----------------------------------------------------------------------------
1096 #if wxUSE_ON_FATAL_EXCEPTION
1100 extern "C" void wxFatalSignalHandler(wxTYPE_SA_HANDLER
)
1104 // give the user a chance to do something special about this
1105 wxTheApp
->OnFatalException();
1111 bool wxHandleFatalExceptions(bool doit
)
1114 static bool s_savedHandlers
= FALSE
;
1115 static struct sigaction s_handlerFPE
,
1121 if ( doit
&& !s_savedHandlers
)
1123 // install the signal handler
1124 struct sigaction act
;
1126 // some systems extend it with non std fields, so zero everything
1127 memset(&act
, 0, sizeof(act
));
1129 act
.sa_handler
= wxFatalSignalHandler
;
1130 sigemptyset(&act
.sa_mask
);
1133 ok
&= sigaction(SIGFPE
, &act
, &s_handlerFPE
) == 0;
1134 ok
&= sigaction(SIGILL
, &act
, &s_handlerILL
) == 0;
1135 ok
&= sigaction(SIGBUS
, &act
, &s_handlerBUS
) == 0;
1136 ok
&= sigaction(SIGSEGV
, &act
, &s_handlerSEGV
) == 0;
1139 wxLogDebug(_T("Failed to install our signal handler."));
1142 s_savedHandlers
= TRUE
;
1144 else if ( s_savedHandlers
)
1146 // uninstall the signal handler
1147 ok
&= sigaction(SIGFPE
, &s_handlerFPE
, NULL
) == 0;
1148 ok
&= sigaction(SIGILL
, &s_handlerILL
, NULL
) == 0;
1149 ok
&= sigaction(SIGBUS
, &s_handlerBUS
, NULL
) == 0;
1150 ok
&= sigaction(SIGSEGV
, &s_handlerSEGV
, NULL
) == 0;
1153 wxLogDebug(_T("Failed to uninstall our signal handler."));
1156 s_savedHandlers
= FALSE
;
1158 //else: nothing to do
1163 #endif // wxUSE_ON_FATAL_EXCEPTION
1165 // ----------------------------------------------------------------------------
1166 // error and debug output routines (deprecated, use wxLog)
1167 // ----------------------------------------------------------------------------
1169 #if WXWIN_COMPATIBILITY_2_2
1171 void wxDebugMsg( const char *format
, ... )
1174 va_start( ap
, format
);
1175 vfprintf( stderr
, format
, ap
);
1180 void wxError( const wxString
&msg
, const wxString
&title
)
1182 wxFprintf( stderr
, _("Error ") );
1183 if (!title
.IsNull()) wxFprintf( stderr
, wxT("%s "), WXSTRINGCAST(title
) );
1184 if (!msg
.IsNull()) wxFprintf( stderr
, wxT(": %s"), WXSTRINGCAST(msg
) );
1185 wxFprintf( stderr
, wxT(".\n") );
1188 void wxFatalError( const wxString
&msg
, const wxString
&title
)
1190 wxFprintf( stderr
, _("Error ") );
1191 if (!title
.IsNull()) wxFprintf( stderr
, wxT("%s "), WXSTRINGCAST(title
) );
1192 if (!msg
.IsNull()) wxFprintf( stderr
, wxT(": %s"), WXSTRINGCAST(msg
) );
1193 wxFprintf( stderr
, wxT(".\n") );
1194 exit(3); // the same exit code as for abort()
1197 #endif // WXWIN_COMPATIBILITY_2_2