Patches from Norman Vine <nhv@cape.com> to catch and properly report "errno"

conditions.
This commit is contained in:
curt
2001-03-06 16:33:39 +00:00
parent e07af68018
commit 9f516a8ccc
4 changed files with 42 additions and 8 deletions

View File

@@ -23,6 +23,12 @@
#include <ctype.h> // isspace()
#ifdef FG_HAVE_STD_INCLUDES
# include <cerrno>
#else
# include <errno.h>
#endif
#include "fgstream.hxx"
fg_gzifstream::fg_gzifstream()

View File

@@ -22,7 +22,16 @@
//
// $Id$
#include <simgear/compiler.h>
#ifdef FG_HAVE_STD_INCLUDES
# include <cerrno>
#else
# include <errno.h>
#endif
#include <memory.h>
#include <stdio.h>
#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;

View File

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

View File

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