From f11fe18798a532bbe6222d05f3f70b3e27dec82e Mon Sep 17 00:00:00 2001 From: Aditya Mandaleeka Date: Tue, 3 Nov 2015 12:02:01 -0800 Subject: Remove some unnecessary file-related functions from PAL --- src/pal/src/cruntime/filecrt.cpp | 156 +++------------------------------- src/pal/src/file/file.cpp | 16 ++-- src/pal/src/include/pal/file.h | 14 ++- src/pal/src/include/pal/file.hpp | 49 ----------- src/pal/src/map/map.cpp | 4 +- src/pal/src/misc/dbgmsg.cpp | 13 +-- src/pal/src/synchmgr/synchmanager.cpp | 8 +- 7 files changed, 32 insertions(+), 228 deletions(-) (limited to 'src/pal') diff --git a/src/pal/src/cruntime/filecrt.cpp b/src/pal/src/cruntime/filecrt.cpp index 2d407d87ec..790a262670 100644 --- a/src/pal/src/cruntime/filecrt.cpp +++ b/src/pal/src/cruntime/filecrt.cpp @@ -153,7 +153,7 @@ PAL_fflush( PAL_FILE *stream ) PERF_ENTRY(fflush); ENTRY( "fflush( %p )\n", stream ); - nRetVal = InternalFflush(stream ? stream->bsdFilePtr : NULL); + nRetVal = fflush(stream ? stream->bsdFilePtr : NULL); LOGEXIT( "fflush returning %d\n", nRetVal ); PERF_EXIT(fflush); @@ -161,36 +161,10 @@ PAL_fflush( PAL_FILE *stream ) } -/*++ -Function: - InternalFflush - -Wrapper for fflush. If stream points to an output stream or an -update stream, fflush causes any unwritten data for that stream -to be written to the file. - -InternalFflush is called in DBG_printf_gcc and DBG_printf_c99, -in dbgmsg.cpp. We can do this since InternalFflush doesn't use -ENTRY/LOGEXIT macros, which would cause a recursion otherwise. - -fflush takes an internal lock so the thread calling it -should not be suspended while inside it. ---*/ -int -CorUnix::InternalFflush( - FILE *stream - ) -{ - int nRet = 0; - nRet = fflush(stream); - return nRet; -} - - /*++ PAL__getcwd -Wrapper function for InternalGetcwd. +Wrapper function for getcwd. Input parameters: @@ -208,44 +182,7 @@ PAL__getcwd( size_t nSize ) { - return InternalGetcwd(szBuf, nSize); -} - - -/*++ -InternalGetcwd - -Wrapper for getcwd. getcwd returns a pointer to the current directory pathname. -getcwd invokes malloc when szBuf is NULL to allocate space to store the path name. - -Input parameters: - -szBuf = a copy of the absolute pathname of the current working directory -is copied into szBuf. -nSize = size, in bytes, of the array referenced by szBuf. - -Return value: - A pointer to the pathname if successful, otherwise NULL is returned - and errno is set. ---*/ -char * -CorUnix::InternalGetcwd( - char *szBuf, - size_t nSize - ) -{ - char *szBufCopy; - if (szBuf == NULL) - { - // malloc is used to allocate space to store the pathname when szBuf is NULL. - szBufCopy = (char *)getcwd(szBuf, nSize); - } - else - { - szBufCopy = (char *)getcwd(szBuf, nSize); - } - - return szBufCopy; + return (char *)getcwd(szBuf, nSize); } @@ -378,7 +315,7 @@ CorUnix::InternalOpen( /*++ PAL_unlink -Wrapper function for InternalUnlink. +Wrapper function for unlink. Input parameters: @@ -391,36 +328,14 @@ int __cdecl PAL_unlink(const char *szPath) { - return InternalUnlink(szPath); -} - -/*++ -InternalUnlink - -Wrapper for unlink. - -Input parameters: - -szPath = a symbolic link or a hard link to a file - -Return value: - Returns 0 on success and -1 on failure ---*/ -int -CorUnix::InternalUnlink( - const char *szPath - ) -{ - int nRet = -1; - nRet = unlink(szPath); - return nRet; + return unlink(szPath); } /*++ InternalDeleteFile -Wrapper that does the same thing as InternalUnlink, except that +Wrapper that does the same thing as unlink, except that it uses the SYS_Delete system call present on Apple instead of unlink. Input parameters: @@ -448,7 +363,7 @@ CorUnix::InternalDeleteFile( /*++ PAL_rename -Wrapper function for InternalRename. +Wrapper function for rename. Input parameters: @@ -465,32 +380,9 @@ PAL_rename( const char *szNewName ) { - return InternalRename(szOldName, szNewName); + return rename(szOldName, szNewName); } -/*++ -InternalRename - -Wrapper for rename. - -Input parameters: - -szOldName = pointer to the pathname of the file to be renamed -szNewName = pointer to the new pathname of the file - -Return value: - Returns 0 on success and -1 on failure ---*/ -int -CorUnix::InternalRename( - const char *szOldName, - const char *szNewName - ) -{ - int nRet = -1; - nRet = rename(szOldName, szNewName); - return nRet; -} /*++ PAL_fgets @@ -696,7 +588,7 @@ CorUnix::InternalFwrite( /*++ PAL_fseek -Wrapper function for InternalFseek. +Wrapper function for fseek. Input parameters: @@ -720,37 +612,9 @@ PAL_fseek( PERF_ENTRY(fseek); ENTRY( "fseek( %p, %ld, %d )\n", pf, lOffset, nWhence ); - nRet = InternalFseek(pf ? pf->bsdFilePtr : NULL, lOffset, nWhence); + nRet = fseek(pf ? pf->bsdFilePtr : NULL, lOffset, nWhence); LOGEXIT("fseek returning %d\n", nRet); PERF_EXIT(fseek); return nRet; } - -/*++ -InternalFseek - -Wrapper for fseek. - -Input parameters: - -f = a given file stream -lOffset = distance from position to set file-position indicator -nWhence = method used to determine the file_position indicator location relative to lOffset - -Return value: - 0 on success, -1 on failure. ---*/ -int -CorUnix::InternalFseek( - FILE *f, - long lOffset, - int nWhence - ) -{ - int nRet = -1; - _ASSERTE(f != NULL); - - nRet = fseek(f, lOffset, nWhence); - return nRet; -} diff --git a/src/pal/src/file/file.cpp b/src/pal/src/file/file.cpp index c8d2945271..315687366f 100644 --- a/src/pal/src/file/file.cpp +++ b/src/pal/src/file/file.cpp @@ -284,9 +284,9 @@ CorUnix::InternalCanonicalizeRealPath(LPCSTR lpUnixPath, LPSTR lpBuffer, DWORD c char pszCwdBuffer[MAXPATHLEN+1]; // MAXPATHLEN is for getcwd() DWORD cchCwdBuffer = sizeof(pszCwdBuffer)/sizeof(pszCwdBuffer[0]); - if (InternalGetcwd(pszCwdBuffer, cchCwdBuffer) == NULL) + if (getcwd(pszCwdBuffer, cchCwdBuffer) == NULL) { - WARN("InternalGetcwd(NULL) failed with error %d\n", errno); + WARN("getcwd(NULL) failed with error %d\n", errno); palError = DIRGetLastErrorFromErrno(); goto LExit; } @@ -842,7 +842,7 @@ done: } if (bFileCreated) { - if (-1 == InternalUnlink(lpUnixPath)) + if (-1 == unlink(lpUnixPath)) { WARN("can't delete file; unlink() failed with errno %d (%s)\n", errno, strerror(errno)); @@ -1243,10 +1243,10 @@ DeleteFileA( // Instead, we call unlink which will succeed. if (palError == NO_ERROR && - dwShareMode != SHARE_MODE_NOT_INITALIZED && - (dwShareMode & FILE_SHARE_DELETE) != 0) + dwShareMode != SHARE_MODE_NOT_INITALIZED && + (dwShareMode & FILE_SHARE_DELETE) != 0) { - result = InternalUnlink( lpFullUnixFileName ); + result = unlink( lpFullUnixFileName ); } else { @@ -1497,7 +1497,7 @@ MoveFileExA( } } - result = InternalRename( source, dest ); + result = rename( source, dest ); if ((result < 0) && (dwFlags & MOVEFILE_REPLACE_EXISTING) && ((errno == ENOTDIR) || (errno == EEXIST))) { @@ -1505,7 +1505,7 @@ MoveFileExA( if ( bRet ) { - result = InternalRename( source, dest ); + result = rename( source, dest ); } else { diff --git a/src/pal/src/include/pal/file.h b/src/pal/src/include/pal/file.h index 8d9331dfc0..caf982b6c7 100644 --- a/src/pal/src/include/pal/file.h +++ b/src/pal/src/include/pal/file.h @@ -189,8 +189,7 @@ void FILEGetProperNotFoundError( LPSTR lpPath, LPDWORD lpErrorCode ); /*++ PAL__getcwd -Calls InternalGetcwd to call getcwd with a thread that is marked -as suspension unsafe. +Calls getcwd Input parameters: @@ -206,8 +205,7 @@ char * __cdecl PAL__getcwd(char *szBuf, size_t nSize); /*++ PAL_fflush -Calls InternalFflush to call fflush with a thread that is marked -as suspension unsafe. +Calls fflush Input parameters: @@ -235,8 +233,7 @@ int __cdecl PAL_mkstemp(char *szNameTemplate); /*++ PAL_unlink -Calls InternalUnlink to call unlink with a thread that is marked -as suspension unsafe. +Calls unlink. Input parameters: @@ -250,8 +247,7 @@ int __cdecl PAL_unlink(const char *szPath); /*++ PAL_rename -Calls InternalRename to call rename with a thread that is marked -as suspension unsafe. +Calls rename Input parameters: @@ -316,7 +312,7 @@ int __cdecl PAL__open(const char *szPath, int nFlags, ...); /*++ PAL_fseek -Wrapper function for InternalFseek +Wrapper function for fseek Input parameters: diff --git a/src/pal/src/include/pal/file.hpp b/src/pal/src/include/pal/file.hpp index 0214c9e902..909ba6c53d 100644 --- a/src/pal/src/include/pal/file.hpp +++ b/src/pal/src/include/pal/file.hpp @@ -185,25 +185,6 @@ namespace CorUnix DWORD cch ); - /*++ - InternalGetcwd - Wraps getcwd - --*/ - char * - InternalGetcwd( - char *szBuf, - size_t nSize - ); - - /*++ - InternalFflush - Wraps fflush - --*/ - int - InternalFflush( - FILE * stream - ); - /*++ InternalMkstemp Wraps mkstemp @@ -213,15 +194,6 @@ namespace CorUnix char *szNameTemplate ); - /*++ - InternalUnlink - Wraps unlink - --*/ - int - InternalUnlink( - const char *szPath - ); - /*++ InternalDeleteFile Wraps SYS_delete @@ -231,16 +203,6 @@ namespace CorUnix const char *szPath ); - /*++ - InternalRename - Wraps rename - --*/ - int - InternalRename( - const char *szOldName, - const char *szNewName - ); - /*++ InternalFgets Wraps fgets @@ -276,17 +238,6 @@ namespace CorUnix int nFlags, ... ); - - /*++ - InternalFseek - Wraps fseek - --*/ - int - InternalFseek( - FILE *f, - long lOffset, - int nWhence - ); } extern "C" diff --git a/src/pal/src/map/map.cpp b/src/pal/src/map/map.cpp index fe0d2c18ab..ea59b71330 100644 --- a/src/pal/src/map/map.cpp +++ b/src/pal/src/map/map.cpp @@ -179,7 +179,7 @@ FileMappingCleanupRoutine( if (pImmutableData->bPALCreatedTempFile) { - InternalUnlink(pImmutableData->szFileName); + unlink(pImmutableData->szFileName); } } @@ -766,7 +766,7 @@ ExitInternalCreateFileMapping: if (bPALCreatedTempFile) { - InternalUnlink(pImmutableData->szFileName); + unlink(pImmutableData->szFileName); } if (-1 != UnixFd) diff --git a/src/pal/src/misc/dbgmsg.cpp b/src/pal/src/misc/dbgmsg.cpp index d7491cef15..4d345649b1 100644 --- a/src/pal/src/misc/dbgmsg.cpp +++ b/src/pal/src/misc/dbgmsg.cpp @@ -547,17 +547,14 @@ int DBG_printf_gcc(DBG_CHANNEL_ID channel, DBG_LEVEL_ID level, BOOL bHeader, InternalLeaveCriticalSection(pthrCurrent, &fprintf_crit_section); /* flush the output to file */ - /* Can call InternalFflush since InternalFflush does not have ENTRY/LOGEXIT - macros. If that changes, then this will need to be switched back to calling the - cruntime fflush with some other protection from suspension. */ - if (InternalFflush(output_file) != 0) + if ( fflush(output_file) != 0 ) { fprintf(stderr, "ERROR : fflush() failed errno:%d (%s)\n", errno, strerror(errno)); } // Some systems support displaying a GUI dialog. We attempt this only for asserts. - if (level == DLI_ASSERT) + if ( level == DLI_ASSERT ) PAL_DisplayDialog("PAL ASSERT", buffer); if ( old_errno != errno ) @@ -657,11 +654,7 @@ int DBG_printf_c99(DBG_CHANNEL_ID channel, DBG_LEVEL_ID level, BOOL bHeader, if(call_count>5) { call_count=0; - /* Can call InternalFflush since InternalFflush does not have - ENTRY/LOGEXIT macros. If that changes, then this will need - to be switched back to calling the cruntime fflush with some - other protection from suspension. */ - if (InternalFflush(output_file) != 0) + if ( fflush(output_file) != 0 ) { fprintf(stderr, "ERROR : fflush() failed errno:%d (%s)\n", errno, strerror(errno)); diff --git a/src/pal/src/synchmgr/synchmanager.cpp b/src/pal/src/synchmgr/synchmanager.cpp index f1b8572798..0adbb3d72e 100644 --- a/src/pal/src/synchmgr/synchmanager.cpp +++ b/src/pal/src/synchmgr/synchmanager.cpp @@ -3778,7 +3778,7 @@ namespace CorUnix { /* Some how no one deleted the pipe, perhaps it was left behind from a crash?? Delete the pipe and try again. */ - if ( -1 == InternalUnlink( szPipeFilename ) ) + if ( -1 == unlink( szPipeFilename ) ) { ERROR( "Unable to delete the process pipe that was left behind.\n" ); fRet = false; @@ -3858,7 +3858,7 @@ namespace CorUnix // Failed if (0 != szPipeFilename[0]) { - InternalUnlink(szPipeFilename); + unlink(szPipeFilename); } if (-1 != iPipeRd) { @@ -3901,13 +3901,13 @@ namespace CorUnix PAL_ERROR CPalSynchronizationManager::ShutdownProcessPipe( CPalThread *pthrCurrent) { - PAL_ERROR palErr = NO_ERROR; + PAL_ERROR palErr = NO_ERROR; #ifndef CORECLR char szPipeFilename[MAX_PATH]; if(GetProcessPipeName(szPipeFilename, MAX_PATH, gPID)) { - if (InternalUnlink(szPipeFilename) == -1) + if (unlink(szPipeFilename) == -1) { ERROR("Unable to unlink the pipe file name errno=%d (%s)\n", errno, strerror(errno)); -- cgit v1.2.3