From 9f516a8ccc7e6e5865523a87a7950b501f0959be Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 6 Mar 2001 16:33:39 +0000 Subject: [PATCH] Patches from Norman Vine to catch and properly report "errno" conditions. --- simgear/misc/fgstream.cxx | 6 ++++++ simgear/misc/zfstream.cxx | 19 +++++++++++++++++-- simgear/timing/lowleveltime.cxx | 8 ++++++-- simgear/timing/sg_time.cxx | 17 +++++++++++++---- 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/simgear/misc/fgstream.cxx b/simgear/misc/fgstream.cxx index 3f14dbb2..24001681 100644 --- a/simgear/misc/fgstream.cxx +++ b/simgear/misc/fgstream.cxx @@ -23,6 +23,12 @@ #include // isspace() +#ifdef FG_HAVE_STD_INCLUDES +# include +#else +# include +#endif + #include "fgstream.hxx" fg_gzifstream::fg_gzifstream() diff --git a/simgear/misc/zfstream.cxx b/simgear/misc/zfstream.cxx index 63d11477..7dcf701f 100644 --- a/simgear/misc/zfstream.cxx +++ b/simgear/misc/zfstream.cxx @@ -22,7 +22,16 @@ // // $Id$ +#include + +#ifdef FG_HAVE_STD_INCLUDES +# include +#else +# include +#endif #include +#include + #include "zfstream.hxx" // @@ -106,8 +115,11 @@ gzfilebuf::open( const char *name, ios_openmode io_mode ) char char_mode[10]; cvt_iomode( char_mode, io_mode ); - if ( (file = gzopen(name, char_mode)) == NULL ) + if ( (file = gzopen(name, char_mode)) == NULL ) { + perror( "gzfilebuf::open(): " ); + errno = 0; return NULL; + } own_file_descriptor = true; @@ -122,8 +134,11 @@ gzfilebuf::attach( int file_descriptor, ios_openmode io_mode ) char char_mode[10]; cvt_iomode( char_mode, io_mode ); - if ( (file = gzdopen(file_descriptor, char_mode)) == NULL ) + if ( (file = gzdopen(file_descriptor, char_mode)) == NULL ) { + perror( "gzfilebuf::attach(): " ); + errno = 0; return NULL; + } own_file_descriptor = false; diff --git a/simgear/timing/lowleveltime.cxx b/simgear/timing/lowleveltime.cxx index ec3cf988..84e72c83 100644 --- a/simgear/timing/lowleveltime.cxx +++ b/simgear/timing/lowleveltime.cxx @@ -862,8 +862,12 @@ void fgtzfile_read (const char *file) // } f = fopen (file, "rb"); - if (f == NULL) - return; + + if (f == NULL) { + perror( "fgtzfile_read(): " ); + errno = 0; + return; + } if (fread ((void *) &tzhead, sizeof (tzhead), 1, f) != 1) goto lose; diff --git a/simgear/timing/sg_time.cxx b/simgear/timing/sg_time.cxx index 3ee4bc9d..6ba31e9a 100644 --- a/simgear/timing/sg_time.cxx +++ b/simgear/timing/sg_time.cxx @@ -407,14 +407,23 @@ time_t sgTimeGetGMT(int year, int month, int day, int hour, int min, int sec) # define MK_TIME_IS_GMT 1 #endif -#if defined( HAVE_TIMEGM ) +#if defined( HAVE_TIMEGM ) return ( timegm(&mt) ); #elif defined( MK_TIME_IS_GMT ) - return ( mktime(&mt) ); + time_t ret = mktime(&mt); + // This is necessary as some mktime() calls may + // try to access the system timezone files + // if this open fails errno is set to 2 + // CYGWIN for one does this + if ( errno ) { + perror( "sgTimeGetGMT(): " ); + errno = 0; + } + return ret; #else // ! defined ( MK_TIME_IS_GMT ) // timezone seems to work as a proper offset for Linux & Solaris -# if defined( __linux__ ) || defined( __sun__ ) +# if defined( __linux__ ) || defined( __sun__ ) # define TIMEZONE_OFFSET_WORKS 1 # endif @@ -429,7 +438,7 @@ time_t sgTimeGetGMT(int year, int month, int day, int hour, int min, int sec) timezone = fix_up_timezone( timezone ); # if defined( TIMEZONE_OFFSET_WORKS ) - FG_LOG( FG_EVENT, FG_DEBUG, + FG_LOG( FG_EVENT, FG_DEBUG, "start = " << start << ", timezone = " << timezone ); return( start - timezone ); # else // ! defined( TIMEZONE_OFFSET_WORKS ) -- 2.39.5