diff --git a/harbour/ChangeLog b/harbour/ChangeLog index b8934b9f04..8cd009ffe8 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,18 @@ +2001-11-07 01:45 UTC+0100 Viktor Szakats + + * include/hbextern.ch + * include/hbapifs.h + * source/rtl/fstemp.c + - Removed (made static) hb_fsTempName() low-level function, + since it's unsafe, and will be incorporated into hb_fsCreateTemp(). + - Removed HB_FTEMPNAME function, since it's unsafe. + ! Fixed some recent HB_FTEMPCREATE bugs. + + HB_FTEMPCREATE() now will store the generated filename in the + fourth parameter if it's passed by reference. + + * makefile.bc + ! Fixed a bug introduced in the prev. session. + 2001-11-07 01:17 UTC+0100 Viktor Szakats - b16_slex.bat diff --git a/harbour/include/hbapifs.h b/harbour/include/hbapifs.h index 2ffab92b90..d31e39536b 100644 --- a/harbour/include/hbapifs.h +++ b/harbour/include/hbapifs.h @@ -108,7 +108,6 @@ extern BOOL hb_fsRmDir ( BYTE * pszDirName ); /* remove a directory */ extern int hb_fsRename ( BYTE * pszOldName, BYTE * pszNewName ); /* rename a file */ extern ULONG hb_fsSeek ( FHANDLE hFileHandle, LONG lOffset, USHORT uiMode ); /* reposition an open file */ extern ULONG hb_fsTell ( FHANDLE hFileHandle ); /* retrieve the current position of a file */ -extern void hb_fsTempName ( BYTE * pszBuffer, const BYTE * pszDir, const BYTE * pszPrefix ); /* create a temporary file name in a buffer */ extern void hb_fsSetDevMode ( FHANDLE hFileHandle, USHORT uiDevMode ); /* change the device mode of a file (text/binary) */ extern void hb_fsSetDevRaw ( FHANDLE hFileHandle ); /* change the device mode of a file to raw (binary) */ extern void hb_fsSetDevText ( FHANDLE hFileHandle ); /* change the device mode of a file to text */ diff --git a/harbour/include/hbextern.ch b/harbour/include/hbextern.ch index f6a04d4b66..7240d2ddee 100644 --- a/harbour/include/hbextern.ch +++ b/harbour/include/hbextern.ch @@ -918,7 +918,6 @@ EXTERNAL __PREPROCESS #ifdef HB_EXTENSION EXTERNAL HB_FSIZE -EXTERNAL HB_FTEMPNAME EXTERNAL HB_FTEMPCREATE #endif diff --git a/harbour/makefile.bc b/harbour/makefile.bc index e7b0afa435..a0f2e333b1 100644 --- a/harbour/makefile.bc +++ b/harbour/makefile.bc @@ -593,7 +593,6 @@ GTWIN_LIB_OBJS = \ HARBOUR_EXE_OBJS = \ $(OBJ_DIR)\harbour.obj \ $(OBJ_DIR)\harboury.obj \ - $(OBJ_DIR)\hbslex.obj \ $(OBJ_DIR)\cmdcheck.obj \ $(OBJ_DIR)\hbusage.obj \ $(OBJ_DIR)\hbident.obj \ diff --git a/harbour/source/rtl/fstemp.c b/harbour/source/rtl/fstemp.c index 030a221958..c92b9b1915 100644 --- a/harbour/source/rtl/fstemp.c +++ b/harbour/source/rtl/fstemp.c @@ -4,7 +4,7 @@ /* * Harbour Project source code: - * HB_FTEMPNAME(), HB_FTEMPCREATE() functions + * HB_FTEMPCREATE() function * * Copyright 2000-2001 Jose Lalin * Viktor Szakats @@ -58,7 +58,7 @@ /* NOTE: The buffer must be at least _POSIX_PATH_MAX chars long */ -void hb_fsTempName( BYTE * pszBuffer, const BYTE * pszDir, const BYTE * pszPrefix ) +static BOOL hb_fsTempName( BYTE * pszBuffer, const BYTE * pszDir, const BYTE * pszPrefix ) { /* TODO: Implement these: */ HB_SYMBOL_UNUSED( pszDir ); @@ -69,19 +69,41 @@ void hb_fsTempName( BYTE * pszBuffer, const BYTE * pszDir, const BYTE * pszPrefi at least this large. */ pszBuffer[ 0 ] = '\0'; + tmpnam( ( char * ) pszBuffer ); + + return pszBuffer[ 0 ] != '\0'; } /* NOTE: The buffer must be at least _POSIX_PATH_MAX chars long */ FHANDLE hb_fsCreateTemp( const BYTE * pszDir, const BYTE * pszPrefix, USHORT uiAttr, BYTE * pszName ) { - hb_fsTempName( pszName, pszDir, pszPrefix ); + USHORT nAttemptLeft = 999; errno = 0; - if( pszName[ 0 ] != '\0' ) - return hb_fsCreateEx( pszName, uiAttr, FO_EXCLUSIVE ); + while( --nAttemptLeft ) + { + if( hb_fsTempName( pszName, pszDir, pszPrefix ) ) + { + FHANDLE fhnd = hb_fsCreateEx( pszName, uiAttr, FO_EXCLUSIVE ); + + /* This function may fail, if the generated filename got + used between generation and the file creation. */ + + if( fhnd != FS_ERROR ) + { + return fhnd; + } + } + else + { + /* Don't attempt to retry if the filename generator is + failing for some reason. */ + break; + } + } hb_fsSetError( FS_ERROR ); return FS_ERROR; @@ -89,23 +111,16 @@ FHANDLE hb_fsCreateTemp( const BYTE * pszDir, const BYTE * pszPrefix, USHORT uiA #ifdef HB_EXTENSION -HB_FUNC( HB_FTEMPNAME ) -{ - BYTE szName[ _POSIX_PATH_MAX + 1 ]; - - hb_fsTempName( szName, NULL, NULL ); - - hb_retc( ( char * ) szName ); -} - HB_FUNC( HB_FTEMPCREATE ) { BYTE szName[ _POSIX_PATH_MAX + 1 ]; hb_retni( hb_fsCreateTemp( ( BYTE * ) hb_parc( 1 ), ( BYTE * ) hb_parc( 2 ), - ISNUM( 2 ) ? hb_parni( 2 ) : FC_NORMAL, + ISNUM( 3 ) ? hb_parni( 3 ) : FC_NORMAL, szName ) ); + + hb_storc( szName, 4 ); } #endif