From 2b5783fd52d6fa36b0059a28a68eb818ca3bbfbd Mon Sep 17 00:00:00 2001 From: Owen Shepherd Date: Wed, 15 Aug 2012 15:23:40 +0100 Subject: [PATCH] fclose.c: don't try to open testfile2 while already open; [win32] implement rename --- functions/stdio/fclose.c | 2 +- platform/win32/functions/_PDCLIB/_PDCLIB_open.c | 15 +++++++++++++++ platform/win32/functions/_PDCLIB/_PDCLIB_rename.c | 9 ++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/functions/stdio/fclose.c b/functions/stdio/fclose.c index 113845b..d20cb3e 100644 --- a/functions/stdio/fclose.c +++ b/functions/stdio/fclose.c @@ -83,7 +83,7 @@ int main( void ) TESTCASE( _PDCLIB_filelist == file2 ); TESTCASE( fclose( file2 ) == 0 ); TESTCASE( _PDCLIB_filelist == file1 ); - TESTCASE( ( file2 = fopen( testfile1, "w" ) ) != NULL ); + TESTCASE( ( file2 = fopen( testfile2, "w" ) ) != NULL ); TESTCASE( _PDCLIB_filelist == file2 ); TESTCASE( fclose( file1 ) == 0 ); TESTCASE( _PDCLIB_filelist == file2 ); diff --git a/platform/win32/functions/_PDCLIB/_PDCLIB_open.c b/platform/win32/functions/_PDCLIB/_PDCLIB_open.c index bfdb897..a6ac387 100644 --- a/platform/win32/functions/_PDCLIB/_PDCLIB_open.c +++ b/platform/win32/functions/_PDCLIB/_PDCLIB_open.c @@ -59,6 +59,21 @@ HANDLE _PDCLIB_open( char const * const filename, unsigned int mode ) NULL, creationDisposition, FILE_ATTRIBUTE_NORMAL, NULL); if(fd == INVALID_HANDLE_VALUE) { +#if 0 + DWORD dw = GetLastError(); + char* msgBuf; + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + dw, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPSTR) &msgBuf, + 0, NULL ); + + fprintf(stderr, "Error: %s\n", msgBuf); +#endif _PDCLIB_w32errno(); return NULL; } diff --git a/platform/win32/functions/_PDCLIB/_PDCLIB_rename.c b/platform/win32/functions/_PDCLIB/_PDCLIB_rename.c index a65715d..cac1958 100644 --- a/platform/win32/functions/_PDCLIB/_PDCLIB_rename.c +++ b/platform/win32/functions/_PDCLIB/_PDCLIB_rename.c @@ -11,10 +11,17 @@ #ifndef REGTEST #include <_PDCLIB_glue.h> #include +#include +void _PDCLIB_w32errno( void ); int _PDCLIB_rename( const char * old, const char * new ) { - errno = ENOTSUP; + + BOOL ok = MoveFile(old, new); + if(!ok) { + _PDCLIB_w32errno(); + } + return !ok; } #endif -- 2.40.0