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
This commit is contained in:
fayjf 2009-11-03 13:45:32 +00:00
parent 2bebcfa23f
commit 0027c2521f
4 changed files with 38 additions and 9 deletions

View File

@ -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

View File

@ -36,7 +36,9 @@
#include "freeglut_internal.h"
#if TARGET_HOST_POSIX_X11
#if HAVE_ERRNO
#include <errno.h>
#endif
#include <sys/ioctl.h>
#include <sys/time.h>
#include <time.h>
@ -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);

View File

@ -75,7 +75,9 @@
# if HAVE_FCNTL_H
# include <fcntl.h>
# endif
# if HAVE_ERRNO
# include <errno.h>
# 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 );

View File

@ -27,7 +27,9 @@
#include <GL/freeglut.h>
#include "freeglut_internal.h"
#if HAVE_ERRNO
# include <errno.h>
#endif
#include <stdarg.h>
#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 );