Engine/lib/sdl/src/video/x11/SDL_x11messagebox.c
/* Display an x11 message box. */
Display an x11 message box.
Display an x11 message box .
int
X11_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
{
#if SDL_FORK_MESSAGEBOX
    pid_t pid;
    int fds[2];
    int status = 0;
    if (pipe(fds) == -1) {
        return X11_ShowMessageBoxImpl(messageboxdata, buttonid); 
    }
    pid = fork();
    if (pid == -1) {  
        close(fds[0]);
        close(fds[1]);
        return X11_ShowMessageBoxImpl(messageboxdata, buttonid); 
    } else if (pid == 0) {  
        int exitcode = 0;
        close(fds[0]);
        status = X11_ShowMessageBoxImpl(messageboxdata, buttonid);
        if (write(fds[1], &status, sizeof (int)) != sizeof (int))
            exitcode = 1;
        else if (write(fds[1], buttonid, sizeof (int)) != sizeof (int))
            exitcode = 1;
        close(fds[1]);
        _exit(exitcode);  
    } else {  
        pid_t rc;
        close(fds[1]);
        do {
            rc = waitpid(pid, &status, 0);
        } while ((rc == -1) && (errno == EINTR));
        SDL_assert(rc == pid);  
        if ((rc == -1) || (!WIFEXITED(status)) || (WEXITSTATUS(status) != 0)) {
            return SDL_SetError("msgbox child process failed");
        }
        if (read(fds[0], &status, sizeof (int)) != sizeof (int))
            status = -1;
        else if (read(fds[0], buttonid, sizeof (int)) != sizeof (int))
            status = -1;
        close(fds[0]);
        return status;
    }
#else
    return X11_ShowMessageBoxImpl(messageboxdata, buttonid);
#endif
}
int X11_ShowMessageBox ( const SDL_MessageBoxData * messageboxdata , int * buttonid ) { #if SDL_FORK_MESSAGEBOX pid_t pid ; int fds [ 2 ] ; int status = 0 ; if ( pipe ( fds ) == -1 ) { return X11_ShowMessageBoxImpl ( messageboxdata , buttonid ) ; } pid = fork ( ) ; if ( pid == -1 ) { close ( fds [ 0 ] ) ; close ( fds [ 1 ] ) ; return X11_ShowMessageBoxImpl ( messageboxdata , buttonid ) ; } else if ( pid == 0 ) { int exitcode = 0 ; close ( fds [ 0 ] ) ; status = X11_ShowMessageBoxImpl ( messageboxdata , buttonid ) ; if ( write ( fds [ 1 ] , & status , sizeof ( int ) ) != sizeof ( int ) ) exitcode = 1 ; else if ( write ( fds [ 1 ] , buttonid , sizeof ( int ) ) != sizeof ( int ) ) exitcode = 1 ; close ( fds [ 1 ] ) ; _exit ( exitcode ) ; } else { pid_t rc ; close ( fds [ 1 ] ) ; do { rc = waitpid ( pid , & status , 0 ) ; } while ( ( rc == -1 ) && ( errno == EINTR ) ) ; SDL_assert ( rc == pid ) ; if ( ( rc == -1 ) || ( ! WIFEXITED ( status ) ) || ( WEXITSTATUS ( status ) != 0 ) ) { return SDL_SetError ( " " ) ; } if ( read ( fds [ 0 ] , & status , sizeof ( int ) ) != sizeof ( int ) ) status = -1 ; else if ( read ( fds [ 0 ] , buttonid , sizeof ( int ) ) != sizeof ( int ) ) status = -1 ; close ( fds [ 0 ] ) ; return status ; } #else return X11_ShowMessageBoxImpl ( messageboxdata , buttonid ) ; #endif }
Display an x11 message box.
Display an x11 message box .
/* Use a child process to protect against setlocale(). Annoying. */ /* oh well. */ /* failed */ /* oh well. */ /* we're the child */ /* don't run atexit() stuff, static destructors, etc. */ /* we're the parent */ /* not sure what to do if this fails. */