15796c8dcSSimon Schubert /* Host support routines for MinGW, for GDB, the GNU debugger. 25796c8dcSSimon Schubert 3*cf7f2e2dSJohn Marino Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. 45796c8dcSSimon Schubert 55796c8dcSSimon Schubert This file is part of GDB. 65796c8dcSSimon Schubert 75796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 85796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 95796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 105796c8dcSSimon Schubert (at your option) any later version. 115796c8dcSSimon Schubert 125796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 135796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 145796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 155796c8dcSSimon Schubert GNU General Public License for more details. 165796c8dcSSimon Schubert 175796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 185796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 195796c8dcSSimon Schubert 205796c8dcSSimon Schubert #include "defs.h" 215796c8dcSSimon Schubert #include "event-loop.h" 225796c8dcSSimon Schubert 235796c8dcSSimon Schubert #include "gdb_string.h" 245796c8dcSSimon Schubert 255796c8dcSSimon Schubert #include "gdb_select.h" 265796c8dcSSimon Schubert 275796c8dcSSimon Schubert /* The strerror() function can return NULL for errno values that are 285796c8dcSSimon Schubert out of range. Provide a "safe" version that always returns a 295796c8dcSSimon Schubert printable string. */ 305796c8dcSSimon Schubert 315796c8dcSSimon Schubert char * 325796c8dcSSimon Schubert safe_strerror (int errnum) 335796c8dcSSimon Schubert { 345796c8dcSSimon Schubert char *msg; 355796c8dcSSimon Schubert 365796c8dcSSimon Schubert msg = strerror (errnum); 375796c8dcSSimon Schubert if (msg == NULL) 385796c8dcSSimon Schubert { 395796c8dcSSimon Schubert static char buf[32]; 40*cf7f2e2dSJohn Marino 415796c8dcSSimon Schubert xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum); 425796c8dcSSimon Schubert msg = buf; 435796c8dcSSimon Schubert } 445796c8dcSSimon Schubert return (msg); 455796c8dcSSimon Schubert } 465796c8dcSSimon Schubert 475796c8dcSSimon Schubert /* Wrapper for select. Nothing special needed on POSIX platforms. */ 485796c8dcSSimon Schubert 495796c8dcSSimon Schubert int 505796c8dcSSimon Schubert gdb_select (int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, 515796c8dcSSimon Schubert struct timeval *timeout) 525796c8dcSSimon Schubert { 535796c8dcSSimon Schubert return select (n, readfds, writefds, exceptfds, timeout); 545796c8dcSSimon Schubert } 555796c8dcSSimon Schubert 565796c8dcSSimon Schubert /* Wrapper for the body of signal handlers. Nothing special needed on 575796c8dcSSimon Schubert POSIX platforms. */ 585796c8dcSSimon Schubert 595796c8dcSSimon Schubert void 605796c8dcSSimon Schubert gdb_call_async_signal_handler (struct async_signal_handler *handler, 615796c8dcSSimon Schubert int immediate_p) 625796c8dcSSimon Schubert { 635796c8dcSSimon Schubert if (immediate_p) 645796c8dcSSimon Schubert call_async_signal_handler (handler); 655796c8dcSSimon Schubert else 665796c8dcSSimon Schubert mark_async_signal_handler (handler); 675796c8dcSSimon Schubert } 68