From 0027c2521ff07efcc992a31cfe88a91fe21cec56 Mon Sep 17 00:00:00 2001 From: fayjf Date: Tue, 3 Nov 2009 13:45:32 +0000 Subject: [PATCH] Protecting "errno" in case it is not defined per e-mail from Vincent R dated 5:37 AM, October 3, 2009. git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@834 7f0cb862-5218-0410-a997-914c9d46530a --- freeglut/freeglut/src/freeglut_init.c | 10 +++++--- .../freeglut/src/freeglut_input_devices.c | 6 +++-- freeglut/freeglut/src/freeglut_joystick.c | 25 +++++++++++++++++-- freeglut/freeglut/src/freeglut_main.c | 6 ++++- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/freeglut/freeglut/src/freeglut_init.c b/freeglut/freeglut/src/freeglut_init.c index 83b7804..7893f05 100644 --- a/freeglut/freeglut/src/freeglut_init.c +++ b/freeglut/freeglut/src/freeglut_init.c @@ -683,7 +683,9 @@ void FGAPIENTRY glutInit( int* pargc, char** argv ) /* will return true for VC8 (VC2005) and higher */ #if TARGET_HOST_MS_WINDOWS && ( _MSC_VER >= 1400 ) size_t sLen; +#if HAVE_ERRNO errno_t err; +#endif #endif if( fgState.Initialised ) @@ -706,7 +708,7 @@ void FGAPIENTRY glutInit( int* pargc, char** argv ) #ifndef _WIN32_WCE { /* will return true for VC8 (VC2005) and higher */ -#if TARGET_HOST_MS_WINDOWS && ( _MSC_VER >= 1400 ) +#if TARGET_HOST_MS_WINDOWS && ( _MSC_VER >= 1400 ) && HAVE_ERRNO char* fps = NULL; err = _dupenv_s( &fps, &sLen, "GLUT_FPS" ); if (err) @@ -725,13 +727,13 @@ void FGAPIENTRY glutInit( int* pargc, char** argv ) fgState.FPSInterval = interval; } /* will return true for VC8 (VC2005) and higher */ -#if TARGET_HOST_MS_WINDOWS && ( _MSC_VER >= 1400 ) +#if TARGET_HOST_MS_WINDOWS && ( _MSC_VER >= 1400 ) && HAVE_ERRNO free ( fps ); fps = NULL; /* dupenv_s allocates a string that we must free */ #endif } /* will return true for VC8 (VC2005) and higher */ -#if TARGET_HOST_MS_WINDOWS && ( _MSC_VER >= 1400 ) +#if TARGET_HOST_MS_WINDOWS && ( _MSC_VER >= 1400 ) && HAVE_ERRNO err = _dupenv_s( &displayName, &sLen, "DISPLAY" ); if (err) fgError("Error getting DISPLAY environment variable"); @@ -823,7 +825,7 @@ void FGAPIENTRY glutInit( int* pargc, char** argv ) */ fghInitialize( displayName ); /* will return true for VC8 (VC2005) and higher */ -#if TARGET_HOST_MS_WINDOWS && ( _MSC_VER >= 1400 ) +#if TARGET_HOST_MS_WINDOWS && ( _MSC_VER >= 1400 ) && HAVE_ERRNO free ( displayName ); displayName = NULL; /* dupenv_s allocates a string that we must free */ #endif diff --git a/freeglut/freeglut/src/freeglut_input_devices.c b/freeglut/freeglut/src/freeglut_input_devices.c index 0e3dc8d..0e202fa 100755 --- a/freeglut/freeglut/src/freeglut_input_devices.c +++ b/freeglut/freeglut/src/freeglut_input_devices.c @@ -36,7 +36,9 @@ #include "freeglut_internal.h" #if TARGET_HOST_POSIX_X11 +#if HAVE_ERRNO #include +#endif #include #include #include @@ -139,7 +141,7 @@ void fgInitialiseInputDevices ( void ) if( !fgState.InputDevsInitialised ) { /* will return true for VC8 (VC2005) and higher */ -#if TARGET_HOST_MS_WINDOWS && ( _MSC_VER >= 1400 ) +#if TARGET_HOST_MS_WINDOWS && ( _MSC_VER >= 1400 ) && HAVE_ERRNO char *dial_device=NULL; size_t sLen; errno_t err = _dupenv_s( &dial_device, &sLen, "GLUT_DIALS_SERIAL" ); @@ -166,7 +168,7 @@ void fgInitialiseInputDevices ( void ) if ( !dial_device ) return; if ( !( dialbox_port = serial_open ( dial_device ) ) ) return; /* will return true for VC8 (VC2005) and higher */ -#if TARGET_HOST_MS_WINDOWS && ( _MSC_VER >= 1400 ) +#if TARGET_HOST_MS_WINDOWS && ( _MSC_VER >= 1400 ) && HAVE_ERRNO free ( dial_device ); dial_device = NULL; /* dupenv_s allocates a string that we must free */ #endif serial_putchar(dialbox_port,DIAL_INITIALIZE); diff --git a/freeglut/freeglut/src/freeglut_joystick.c b/freeglut/freeglut/src/freeglut_joystick.c index 8260340..0214d64 100644 --- a/freeglut/freeglut/src/freeglut_joystick.c +++ b/freeglut/freeglut/src/freeglut_joystick.c @@ -75,7 +75,9 @@ # if HAVE_FCNTL_H # include # endif -# include +# if HAVE_ERRNO +# include +# endif # if defined(__FreeBSD__) || defined(__NetBSD__) /* XXX The below hack is done until freeglut's autoconf is updated. */ # define HAVE_USB_JS 1 @@ -237,12 +239,15 @@ static int fghJoystickFindUSBdev(char *name, char *out, int outlen) close(f); if (cp) return 1; - } else if (errno == EACCES) { + } +#if HAVE_ERRNO + else if (errno == EACCES) { if (!protection_warned) { fgWarning ( "Can't open %s for read!", buf ); protection_warned = 1; } } +#endif } return 0; } @@ -260,7 +265,11 @@ static int fghJoystickInitializeHID(struct os_specific_s *os, if ( ( rd = hid_get_report_desc( os->fd ) ) == 0 ) { +#if HAVE_ERRNO fgWarning ( "error: %s: %s", os->fname, strerror( errno ) ); +#else + fgWarning ( "error: %s", os->fname ); +#endif return FALSE; } @@ -270,7 +279,11 @@ static int fghJoystickInitializeHID(struct os_specific_s *os, if( ioctl( os->fd, USB_GET_REPORT_ID, &report_id ) < 0) { /*** XXX {report_id} may not be the right variable? ***/ +#if HAVE_ERRNO fgWarning ( "error: %s%d: %s", UHIDDEV, report_id, strerror( errno ) ); +#else + fgWarning ( "error: %s%d", UHIDDEV, report_id ); +#endif return FALSE; } @@ -663,7 +676,11 @@ static void fghJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes ) } } } +#if HAVE_ERRNO if ( len < 0 && errno != EAGAIN ) +#else + if ( len < 0 ) +#endif { perror( joy->os->fname ); joy->error = 1; @@ -682,6 +699,7 @@ static void fghJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes ) if ( status != sizeof( struct js_event ) ) { +#if HAVE_ERRNO if ( errno == EAGAIN ) { /* Use the old values */ @@ -692,6 +710,7 @@ static void fghJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes ) sizeof( float ) * joy->num_axes ); return; } +#endif fgWarning ( "%s", joy->fname ); joy->error = GL_TRUE; @@ -1298,8 +1317,10 @@ static void fghJoystickOpen( SFG_Joystick* joy ) joy->os->fd = open( joy->os->fname, O_RDONLY | O_NONBLOCK); +#if HAVE_ERRNO if( joy->os->fd < 0 && errno == EACCES ) fgWarning ( "%s exists but is not readable by you", joy->os->fname ); +#endif joy->error =( joy->os->fd < 0 ); diff --git a/freeglut/freeglut/src/freeglut_main.c b/freeglut/freeglut/src/freeglut_main.c index 058f462..fa0174e 100644 --- a/freeglut/freeglut/src/freeglut_main.c +++ b/freeglut/freeglut/src/freeglut_main.c @@ -27,7 +27,9 @@ #include #include "freeglut_internal.h" -#include +#if HAVE_ERRNO +# include +#endif #include #if HAVE_VPRINTF # define VFPRINTF(s,f,a) vfprintf((s),(f),(a)) @@ -471,8 +473,10 @@ static void fghSleepForEvents( void ) wait.tv_usec = (msec % 1000) * 1000; err = select( socket+1, &fdset, NULL, NULL, &wait ); +#if HAVE_ERRNO if( ( -1 == err ) && ( errno != EINTR ) ) fgWarning ( "freeglut select() error: %d", errno ); +#endif } #elif TARGET_HOST_MS_WINDOWS MsgWaitForMultipleObjects( 0, NULL, FALSE, msec, QS_ALLINPUT );