Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove _fdopen from PAL #77272

Merged
merged 1 commit into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/coreclr/pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -4408,7 +4408,6 @@ PALIMPORT int __cdecl PAL_ferror(PAL_FILE *);
PALIMPORT PAL_FILE * __cdecl PAL_fopen(const char *, const char *);
PALIMPORT int __cdecl PAL_setvbuf(PAL_FILE *stream, char *, int, size_t);

PALIMPORT PAL_FILE * __cdecl _fdopen(int, const char *);
PALIMPORT PAL_FILE * __cdecl _wfopen(const WCHAR *, const WCHAR *);

/* Maximum value that can be returned by the rand function. */
Expand Down
59 changes: 1 addition & 58 deletions src/coreclr/pal/src/cruntime/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static LPSTR MapFileOpenModes(LPSTR str , BOOL * bTextMode)
The PAL does not support this behavior. */
if (NULL != strchr(str,'D'))
{
ASSERT("The PAL doesn't support the 'D' flag for _fdopen and fopen.\n");
ASSERT("The PAL doesn't support the 'D' flag for fopen.\n");
return NULL;
}

Expand Down Expand Up @@ -193,63 +193,6 @@ static BOOL WriteOnlyMode(FILE* pFile)
}
#endif //UNGETC_NOT_RETURN_EOF

/*++
Function:
_fdopen

see MSDN

--*/
PAL_FILE *
__cdecl
_fdopen(
int handle,
const char *mode)
{
PAL_FILE *f = NULL;
LPSTR supported = NULL;
BOOL bTextMode = TRUE;

PERF_ENTRY(_fdopen);
ENTRY("_fdopen (handle=%d mode=%p (%s))\n", handle, mode, mode);

_ASSERTE(mode != NULL);

f = (PAL_FILE*)PAL_malloc( sizeof( PAL_FILE ) );
if ( f )
{
supported = MapFileOpenModes( (char*)mode , &bTextMode);
if ( !supported )
{
PAL_free(f);
f = NULL;
goto EXIT;
}

f->bsdFilePtr = (FILE *)fdopen( handle, supported );
f->PALferrorCode = PAL_FILE_NOERROR;
/* Make sure fdopen did not fail. */
if ( !f->bsdFilePtr )
{
PAL_free( f );
f = NULL;
}

PAL_free( supported );
supported = NULL;
}
else
{
ERROR( "Unable to allocate memory for the PAL_FILE wrapper!\n" );
}

EXIT:
LOGEXIT( "_fdopen returns FILE* %p\n", f );
PERF_EXIT(_fdopen);
return f;
}


/*++

Function :
Expand Down
28 changes: 0 additions & 28 deletions src/coreclr/pal/tests/palsuite/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
3.2 Other Notes

4. ADDITIONAL NOTES ON TESTING/SPECIFIC TEST CASE ISSUES
C_runtime: _fdopen testing issues
File_IO: getfilesize/test1, setfilepointer/test(5,6,7)
File_IO: gettempfilename(a,w)/test2
File_IO: setfileattributesa/test(1,4), setfileattributesw/test(1,4)
Expand Down Expand Up @@ -53,33 +52,6 @@ See notes in section 4 on the following test cases if running automated tests:
4. ADDITIONAL NOTES ON TESTING/SPECIFIC TEST CASE ISSUES
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

C Runtime: _fdopen testing issues

There is a very specific manner in which _fdopen has been documented to work,
this will determine how the function will be tested.

_fdopen takes a parameter of a c run-time file handle, to open a stream to the
file. This file handle can only be returned from the _open_osfhandle function.
The Rotor documentation states that _open_osfhandle will only return a
READ-ONLY file handle, from an operating-system file handle returned from
CreatePipe().

With these restrictions _fdopen will only be tested with a mode of read(r).
The other modes are not possible to test. _open_osfhandle returns an error
when attempting to open a write pipe handle in a mode of read-only. As well,
it is not possible to read and write to the same handle that is returned from
CreatePipe().

The modes that will not be tested are as follows:

"w" - Opens an empty file for writing.
"a" - Opens for writing at the end of the file (appending).
"r+" - Opens for both reading and writing.
"w+" - Opens an empty file for both reading and writing.
"a+" - Opens for reading and appending.



File_IO: getfilesize/test1, getfilesizeex/test1 setfilepointer/test(5,6,7)

These tests cases create a large number of temporary files which require
Expand Down