Patches from Norman Vine <nhv@cape.com> to catch and properly report "errno"
conditions.
This commit is contained in:
@@ -23,6 +23,12 @@
|
|||||||
|
|
||||||
#include <ctype.h> // isspace()
|
#include <ctype.h> // isspace()
|
||||||
|
|
||||||
|
#ifdef FG_HAVE_STD_INCLUDES
|
||||||
|
# include <cerrno>
|
||||||
|
#else
|
||||||
|
# include <errno.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "fgstream.hxx"
|
#include "fgstream.hxx"
|
||||||
|
|
||||||
fg_gzifstream::fg_gzifstream()
|
fg_gzifstream::fg_gzifstream()
|
||||||
|
|||||||
@@ -22,7 +22,16 @@
|
|||||||
//
|
//
|
||||||
// $Id$
|
// $Id$
|
||||||
|
|
||||||
|
#include <simgear/compiler.h>
|
||||||
|
|
||||||
|
#ifdef FG_HAVE_STD_INCLUDES
|
||||||
|
# include <cerrno>
|
||||||
|
#else
|
||||||
|
# include <errno.h>
|
||||||
|
#endif
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "zfstream.hxx"
|
#include "zfstream.hxx"
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -106,8 +115,11 @@ gzfilebuf::open( const char *name, ios_openmode io_mode )
|
|||||||
|
|
||||||
char char_mode[10];
|
char char_mode[10];
|
||||||
cvt_iomode( char_mode, io_mode );
|
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;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
own_file_descriptor = true;
|
own_file_descriptor = true;
|
||||||
|
|
||||||
@@ -122,8 +134,11 @@ gzfilebuf::attach( int file_descriptor, ios_openmode io_mode )
|
|||||||
|
|
||||||
char char_mode[10];
|
char char_mode[10];
|
||||||
cvt_iomode( char_mode, io_mode );
|
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;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
own_file_descriptor = false;
|
own_file_descriptor = false;
|
||||||
|
|
||||||
|
|||||||
@@ -862,8 +862,12 @@ void fgtzfile_read (const char *file)
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
f = fopen (file, "rb");
|
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)
|
if (fread ((void *) &tzhead, sizeof (tzhead), 1, f) != 1)
|
||||||
goto lose;
|
goto lose;
|
||||||
|
|||||||
@@ -410,7 +410,16 @@ time_t sgTimeGetGMT(int year, int month, int day, int hour, int min, int sec)
|
|||||||
#if defined( HAVE_TIMEGM )
|
#if defined( HAVE_TIMEGM )
|
||||||
return ( timegm(&mt) );
|
return ( timegm(&mt) );
|
||||||
#elif defined( MK_TIME_IS_GMT )
|
#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 )
|
#else // ! defined ( MK_TIME_IS_GMT )
|
||||||
|
|
||||||
// timezone seems to work as a proper offset for Linux & Solaris
|
// timezone seems to work as a proper offset for Linux & Solaris
|
||||||
|
|||||||
Reference in New Issue
Block a user