From 4402d66336edfa25959b50834415fbfc13196c86 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 9 Feb 2024 10:17:59 -0800 Subject: [PATCH 1/5] Remove FILE pal --- .../debug/createdump/crashinfounix.cpp | 4 +- .../debug/createdump/createdumppal.cpp | 20 - .../dlls/mscordac/mscordac_unixexports.src | 6 - src/coreclr/gc/unix/cgroup.cpp | 8 +- src/coreclr/gc/unix/gcenv.unix.cpp | 6 +- src/coreclr/ilasm/main.cpp | 3 +- src/coreclr/ildasm/dasm.cpp | 5 + src/coreclr/ildasm/dis.cpp | 9 +- src/coreclr/pal/inc/pal.h | 148 ++-- src/coreclr/pal/inc/pal_assert.h | 2 +- src/coreclr/pal/inc/rt/palrt.h | 8 +- src/coreclr/pal/src/CMakeLists.txt | 3 - src/coreclr/pal/src/cruntime/file.cpp | 665 ------------------ src/coreclr/pal/src/cruntime/filecrt.cpp | 378 ---------- src/coreclr/pal/src/cruntime/misc.cpp | 5 +- src/coreclr/pal/src/cruntime/printfcpp.cpp | 84 --- src/coreclr/pal/src/cruntime/wchar.cpp | 48 ++ src/coreclr/pal/src/file/file.cpp | 85 ++- src/coreclr/pal/src/include/pal/cruntime.h | 115 --- src/coreclr/pal/src/include/pal/file.h | 89 --- src/coreclr/pal/src/include/pal/file.hpp | 34 - src/coreclr/pal/src/include/pal/palinternal.h | 21 +- src/coreclr/pal/src/include/pal/printfcpp.hpp | 46 -- .../pal/src/include/pal/threadsusp.hpp | 1 - src/coreclr/pal/src/init/pal.cpp | 17 - src/coreclr/pal/src/locale/unicode.cpp | 8 +- src/coreclr/pal/src/misc/cgroup.cpp | 8 +- src/coreclr/pal/src/misc/fmtmessage.cpp | 2 - src/coreclr/pal/src/misc/perftrace.cpp | 43 +- src/coreclr/pal/src/thread/process.cpp | 2 +- src/coreclr/pal/tests/palsuite/CMakeLists.txt | 27 - .../palsuite/c_runtime/errno/test1/test1.cpp | 42 -- .../palsuite/c_runtime/errno/test2/test2.cpp | 75 -- .../palsuite/c_runtime/ferror/test1/test1.cpp | 73 -- .../palsuite/c_runtime/ferror/test1/testfile | 1 - .../palsuite/c_runtime/ferror/test2/test2.cpp | 68 -- .../palsuite/c_runtime/ferror/test2/testfile | 1 - .../palsuite/c_runtime/fflush/test1/test1.cpp | 79 --- .../palsuite/c_runtime/fgets/test1/test1.cpp | 101 --- .../palsuite/c_runtime/fgets/test2/test2.cpp | 96 --- .../palsuite/c_runtime/fgets/test3/test3.cpp | 72 -- .../palsuite/c_runtime/fopen/test1/test1.cpp | 81 --- .../palsuite/c_runtime/fopen/test2/test2.cpp | 64 -- .../palsuite/c_runtime/fopen/test3/test3.cpp | 65 -- .../palsuite/c_runtime/fopen/test4/test4.cpp | 81 --- .../palsuite/c_runtime/fopen/test5/test5.cpp | 77 -- .../palsuite/c_runtime/fopen/test6/test6.cpp | 130 ---- .../palsuite/c_runtime/fopen/test7/test7.cpp | 116 --- .../palsuite/c_runtime/fputs/test1/test1.cpp | 99 --- .../palsuite/c_runtime/fputs/test2/test2.cpp | 87 --- .../palsuite/c_runtime/fread/test1/test1.cpp | 134 ---- .../palsuite/c_runtime/fread/test1/testfile | 1 - .../palsuite/c_runtime/fread/test2/test2.cpp | 142 ---- .../palsuite/c_runtime/fread/test2/testfile | 1 - .../palsuite/c_runtime/fread/test3/test3.cpp | 130 ---- .../palsuite/c_runtime/fread/test3/testfile | 1 - .../palsuite/c_runtime/fseek/test1/test1.cpp | 192 ----- .../palsuite/c_runtime/ftell/test1/ftell.cpp | 144 ---- .../c_runtime/ftell/test1/testfile.txt | 1 - .../palsuite/c_runtime/fwrite/test1/test1.cpp | 103 --- .../pal/tests/palsuite/common/palsuite.h | 1 + .../pal/tests/palsuite/compilableTests.txt | 22 - .../PAL_errno/test1/PAL_errno.cpp | 52 -- .../PAL_get_stderr/test1/PAL_get_stderr.cpp | 51 -- .../PAL_get_stdin/test1/PAL_get_stdin.cpp | 67 -- .../PAL_get_stdout/test1/PAL_get_stdout.cpp | 51 -- .../pal/tests/palsuite/paltestlist.txt | 15 - .../SignalObjectAndWaitTest.cpp | 4 +- .../tools/StressLogAnalyzer/StressLogDump.cpp | 4 +- src/coreclr/utilcode/debug.cpp | 9 +- src/coreclr/vm/pgo.cpp | 6 +- 71 files changed, 240 insertions(+), 4199 deletions(-) delete mode 100644 src/coreclr/pal/src/cruntime/file.cpp delete mode 100644 src/coreclr/pal/src/cruntime/filecrt.cpp delete mode 100644 src/coreclr/pal/src/cruntime/printfcpp.cpp delete mode 100644 src/coreclr/pal/src/include/pal/printfcpp.hpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/errno/test1/test1.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/errno/test2/test2.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/ferror/test1/test1.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/ferror/test1/testfile delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/ferror/test2/test2.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/ferror/test2/testfile delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/fflush/test1/test1.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/fgets/test1/test1.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/fgets/test2/test2.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/fgets/test3/test3.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/fopen/test1/test1.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/fopen/test2/test2.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/fopen/test3/test3.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/fopen/test4/test4.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/fopen/test5/test5.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/fopen/test6/test6.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/fopen/test7/test7.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/fputs/test1/test1.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/fputs/test2/test2.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/fread/test1/test1.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/fread/test1/testfile delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/fread/test2/test2.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/fread/test2/testfile delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/fread/test3/test3.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/fread/test3/testfile delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/fseek/test1/test1.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/ftell/test1/ftell.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/ftell/test1/testfile.txt delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/fwrite/test1/test1.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/pal_specific/PAL_errno/test1/PAL_errno.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/pal_specific/PAL_get_stderr/test1/PAL_get_stderr.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/pal_specific/PAL_get_stdin/test1/PAL_get_stdin.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/pal_specific/PAL_get_stdout/test1/PAL_get_stdout.cpp diff --git a/src/coreclr/debug/createdump/crashinfounix.cpp b/src/coreclr/debug/createdump/crashinfounix.cpp index 9f72707263b07..263818e7ad79f 100644 --- a/src/coreclr/debug/createdump/crashinfounix.cpp +++ b/src/coreclr/debug/createdump/crashinfounix.cpp @@ -221,7 +221,7 @@ CrashInfo::EnumerateMemoryRegions() printf_error("snprintf failed building /proc//maps\n"); return false; } - FILE* mapsFile = fopen(mapPath, "r"); + FILE* mapsFile = fopen(mapPath, "rb"); if (mapsFile == nullptr) { printf_error("Problem reading maps file: fopen(%s) FAILED %s (%d)\n", mapPath, strerror(errno), errno); @@ -554,7 +554,7 @@ GetStatus(pid_t pid, pid_t* ppid, pid_t* tgid, std::string* name) return false; } - FILE *statusFile = fopen(statusPath, "r"); + FILE *statusFile = fopen(statusPath, "rb"); if (statusFile == nullptr) { printf_error("GetStatus fopen(%s) FAILED %s (%d)\n", statusPath, strerror(errno), errno); diff --git a/src/coreclr/debug/createdump/createdumppal.cpp b/src/coreclr/debug/createdump/createdumppal.cpp index 4dd7204ce91fd..03b06a84a4613 100644 --- a/src/coreclr/debug/createdump/createdumppal.cpp +++ b/src/coreclr/debug/createdump/createdumppal.cpp @@ -230,26 +230,6 @@ size_t u16_strlen(const WCHAR* str) // #ifdef _DEBUG - -PAL_FILE * -__cdecl -PAL_get_stderr(int caller) -{ - return (PAL_FILE*)stderr; -} - -int -__cdecl -PAL_fprintf(PAL_FILE* stream, const char* format, ...) -{ - va_list args; - va_start(args, format); - int result = vfprintf((FILE*)stream, format, args); - fflush((FILE*)stream); - va_end(args); - return result; -} - DWORD PALAPI GetCurrentProcessId() diff --git a/src/coreclr/dlls/mscordac/mscordac_unixexports.src b/src/coreclr/dlls/mscordac/mscordac_unixexports.src index 6cdd5ff733bcf..1eb94680cb6dd 100644 --- a/src/coreclr/dlls/mscordac/mscordac_unixexports.src +++ b/src/coreclr/dlls/mscordac/mscordac_unixexports.src @@ -25,8 +25,6 @@ nativeStringResourceTable_mscorrc #PAL_bsearch #PAL_CopyModuleData #PAL_errno -#PAL_fflush -#PAL__flushall #PAL_free #PAL_GetLogicalCpuCountFromOS #PAL_GetTotalCpuCount @@ -52,7 +50,6 @@ nativeStringResourceTable_mscorrc #PAL_malloc #PAL_realloc #PAL_qsort -#PAL_fprintf #PAL__wcstoui64 #PAL_wcstoul #PAL_wcstod @@ -65,9 +62,6 @@ nativeStringResourceTable_mscorrc #PAL_wcschr #PAL_wcscat #PAL_wcsstr -#PAL__open -#PAL__pread -#PAL__close #_wcsicmp #_stricmp diff --git a/src/coreclr/gc/unix/cgroup.cpp b/src/coreclr/gc/unix/cgroup.cpp index d2ad75bbf787b..b7b9c37ae5652 100644 --- a/src/coreclr/gc/unix/cgroup.cpp +++ b/src/coreclr/gc/unix/cgroup.cpp @@ -213,7 +213,7 @@ class CGroup char *mountpath = nullptr; char *mountroot = nullptr; - FILE *mountinfofile = fopen(PROC_MOUNTINFO_FILENAME, "r"); + FILE *mountinfofile = fopen(PROC_MOUNTINFO_FILENAME, "rb"); if (mountinfofile == nullptr) goto done; @@ -302,7 +302,7 @@ class CGroup char *cgroup_path = nullptr; bool result = false; - FILE *cgroupfile = fopen(PROC_CGROUP_FILENAME, "r"); + FILE *cgroupfile = fopen(PROC_CGROUP_FILENAME, "rb"); if (cgroupfile == nullptr) goto done; @@ -388,7 +388,7 @@ class CGroup if (asprintf(&stat_filename, "%s%s", s_memory_cgroup_path, CGROUP_MEMORY_STAT_FILENAME) < 0) return false; - FILE *stat_file = fopen(stat_filename, "r"); + FILE *stat_file = fopen(stat_filename, "rb"); free(stat_filename); if (stat_file == nullptr) return false; @@ -625,7 +625,7 @@ bool GetPhysicalMemoryUsed(size_t* val) return true; // process resident set size. - FILE* file = fopen(PROC_STATM_FILENAME, "r"); + FILE* file = fopen(PROC_STATM_FILENAME, "rb"); if (file != nullptr && getline(&line, &linelen, file) != -1) { char* context = nullptr; diff --git a/src/coreclr/gc/unix/gcenv.unix.cpp b/src/coreclr/gc/unix/gcenv.unix.cpp index 6f1a254a0528c..a6f3f0f098769 100644 --- a/src/coreclr/gc/unix/gcenv.unix.cpp +++ b/src/coreclr/gc/unix/gcenv.unix.cpp @@ -832,7 +832,7 @@ bool ReadMemoryValueFromFile(const char* filename, uint64_t* val) if (val == nullptr) goto done; - file = fopen(filename, "r"); + file = fopen(filename, "rb"); if (file == nullptr) goto done; @@ -1037,7 +1037,7 @@ static uint64_t GetMemorySizeMultiplier(char units) static bool ReadMemAvailable(uint64_t* memAvailable) { bool foundMemAvailable = false; - FILE* memInfoFile = fopen("/proc/meminfo", "r"); + FILE* memInfoFile = fopen("/proc/meminfo", "rb"); if (memInfoFile != NULL) { char *line = nullptr; @@ -1170,7 +1170,7 @@ static size_t GetCurrentVirtualMemorySize() char* line = nullptr; // process virtual memory size is reported in the first column of the /proc/self/statm - FILE* file = fopen("/proc/self/statm", "r"); + FILE* file = fopen("/proc/self/statm", "rb"); if (file != nullptr && getline(&line, &linelen, file) != -1) { // The first column of the /proc/self/statm contains the virtual memory size diff --git a/src/coreclr/ilasm/main.cpp b/src/coreclr/ilasm/main.cpp index 838f05aa996cf..0fe683838d899 100644 --- a/src/coreclr/ilasm/main.cpp +++ b/src/coreclr/ilasm/main.cpp @@ -531,7 +531,8 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) else { InvalidOption: - fprintf(stderr, "Error : Invalid Option: %LS\n", argv[i]); + MAKE_UTF8PTR_FROMWIDE_NOTHROW(invalidOpt, argv[i]); + fprintf(stderr, "Error : Invalid Option: %s\n", invalidOpt); goto ErrorExit; } } diff --git a/src/coreclr/ildasm/dasm.cpp b/src/coreclr/ildasm/dasm.cpp index 860b36f2e9366..be95e36fa5d53 100644 --- a/src/coreclr/ildasm/dasm.cpp +++ b/src/coreclr/ildasm/dasm.cpp @@ -7352,9 +7352,14 @@ void CloseNamespace(__inout __nullterminated char* szString) FILE* OpenOutput(_In_ __nullterminated const WCHAR* wzFileName) { +#ifdef HOST_WINDOWS FILE* pfile = NULL; if(g_uCodePage == 0xFFFFFFFF) _wfopen_s(&pfile,wzFileName,W("wb")); else _wfopen_s(&pfile,wzFileName,W("wt")); +#else + FILE* pfile = NULL; + _wfopen_s(&pfile,wzFileName,W("w")); +#endif if(pfile) { diff --git a/src/coreclr/ildasm/dis.cpp b/src/coreclr/ildasm/dis.cpp index 58c86e0e9ae74..21fc8c8679028 100644 --- a/src/coreclr/ildasm/dis.cpp +++ b/src/coreclr/ildasm/dis.cpp @@ -1113,14 +1113,19 @@ BOOL Disassemble(IMDInternalImport *pImport, BYTE *ILHeader, void *GUICookie, md { if(pFile) fclose(pFile); pFile = NULL; - if(fopen_s(&pFile,szFileName,"rt") != 0) +#ifdef HOST_WINDOWS + const char* const mode = "rt"; +#else + const char* const mode = "r"; +#endif + if(fopen_s(&pFile,szFileName, mode) != 0) { char* pch = strrchr(szFileName, DIRECTORY_SEPARATOR_CHAR_A); #ifdef HOST_WINDOWS if(pch == NULL) pch = strrchr(szFileName,':'); #endif pFile = NULL; - if(pch) fopen_s(&pFile,pch+1,"rt"); + if(pch) fopen_s(&pFile,pch+1, mode); } if(bIsNewFile) { diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index 1a67e6203501f..8a0308b83a193 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -3981,28 +3981,13 @@ PAL_GetCurrentThreadAffinitySet(SIZE_T size, UINT_PTR* data); #ifndef PAL_STDCPP_COMPAT #define exit PAL_exit #define realloc PAL_realloc -#define fopen PAL_fopen #define strtoul PAL_strtoul #define strtoull PAL_strtoull -#define fprintf PAL_fprintf -#define vfprintf PAL_vfprintf #define rand PAL_rand #define time PAL_time #define getenv PAL_getenv -#define fgets PAL_fgets #define qsort PAL_qsort #define bsearch PAL_bsearch -#define ferror PAL_ferror -#define fread PAL_fread -#define fwrite PAL_fwrite -#define ftell PAL_ftell -#define fclose PAL_fclose -#define fflush PAL_fflush -#define fputs PAL_fputs -#define fseek PAL_fseek -#define fgetpos PAL_fgetpos -#define fsetpos PAL_fsetpos -#define setvbuf PAL_setvbuf #define acos PAL_acos #define asin PAL_asin #define atan2 PAL_atan2 @@ -4024,10 +4009,6 @@ PAL_GetCurrentThreadAffinitySet(SIZE_T size, UINT_PTR* data); #define malloc PAL_malloc #define free PAL_free #define _strdup PAL__strdup -#define _open PAL__open -#define _pread PAL__pread -#define _close PAL__close -#define _flushall PAL__flushall #define strnlen PAL_strnlen #ifdef HOST_AMD64 @@ -4105,6 +4086,58 @@ PALIMPORT int __cdecl iswxdigit(wint_t); PALIMPORT wint_t __cdecl towupper(wint_t); PALIMPORT wint_t __cdecl towlower(wint_t); PALIMPORT int remove(const char*); + +#define SEEK_SET 0 +#define SEEK_CUR 1 +#define SEEK_END 2 + +/* Locale categories */ +#define LC_ALL 0 +#define LC_COLLATE 1 +#define LC_CTYPE 2 +#define LC_MONETARY 3 +#define LC_NUMERIC 4 +#define LC_TIME 5 + +#define _IOFBF 0 /* setvbuf should set fully buffered */ +#define _IOLBF 1 /* setvbuf should set line buffered */ +#define _IONBF 2 /* setvbuf should set unbuffered */ + +struct _FILE; + +#ifndef SKIP_STD_FILE_DECLS +typedef struct _FILE FILE; +extern FILE * stdout; +extern FILE * stdin; +extern FILE * stderr; +#else +#define FILE _PAL_FILE +struct _PAL_FILE; +#endif // SKIP_STD_FILE_DECLS + +PALIMPORT int __cdecl fclose(FILE *); +PALIMPORT int __cdecl fflush(FILE *); +PALIMPORT size_t __cdecl fwrite(const void *, size_t, size_t, FILE *); +PALIMPORT size_t __cdecl fread(void *, size_t, size_t, FILE *); +PALIMPORT char * __cdecl fgets(char *, int, FILE *); +PALIMPORT int __cdecl fputs(const char *, FILE *); +PALIMPORT int __cdecl fprintf(FILE *, const char *, ...); +PALIMPORT int __cdecl vfprintf(FILE *, const char *, va_list); +PALIMPORT int __cdecl fseek(FILE *, LONG, int); +PALIMPORT LONG __cdecl ftell(FILE *); +PALIMPORT int __cdecl ferror(FILE *); +PALIMPORT FILE * __cdecl fopen(const char *, const char *); +PALIMPORT int __cdecl setvbuf(FILE *stream, char *, int, size_t); + +#ifdef SKIP_STD_FILE_DECLS +#undef FILE +#endif + +// We need a PAL shim for errno as it's not possible to replicate the errno definition from the standard library +// in all cases. Instead, we shim it and implement the PAL function where we can include the standard headers. +// When we allow people to include the standard headers, then we can remove this. +PALIMPORT DLLEXPORT int * __cdecl PAL_errno(); +#define errno (*PAL_errno()) #endif // PAL_STDCPP_COMPAT /* _TRUNCATE */ @@ -4144,6 +4177,10 @@ PALIMPORT errno_t __cdecl _wcslwr_s(WCHAR *, size_t sz); PALIMPORT DLLEXPORT errno_t __cdecl _i64tow_s(long long, WCHAR *, size_t, int); PALIMPORT int __cdecl _wtoi(const WCHAR *); +#ifndef SKIP_STD_FILE_DECLS +PALIMPORT FILE * __cdecl _wfopen(const WCHAR *, const WCHAR *); +#endif + #ifdef __cplusplus extern "C++" { inline WCHAR *PAL_wcschr(WCHAR* S, WCHAR C) @@ -4324,56 +4361,6 @@ PALIMPORT time_t __cdecl time(time_t *); #endif // !PAL_STDCPP_COMPAT -PALIMPORT DLLEXPORT int __cdecl _open(const char *szPath, int nFlags, ...); -PALIMPORT DLLEXPORT size_t __cdecl _pread(int fd, void *buf, size_t nbytes, ULONG64 offset); -PALIMPORT DLLEXPORT int __cdecl _close(int); -PALIMPORT DLLEXPORT int __cdecl _flushall(); - -#ifdef PAL_STDCPP_COMPAT - -struct _PAL_FILE; -typedef struct _PAL_FILE PAL_FILE; - -#else // PAL_STDCPP_COMPAT - -struct _FILE; -typedef struct _FILE FILE; -typedef struct _FILE PAL_FILE; - -#define SEEK_SET 0 -#define SEEK_CUR 1 -#define SEEK_END 2 - -/* Locale categories */ -#define LC_ALL 0 -#define LC_COLLATE 1 -#define LC_CTYPE 2 -#define LC_MONETARY 3 -#define LC_NUMERIC 4 -#define LC_TIME 5 - -#define _IOFBF 0 /* setvbuf should set fully buffered */ -#define _IOLBF 1 /* setvbuf should set line buffered */ -#define _IONBF 2 /* setvbuf should set unbuffered */ - -#endif // PAL_STDCPP_COMPAT - -PALIMPORT int __cdecl PAL_fclose(PAL_FILE *); -PALIMPORT DLLEXPORT int __cdecl PAL_fflush(PAL_FILE *); -PALIMPORT size_t __cdecl PAL_fwrite(const void *, size_t, size_t, PAL_FILE *); -PALIMPORT size_t __cdecl PAL_fread(void *, size_t, size_t, PAL_FILE *); -PALIMPORT char * __cdecl PAL_fgets(char *, int, PAL_FILE *); -PALIMPORT int __cdecl PAL_fputs(const char *, PAL_FILE *); -PALIMPORT DLLEXPORT int __cdecl PAL_fprintf(PAL_FILE *, const char *, ...); -PALIMPORT int __cdecl PAL_vfprintf(PAL_FILE *, const char *, va_list); -PALIMPORT int __cdecl PAL_fseek(PAL_FILE *, LONG, int); -PALIMPORT LONG __cdecl PAL_ftell(PAL_FILE *); -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 _wfopen(const WCHAR *, const WCHAR *); - /* Maximum value that can be returned by the rand function. */ #ifndef PAL_STDCPP_COMPAT @@ -4383,29 +4370,6 @@ PALIMPORT PAL_FILE * __cdecl _wfopen(const WCHAR *, const WCHAR *); PALIMPORT int __cdecl rand(void); PALIMPORT void __cdecl srand(unsigned int); -#ifdef _MSC_VER -#define PAL_get_caller _MSC_VER -#else -#define PAL_get_caller 0 -#endif - -PALIMPORT DLLEXPORT PAL_FILE * __cdecl PAL_get_stdout(int caller); -PALIMPORT PAL_FILE * __cdecl PAL_get_stdin(int caller); -PALIMPORT DLLEXPORT PAL_FILE * __cdecl PAL_get_stderr(int caller); -PALIMPORT DLLEXPORT int * __cdecl PAL_errno(int caller); - -#ifdef PAL_STDCPP_COMPAT -#define PAL_stdout (PAL_get_stdout(PAL_get_caller)) -#define PAL_stdin (PAL_get_stdin(PAL_get_caller)) -#define PAL_stderr (PAL_get_stderr(PAL_get_caller)) -#define PAL_errno (*PAL_errno(PAL_get_caller)) -#else // PAL_STDCPP_COMPAT -#define stdout (PAL_get_stdout(PAL_get_caller)) -#define stdin (PAL_get_stdin(PAL_get_caller)) -#define stderr (PAL_get_stderr(PAL_get_caller)) -#define errno (*PAL_errno(PAL_get_caller)) -#endif // PAL_STDCPP_COMPAT - PALIMPORT DLLEXPORT char * __cdecl getenv(const char *); PALIMPORT DLLEXPORT int __cdecl _putenv(const char *); diff --git a/src/coreclr/pal/inc/pal_assert.h b/src/coreclr/pal/inc/pal_assert.h index 87af991d9abbc..a4b49c1ddafc5 100644 --- a/src/coreclr/pal/inc/pal_assert.h +++ b/src/coreclr/pal/inc/pal_assert.h @@ -35,7 +35,7 @@ extern "C" { #if defined(_DEBUG) #define _ASSERTE(e) do { \ if (!(e)) { \ - PAL_fprintf (PAL_get_stderr(PAL_get_caller), \ + fprintf (stderr, \ "ASSERT FAILED\n" \ "\tExpression: %s\n" \ "\tLocation: line %d in %s\n" \ diff --git a/src/coreclr/pal/inc/rt/palrt.h b/src/coreclr/pal/inc/rt/palrt.h index 1e52727ccdba9..1f7f413456965 100644 --- a/src/coreclr/pal/inc/rt/palrt.h +++ b/src/coreclr/pal/inc/rt/palrt.h @@ -681,9 +681,9 @@ inline int __cdecl _vscprintf_unsafe(const char *_Format, va_list _ArgList) } } -inline errno_t __cdecl _wfopen_unsafe(PAL_FILE * *ff, const WCHAR *fileName, const WCHAR *mode) +inline errno_t __cdecl _wfopen_unsafe(FILE * *ff, const WCHAR *fileName, const WCHAR *mode) { - PAL_FILE *result = _wfopen(fileName, mode); + FILE *result = _wfopen(fileName, mode); if(result == 0) { return 1; } else { @@ -692,9 +692,9 @@ inline errno_t __cdecl _wfopen_unsafe(PAL_FILE * *ff, const WCHAR *fileName, con } } -inline errno_t __cdecl _fopen_unsafe(PAL_FILE * *ff, const char *fileName, const char *mode) +inline errno_t __cdecl _fopen_unsafe(FILE * *ff, const char *fileName, const char *mode) { - PAL_FILE *result = PAL_fopen(fileName, mode); + FILE *result = fopen(fileName, mode); if(result == 0) { return 1; } else { diff --git a/src/coreclr/pal/src/CMakeLists.txt b/src/coreclr/pal/src/CMakeLists.txt index 291f7ee2b031b..5e1493f5aea2f 100644 --- a/src/coreclr/pal/src/CMakeLists.txt +++ b/src/coreclr/pal/src/CMakeLists.txt @@ -129,12 +129,9 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND (CLR_CMAKE_HOST_ARCH_AMD64 OR CLR_CM endif() set(SOURCES - cruntime/file.cpp - cruntime/filecrt.cpp cruntime/malloc.cpp cruntime/math.cpp cruntime/misc.cpp - cruntime/printfcpp.cpp cruntime/string.cpp cruntime/thread.cpp cruntime/wchar.cpp diff --git a/src/coreclr/pal/src/cruntime/file.cpp b/src/coreclr/pal/src/cruntime/file.cpp deleted file mode 100644 index a7a7a12a33375..0000000000000 --- a/src/coreclr/pal/src/cruntime/file.cpp +++ /dev/null @@ -1,665 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*++ - - - -Module Name: - - file.c - -Abstract: - - Implementation of the file functions in the C runtime library that - are Windows specific. - - - ---*/ - -#include "pal/palinternal.h" -#include "pal/dbgmsg.h" -#include "pal/file.h" -#include "pal/cruntime.h" - -#include "pal/thread.hpp" -#include "pal/threadsusp.hpp" - -#include -#include -#include -#include - -#if FILE_OPS_CHECK_FERROR_OF_PREVIOUS_CALL - #define CLEARERR(f) clearerr((f)->bsdFilePtr) -#else - #define CLEARERR(f) -#endif - -SET_DEFAULT_DEBUG_CHANNEL(CRT); - -/* Global variables storing the std streams.*/ -PAL_FILE PAL_Stdout; -PAL_FILE PAL_Stdin; -PAL_FILE PAL_Stderr; - -/*++ - -Function: - - CRTInitStdStreams. - - Initializes the standard streams. - Returns TRUE on success, FALSE otherwise. ---*/ -BOOL CRTInitStdStreams() -{ - /* stdout */ - PAL_Stdout.bsdFilePtr = stdout; - PAL_Stdout.PALferrorCode = PAL_FILE_NOERROR; - PAL_Stdout.bTextMode = TRUE; - - /* stdin */ - PAL_Stdin.bsdFilePtr = stdin; - PAL_Stdin.PALferrorCode = PAL_FILE_NOERROR; - PAL_Stdin.bTextMode = TRUE; - - /* stderr */ - PAL_Stderr.bsdFilePtr = stderr; - PAL_Stderr.PALferrorCode = PAL_FILE_NOERROR; - PAL_Stderr.bTextMode = TRUE; - return TRUE; -} - -/*++ -Function : - - MapFileOpenModes - - Maps Windows file open modes to Unix fopen modes and validates. - ---*/ -static LPSTR MapFileOpenModes(LPSTR str , BOOL * bTextMode) -{ - LPSTR retval = NULL; - LPSTR temp = NULL; - - if (NULL == bTextMode) - { - ASSERT("MapFileOpenModes called with a NULL parameter for bTextMode.\n"); - return NULL; - } - - *bTextMode = TRUE; - - if (NULL == str) - { - ASSERT("MapFileOpenModes called with a NULL parameter for str.\n"); - return NULL; - } - - /* The PAL behaves differently for some Windows file open modes: - - c, n, S, R, and T: these are all hints to the system that aren't supported - by the PAL. Since the user cannot depend on this behavior, it's safe to - simply ignore these modes. - - D: specifies a file as temporary. This file is expected to be deleted when - the last file descriptor is closed. The PAL does not support this behavior - and asserts when this mode is used. - - t: represents opening in text mode. Calls to fdopen on Unix don't accept - 't' so it is silently stripped out. However, the PAL supports the mode by - having the PAL wrappers do the translation of CR-LF to LF and vice versa. - - t vs. b: To get binary mode, you must explicitly use 'b'. If neither mode - is specified on Windows, the default mode is defined by the global - variable _fmode. The PAL simply defaults to text mode. After examining - CLR usage patterns, the PAL behavior seems acceptable. */ - - /* Check if the mode specifies deleting the temporary file - automatically when the last file descriptor is closed. - The PAL does not support this behavior. */ - if (NULL != strchr(str,'D')) - { - ASSERT("The PAL doesn't support the 'D' flag for fopen.\n"); - return NULL; - } - - /* Check if the mode specifies opening in binary. - If so, set the bTextMode to false. */ - if(NULL != strchr(str,'b')) - { - *bTextMode = FALSE; - } - - retval = (LPSTR)PAL_malloc( ( strlen( str ) + 1 ) * sizeof( CHAR ) ); - if (NULL == retval) - { - ERROR("Unable to allocate memory.\n"); - return NULL; - } - - temp = retval; - while ( *str ) - { - if ( *str == 'r' || *str == 'w' || *str == 'a' ) - { - *temp = *str; - temp++; - if ( ( ++str != NULL ) && *str == '+' ) - { - *temp = *str; - temp++; - str++; - } - } - else - { - str++; - } - } - *temp = '\0'; - return retval; -} - -#if UNGETC_NOT_RETURN_EOF -/*++ -Function : - - WriteOnlyMode - - Returns TRUE to if a file is opened in write-only mode, - Otherwise FALSE. - ---*/ -static BOOL WriteOnlyMode(FILE* pFile) -{ - INT fd, flags; - - if (pFile != NULL) - { - fd = fileno(pFile); - if ((flags = fcntl(fd, F_GETFL)) >= 0) - { - if ((flags & O_ACCMODE) == O_WRONLY) - { - return TRUE; - } - } - } - return FALSE; -} -#endif //UNGETC_NOT_RETURN_EOF - -/*++ - -Function : - fopen - -see MSDN doc. - ---*/ -PAL_FILE * -__cdecl -PAL_fopen(const char * fileName, const char * mode) -{ - PAL_FILE *f = NULL; - LPSTR supported = NULL; - LPSTR UnixFileName = NULL; - struct stat stat_data; - BOOL bTextMode = TRUE; - - PERF_ENTRY(fopen); - ENTRY("fopen ( fileName=%p (%s) mode=%p (%s))\n", fileName, fileName, mode , mode ); - - _ASSERTE(fileName != NULL); - _ASSERTE(mode != NULL); - - if ( *mode == 'r' || *mode == 'w' || *mode == 'a' ) - { - supported = MapFileOpenModes( (char*)mode,&bTextMode); - - if ( !supported ) - { - goto done; - } - - UnixFileName = PAL__strdup(fileName); - if (UnixFileName == NULL ) - { - ERROR("PAL__strdup() failed\n"); - SetLastError(ERROR_NOT_ENOUGH_MEMORY); - goto done; - } - - /*I am not checking for the case where stat fails - *as fopen will handle the error more gracefully in case - *UnixFileName is invalid*/ - if ((stat(UnixFileName, &stat_data) == 0 ) && - ((stat_data.st_mode & S_IFMT) == S_IFDIR)) - { - goto done; - } - - f = (PAL_FILE*)PAL_malloc( sizeof( PAL_FILE ) ); - if ( f ) - { - f->bsdFilePtr = (FILE*)fopen( UnixFileName, supported ); - f->PALferrorCode = PAL_FILE_NOERROR; - f->bTextMode = bTextMode; - if ( !f->bsdFilePtr ) - { - /* Failed */ - PAL_free( f ); - f = NULL; - } -#if UNGETC_NOT_RETURN_EOF - else - { - f->bWriteOnlyMode = WriteOnlyMode(f->bsdFilePtr); - } -#endif //UNGETC_NOT_RETURN_EOF - } - else - { - ERROR( "Unable to allocate memory to the PAL_FILE wrapper\n" ); - } - } - else - { - ERROR( "The mode flags must start with either an a, w, or r.\n" ); - } - -done: - PAL_free( supported ); - supported = NULL; - PAL_free( UnixFileName ); - - LOGEXIT( "fopen returns FILE* %p\n", f ); - PERF_EXIT(fopen); - return f; -} - -/*++ -Function: - _wfopen - -see MSDN doc. - ---*/ -PAL_FILE * -__cdecl -_wfopen( - const wchar_16 *fileName, - const wchar_16 *mode) -{ - CHAR mbFileName[ _MAX_PATH ]; - CHAR mbMode[ 10 ]; - PAL_FILE * filePtr = NULL; - - PERF_ENTRY(_wfopen); - ENTRY("_wfopen(fileName:%p (%S), mode:%p (%S))\n", fileName, fileName, mode, mode); - - _ASSERTE(fileName != NULL); - _ASSERTE(mode != NULL); - - /* Convert the parameters to ASCII and defer to PAL_fopen */ - if ( WideCharToMultiByte( CP_ACP, 0, fileName, -1, mbFileName, - sizeof mbFileName, NULL, NULL ) != 0 ) - { - if ( WideCharToMultiByte( CP_ACP, 0, mode, -1, mbMode, - sizeof mbMode, NULL, NULL ) != 0 ) - { - filePtr = PAL_fopen(mbFileName, mbMode); - } - else - { - ERROR( "An error occurred while converting mode to ANSI.\n" ); - } - } - else - { - ERROR( "An error occurred while converting" - " fileName to ANSI string.\n" ); - } - LOGEXIT("_wfopen returning FILE* %p\n", filePtr); - PERF_EXIT(_wfopen); - return filePtr; -} - -/*++ -Function - PAL_get_stdout. - - Returns the stdout stream. ---*/ -PAL_FILE * __cdecl PAL_get_stdout(int caller) -{ - PERF_ENTRY(get_stdout); - ENTRY("PAL_get_stdout\n"); - LOGEXIT("PAL_get_stdout returns PAL_FILE * %p\n", &PAL_Stdout ); - PERF_EXIT(get_stdout); - return &PAL_Stdout; -} - -/*++ -Function - PAL_get_stdin. - - Returns the stdin stream. ---*/ -PAL_FILE * __cdecl PAL_get_stdin(int caller) -{ - PERF_ENTRY(get_stdin); - ENTRY("PAL_get_stdin\n"); - LOGEXIT("PAL_get_stdin returns PAL_FILE * %p\n", &PAL_Stdin ); - PERF_EXIT(get_stdin); - return &PAL_Stdin; -} - -/*++ -Function - PAL_get_stderr. - - Returns the stderr stream. ---*/ -PAL_FILE * __cdecl PAL_get_stderr(int caller) -{ - PERF_ENTRY(get_stderr); - ENTRY("PAL_get_stderr\n"); - LOGEXIT("PAL_get_stderr returns PAL_FILE * %p\n", &PAL_Stderr ); - PERF_EXIT(get_stderr); - return &PAL_Stderr; -} - -/*++ - -Function: - - PAL_pread - -See msdn for more details. ---*/ -size_t __cdecl PAL__pread(int fd, void *buf, size_t nbytes, ULONG64 offset) -{ - return pread(fd, buf, nbytes, offset); -} - -/*++ - -Function: - - _close - -See msdn for more details. ---*/ -int __cdecl PAL__close(int handle) -{ - INT nRetVal = 0; - - PERF_ENTRY(_close); - ENTRY( "_close( handle=%d )\n", handle ); - - nRetVal = close( handle ); - - LOGEXIT( "_close returning %d.\n", nRetVal ); - PERF_EXIT(_close); - return nRetVal; -} - -int __cdecl PAL__flushall() -{ - return fflush(NULL); -} - -int __cdecl PAL_getc(PAL_FILE *stream); - -/*++ -Function : - - fread - - See MSDN for more details. ---*/ - -size_t -__cdecl -PAL_fread(void * buffer, size_t size, size_t count, PAL_FILE * f) -{ - size_t nReadBytes = 0; - - PERF_ENTRY(fread); - ENTRY( "fread( buffer=%p, size=%d, count=%d, f=%p )\n", - buffer, size, count, f ); - - _ASSERTE(f != NULL); - - CLEARERR(f); - - if(f->bTextMode != TRUE) - { - nReadBytes = fread( buffer, size, count, f->bsdFilePtr ); - } - else - { - size_t i=0; - if(size > 0) - { - size_t j=0; - LPSTR temp = (LPSTR)buffer; - int nChar = 0; - int nCount =0; - - for(i=0; i< count; i++) - { - for(j=0; j< size; j++) - { - if((nChar = PAL_getc(f)) == EOF) - { - nReadBytes = i; - goto done; - } - else - { - temp[nCount++]= (char)nChar; - } - } - } - } - nReadBytes = i; - } - -done: - LOGEXIT( "fread returning size_t %d\n", nReadBytes ); - PERF_EXIT(fread); - return nReadBytes; -} - - -/*++ -Function : - - ferror - - See MSDN for more details. ---*/ -int -_cdecl -PAL_ferror(PAL_FILE * f) -{ - INT nErrorCode = PAL_FILE_NOERROR; - - PERF_ENTRY(ferror); - ENTRY( "ferror( f=%p )\n", f ); - - _ASSERTE(f != NULL); - - nErrorCode = ferror( f->bsdFilePtr ); - if ( 0 == nErrorCode ) - { - /* See if the PAL file error code is set. */ - nErrorCode = f->PALferrorCode; - } - - LOGEXIT( "ferror returns %d\n", nErrorCode ); - PERF_EXIT(ferror); - return nErrorCode; -} - - -/*++ -Function : - - fclose - - See MSDN for more details. ---*/ -int -_cdecl -PAL_fclose(PAL_FILE * f) -{ - INT nRetVal = 0; - - PERF_ENTRY(fclose); - ENTRY( "fclose( f=%p )\n", f ); - - _ASSERTE(f != NULL); - - CLEARERR(f); - - nRetVal = fclose( f->bsdFilePtr ); - PAL_free( f ); - - LOGEXIT( "fclose returning %d\n", nRetVal ); - PERF_EXIT(fclose); - return nRetVal; -} - -/*++ -Function : - - fputs - - See MSDN for more details. ---*/ -int -_cdecl -PAL_fputs(const char * str, PAL_FILE * f) -{ - INT nRetVal = 0; - - PERF_ENTRY(fputs); - ENTRY( "fputs( %p (%s), %p )\n", str, str, f); - - _ASSERTE(str != NULL); - _ASSERTE(f != NULL); - - CLEARERR(f); - - nRetVal = fputs( str, f->bsdFilePtr ); - - LOGEXIT( "fputs returning %d\n", nRetVal ); - PERF_EXIT(fputs); - return nRetVal; -} - -/*++ -Function : - - ftell - - See MSDN for more details. ---*/ -LONG -_cdecl -PAL_ftell(PAL_FILE * f) -{ - long lRetVal = 0; - - PERF_ENTRY(ftell); - ENTRY( "ftell( %p )\n", f ); - - _ASSERTE(f != NULL); - lRetVal = ftell( f->bsdFilePtr ); - -#ifdef HOST_64BIT - /* Windows does not set an error if the file pointer's position - is greater than _I32_MAX. It just returns -1. */ - if (lRetVal > _I32_MAX) - { - lRetVal = -1; - } -#endif - - LOGEXIT( "ftell returning %ld\n", lRetVal ); - PERF_EXIT(ftell); - /* This explicit cast to LONG is used to silence any potential warnings - due to implicitly casting the native long lRetVal to LONG when returning. */ - return (LONG)lRetVal; -} - -/*++ -Function : - getc - - See MSDN for more details. ---*/ -int -_cdecl -PAL_getc(PAL_FILE * f) -{ - INT nRetVal = 0; - INT temp =0; - - PERF_ENTRY(getc); - ENTRY( "getc( %p )\n", f ); - - _ASSERTE(f != NULL); - - CLEARERR(f); - - nRetVal = getc( f->bsdFilePtr ); - - if ( (f->bTextMode) && (nRetVal == '\r') ) - { - if ((temp = getc( f->bsdFilePtr ))== '\n') - { - nRetVal ='\n'; - } - else if (EOF == ungetc( temp, f->bsdFilePtr )) - { - ERROR("ungetc operation failed\n"); - } - } - - LOGEXIT( "getc returning %d\n", nRetVal ); - PERF_EXIT(getc); - return nRetVal; -} - -/*++ -Function : - - setvbuf - - See MSDN for more details. ---*/ -int -_cdecl -PAL_setvbuf(PAL_FILE *f, char *buf, int type, size_t size) -{ - INT nRetVal = 0; - - PERF_ENTRY(setvbuf); - ENTRY( "setvbuf( %p, %p, %d, %ul )\n", f, buf, type, size); - - _ASSERTE(f != NULL); - - nRetVal = setvbuf(f->bsdFilePtr, buf, type, size); - - LOGEXIT( "setvbuf returning %d\n", nRetVal ); - PERF_EXIT(setvbuf); - return nRetVal; -} diff --git a/src/coreclr/pal/src/cruntime/filecrt.cpp b/src/coreclr/pal/src/cruntime/filecrt.cpp deleted file mode 100644 index 5d2fe0e5d999f..0000000000000 --- a/src/coreclr/pal/src/cruntime/filecrt.cpp +++ /dev/null @@ -1,378 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*++ - -Module Name: - - filecrt.cpp - -Abstract: - - Implementation of the file functions in the C runtime library that - are Windows specific. - ---*/ - -#include "pal/thread.hpp" -#include "pal/file.hpp" - -#include "pal/palinternal.h" -#include "pal/dbgmsg.h" -#include "pal/file.h" -#include "pal/cruntime.h" - -#include -#include -#include - -#ifdef __APPLE__ -#include -#endif // __APPLE__ - -using namespace CorUnix; - -SET_DEFAULT_DEBUG_CHANNEL(CRT); - -/*++ -Function: - PAL_fflush - -See MSDN for more details. ---*/ -int -_cdecl -PAL_fflush( PAL_FILE *stream ) -{ - int nRetVal = 0; - - PERF_ENTRY(fflush); - ENTRY( "fflush( %p )\n", stream ); - - nRetVal = fflush(stream ? stream->bsdFilePtr : NULL); - - LOGEXIT( "fflush returning %d\n", nRetVal ); - PERF_EXIT(fflush); - return nRetVal; -} - - -/*++ -PAL__open - -Wrapper function for InternalOpen. - -Input parameters: - -szPath = pointer to a pathname of a file to be opened -nFlags = arguments that control how the file should be accessed -mode = file permission settings that are used only when a file is created - -Return value: - File descriptor on success, -1 on failure ---*/ -int -__cdecl -PAL__open( - const char *szPath, - int nFlags, - ... - ) -{ - int nRet = -1; - int mode = 0; - va_list ap; - - // If nFlags does not contain O_CREAT, the mode parameter will be ignored. - if (nFlags & O_CREAT) - { - va_start(ap, nFlags); - mode = va_arg(ap, int); - va_end(ap); - } - - nRet = InternalOpen(szPath, nFlags, mode); - return nRet; -} - -/*++ -InternalOpen - -Wrapper for open. - -Input parameters: - -szPath = pointer to a pathname of a file to be opened -nFlags = arguments that control how the file should be accessed -mode = file permission settings that are used only when a file is created - -Return value: - File descriptor on success, -1 on failure ---*/ -int -CorUnix::InternalOpen( - const char *szPath, - int nFlags, - ... - ) -{ - int nRet = -1; - int mode = 0; - va_list ap; - - // If nFlags does not contain O_CREAT, the mode parameter will be ignored. - if (nFlags & O_CREAT) - { - va_start(ap, nFlags); - mode = va_arg(ap, int); - va_end(ap); - } - - do - { -#if OPEN64_IS_USED_INSTEAD_OF_OPEN - nRet = open64(szPath, nFlags, mode); -#else - nRet = open(szPath, nFlags, mode); -#endif - } - while ((nRet == -1) && (errno == EINTR)); - - return nRet; -} - - -/*++ -PAL_fgets - -Wrapper function for InternalFgets. - -Input parameters: - -sz = stores characters read from the given file stream -nSize = number of characters to be read -pf = stream to read characters from - -Return value: - Returns a pointer to the string storing the characters on success - and NULL on failure. ---*/ -char * -__cdecl -PAL_fgets( - char *sz, - int nSize, - PAL_FILE *pf - ) -{ - char * szBuf; - - PERF_ENTRY(fgets); - ENTRY( "fgets(sz=%p (%s) nSize=%d pf=%p)\n", sz, sz, nSize, pf); - - if (pf != NULL) - { - szBuf = InternalFgets(sz, nSize, pf->bsdFilePtr, pf->bTextMode); - } - else - { - szBuf = NULL; - } - - LOGEXIT("fgets() returns %p\n", szBuf); - PERF_EXIT(fgets); - - return szBuf; -} - -/*++ -InternalFgets - -Wrapper for fgets. - -Input parameters: - -sz = stores characters read from the given file stream -nSize = number of characters to be read -f = stream to read characters from -fTextMode = flag that indicates if file contents are text or binary - -Return value: - Returns a pointer to the string storing the characters on success - and NULL on failure. - -Notes: -In Unix systems, fgets() can return an error if it gets interrupted by a -signal before reading anything, and errno is set to EINTR. When this -happens, it is SOP to call fgets again. ---*/ -char * -CorUnix::InternalFgets( - char *sz, - int nSize, - FILE *f, - bool fTextMode - ) -{ - char *retval = NULL; - - _ASSERTE(sz != NULL); - _ASSERTE(f != NULL); - -#if FILE_OPS_CHECK_FERROR_OF_PREVIOUS_CALL - clearerr(f); -#endif - - do - { - retval = fgets(sz, nSize, f); - if (NULL==retval) - { - if (feof(f)) - { - TRACE("Reached EOF\n"); - break; - } - /* The man page suggests using ferror and feof to distinguish - between error and EOF, but feof and errno is sufficient. - Not all cases that set errno also flag ferror, so just - checking errno is the best solution. */ - if (EINTR != errno) - { - WARN("got error; errno is %d (%s)\n",errno, strerror(errno)); - break; - } - /* we ignored a EINTR error, reset the stream's error state */ - clearerr(f); - TRACE("call got interrupted (EINTR), trying again\n"); - } - if (fTextMode) - { - int len = strlen(sz); - if ((len>=2) && (sz[len-1]=='\n') && (sz[len-2]=='\r')) - { - sz[len-2]='\n'; - sz[len-1]='\0'; - } - } - } while(NULL == retval); - - return retval; -} - -/*++ -PAL_fwrite - -Wrapper function for InternalFwrite. - -Input parameters: - -pvBuffer = array of objects to write to the given file stream -nSize = size of a object in bytes -nCount = number of objects to write -pf = stream to write characters to - -Return value: - Returns the number of objects written. ---*/ -size_t -__cdecl -PAL_fwrite( - const void *pvBuffer, - size_t nSize, - size_t nCount, - PAL_FILE *pf - ) -{ - size_t nWrittenBytes = 0; - - PERF_ENTRY(fwrite); - ENTRY( "fwrite( pvBuffer=%p, nSize=%d, nCount=%d, pf=%p )\n", - pvBuffer, nSize, nCount, pf); - _ASSERTE(pf != NULL); - - nWrittenBytes = InternalFwrite(pvBuffer, nSize, nCount, pf->bsdFilePtr, &pf->PALferrorCode); - - LOGEXIT( "fwrite returning size_t %d\n", nWrittenBytes ); - PERF_EXIT(fwrite); - return nWrittenBytes; -} - -/*++ -InternalFwrite - -Wrapper for fwrite. - -Input parameters: - -pvBuffer = array of objects to write to the given file stream -nSize = size of a object in bytes -nCount = number of objects to write -f = stream to write characters to -pnErrorCode = reference to a PAL_FILE's fwrite error code field - -Return value: - Returns the number of objects written. ---*/ -size_t -CorUnix::InternalFwrite( - const void *pvBuffer, - size_t nSize, - size_t nCount, - FILE *f, - INT *pnErrorCode - ) -{ - size_t nWrittenBytes = 0; - _ASSERTE(f != NULL); - -#if FILE_OPS_CHECK_FERROR_OF_PREVIOUS_CALL - clearerr(f); -#endif - - nWrittenBytes = fwrite(pvBuffer, nSize, nCount, f); - - // Make sure no error occurred. - if ( nWrittenBytes < nCount ) - { - // Set the FILE* error code - *pnErrorCode = PAL_FILE_ERROR; - } - - return nWrittenBytes; -} - - -/*++ -PAL_fseek - -Wrapper function for fseek. - -Input parameters: - -pf = 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 -_cdecl -PAL_fseek( - PAL_FILE * pf, - LONG lOffset, - int nWhence - ) -{ - int nRet = 0; - - PERF_ENTRY(fseek); - ENTRY( "fseek( %p, %ld, %d )\n", pf, lOffset, nWhence ); - - nRet = fseek(pf ? pf->bsdFilePtr : NULL, lOffset, nWhence); - - LOGEXIT("fseek returning %d\n", nRet); - PERF_EXIT(fseek); - return nRet; -} diff --git a/src/coreclr/pal/src/cruntime/misc.cpp b/src/coreclr/pal/src/cruntime/misc.cpp index 0820be8c2579e..66b347bcf06f0 100644 --- a/src/coreclr/pal/src/cruntime/misc.cpp +++ b/src/coreclr/pal/src/cruntime/misc.cpp @@ -108,8 +108,6 @@ __iscsym( int c ) PERF_EXIT(__iscsym); return 0; } - - /*++ Function : @@ -119,7 +117,7 @@ Function : Returns the address of the errno. --*/ -int * __cdecl PAL_errno( int caller ) +int * __cdecl PAL_errno() { int *retval; PERF_ENTRY(errno); @@ -130,7 +128,6 @@ int * __cdecl PAL_errno( int caller ) return retval; } - /*++ Function: diff --git a/src/coreclr/pal/src/cruntime/printfcpp.cpp b/src/coreclr/pal/src/cruntime/printfcpp.cpp deleted file mode 100644 index b9c1c92b9bc8d..0000000000000 --- a/src/coreclr/pal/src/cruntime/printfcpp.cpp +++ /dev/null @@ -1,84 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*++ - - - -Module Name: - - printfcpp.cpp - -Abstract: - - Implementation of suspension safe printf functions. - -Revision History: - - - ---*/ - -#include "pal/corunix.hpp" -#include "pal/thread.hpp" -#include "pal/malloc.hpp" -#include "pal/file.hpp" -#include "pal/printfcpp.hpp" -#include "pal/palinternal.h" -#include "pal/dbgmsg.h" -#include "pal/cruntime.h" - -#include - -SET_DEFAULT_DEBUG_CHANNEL(CRT); - -extern "C" -{ - -// Forward declare functions that are in header files we can't include yet -int vfprintf(FILE* stream, const char* format, va_list ap); - -/*++ -Function: - PAL_fprintf - -See MSDN doc. ---*/ -int -__cdecl -PAL_fprintf(PAL_FILE *stream,const char *format,...) -{ - LONG Length = 0; - va_list ap; - - PERF_ENTRY(fprintf); - ENTRY("PAL_fprintf(stream=%p,format=%p (%s))\n",stream, format, format); - - va_start(ap, format); - Length = vfprintf(stream->bsdFilePtr, format, ap); - va_end(ap); - - LOGEXIT("PAL_fprintf returns int %d\n", Length); - PERF_EXIT(fprintf); - return Length; -} - -/******************************************************************************* -Function: - PAL_vfprintf - -Parameters: - stream - - out stream - Format - - format string - ap - - stdarg parameter list -*******************************************************************************/ - -int __cdecl PAL_vfprintf(PAL_FILE *stream, const char *format, va_list ap) -{ - return vfprintf(stream->bsdFilePtr, format, ap); -} - -} // end extern "C" diff --git a/src/coreclr/pal/src/cruntime/wchar.cpp b/src/coreclr/pal/src/cruntime/wchar.cpp index 3d887aecdb883..59b9ead3ab87f 100644 --- a/src/coreclr/pal/src/cruntime/wchar.cpp +++ b/src/coreclr/pal/src/cruntime/wchar.cpp @@ -944,3 +944,51 @@ PAL_wcstod( const wchar_16 * nptr, wchar_16 **endptr ) PERF_EXIT(wcstod); return RetVal; } + +/*++ +Function: + _wfopen + +see MSDN doc. + +--*/ +extern "C" +FILE * +__cdecl +_wfopen( + const wchar_16 *fileName, + const wchar_16 *mode) +{ + CHAR mbFileName[ _MAX_PATH ]; + CHAR mbMode[ 10 ]; + FILE * filePtr = NULL; + + PERF_ENTRY(_wfopen); + ENTRY("_wfopen(fileName:%p (%S), mode:%p (%S))\n", fileName, fileName, mode, mode); + + _ASSERTE(fileName != NULL); + _ASSERTE(mode != NULL); + + /* Convert the parameters to ASCII and defer to PAL_fopen */ + if ( WideCharToMultiByte( CP_ACP, 0, fileName, -1, mbFileName, + sizeof mbFileName, NULL, NULL ) != 0 ) + { + if ( WideCharToMultiByte( CP_ACP, 0, mode, -1, mbMode, + sizeof mbMode, NULL, NULL ) != 0 ) + { + filePtr = fopen(mbFileName, mbMode); + } + else + { + ERROR( "An error occurred while converting mode to ANSI.\n" ); + } + } + else + { + ERROR( "An error occurred while converting" + " fileName to ANSI string.\n" ); + } + LOGEXIT("_wfopen returning FILE* %p\n", filePtr); + PERF_EXIT(_wfopen); + return filePtr; +} diff --git a/src/coreclr/pal/src/file/file.cpp b/src/coreclr/pal/src/file/file.cpp index a15be4dba7418..8139f87c5d861 100644 --- a/src/coreclr/pal/src/file/file.cpp +++ b/src/coreclr/pal/src/file/file.cpp @@ -1529,6 +1529,52 @@ SetFileAttributesW( return bRet; } +/*++ +InternalOpen + +Wrapper for open. + +Input parameters: + +szPath = pointer to a pathname of a file to be opened +nFlags = arguments that control how the file should be accessed +mode = file permission settings that are used only when a file is created + +Return value: + File descriptor on success, -1 on failure +--*/ +int +CorUnix::InternalOpen( + const char *szPath, + int nFlags, + ... + ) +{ + int nRet = -1; + int mode = 0; + va_list ap; + + // If nFlags does not contain O_CREAT, the mode parameter will be ignored. + if (nFlags & O_CREAT) + { + va_start(ap, nFlags); + mode = va_arg(ap, int); + va_end(ap); + } + + do + { +#if OPEN64_IS_USED_INSTEAD_OF_OPEN + nRet = open64(szPath, nFlags, mode); +#else + nRet = open(szPath, nFlags, mode); +#endif + } + while ((nRet == -1) && (errno == EINTR)); + + return nRet; +} + PAL_ERROR CorUnix::InternalWriteFile( CPalThread *pThread, @@ -3547,42 +3593,3 @@ BOOL FILEInitStdHandles(void) pStdErr = INVALID_HANDLE_VALUE; return FALSE; } - -/*++ -FILECleanupStdHandles - -Remove all regions, locked by a file pointer, from shared memory - -(no parameters) - ---*/ -void FILECleanupStdHandles(void) -{ - HANDLE stdin_handle; - HANDLE stdout_handle; - HANDLE stderr_handle; - - TRACE("closing standard handles\n"); - stdin_handle = pStdIn; - stdout_handle = pStdOut; - stderr_handle = pStdErr; - - pStdIn = INVALID_HANDLE_VALUE; - pStdOut = INVALID_HANDLE_VALUE; - pStdErr = INVALID_HANDLE_VALUE; - - if (stdin_handle != INVALID_HANDLE_VALUE) - { - CloseHandle(stdin_handle); - } - - if (stdout_handle != INVALID_HANDLE_VALUE) - { - CloseHandle(stdout_handle); - } - - if (stderr_handle != INVALID_HANDLE_VALUE) - { - CloseHandle(stderr_handle); - } -} diff --git a/src/coreclr/pal/src/include/pal/cruntime.h b/src/coreclr/pal/src/include/pal/cruntime.h index a2ce2789c3063..b09559565fd15 100644 --- a/src/coreclr/pal/src/include/pal/cruntime.h +++ b/src/coreclr/pal/src/include/pal/cruntime.h @@ -27,121 +27,6 @@ Module Name: #ifdef __cplusplus typedef char16_t wchar_16; // __wchar_16 (which is defined in palinternal.h) is defined as wchar_16_cpp. -extern "C" -{ -#endif // __cplusplus - -typedef enum -{ - PFF_NONE = 0, - PFF_MINUS = 1, - PFF_POUND = 2, - PFF_ZERO = 4, - PFF_SPACE = 8, - PFF_PLUS = 16 -}PRINTF_FORMAT_FLAGS; - -typedef enum -{ - WIDTH_DEFAULT = -1, - WIDTH_STAR = -2, /* e.g. "%*.10s" */ - WIDTH_INVALID = -3 /* e.g. "%*3.10s" */ -}WIDTH_FLAGS; - -typedef enum -{ - PRECISION_DEFAULT = -1, - PRECISION_STAR = -2, /* e.g. "%10.*s" */ - PRECISION_DOT = -3, /* e.g. "%10.s" */ - PRECISION_INVALID = -4 /* e.g. "%10.*3s" */ -}PRECISION_FLAGS; - -typedef enum -{ - PFF_PREFIX_DEFAULT = -1, - PFF_PREFIX_SHORT = 1, - PFF_PREFIX_LONG = 2, - PFF_PREFIX_LONGLONG = 3, - PFF_PREFIX_LONG_W = 4 -}PRINTF_PREFIXES; - -typedef enum -{ - PFF_TYPE_DEFAULT = -1, - PFF_TYPE_CHAR = 1, - PFF_TYPE_STRING = 2, - PFF_TYPE_WSTRING = 3, - PFF_TYPE_INT = 4, - PFF_TYPE_P = 5, - PFF_TYPE_N = 6, - PFF_TYPE_FLOAT = 7 -}PRINTF_TYPES; - -typedef enum -{ - SCANF_PREFIX_SHORT = 1, - SCANF_PREFIX_LONG = 2, - SCANF_PREFIX_LONGLONG = 3 -}SCANF_PREFIXES; - -typedef enum -{ - SCANF_TYPE_CHAR = 1, - SCANF_TYPE_STRING = 2, - SCANF_TYPE_INT = 3, - SCANF_TYPE_N = 4, - SCANF_TYPE_FLOAT = 5, - SCANF_TYPE_BRACKETS = 6, - SCANF_TYPE_SPACE = 7 -}SCANF_TYPES; - -/*++ - -struct PAL_FILE. -Used to mimic the behavior of windows. -fwrite under windows can set the ferror flag, -under BSD fwrite doesn't. ---*/ -struct _FILE -{ - FILE * bsdFilePtr; /* The BSD file to be passed to the - functions needing it. */ - - INT PALferrorCode; /* The ferror code that fwrite sets, - incase of error */ - - BOOL bTextMode; /* Boolean variable to denote that the - fle is opened in text/binary mode*/ -#if UNGETC_NOT_RETURN_EOF - BOOL bWriteOnlyMode;/* Boolean variable to denote that the - fle is opened in write-only mode*/ -#endif //UNGETC_NOT_RETURN_EOF -}; - -enum CRT_ERROR_CODES -{ - PAL_FILE_NOERROR = 0, - PAL_FILE_ERROR -}; - -/* Global variables storing the std streams. Defined in cruntime/file.c. */ -extern PAL_FILE PAL_Stdout; -extern PAL_FILE PAL_Stdin; -extern PAL_FILE PAL_Stderr; - -/*++ - -Functio: - - CRTInitStdStreams. - - Initializes the standard streams. - Returns TRUE on success, FALSE otherwise. ---*/ -BOOL CRTInitStdStreams( void ); - -#ifdef __cplusplus -} #endif // __cplusplus #endif /* _PAL_CRUNTIME_H_ */ diff --git a/src/coreclr/pal/src/include/pal/file.h b/src/coreclr/pal/src/include/pal/file.h index 52054306cb3a6..9b6e319536404 100644 --- a/src/coreclr/pal/src/include/pal/file.h +++ b/src/coreclr/pal/src/include/pal/file.h @@ -101,15 +101,6 @@ Return value: --*/ BOOL FILEInitStdHandles(void); -/*++ -FILECleanupStdHandles - -Close promary handles for stdin, stdout and stderr - -(no parameters, no return value) ---*/ -void FILECleanupStdHandles(void); - /*++ Function : @@ -123,86 +114,6 @@ Windows behavoir. */ void FILEGetProperNotFoundError( LPCSTR lpPath, LPDWORD lpErrorCode ); -/*++ -PAL_fflush - -Calls fflush - -Input parameters: - -PAL_FILE *stream = stream to be flushed. - -Return value: - 0 is returned on success, otherwise EOF is returned. ---*/ -int _cdecl PAL_fflush( PAL_FILE *stream ); - -/*++ -PAL_fgets - -Wrapper function for InternalFgets. - -Input parameters: - -sz = stores characters read from the given file stream -nSize = number of characters to be read -pf = stream to read characters from - -Return value: - Returns a pointer to the string storing the characters on success - and NULL on failure. ---*/ -char * __cdecl PAL_fgets(char *sz, int nSize, PAL_FILE *pf); - -/*++ -PAL_fwrite - -Wrapper function for InternalFwrite - -Input parameters: - -pvBuffer = array of objects to write to the given file stream -nSize = size of a object in bytes -nCount = number of objects to write -pf = stream to write characters to - -Return value: - Returns the number of objects written. ---*/ -size_t __cdecl PAL_fwrite(const void *pvBuffer, size_t nSize, size_t nCount, PAL_FILE *pf); - -/*++ -PAL__open - -Wrapper function for InternalOpen. - -Input parameters: - -szPath = pointer to a pathname of a file to be opened -nFlags = arguments that control how the file should be accessed -mode = file permission settings that are used only when a file is created - -Return value: - File descriptor on success, -1 on failure ---*/ -int __cdecl PAL__open(const char *szPath, int nFlags, ...); - -/*++ -PAL_fseek - -Wrapper function for fseek - -Input parameters: - -pf = 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 _cdecl PAL_fseek(PAL_FILE *pf, LONG lOffset, int nWhence); - #ifdef __cplusplus } #endif // __cplusplus diff --git a/src/coreclr/pal/src/include/pal/file.hpp b/src/coreclr/pal/src/include/pal/file.hpp index c35aa5cbeb86d..9f162b70ff493 100644 --- a/src/coreclr/pal/src/include/pal/file.hpp +++ b/src/coreclr/pal/src/include/pal/file.hpp @@ -126,31 +126,6 @@ namespace CorUnix PathCharString& lpBuffer ); - /*++ - InternalFgets - Wraps fgets - --*/ - char * - InternalFgets( - char *sz, - int nSize, - FILE *f, - bool fTextMode - ); - - /*++ - InternalFwrite - Wraps fwrite - --*/ - size_t - InternalFwrite( - const void *pvBuffer, - size_t nSize, - size_t nCount, - FILE *f, - INT *pnErrorCode - ); - /*++ InternalOpen Wraps open @@ -224,15 +199,6 @@ Return value: --*/ BOOL FILEInitStdHandles(void); -/*++ -FILECleanupStdHandles - -Close primary handles for stdin, stdout and stderr - -(no parameters, no return value) ---*/ -void FILECleanupStdHandles(void); - /*++ Function : diff --git a/src/coreclr/pal/src/include/pal/palinternal.h b/src/coreclr/pal/src/include/pal/palinternal.h index 2193307d21452..0166d6087450d 100644 --- a/src/coreclr/pal/src/include/pal/palinternal.h +++ b/src/coreclr/pal/src/include/pal/palinternal.h @@ -233,6 +233,21 @@ function_name() to call the system's implementation #define remove DUMMY_remove #define printf DUMMY_printf #define vprintf DUMMY_vprintf +#define fopen DUMMY_fopen +#define setvbuf DUMMY_setvbuf +#define fprintf DUMMY_fprintf +#define vfprintf DUMMY_vfprintf +#define fgets DUMMY_fgets +#define ferror DUMMY_ferror +#define fread DUMMY_fread +#define fwrite DUMMY_fwrite +#define ftell DUMMY_ftell +#define fclose DUMMY_fclose +#define fflush DUMMY_fflush +#define fputs DUMMY_fputs +#define fseek DUMMY_fseek +#define fgetpos DUMMY_fgetpos +#define fsetpos DUMMY_fsetpos /* RAND_MAX needed to be renamed to avoid duplicate definition when including stdlib.h header files. PAL_RAND_MAX should have the same value as RAND_MAX @@ -327,7 +342,8 @@ function_name() to call the system's implementation #define intptr_t PAL_intptr_t #define uintptr_t PAL_uintptr_t #define timeval PAL_timeval -#define FILE PAL_FILE + +#define SKIP_STD_FILE_DECLS #include "pal.h" #include "palprivate.h" @@ -404,7 +420,6 @@ function_name() to call the system's implementation #undef qsort #undef bsearch #undef time -#undef FILE #undef fclose #undef fopen #undef fread @@ -418,7 +433,6 @@ function_name() to call the system's implementation #undef fgetpos #undef fsetpos #undef getcwd -#undef _flushall #undef setvbuf #undef unlink #undef size_t @@ -570,6 +584,7 @@ function_name() to call the system's implementation #include #include #include +#include #ifdef __APPLE__ diff --git a/src/coreclr/pal/src/include/pal/printfcpp.hpp b/src/coreclr/pal/src/include/pal/printfcpp.hpp deleted file mode 100644 index 44526cb8a4eaa..0000000000000 --- a/src/coreclr/pal/src/include/pal/printfcpp.hpp +++ /dev/null @@ -1,46 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*++ - - - -Module Name: - - pal/printfcpp.hpp - -Abstract: - Declarations for suspension safe memory allocation functions - - - ---*/ - -#ifndef _PRINTFCPP_HPP -#define _PRINTFCPP_HPP - -#ifdef __cplusplus -#include "pal/threadinfo.hpp" -#endif - -#include - -#ifdef __cplusplus -typedef char16_t wchar_16; // __wchar_16_cpp (which is defined in palinternal.h) needs to be redefined to wchar_16. -extern "C" -{ -#endif // __cplusplus - - int - __cdecl - PAL_vfprintf( - PAL_FILE *stream, - const char *format, - va_list ap); - -#ifdef __cplusplus -} -#endif // __cplusplus - -#endif // _PRINTFCPP_HPP - diff --git a/src/coreclr/pal/src/include/pal/threadsusp.hpp b/src/coreclr/pal/src/include/pal/threadsusp.hpp index c3e59df89d799..d9441372a5a27 100644 --- a/src/coreclr/pal/src/include/pal/threadsusp.hpp +++ b/src/coreclr/pal/src/include/pal/threadsusp.hpp @@ -32,7 +32,6 @@ Module Name: // instantiation time. #include "pal/threadinfo.hpp" #include "pal/thread.hpp" -#include "pal/printfcpp.hpp" #include "pal/mutex.hpp" #include "pal/init.h" #if !HAVE_MACH_EXCEPTIONS diff --git a/src/coreclr/pal/src/init/pal.cpp b/src/coreclr/pal/src/init/pal.cpp index c88febfc26162..c1b173bc5db91 100644 --- a/src/coreclr/pal/src/init/pal.cpp +++ b/src/coreclr/pal/src/init/pal.cpp @@ -96,13 +96,6 @@ int CacheLineSize; using namespace CorUnix; -// -// $$TODO The C++ compiler doesn't like pal/cruntime.h so duplicate the -// necessary prototype here -// - -extern "C" BOOL CRTInitStdStreams(void); - extern bool g_running_in_exe; #if defined(HOST_ARM64) @@ -665,13 +658,6 @@ Initialize( } } - if (FALSE == CRTInitStdStreams()) - { - ERROR("Unable to initialize CRT standard streams\n"); - palError = ERROR_PALINIT_STD_STREAMS; - goto CLEANUP15; - } - TRACE("First-time PAL initialization complete.\n"); init_count++; @@ -691,9 +677,6 @@ Initialize( } goto done; - /* No cleanup required for CRTInitStdStreams */ -CLEANUP15: - FILECleanupStdHandles(); CLEANUP14: SEHCleanup(); CLEANUP13: diff --git a/src/coreclr/pal/src/locale/unicode.cpp b/src/coreclr/pal/src/locale/unicode.cpp index 8bfa58608e594..862f98a6b2127 100644 --- a/src/coreclr/pal/src/locale/unicode.cpp +++ b/src/coreclr/pal/src/locale/unicode.cpp @@ -109,9 +109,9 @@ BOOL GetUnicodeData(INT nUnicodeValue, UnicodeDataRec *pDataRec) return bRet; } -wchar_16 +char16_t __cdecl -PAL_ToUpperInvariant( wchar_16 c ) +PAL_ToUpperInvariant( char16_t c ) { UnicodeDataRec dataRec; @@ -140,9 +140,9 @@ PAL_ToUpperInvariant( wchar_16 c ) } } -wchar_16 +char16_t __cdecl -PAL_ToLowerInvariant( wchar_16 c ) +PAL_ToLowerInvariant( char16_t c ) { UnicodeDataRec dataRec; diff --git a/src/coreclr/pal/src/misc/cgroup.cpp b/src/coreclr/pal/src/misc/cgroup.cpp index ee3c0ae584392..d9916a923d333 100644 --- a/src/coreclr/pal/src/misc/cgroup.cpp +++ b/src/coreclr/pal/src/misc/cgroup.cpp @@ -179,7 +179,7 @@ class CGroup char *mountpath = nullptr; char *mountroot = nullptr; - FILE *mountinfofile = fopen(PROC_MOUNTINFO_FILENAME, "r"); + FILE *mountinfofile = fopen(PROC_MOUNTINFO_FILENAME, "rb"); if (mountinfofile == nullptr) goto done; @@ -267,7 +267,7 @@ class CGroup char *cgroup_path = nullptr; bool result = false; - FILE *cgroupfile = fopen(PROC_CGROUP_FILENAME, "r"); + FILE *cgroupfile = fopen(PROC_CGROUP_FILENAME, "rb"); if (cgroupfile == nullptr) goto done; @@ -384,7 +384,7 @@ class CGroup if (asprintf(&filename, "%s%s", s_cpu_cgroup_path, CGROUP2_CPU_MAX_FILENAME) < 0) return false; - file = fopen(filename, "r"); + file = fopen(filename, "rb"); if (file == nullptr) goto done; @@ -476,7 +476,7 @@ class CGroup if (val == nullptr) return false; - FILE* file = fopen(filename, "r"); + FILE* file = fopen(filename, "rb"); if (file == nullptr) goto done; diff --git a/src/coreclr/pal/src/misc/fmtmessage.cpp b/src/coreclr/pal/src/misc/fmtmessage.cpp index bd9a649a35835..c7de98718c1d3 100644 --- a/src/coreclr/pal/src/misc/fmtmessage.cpp +++ b/src/coreclr/pal/src/misc/fmtmessage.cpp @@ -25,8 +25,6 @@ Revision History: #include "pal/module.h" #include "pal/misc.h" -#include "pal/printfcpp.hpp" - #include "errorstrings.h" #include diff --git a/src/coreclr/pal/src/misc/perftrace.cpp b/src/coreclr/pal/src/misc/perftrace.cpp index 5dd0d38209d16..a0d52a415017b 100644 --- a/src/coreclr/pal/src/misc/perftrace.cpp +++ b/src/coreclr/pal/src/misc/perftrace.cpp @@ -92,12 +92,9 @@ typedef struct _pal_perf_program_info char start_time[32]; /* must be at least 26 characters */ } pal_perf_program_info; -typedef PAL_FILE PERF_FILE; -#define PERF_FILEFN(x) PAL_ ## x - static ULONGLONG PERFGetTicks(); static double PERFComputeStandardDeviation(pal_perf_api_info *api); -static void PERFPrintProgramHeaderInfo(PERF_FILE * hFile, BOOL completedExecution); +static void PERFPrintProgramHeaderInfo(FILE * hFile, BOOL completedExecution); static BOOL PERFInitProgramInfo(LPWSTR command_line, LPWSTR exe_path); static BOOL PERFReadSetting( ); static void PERFLogFileName(PathCharString * destFileString, const char *fileName, const char *suffix, int max_length); @@ -212,7 +209,7 @@ PERFComputeStandardDeviation(pal_perf_api_info *api) static void -PERFPrintProgramHeaderInfo(PERF_FILE * hFile, BOOL completedExecution) +PERFPrintProgramHeaderInfo(FILE * hFile, BOOL completedExecution) { ULONGLONG etime = 0; ULONGLONG ttime = 0; @@ -222,11 +219,11 @@ PERFPrintProgramHeaderInfo(PERF_FILE * hFile, BOOL completedExecution) ttime = program_info.total_duration; ptime = program_info.pal_duration; } - PERF_FILEFN(fprintf)(hFile,"#LOG\tversion=1.00\n"); + fprintf(hFile,"#LOG\tversion=1.00\n"); - PERF_FILEFN(fprintf)(hFile, "#MACHINE\thostname=%s\tcpu_clock_frequency=%g\n", program_info.hostname, + fprintf(hFile, "#MACHINE\thostname=%s\tcpu_clock_frequency=%g\n", program_info.hostname, program_info.cpu_clock_frequency); - PERF_FILEFN(fprintf)(hFile, "#PROCESS\tprocess_id=%d\ttotal_latency=" LLFORMAT "\tthread_times=" LLFORMAT "\tpal_time=" LLFORMAT "\texe_path=%s\tcommand_line=%s\tstart_time=%s", + fprintf(hFile, "#PROCESS\tprocess_id=%d\ttotal_latency=" LLFORMAT "\tthread_times=" LLFORMAT "\tpal_time=" LLFORMAT "\texe_path=%s\tcommand_line=%s\tstart_time=%s", program_info.process_id, etime, ttime, ptime, program_info.exe_path,program_info.command_line,program_info.start_time); } @@ -619,11 +616,11 @@ PERFWriteCounters( pal_perf_api_info * table ) off = table; PERFLogFileName(fileName, profile_summary_log_name, "_perf_summary.log"); - hFile = PERF_FILEFN(fopen)(fileName, "a+"); + hFile = fopen(fileName, "a+"); if(hFile != NULL) { PERFPrintProgramHeaderInfo(hFile, TRUE); - PERF_FILEFN(fprintf)(hFile,"#api_name\tapi_id\tperf_entries\tperf_exits\tsum_of_latency\tmin_latency\tmax_latency\tstd_dev_latency\tsum_of_square_latency\n"); + fprintf(hFile,"#api_name\tapi_id\tperf_entries\tperf_exits\tsum_of_latency\tmin_latency\tmax_latency\tstd_dev_latency\tsum_of_square_latency\n"); for(i=0;icounter > 0 || !report_only_called_apis) { - PERF_FILEFN(fprintf)(hFile,"%s\t%d\t" LLFORMAT "\t" LLFORMAT "\t" LLFORMAT "\t" LLFORMAT "\t" LLFORMAT "\t%g\t%g\n", + fprintf(hFile,"%s\t%d\t" LLFORMAT "\t" LLFORMAT "\t" LLFORMAT "\t" LLFORMAT "\t" LLFORMAT "\t%g\t%g\n", API_list[i], i, off->entries, off->counter,off->sum_duration, min_duration, off->max_duration, dev, off->sum_of_square_duration); } @@ -653,36 +650,36 @@ PERFWriteCounters( pal_perf_api_info * table ) { return -1; } - PERF_FILEFN(fclose)(hFile); + fclose(hFile); if (pal_perf_histogram_size > 0) { off = table; PERFLogFileName(fileName, profile_summary_log_name, "_perf_summary.hist"); - hFile = PERF_FILEFN(fopen)(fileName, "a+"); + hFile = fopen(fileName, "a+"); if (hFile != NULL) { DWORD j; - PERF_FILEFN(fprintf)(hFile,"#api_name\tapi_id"); + fprintf(hFile,"#api_name\tapi_id"); for (j = 0; j < pal_perf_histogram_size; j++) { - PERF_FILEFN(fprintf)(hFile, "\t%d", j*pal_perf_histogram_step); + fprintf(hFile, "\t%d", j*pal_perf_histogram_step); } - PERF_FILEFN(fprintf)(hFile, "\n"); + fprintf(hFile, "\n"); for(i = 0; i < PAL_API_NUMBER; i++) { if (off->counter > 0) { - PERF_FILEFN(fprintf)(hFile,"%s\t%d", API_list[i], i); + fprintf(hFile,"%s\t%d", API_list[i], i); for (j = 0; j < pal_perf_histogram_size; j++) { - PERF_FILEFN(fprintf)(hFile, "\t%d", off->histograms[j]); + fprintf(hFile, "\t%d", off->histograms[j]); } - PERF_FILEFN(fprintf)(hFile, "\n"); + fprintf(hFile, "\n"); } off++; @@ -692,7 +689,7 @@ PERFWriteCounters( pal_perf_api_info * table ) { return -1; } - PERF_FILEFN(fclose)(hFile); + fclose(hFile); } return 0; @@ -993,7 +990,7 @@ PERFFlushLog(pal_perf_thread_info * local_info, BOOL output_header) PERFLogFileName(fileName, profile_time_log_name, "_perf_time.log"); - hFile = PERF_FILEFN(fopen)(fileName, "a+"); + hFile = fopen(fileName, "a+"); if(hFile) { @@ -1003,7 +1000,7 @@ PERFFlushLog(pal_perf_thread_info * local_info, BOOL output_header) } if (local_info->buf_offset > 0) { - nWrittenBytes = PERF_FILEFN(fwrite)(local_info->pal_write_buf, local_info->buf_offset, 1, hFile); + nWrittenBytes = fwrite(local_info->pal_write_buf, local_info->buf_offset, 1, hFile); if (nWrittenBytes < 1) { ERROR("fwrite() failed with errno == %d\n", errno); @@ -1011,7 +1008,7 @@ PERFFlushLog(pal_perf_thread_info * local_info, BOOL output_header) } local_info->buf_offset = 0; } - PERF_FILEFN(fclose)(hFile); + fclose(hFile); ret = TRUE; } diff --git a/src/coreclr/pal/src/thread/process.cpp b/src/coreclr/pal/src/thread/process.cpp index b23eab001cca4..0d516f3ed1232 100644 --- a/src/coreclr/pal/src/thread/process.cpp +++ b/src/coreclr/pal/src/thread/process.cpp @@ -1690,7 +1690,7 @@ GetProcessIdDisambiguationKey(DWORD processId, UINT64 *disambiguationKey) snprintf(statFileName, sizeof(statFileName), "/proc/%d/stat", processId); _ASSERTE(chars > 0 && chars <= (int)sizeof(statFileName)); - FILE *statFile = fopen(statFileName, "r"); + FILE *statFile = fopen(statFileName, "rb"); if (statFile == nullptr) { TRACE("GetProcessIdDisambiguationKey: fopen() FAILED"); diff --git a/src/coreclr/pal/tests/palsuite/CMakeLists.txt b/src/coreclr/pal/tests/palsuite/CMakeLists.txt index 2acc3f31b413d..98cc954779cd6 100644 --- a/src/coreclr/pal/tests/palsuite/CMakeLists.txt +++ b/src/coreclr/pal/tests/palsuite/CMakeLists.txt @@ -90,42 +90,19 @@ add_executable_clr(paltests c_runtime/cosf/test1/test1.cpp c_runtime/cosh/test1/test1.cpp c_runtime/coshf/test1/test1.cpp - c_runtime/errno/test1/test1.cpp - c_runtime/errno/test2/test2.cpp c_runtime/exit/test1/test1.cpp c_runtime/exit/test2/test2.cpp c_runtime/exp/test1/test1.cpp c_runtime/expf/test1/test1.cpp c_runtime/fabs/test1/test1.cpp c_runtime/fabsf/test1/test1.cpp - c_runtime/ferror/test1/test1.cpp - c_runtime/ferror/test2/test2.cpp - c_runtime/fflush/test1/test1.cpp - c_runtime/fgets/test1/test1.cpp - c_runtime/fgets/test2/test2.cpp - c_runtime/fgets/test3/test3.cpp c_runtime/floor/test1/test1.cpp c_runtime/floorf/test1/test1.cpp c_runtime/fma/test1/test1.cpp c_runtime/fmaf/test1/test1.cpp c_runtime/fmod/test1/test1.cpp c_runtime/fmodf/test1/test1.cpp - c_runtime/fopen/test1/test1.cpp - c_runtime/fopen/test2/test2.cpp - c_runtime/fopen/test3/test3.cpp - c_runtime/fopen/test4/test4.cpp - c_runtime/fopen/test5/test5.cpp - c_runtime/fopen/test6/test6.cpp - c_runtime/fopen/test7/test7.cpp - c_runtime/fputs/test1/test1.cpp - c_runtime/fputs/test2/test2.cpp - c_runtime/fread/test1/test1.cpp - c_runtime/fread/test2/test2.cpp - c_runtime/fread/test3/test3.cpp c_runtime/free/test1/test1.cpp - c_runtime/fseek/test1/test1.cpp - c_runtime/ftell/test1/ftell.cpp - c_runtime/fwrite/test1/test1.cpp c_runtime/ilogb/test1/test1.cpp c_runtime/ilogbf/test1/test1.cpp c_runtime/isalnum/test1/test1.cpp @@ -519,11 +496,7 @@ add_executable_clr(paltests miscellaneous/SetEnvironmentVariableW/test4/test4.cpp miscellaneous/SetLastError/test1/test.cpp miscellaneous/_i64tow/test1/test1.cpp - pal_specific/PAL_errno/test1/PAL_errno.cpp # pal_specific/PAL_GetUserTempDirectoryW/test1/PAL_GetUserTempDirectoryW.cpp - #pal_specific/PAL_get_stderr/test1/PAL_get_stderr.cpp - #pal_specific/PAL_get_stdin/test1/PAL_get_stdin.cpp - #pal_specific/PAL_get_stdout/test1/PAL_get_stdout.cpp pal_specific/PAL_Initialize_Terminate/test1/PAL_Initialize_Terminate.cpp pal_specific/PAL_Initialize_Terminate/test2/pal_initialize_twice.cpp # pal_specific/PAL_RegisterLibraryW_UnregisterLibraryW/test1/PAL_RegisterLibraryW_UnregisterLibraryW.cpp diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/errno/test1/test1.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/errno/test1/test1.cpp deleted file mode 100644 index 7daab481ef10c..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/errno/test1/test1.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*============================================================================ -** -** Source: test1.c -** -** Purpose: Test that errno begins as 0, and sets to ERANGE when that -** error is forced with wcstoul. -** -** -**==========================================================================*/ - -#include - -PALTEST(c_runtime_errno_test1_paltest_errno_test1, "c_runtime/errno/test1/paltest_errno_test1") -{ - WCHAR overstr[] = {'4','2','9','4','9','6','7','2','9','6',0}; - WCHAR *end; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* - The only value that must be supported is - ERANGE, in the event that wcstoul() fails due to overflow. - */ - - wcstoul(overstr, &end, 10); - - if (errno != ERANGE) - { - Fail("ERROR: wcstoul did not set errno to ERANGE. Instead " - "the value of errno is %d\n", errno); - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/errno/test2/test2.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/errno/test2/test2.cpp deleted file mode 100644 index 7a0e27007f718..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/errno/test2/test2.cpp +++ /dev/null @@ -1,75 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*============================================================================ -** -** Source: test2.c -** -** Purpose: Test that errno is 'per-thread' as noted in the documentation. -** -** -**==========================================================================*/ - -#include - -/* - This thread function just checks that errno is initially 0 and then sets - it to a new value before returning. -*/ -DWORD PALAPI ThreadFunc_errno_test2( LPVOID lpParam ) -{ - - if(errno != 0) - { - *((DWORD*)lpParam) = 1; - } - - errno = 20; - - return 0; -} - - -PALTEST(c_runtime_errno_test2_paltest_errno_test2, "c_runtime/errno/test2/paltest_errno_test2") -{ - DWORD dwThreadId, dwThrdParam = 0; - HANDLE hThread; - - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Set errno to a value within this thread */ - - errno = 50; - - hThread = CreateThread(NULL, 0, ThreadFunc_errno_test2, &dwThrdParam, 0, &dwThreadId); - - if (hThread == NULL) - { - Fail("ERROR: CreateThread failed to create a thread. " - "GetLastError() returned %d.\n",GetLastError()); - } - - WaitForSingleObject(hThread, INFINITE); - - /* This checks the result of calling the thread */ - if(dwThrdParam) - { - Fail("ERROR: errno was not set to 0 in the new thread. Each " - "thread should have its own value for errno.\n"); - } - - /* Check to make sure errno is still set to 50 */ - if(errno != 50) - { - Fail("ERROR: errno should be 50 in the main thread, even though " - "it was set to 20 in another thread. Currently it is %d.\n", - errno); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/ferror/test1/test1.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/ferror/test1/test1.cpp deleted file mode 100644 index 5863d51d0c091..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/ferror/test1/test1.cpp +++ /dev/null @@ -1,73 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*===================================================================== -** -** Source: test1.c -** -** Purpose: Tests the PAL implementation of the ferror function. -** -** Depends: -** fopen -** fread -** fclose -** -** -** -**===================================================================*/ - -#include - -PALTEST(c_runtime_ferror_test1_paltest_ferror_test1, "c_runtime/ferror/test1/paltest_ferror_test1") -{ - const char filename[] = "testfile"; - char buffer[128]; - FILE * fp = NULL; - int result; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Open a file in READ mode */ - - if((fp = fopen(filename, "r")) == NULL) - { - Fail("Unable to open a file for reading. Is the file " - "in the directory? It should be."); - } - - /* Read 10 characters from the file. The file has 15 - characters in it. - */ - - if((result = fread(buffer,1,10,fp)) == 0) - { - Fail("ERROR: Zero characters read from the file. It should have " - "read 10 character in from a 15 character file."); - } - - if(ferror(fp) != 0) - { - Fail("ERROR: ferror returned a value not equal to 0. The read " - "operation shouldn't have caused an error, and ferror should " - "return 0 still."); - } - - /* - Close the open file and end the test. - */ - - if(fclose(fp) != 0) - { - Fail("ERROR: fclose failed when trying to close a file pointer. " - "This test depends on fclose working properly."); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/ferror/test1/testfile b/src/coreclr/pal/tests/palsuite/c_runtime/ferror/test1/testfile deleted file mode 100644 index 273c1a9ffdc20..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/ferror/test1/testfile +++ /dev/null @@ -1 +0,0 @@ -This is a test. \ No newline at end of file diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/ferror/test2/test2.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/ferror/test2/test2.cpp deleted file mode 100644 index 3ac444b0ec35c..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/ferror/test2/test2.cpp +++ /dev/null @@ -1,68 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*===================================================================== -** -** Source: test2.c -** -** Purpose: Open a read-only file and attempt to write some data to it. -** Check to ensure that an ferror occurs. -** -** Depends: -** fopen -** fwrite -** fclose -** -** -** -**===================================================================*/ - -#include - -PALTEST(c_runtime_ferror_test2_paltest_ferror_test2, "c_runtime/ferror/test2/paltest_ferror_test2") -{ - const char filename[] = "testfile"; - FILE * fp = NULL; - int result; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Open a file in READONLY mode */ - - if((fp = fopen(filename, "r")) == NULL) - { - Fail("Unable to open a file for reading."); - } - - /* Attempt to write 14 characters to the file. */ - - if((result = fwrite("This is a test",1,14,fp)) != 0) - { - Fail("ERROR: %d characters written. 0 characters should " - "have been written, since this file is read-only.", result); - } - - if(ferror(fp) == 0) - { - Fail("ERROR: ferror should have generated an error when " - "write was called on a read-only file. But, it " - "retured 0, indicating no error.\n"); - } - - /* Close the file. */ - - if(fclose(fp) != 0) - { - Fail("ERROR: fclose failed when trying to close a file pointer. " - "This test depends on fclose working properly."); - } - - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/ferror/test2/testfile b/src/coreclr/pal/tests/palsuite/c_runtime/ferror/test2/testfile deleted file mode 100644 index 0135842a03e1a..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/ferror/test2/testfile +++ /dev/null @@ -1 +0,0 @@ -This is a test file. This needs to be kept in CVS. \ No newline at end of file diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/fflush/test1/test1.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/fflush/test1/test1.cpp deleted file mode 100644 index 716a151b5f8f7..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/fflush/test1/test1.cpp +++ /dev/null @@ -1,79 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*============================================================================ -** -** Source: test1.c -** -** Purpose: Tests to see that fflush is working properly. Flushes a couple -** buffers and checks the return value. Can't figure out a way to test -** and ensure it is really dropping the buffers, since the system -** does this automatically most of the time ... -** -** -**==========================================================================*/ - -/* This function is really tough to test. Right now it just tests - a bunch of return values. No solid way to ensure that it is really - flushing a buffer or not -- might have to be a manual test someday. -*/ - -#include - - -PALTEST(c_runtime_fflush_test1_paltest_fflush_test1, "c_runtime/fflush/test1/paltest_fflush_test1") -{ - - int TheReturn; - FILE* TheFile; - FILE* AnotherFile = NULL; - - PAL_Initialize(argc,argv); - - TheFile = fopen("theFile","w+"); - - if(TheFile == NULL) - { - Fail("ERROR: fopen failed. Test depends on this function."); - } - - TheReturn = fwrite("foo",3,3,TheFile); - - if(TheReturn != 3) - { - Fail("ERROR: fwrite failed. Test depends on this function."); - } - - /* Test to see that FlushFileBuffers returns a success value */ - TheReturn = fflush(TheFile); - - if(TheReturn != 0) - { - Fail("ERROR: The fflush function returned non-zero, which " - "indicates failure, when trying to flush a buffer."); - } - - /* Test to see that FlushFileBuffers returns a success value */ - TheReturn = fflush(NULL); - - if(TheReturn != 0) - { - Fail("ERROR: The fflush function returned non-zero, which " - "indicates failure, when trying to flush all buffers."); - } - - /* Test to see that FlushFileBuffers returns a success value */ - TheReturn = fflush(AnotherFile); - - if(TheReturn != 0) - { - Fail("ERROR: The fflush function returned non-zero, which " - "indicates failure, when trying to flush a stream not " - "associated with a file."); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/fgets/test1/test1.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/fgets/test1/test1.cpp deleted file mode 100644 index e16c9e2ad9d07..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/fgets/test1/test1.cpp +++ /dev/null @@ -1,101 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*============================================================================ -** -** Source: test1.c -** -** Purpose: Writes a simple file and calls fgets() to get a string shorter -** than the first line of the file. Verifies that the correct -** string is returned. -** -** -**==========================================================================*/ - -#include - -PALTEST(c_runtime_fgets_test1_paltest_fgets_test1, "c_runtime/fgets/test1/paltest_fgets_test1") -{ - const char outBuf1[] = "This is a test.\n"; - const char outBuf2[] = "This is too."; - char inBuf[sizeof(outBuf1) + sizeof(outBuf2)]; - const char filename[] = "testfile.tmp"; - const int offset = 5; /* value chosen arbitrarily */ - int actualLen; - int expectedLen; - FILE * fp; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /*write the file that we will use to test */ - fp = fopen(filename, "w"); - if (fp == NULL) - { - Fail("Unable to open file for write.\n"); - } - - fwrite(outBuf1, sizeof(outBuf1[0]), sizeof(outBuf1), fp); - fwrite(outBuf2, sizeof(outBuf2[0]), sizeof(outBuf2), fp); - - if (fclose(fp) != 0) - { - Fail("Error closing a file opened for write.\n"); - } - - - /*now read back the entire first string*/ - fp = fopen(filename, "r"); - if (fp == NULL) - { - Fail("Unable to open file for read.\n"); - } - - /*note: +1 because strlen() returns the length of a string _not_ - including the NULL, while fgets() returns a string of specified - maximum length _including_ the NULL.*/ - if (fgets(inBuf, strlen(outBuf1) - offset + 1, fp) != inBuf) - { - Fail("Error reading from file using fgets.\n"); - } - - - expectedLen = strlen(outBuf1) - offset; - actualLen = strlen(inBuf); - - if (actualLen < expectedLen) - { - Fail("fgets() was asked to read a one-line string and given the " - "length of the string as a parameter. The string it has " - "read is too short.\n"); - } - if (actualLen > expectedLen) - { - Fail("fgets() was asked to read a one-line string and given the " - "length of the string as a parameter. The string it has " - "read is too long.\n"); - } - if (memcmp(inBuf, outBuf1, actualLen) != 0) - { - /*We didn't read back exactly outBuf1*/ - Fail("fgets() was asked to read a one-line string, and given the " - "length of the string as an parameter. It has returned a " - "string of the correct length, but the contents are not " - "correct.\n"); - } - - if (fclose(fp) != 0) - { - Fail("Error closing file after using fgets().\n"); - } - - - PAL_Terminate(); - return PASS; - -} - - diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/fgets/test2/test2.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/fgets/test2/test2.cpp deleted file mode 100644 index 7f21d07581752..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/fgets/test2/test2.cpp +++ /dev/null @@ -1,96 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*============================================================================ -** -** Source: test2.c -** -** Purpose: Calls fgets to read a full line from a file. A maximum length -** parameter greater than the length of the line is passed. -** -** -**==========================================================================*/ - -#include - -PALTEST(c_runtime_fgets_test2_paltest_fgets_test2, "c_runtime/fgets/test2/paltest_fgets_test2") -{ - const char outBuf1[] = "This is a test.\n"; - const char outBuf2[] = "This is too."; - - char inBuf[sizeof(outBuf1) + sizeof(outBuf2)]; - const char filename[] = "testfile.tmp"; - const int offset = 5; /*value chosen arbitrarily*/ - int expectedLen; - int actualLen; - - FILE * fp; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /*write the file that we will use to test */ - fp = fopen(filename, "w"); - if (fp == NULL) - { - Fail("Unable to open file for write.\n"); - } - - fwrite(outBuf1, sizeof(outBuf1[0]), sizeof(outBuf1), fp); - fwrite(outBuf2, sizeof(outBuf2[0]), sizeof(outBuf2), fp); - - if (fclose(fp) != 0) - { - Fail("error closing stream opened for write.\n"); - } - - /*Read until the first linebreak*/ - fp = fopen(filename, "r"); - if (fp == NULL) - { - Fail("Unable to open file for read.\n"); - } - - - if (fgets(inBuf, sizeof(outBuf1) + offset , fp) != inBuf) - { - Fail("Error reading from file using fgets.\n"); - } - - /*note: -1 because strlen returns the length of a string _not_ - including the NULL, while fgets returns a string of specified - maximum length _including_ the NULL.*/ - expectedLen = strlen(outBuf1); - actualLen = strlen(inBuf); - if (actualLen > expectedLen) - { - Fail("fgets() was asked to read the first line of a file, but did " - "not stop at the end of the line.\n"); - } - else if (actualLen < expectedLen) - { - Fail("fgets() was asked to read the first line of a file, but did " - "not read the entire line.\n"); - } - else if (memcmp(inBuf, outBuf1, actualLen) != 0) - { - /*We didn't read back exactly outBuf1*/ - Fail("fgets() was asked to read the first line of a file. It " - "has read back a string of the correct length, but the" - " contents are not correct.\n"); - } - - if (fclose(fp) != 0) - { - Fail("Error closing file after using fgets().\n"); - } - - PAL_Terminate(); - return PASS; - -} - - diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/fgets/test3/test3.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/fgets/test3/test3.cpp deleted file mode 100644 index f46b179de1ddc..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/fgets/test3/test3.cpp +++ /dev/null @@ -1,72 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*============================================================================ -** -** Source: test3.c -** -** Purpose: Tries to read from an empty file using fgets(), to verify -** handling of EOF condition. -** -** -**==========================================================================*/ - -#include - -PALTEST(c_runtime_fgets_test3_paltest_fgets_test3, "c_runtime/fgets/test3/paltest_fgets_test3") -{ - char inBuf[10]; - const char filename[] = "testfile.tmp"; - - FILE * fp; - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /*write the empty file that we will use to test */ - fp = fopen(filename, "w"); - if (fp == NULL) - { - Fail("Unable to open file for write.\n"); - } - - /*Don't write anything*/ - - if (fclose(fp) != 0) - { - Fail("Error closing stream opened for write.\n"); - } - - - /*Open the file and try to read.*/ - fp = fopen(filename, "r"); - if (fp == NULL) - { - Fail("Unable to open file for read.\n"); - } - - - if (fgets(inBuf, sizeof(inBuf) , fp) != NULL) - { - /*NULL could also mean an error condition, but since the PAL - doesn't supply feof or ferror, we can't distinguish between - the two.*/ - Fail("fgets doesn't handle EOF properly. When asked to read from " - "an empty file, it didn't return NULL as it should have.\n"); - } - - if (fclose(fp) != 0) - { - Fail("Error closing an empty file after trying to use fgets().\n"); - } - PAL_Terminate(); - return PASS; - -} - - - - - diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/fopen/test1/test1.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/fopen/test1/test1.cpp deleted file mode 100644 index abbc328d59460..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/fopen/test1/test1.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*===================================================================== -** -** Source: test1.c -** -** Purpose: Tests the PAL implementation of the fopen function. -** This test simply attempts to open a number of files -** with different modes. It checks to ensure a valid -** file pointer is returned. It doesn't do any checking -** to ensure the mode is really what it claims. And checks -** for a NULL pointer when attempts to open a directory. -** - -** -**===================================================================*/ - -#include - -struct testCase -{ - int CorrectResult; - char mode[20]; -}; - -PALTEST(c_runtime_fopen_test1_paltest_fopen_test1, "c_runtime/fopen/test1/paltest_fopen_test1") -{ - - FILE *fp; - char name[128]; - int i; - - struct testCase testCases[] = - { - {0, "r"}, {1, "w"}, {1, "a"}, - {0, "r+"}, {1, "w+"}, {1, "a+"}, - {1, "wt"}, {1, "wb"}, {1, "wS"}, - {1, "w+c"}, {1, "w+n"}, {1, "wR"}, - {1, "wT"}, {0, "tw"} - }; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - - for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) - { - strcpy(name,"testfiles"); - strcat(name,testCases[i].mode); - - fp = fopen(name,testCases[i].mode); - - if ((fp == 0 && testCases[i].CorrectResult != 0) || - (testCases[i].CorrectResult == 0 && fp != 0) ) - { - Fail("ERROR: fopen returned incorrectly " - "opening a file in %s mode. Perhaps it opened a " - "read only file which didn't exist and returned a correct " - "pointer?",testCases[i].mode); - } - - memset(name, '\0', 128); - - } - - /* When attempt to open a directory fopen should returned NULL */ - if ( fopen(".", "r") != NULL) - { - Fail("ERROR: fopen returned non-NULL when trying to open a directory" - " the returned value was %d\n", fp); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/fopen/test2/test2.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/fopen/test2/test2.cpp deleted file mode 100644 index b588c41fd23e3..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/fopen/test2/test2.cpp +++ /dev/null @@ -1,64 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*===================================================================== -** -** Source: test2.c -** -** Purpose: Tests the PAL implementation of the fopen function. -** Test to ensure that you can write to a 'w' mode file. -** And that you can't read from a 'w' mode file. -** -** Depends: -** fprintf -** fseek -** fgets -** - -** -**===================================================================*/ - -#include - -PALTEST(c_runtime_fopen_test2_paltest_fopen_test2, "c_runtime/fopen/test2/paltest_fopen_test2") -{ - - FILE *fp; - char buffer[128]; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - if( (fp = fopen( "testfile", "w" )) == NULL ) - { - Fail( "ERROR: The file failed to open with 'w' mode.\n" ); - } - - /* Test that you can write */ - if(fprintf(fp,"%s","some text") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'w' mode " - "but fprintf failed. Either fopen or fprintf have problems."); - } - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - /* Test that you can't read */ - if(fgets(buffer,10,fp) != NULL) - { - Fail("ERROR: Tried to READ from a file with only 'w' mode set. " - "This should fail, but fgets didn't return NULL. Either " - "fgets or fopen is broken."); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/fopen/test3/test3.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/fopen/test3/test3.cpp deleted file mode 100644 index 3be80f1610991..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/fopen/test3/test3.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*===================================================================== -** -** Source: test3.c -** -** Purpose: Tests the PAL implementation of the fopen function. -** Test to ensure that you can write to a 'w+' mode file. -** And that you can read from a 'w+' mode file. -** -** Depends: -** fprintf -** fseek -** fgets -** - -** -**===================================================================*/ - -#include - -PALTEST(c_runtime_fopen_test3_paltest_fopen_test3, "c_runtime/fopen/test3/paltest_fopen_test3") -{ - - FILE *fp; - char buffer[128]; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Open a file with 'w+' mode */ - if( (fp = fopen( "testfile", "w+" )) == NULL ) - { - Fail( "ERROR: The file failed to open with 'w+' mode.\n" ); - } - - /* Write some text to the file */ - if(fprintf(fp,"%s","some text") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'w+' mode " - "but fprintf failed. Either fopen or fprintf have problems."); - } - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - /* Attempt to read from the 'w+' only file, should pass */ - if(fgets(buffer,10,fp) == NULL) - { - Fail("ERROR: Tried to READ from a file with 'w+' mode set. " - "This should succeed, but fgets returned NULL. Either fgets " - "or fopen is broken."); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/fopen/test4/test4.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/fopen/test4/test4.cpp deleted file mode 100644 index 24f8bfa11e79b..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/fopen/test4/test4.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*===================================================================== -** -** Source: test4.c -** -** Purpose: Tests the PAL implementation of the fopen function. -** Test to ensure that you can't write to a 'r' mode file. -** And that you can read from a 'r' mode file. -** -** Depends: -** fprintf -** fclose -** fgets -** - -** -**===================================================================*/ - -#include - -PALTEST(c_runtime_fopen_test4_paltest_fopen_test4, "c_runtime/fopen/test4/paltest_fopen_test4") -{ - - FILE *fp; - char buffer[128]; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Open a file with 'w' mode */ - if( (fp = fopen( "testfile", "w" )) == NULL ) - { - Fail( "ERROR: The file failed to open with 'w' mode.\n" ); - } - - /* Write some text to the file */ - if(fprintf(fp,"%s","some text") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'w' mode " - "but fprintf failed. Either fopen or fprintf have problems."); - } - - if(fclose(fp)) - { - Fail("ERROR: Attempted to close a file, but fclose failed. " - "This test depends upon it."); - } - - /* Open a file with 'r' mode */ - if( (fp = fopen( "testfile", "r" )) == NULL ) - { - Fail( "ERROR: The file failed to open with 'r' mode.\n" ); - } - - /* Attempt to read from the 'r' only file, should pass */ - if(fgets(buffer,10,fp) == NULL) - { - Fail("ERROR: Tried to READ from a file with 'r' mode set. " - "This should succeed, but fgets returned NULL. Either fgets " - "or fopen is broken."); - } - - /* Write some text to the file */ - if(fprintf(fp,"%s","some text") > 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'r' mode " - "but fprintf succeeded It should have failed. " - "Either fopen or fprintf have problems."); - } - - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/fopen/test5/test5.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/fopen/test5/test5.cpp deleted file mode 100644 index 04205aca83352..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/fopen/test5/test5.cpp +++ /dev/null @@ -1,77 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*===================================================================== -** -** Source: test5.c -** -** Purpose: Tests the PAL implementation of the fopen function. -** Test to ensure that you can write to a 'r+' mode file. -** And that you can read from a 'r+' mode file. -** -** Depends: -** fprintf -** fclose -** fgets -** fseek -** - -** -**===================================================================*/ - -#include - -PALTEST(c_runtime_fopen_test5_paltest_fopen_test5, "c_runtime/fopen/test5/paltest_fopen_test5") -{ - - FILE *fp; - char buffer[128]; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Open a file with 'w' mode */ - if( (fp = fopen( "testfile", "w" )) == NULL ) - { - Fail( "ERROR: The file failed to open with 'w' mode.\n" ); - } - - if(fclose(fp)) - { - Fail("ERROR: Attempted to close a file, but fclose failed. " - "This test depends upon it."); - } - - if( (fp = fopen( "testfile", "r+" )) == NULL ) - { - Fail( "ERROR: The file failed to open with 'r+' mode.\n" ); - } - - /* Write some text to the file */ - if(fprintf(fp,"%s","some text") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'r+' mode " - "but fprintf failed. Either fopen or fprintf have problems."); - } - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - /* Attempt to read from the 'r+' only file, should pass */ - if(fgets(buffer,10,fp) == NULL) - { - Fail("ERROR: Tried to READ from a file with 'r+' mode set. " - "This should succeed, but fgets returned NULL. Either fgets " - "or fopen is broken."); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/fopen/test6/test6.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/fopen/test6/test6.cpp deleted file mode 100644 index 13f00cc9300b6..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/fopen/test6/test6.cpp +++ /dev/null @@ -1,130 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*===================================================================== -** -** Source: test6.c -** -** Purpose: Tests the PAL implementation of the fopen function. -** Test to ensure that you can write to an 'a' mode file. -** And that you can't read from a 'a' mode file. Also ensure -** that you can use fseek and still write to the end of a file. -** -** Depends: -** fprintf -** fgets -** fseek -** fclose -** - -** -**===================================================================*/ - -#include - -PALTEST(c_runtime_fopen_test6_paltest_fopen_test6, "c_runtime/fopen/test6/paltest_fopen_test6") -{ - - FILE *fp; - char buffer[128]; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Open a file with 'a+' mode */ - if( (fp = fopen( "testfile", "a" )) == NULL ) - { - Fail( "ERROR: The file failed to open with 'a' mode.\n" ); - } - - /* Write some text to the file */ - if(fprintf(fp,"%s","some text") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'a' mode " - "but fprintf failed. Either fopen or fprintf have problems."); - } - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - /* Attempt to read from the 'a' only file, should fail */ - if(fgets(buffer,10,fp) != NULL) - { - Fail("ERROR: Tried to READ from a file with 'a' mode set. " - "This should fail, but fgets returned success. Either fgets " - "or fopen is broken."); - } - - - /* Attempt to write to a file after using 'a' and fseek */ - fp = fopen("testfile2", "a"); - if(fp == NULL) - { - Fail("ERROR: The file failed to be created with 'a' mode.\n"); - } - - /* write text to the file initially */ - if(fprintf(fp,"%s","abcd") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'a' mode " - "but fprintf failed. Either fopen or fprintf have problems.\n"); - } - - /* set the pointer to the front of the file */ - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it.\n"); - } - - /* using 'a' should still write to the end of the file, not the front */ - if(fputs("efgh",fp) < 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'a' mode " - "but fputs failed.\n"); - } - - /* set the pointer to the front of the file */ - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it.\n"); - } - - /* a file with 'a' mode can only write, so close the file before reading */ - if(fclose(fp)) - { - Fail("ERROR: fclose failed when it should have succeeded.\n"); - } - - /* open the file again to read */ - fp = fopen("testfile2","r"); - if(fp == NULL) - { - Fail("ERROR: fopen failed to open the file using 'r' mode"); - } - - /* Attempt to read from the 'a' only file, should succeed */ - if(fgets(buffer,10,fp) == NULL) - { - Fail("ERROR: Tried to READ from a file with 'a' mode set. " - "This should pass, but fgets returned failure. Either fgets " - "or fopen is broken.\n"); - } - - /* Compare what was read and what should have been in the file */ - if(memcmp(buffer,"abcdefgh",8)) - { - Fail("ERROR: The string read should have equaled 'abcdefgh' " - "but instead it is %s\n", buffer); - } - - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/fopen/test7/test7.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/fopen/test7/test7.cpp deleted file mode 100644 index 0cf274d8c6b78..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/fopen/test7/test7.cpp +++ /dev/null @@ -1,116 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*===================================================================== -** -** Source: test7.c -** -** Purpose: Tests the PAL implementation of the fopen function. -** Test to ensure that you can write to an 'a+' mode file. -** And that you can read from a 'a+' mode file. Also ensure -** that you can use fseek and still write to the end of a file. -** -** Depends: -** fprintf -** fgets -** fseek -** fclose -** - -** -**===================================================================*/ - -#include - -PALTEST(c_runtime_fopen_test7_paltest_fopen_test7, "c_runtime/fopen/test7/paltest_fopen_test7") -{ - - FILE *fp; - char buffer[128]; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /* Open a file with 'a+' mode */ - if( (fp = fopen( "testfile", "a+" )) == NULL ) - { - Fail( "ERROR: The file failed to open with 'a+' mode.\n" ); - } - - /* Write some text to the file */ - if(fprintf(fp,"%s","some text") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'a+' mode " - "but fprintf failed. Either fopen or fprintf have problems.\n"); - } - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it.\n"); - } - - /* Attempt to read from the 'a+' only file, should succeed */ - if(fgets(buffer,10,fp) == NULL) - { - Fail("ERROR: Tried to READ from a file with 'a+' mode set. " - "This should pass, but fgets returned failure. Either fgets " - "or fopen is broken.\n"); - } - - - /* Attempt to write to a file after using 'a+' and fseek */ - fp = fopen("testfile2", "a+"); - if(fp == NULL) - { - Fail("ERROR: The file failed to be created with 'a+' mode.\n"); - } - - /* write text to the file initially */ - if(fprintf(fp,"%s","abcd") <= 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'a+' mode " - "but fprintf failed. Either fopen or fprintf have problems.\n"); - } - - /* set the pointer to the front of the file */ - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it.\n"); - } - - /* using 'a+' should still write to the end of the file, not the front */ - if(fputs("efgh",fp) < 0) - { - Fail("ERROR: Attempted to WRITE to a file opened with 'a+' mode " - "but fputs failed.\n"); - } - - /* set the pointer to the front of the file */ - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it.\n"); - } - - /* Attempt to read from the 'a+' only file, should succeed */ - if(fgets(buffer,10,fp) == NULL) - { - Fail("ERROR: Tried to READ from a file with 'a+' mode set. " - "This should pass, but fgets returned failure. Either fgets " - "or fopen is broken.\n"); - } - - /* Compare what was read and what should have been in the file */ - if(memcmp(buffer,"abcdefgh",8)) - { - Fail("ERROR: The string read should have equaled 'abcdefgh' " - "but instead it is %s\n", buffer); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/fputs/test1/test1.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/fputs/test1/test1.cpp deleted file mode 100644 index c746daff9e6d2..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/fputs/test1/test1.cpp +++ /dev/null @@ -1,99 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*===================================================================== -** -** Source: test1.c -** -** Purpose: Call fputs twice and write two strings to a file. Then -** call fread on the file and check that the data which was written is what -** we expect it to be. -** - -** -**===================================================================*/ - - -#include - - -PALTEST(c_runtime_fputs_test1_paltest_fputs_test1, "c_runtime/fputs/test1/paltest_fputs_test1") -{ - - FILE* TheFile; - char* StringOne = "FooBar"; - char* StringTwo = "BarFoo"; - char* CompleteString = "FooBarBarFoo"; - char ReadBuffer[64]; - int ret; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Open the file that we'll be working with */ - - TheFile = fopen("TestFile", "w+"); - - if(TheFile == NULL) - { - Fail("ERROR: fopen failed to open the file 'TestFile' in read/write " - "mode.\n"); - } - - /* Call fputs twice to write two strings to the file stream */ - - if(fputs(StringOne, TheFile) < 0) - { - Fail("ERROR: fputs returned a negative value when attempting to " - "put the string '%s' to the file.\n",StringOne); - } - - if(fputs(StringTwo, TheFile) < 0) - { - Fail("ERROR: fputs returned a negative value when attempting to " - "put the string '%s' to the file.\n",StringTwo); - } - - /* Flush the buffers */ - if(fflush(TheFile) != 0) - { - Fail("ERROR: fflush failed to properly flush the buffers.\n"); - } - - /* Now read from the file to ensure the data was written correctly. - Note: We read more than what was written to make sure nothing extra - was written. - */ - - if(fseek(TheFile, 0, SEEK_SET) != 0) - { - Fail("ERROR: fseek failed to set the file pointer back to the start " - "of the file.\n"); - } - - - if((ret = fread(ReadBuffer, 1, 20, TheFile)) != 12) - { - Fail("ERROR: fread should have returned that it read in 12 characters " - "from the file, but instead it returned %d.\n", ret); - } - - ReadBuffer[ret] = '\0'; - - if(strcmp(ReadBuffer, CompleteString) != 0) - { - Fail("ERROR: The data read back from the file is not exactly the same " - "as the data that was written by fputs. The file contains '%s' " - "instead of '%s'.\n",ReadBuffer, CompleteString); - } - - if(fclose(TheFile) != 0) - { - Fail("ERROR: fclose failed to close the file stream.\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/fputs/test2/test2.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/fputs/test2/test2.cpp deleted file mode 100644 index aa8d36a5115b0..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/fputs/test2/test2.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*===================================================================== -** -** Source: test2.c -** -** Purpose: Check to see that fputs fails and returns EOF when called on -** a closed file stream and a read-only file stream. -** - -** -**===================================================================*/ - -#include - -PALTEST(c_runtime_fputs_test2_paltest_fputs_test2, "c_runtime/fputs/test2/paltest_fputs_test2") -{ - - FILE* TheFile; - char* StringOne = "FooBar"; - int ret; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Create a file with read/write access */ - - TheFile = fopen("TestFile", "w+"); - - if(TheFile == NULL) - { - Fail("ERROR: fopen failed to open the file 'TestFile' in read/write " - "mode.\n"); - } - - /* Then close that file we just opened */ - - if(fclose(TheFile) != 0) - { - Fail("ERROR: fclose failed to close the file.\n"); - } - - /* Check that calling fputs on this closed file stream fails. */ - - if((ret = fputs(StringOne, TheFile)) >= 0) - { - Fail("ERROR: fputs should have failed to write to a closed " - "file stream, but it didn't return a negative value.\n"); - } - - if(ret != EOF) - { - Fail("ERROR: fputs should have returned EOF on an error, but instead " - "returned %d.\n",ret); - } - - /* Open a file as Readonly */ - - TheFile = fopen("TestFile", "r"); - - if(TheFile == NULL) - { - Fail("ERROR: fopen failed to open the file 'TestFile' in read/write " - "mode.\n"); - } - - /* Check that fputs fails when trying to write to a read-only stream */ - - if((ret = fputs(StringOne, TheFile)) >= 0) - { - Fail("ERROR: fputs should have failed to write to a read-only " - "file stream, but it didn't return a negative value.\n"); - } - - if(ret != EOF) - { - Fail("ERROR: fputs should have returned EOF when writing to a " - "read-only filestream, but instead " - "returned %d.\n",ret); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/fread/test1/test1.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/fread/test1/test1.cpp deleted file mode 100644 index 3cfe9fa444a56..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/fread/test1/test1.cpp +++ /dev/null @@ -1,134 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*===================================================================== -** -** Source: test1.c -** -** Purpose: Tests the PAL implementation of the fread function. -** Open a file in READ mode, and then try to read all -** the characters, more than all the characters, -** 0 characters and 0 sized characters and check that -** the return values are correct. -** -** Depends: -** fopen -** fseek -** fclose -** -** -**===================================================================*/ - -/* Note: testfile should exist in the directory with 15 characters - in it ... something got lost if it isn't here. -*/ - -/* Note: Under win32, fread() crashes when passed NULL. The test to ensure that - it returns 0 has been removed to reflect this. -*/ - -#include - -PALTEST(c_runtime_fread_test1_paltest_fread_test1, "c_runtime/fread/test1/paltest_fread_test1") -{ - const char filename[] = "testfile"; - char buffer[128]; - FILE * fp = NULL; - int result; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Open a file in READ mode */ - - if((fp = fopen(filename, "r")) == NULL) - { - Fail("Unable to open a file for reading. Is the file " - "in the directory? It should be."); - } - - /* Read 15 characters from the file. The file has exactly this many - in it. - */ - if((result = fread(buffer,1,15,fp)) == 0) - { - Fail("ERROR: Zero characters read from the file. It should have " - "15 characters in it."); - } - - if(result != 15) - { - Fail("ERROR: The fread function should have returned that it read " - "in 15 characters from the file. But it indicates having " - "read %i characters.",result); - } - - /* Go back to the start of the file */ - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - /* Attempt to read 17 characters, the return should still be 15 */ - - if((result = fread(buffer,1,17,fp)) == 0) - { - Fail("ERROR: Zero characters read from the file. It should have " - "15 characters in it. Though, it attempted to read 17."); - } - - if(result != 15) - { - Fail("ERROR: The fread function should have returned that it read " - "in 15 characters from the file. " - "But it indicates having read %i characters.",result); - } - - /* Back to the start of the file */ - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - /* Read 0 characters and ensure the function returns 0 */ - - if((result = fread(buffer,1,0,fp)) != 0) - { - Fail("ERROR: The return value should be 0, as we attempted to " - "read 0 characters."); - } - - /* Read characters of 0 size and ensure the return value is 0 */ - - if((result = fread(buffer,0,5,fp)) != 0) - { - Fail("ERROR: The return value should be 0, as we attempted to " - "read 0 sized data."); - } - - /* Close the file */ - - if(fclose(fp)) - { - Fail("ERROR: fclose failed. Test depends on it."); - } - - /* Read 5 characters of 1 size from a closed file pointer - and ensure the return value is 0 - */ - - if((result = fread(buffer,1,5,fp)) != 0) - { - Fail("ERROR: The return value should be 0, as we attempted to " - "read data from a closed file pointer."); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/fread/test1/testfile b/src/coreclr/pal/tests/palsuite/c_runtime/fread/test1/testfile deleted file mode 100644 index 273c1a9ffdc20..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/fread/test1/testfile +++ /dev/null @@ -1 +0,0 @@ -This is a test. \ No newline at end of file diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/fread/test2/test2.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/fread/test2/test2.cpp deleted file mode 100644 index de372204eb66e..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/fread/test2/test2.cpp +++ /dev/null @@ -1,142 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*===================================================================== -** -** Source: test2.c -** -** Purpose: Tests the PAL implementation of the fread function. -** Open a file in READ mode, and then try to read all -** the characters, more than all the characters, -** 0 characters and 0 sized characters and check that -** the strings read in are correct. -** -** Depends: -** fopen -** fseek -** fclose -** strcmp -** memset -** -** -**===================================================================*/ - -/* Note: testfile should exist in the directory with 15 characters - in it ... something got lost if it isn't here. -*/ - -/* Note: The behaviour in win32 is to crash if a NULL pointer is passed to - fread, so the test to check that it returns 0 has been removed. -*/ - -#include - -PALTEST(c_runtime_fread_test2_paltest_fread_test2, "c_runtime/fread/test2/paltest_fread_test2") -{ - const char filename[] = "testfile"; - char buffer[128]; - FILE * fp = NULL; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Open a file in READ mode */ - - if((fp = fopen(filename, "r")) == NULL) - { - Fail("Unable to open a file for reading. Is the file " - "in the directory? It should be."); - } - - /* Read 15 characters from the file. The file has exactly this many - in it. Then check to see that the data read in is correct. - Note: The 'testfile' should have "This is a test." written in it. - */ - memset(buffer,'\0',128); - fread(buffer,1,15,fp); - - if(strcmp(buffer,"This is a test.") != 0) - { - Fail("ERROR: The data read in should have been " - "'This is a test.' but, the buffer contains '%s'.", - buffer); - } - - /* Go back to the start of the file */ - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - /* Attempt to read 17 characters. The same 15 characters should - be in the buffer. - */ - - memset(buffer,'\0',128); - fread(buffer,1,17,fp); - - if(strcmp(buffer,"This is a test.") != 0) - { - Fail("ERROR: The data read in should have been " - "'This is a test.' but, the buffer contains '%s'.", - buffer); - } - - /* Back to the start of the file */ - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - /* Read 0 characters and ensure the buffer is empty */ - - memset(buffer,'\0',128); - fread(buffer,1,0,fp); - - if(strcmp(buffer,"\0") != 0) - { - Fail("ERROR: The data read in should have been " - "NULL but, the buffer contains '%s'.", - buffer); - } - - /* Read characters of 0 size and ensure the buffer is empty */ - - memset(buffer,'\0',128); - fread(buffer,0,5,fp); - - if(strcmp(buffer,"\0") != 0) - { - Fail("ERROR: The data read in should have been " - "NULL but, the buffer contains '%s'.", - buffer); - } - - /* Close the file */ - - if(fclose(fp)) - { - Fail("ERROR: fclose failed. Test depends on it."); - } - - /* Read 5 characters of 1 size from a closed file pointer - and ensure the buffer is empty - */ - memset(buffer,'\0',128); - fread(buffer,1,5,fp); - if(strcmp(buffer,"\0") != 0) - { - Fail("ERROR: The data read in should have been " - "NULL but, the buffer contains '%s'.", - buffer); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/fread/test2/testfile b/src/coreclr/pal/tests/palsuite/c_runtime/fread/test2/testfile deleted file mode 100644 index 273c1a9ffdc20..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/fread/test2/testfile +++ /dev/null @@ -1 +0,0 @@ -This is a test. \ No newline at end of file diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/fread/test3/test3.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/fread/test3/test3.cpp deleted file mode 100644 index 75ae9c6ad1b3d..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/fread/test3/test3.cpp +++ /dev/null @@ -1,130 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*===================================================================== -** -** Source: test3.c -** -** Purpose: Tests the PAL implementation of the fread function. -** Open a file in READ mode, then try to read from the file with -** different 'size' params. Check to ensure the return values and -** the text in the buffer is correct. -** -** Depends: -** fopen -** fseek -** strcmp -** memset -** -** -**===================================================================*/ - -/* Note: testfile should exist in the directory with 15 characters - in it ... something got lost if it isn't here. -*/ - -#include - -PALTEST(c_runtime_fread_test3_paltest_fread_test3, "c_runtime/fread/test3/paltest_fread_test3") -{ - const char filename[] = "testfile"; - char buffer[128]; - FILE * fp = NULL; - int result; - - if (0 != PAL_Initialize(argc, argv)) - { - return FAIL; - } - - /* Open a file in READ mode */ - - if((fp = fopen(filename, "r")) == NULL) - { - Fail("Unable to open a file for reading. Is the file " - "in the directory? It should be."); - } - - memset(buffer,'x',128); - - /* Put the null one character past the end of the text that was read - in, to ensure that it wasn't reading in 0 - */ - - buffer[16] = '\0'; - - /* Attempt to read in 5 bytes at a time. This should return 3 and - contain the full string in the buffer. - */ - - if((result = fread(buffer,5,3,fp)) != 3) - { - Fail("ERROR: Attempted to read in data of size 5. The file has " - "15 bytes in it so 3 items should have been read. But the value " - "returned was %d.",result); - } - - if(strcmp(buffer, "This is a test.x") != 0) - { - Fail("ERROR: The buffer should have contained the text " - "'This is a test.x' but instead contained '%s'.",buffer); - } - - memset(buffer,'x',128); - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - buffer[16] = '\0'; - - /* Attempt to read in 6 bytes at a time. The return should be 2. The - full string should still be in the buffer. - */ - - if((result = fread(buffer,6,3,fp)) != 2) - { - Fail("ERROR: Attempted to read in data of size 6. The file has " - "15 bytes in it, so 2 items should have been read. But the " - "value returned was %d.",result); - } - - if(strcmp(buffer, "This is a test.x") != 0) - { - Fail("ERROR: The buffer should have contained the text " - "'This is a test.x' but instead contained '%s'.",buffer); - } - - memset(buffer,'x',128); - - buffer[7] = '\0'; - - if(fseek(fp, 0, SEEK_SET)) - { - Fail("ERROR: fseek failed, and this test depends on it."); - } - - /* Attempt to read in 6 bytes at a time but only one item max. - The return should be 1. The first 6 characters should be in the - buffer. - */ - - if((result = fread(buffer,6,1,fp)) != 1) - { - Fail("ERROR: Attempted to read in data of size 6 with a max count " - "of 1. Thus, one item should have been read, but the " - "value returned was %d.",result); - } - - if(strcmp(buffer, "This ix") != 0) - { - Fail("ERROR: The buffer should have contained the text " - "'This ix.' but instead contained '%s'.",buffer); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/fread/test3/testfile b/src/coreclr/pal/tests/palsuite/c_runtime/fread/test3/testfile deleted file mode 100644 index 273c1a9ffdc20..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/fread/test3/testfile +++ /dev/null @@ -1 +0,0 @@ -This is a test. \ No newline at end of file diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/fseek/test1/test1.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/fseek/test1/test1.cpp deleted file mode 100644 index 7fdfc2fef2fe4..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/fseek/test1/test1.cpp +++ /dev/null @@ -1,192 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*============================================================================ -** -** Source: test1.c -** -** Purpose: Call fseek to move a file pointer to the start of a file, -** a position offset from the start, a position offset from the -** current position, and a position offset from the end of the -** file. Check that the file pointer is at the correct position -** after each seek. -** -** -**==========================================================================*/ - -#include - -const char filename[] = "testfile.txt"; - -static BOOL Cleanup(HANDLE hFile) -{ - BOOL result= TRUE; - - if (fclose((PAL_FILE*)hFile)) - { - Trace("fseek: ERROR -> Unable to close file \"%s\".\n", - filename); - result= FALSE; - } - if (!DeleteFileA(filename)) - { - result= FALSE; - Trace("fseek: ERROR -> Unable to delete file \"%s\". ", - "GetLastError returned %u.\n", - filename, - GetLastError()); - } - return result; -} - -PALTEST(c_runtime_fseek_test1_paltest_fseek_test1, "c_runtime/fseek/test1/paltest_fseek_test1") -{ - char outBuf[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - char inBuf[20]; - FILE * fp; - int size = ( sizeof(outBuf)/sizeof(char) ) - 1; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - /*create the file*/ - fp = fopen(filename, "w"); - if (fp == NULL) - { - Fail("Unable to open a file for write.\n"); - } - if(fprintf(fp, outBuf) != size) - { - Trace("Unable to write to %s.\n", filename); - Cleanup(fp); - Fail(""); - } - - if (fclose(fp) != 0) - { - Trace("Unable to close newly written file.\n"); - if (!DeleteFileA(filename)) - { - Trace("fseek: ERROR -> Unable to delete file \"%s\". ", - "GetLastError returned %u.\n", - filename, - GetLastError()); - } - Fail(""); - } - - fp = fopen(filename, "r"); - if (fp == NULL) - { - if (!DeleteFileA(filename)) - { - Trace("_putw: ERROR -> Unable to delete file \"%s\". ", - "GetLastError returned %u.\n", - filename, - GetLastError()); - } - Fail("Unable to open a file for read.\n"); - } - - /*seek to the start*/ - if (fseek(fp, 0, SEEK_SET) != 0) - { - Cleanup(fp); - Fail("fseek failed when seeking the start of a file.\n"); - } - if (fgets(inBuf, 11, fp) != inBuf) - { - Cleanup(fp); - Fail("Unable to read from file after using fseek to move to the start.\n"); - } - if (strncmp(inBuf, outBuf, 10) != 0) - { - Cleanup(fp); - Fail("fseek was asked to seek the start of a file," - "but didn't get there.\n"); - } - - /*Seek with an offset from the start*/ - - if (fseek(fp, 10, SEEK_SET) != 0) - { - Cleanup(fp); - Fail("fseek failed when called with SEEK_SET and a positive offset.\n"); - } - - if (fgets(inBuf, 6, fp) != inBuf) - { - Cleanup(fp); - Fail("fgets failed after feek was called with SEEK_SET" - "and a positive offset.\n"); - } - - - if (strncmp(inBuf, "ABCDE", 5) != 0) - { - Cleanup(fp); - Fail("fseek did not move to the correct position when passed SEEK_SET" - " and a positive offset.\n"); - } - - /*now move backwards and read the same string*/ - if (fseek(fp, -5, SEEK_CUR) != 0) - { - Cleanup(fp); - Fail("fseek failed when passed SEEK_CUR and a negative offset.\n"); - } - - if (fgets(inBuf, 6, fp) != inBuf) - { - Cleanup(fp); - Fail("fgets failed after fseek was called with SEEK_CUR and a " - "negative offset.\n"); - } - - if (strncmp(inBuf, "ABCDE", 5) != 0) - { - Cleanup(fp); - Fail("fseek did not move to the correct position when called with" - " SEEK_CUR and a negative offset.\n"); - } - - /*Try seeking relative to the end of the file.*/ - if (fseek(fp, -10, SEEK_END) != 0) - { - Cleanup(fp); - Fail("fseek failed when called with SEEK_END and a negative" - " offset.\n"); - } - if (fgets(inBuf, 2, fp) != inBuf) - { - Cleanup(fp); - Fail("fgets failed after fseek was called with SEEK_END and a " - "negative offset\n"); - } - - if (strncmp(inBuf, "Q", 1) != 0) - { - Cleanup(fp); - Fail("fseek did not move to the correct position when called with " - "SEEK_END and a negative offset.\n"); - } - - - /*close the file*/ - if(!Cleanup(fp)) - { - Fail(""); - } - - PAL_Terminate(); - return PASS; -} - - - - - - diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/ftell/test1/ftell.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/ftell/test1/ftell.cpp deleted file mode 100644 index 1c60fab20791e..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/ftell/test1/ftell.cpp +++ /dev/null @@ -1,144 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*===================================================================== -** -** Source: ftell.c (test 1) -** -** Purpose: Tests the PAL implementation of the ftell function. -** -** -**===================================================================*/ - -#include - -FILE* pFile; -struct TESTS -{ - long lDist; - int nFrom; - long lPosition; -}; - - -/************************************************* -** -** Validate -** -** Purpose: -** Tests whether the move was successful. If -** it passes, it returns TRUE. If it fails -** it outputs some error messages and returns -** FALSE. -** -*************************************************/ -BOOL Validate(long lExpected) -{ - long lPos = -2; - - if (((lPos = ftell(pFile)) == -1) || (lPos != lExpected)) - { - Trace("ftell: ERROR -> ftell returned %ld when expecting %ld.\n", - lPos, - lExpected); - if (fclose(pFile) != 0) - { - Trace("ftell: ERROR -> fclose failed to close the file.\n"); - } - return FALSE; - } - return TRUE; -} - - -/************************************************* -** -** MovePointer -** -** Purpose: -** Accepts the distance to move and the -** distance and calls fseek to move the file -** pointer. If the fseek fails, error messages -** are displayed and FALSE is returned. TRUE -** is returned on a successful fseek. -** -*************************************************/ -BOOL MovePointer(long lDist, int nFrom) -{ - /* move the file pointer*/ - if (fseek(pFile, lDist, nFrom) != 0) - { - Trace("ftell: ERROR -> fseek failed to move the file pointer " - "%l characters.\n", - lDist); - if (fclose(pFile) != 0) - { - Trace("ftell: ERROR -> fclose failed to close the file.\n"); - } - return FALSE; - } - return TRUE; -} - - - -PALTEST(c_runtime_ftell_test1_paltest_ftell_test1, "c_runtime/ftell/test1/paltest_ftell_test1") -{ - const char szFileName[] = {"testfile.txt"}; - long lPos = -1; - int i; - char szTempBuffer[256]; - struct TESTS testCase[] = - { - {0, SEEK_SET, 0}, - {10, SEEK_CUR, 10}, - {-5, SEEK_CUR, 5}, - {-2, SEEK_END, 50} - }; - - - - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - memset(szTempBuffer, 0, 256); - - - /* open the test file */ - pFile = fopen(szFileName, "r"); - if (pFile == NULL) - { - Fail("ftell: ERROR -> fopen failed to open the file \"%s\".\n"); - } - - /* loop through the test cases */ - for (i = 0; i < (sizeof(testCase)/sizeof(struct TESTS)); i++) - { - if (MovePointer(testCase[i].lDist, testCase[i].nFrom) != TRUE) - { - Fail(""); - } - else if (Validate(testCase[i].lPosition) != TRUE) - { - Fail(""); - } - } - - if (fclose(pFile) != 0) - { - Fail("ftell: ERROR -> fclose failed to close the file.\n"); - } - - /* lets just see if we can find out where we are in a closed stream... */ - if ((lPos = ftell(pFile)) != -1) - { - Fail("ftell: ERROR -> ftell returned a valid position (%ld) on a " - "closed file handle\n", - lPos); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/ftell/test1/testfile.txt b/src/coreclr/pal/tests/palsuite/c_runtime/ftell/test1/testfile.txt deleted file mode 100644 index dd0fe15fe101b..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/ftell/test1/testfile.txt +++ /dev/null @@ -1 +0,0 @@ -The quick brown fox jumped over the lazy dog's back. \ No newline at end of file diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/fwrite/test1/test1.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/fwrite/test1/test1.cpp deleted file mode 100644 index 5b74faa8eac92..0000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/fwrite/test1/test1.cpp +++ /dev/null @@ -1,103 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*============================================================================ -** -** Source: test1.c -** -** Purpose: Write a short string to a file and check that it was written -** properly. -** -** -**==========================================================================*/ - -#include - -PALTEST(c_runtime_fwrite_test1_paltest_fwrite_test1, "c_runtime/fwrite/test1/paltest_fwrite_test1") -{ - const char filename[] = "testfile.tmp"; - const char outBuffer[] = "This is a test."; - char inBuffer[sizeof(outBuffer) + 10]; - int itemsExpected; - int itemsWritten; - FILE * fp = NULL; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - if((fp = fopen(filename, "w")) == NULL) - { - Fail("Unable to open a file for write.\n"); - } - - itemsExpected = sizeof(outBuffer); - itemsWritten = fwrite(outBuffer, - sizeof(outBuffer[0]), - sizeof(outBuffer), - fp); - - if (itemsWritten == 0) - { - if(fclose(fp) != 0) - { - Fail("fwrite: Error occurred during the closing of a file.\n"); - } - - Fail("fwrite() couldn't write to a stream at all\n"); - } - else if (itemsWritten != itemsExpected) - { - if(fclose(fp) != 0) - { - Fail("fwrite: Error occurred during the closing of a file.\n"); - } - - Fail("fwrite() produced errors writing to a stream.\n"); - } - - if(fclose(fp) != 0) - { - Fail("fwrite: Error occurred during the closing of a file.\n"); - } - - /* open the file to verify what was written to the file */ - if ((fp = fopen(filename, "r")) == NULL) - { - Fail("Couldn't open newly written file for read.\n"); - } - - if (fgets(inBuffer, sizeof(inBuffer), fp) == NULL) - { - if(fclose(fp) != 0) - { - Fail("fwrite: Error occurred during the closing of a file.\n"); - } - - Fail("We wrote something to a file using fwrite() and got errors" - " when we tried to read it back using fgets(). Either " - "fwrite() or fgets() is broken.\n"); - } - - if (strcmp(inBuffer, outBuffer) != 0) - { - if(fclose(fp) != 0) - { - Fail("fwrite: Error occurred during the closing of a file.\n"); - } - - Fail("fwrite() (or fgets()) is broken. The string read back from" - " the file does not match the string written.\n"); - } - - if(fclose(fp) != 0) - { - Fail("fwrite: Error occurred during the closing of a file.\n"); - } - - PAL_Terminate(); - return PASS; -} - - diff --git a/src/coreclr/pal/tests/palsuite/common/palsuite.h b/src/coreclr/pal/tests/palsuite/common/palsuite.h index c275b3812a256..9494daed71beb 100644 --- a/src/coreclr/pal/tests/palsuite/common/palsuite.h +++ b/src/coreclr/pal/tests/palsuite/common/palsuite.h @@ -25,6 +25,7 @@ typedef unsigned short char16_t; #include #include #include +#include #define PALTEST(testfunc, testname) \ int __cdecl testfunc(int argc, char* argv[]); \ diff --git a/src/coreclr/pal/tests/palsuite/compilableTests.txt b/src/coreclr/pal/tests/palsuite/compilableTests.txt index 6b803fd1d4a83..daaf6a68c6f2a 100644 --- a/src/coreclr/pal/tests/palsuite/compilableTests.txt +++ b/src/coreclr/pal/tests/palsuite/compilableTests.txt @@ -33,34 +33,13 @@ c_runtime/exp/test1/paltest_exp_test1 c_runtime/expf/test1/paltest_expf_test1 c_runtime/fabs/test1/paltest_fabs_test1 c_runtime/fabsf/test1/paltest_fabsf_test1 -c_runtime/ferror/test1/paltest_ferror_test1 -c_runtime/ferror/test2/paltest_ferror_test2 -c_runtime/fflush/test1/paltest_fflush_test1 -c_runtime/fgets/test1/paltest_fgets_test1 -c_runtime/fgets/test2/paltest_fgets_test2 -c_runtime/fgets/test3/paltest_fgets_test3 c_runtime/floor/test1/paltest_floor_test1 c_runtime/floorf/test1/paltest_floorf_test1 c_runtime/fma/test1/paltest_fma_test1 c_runtime/fmaf/test1/paltest_fmaf_test1 c_runtime/fmod/test1/paltest_fmod_test1 c_runtime/fmodf/test1/paltest_fmodf_test1 -c_runtime/fopen/test1/paltest_fopen_test1 -c_runtime/fopen/test2/paltest_fopen_test2 -c_runtime/fopen/test3/paltest_fopen_test3 -c_runtime/fopen/test4/paltest_fopen_test4 -c_runtime/fopen/test5/paltest_fopen_test5 -c_runtime/fopen/test6/paltest_fopen_test6 -c_runtime/fopen/test7/paltest_fopen_test7 -c_runtime/fputs/test1/paltest_fputs_test1 -c_runtime/fputs/test2/paltest_fputs_test2 -c_runtime/fread/test1/paltest_fread_test1 -c_runtime/fread/test2/paltest_fread_test2 -c_runtime/fread/test3/paltest_fread_test3 c_runtime/free/test1/paltest_free_test1 -c_runtime/fseek/test1/paltest_fseek_test1 -c_runtime/ftell/test1/paltest_ftell_test1 -c_runtime/fwrite/test1/paltest_fwrite_test1 c_runtime/ilogb/test1/paltest_ilogb_test1 c_runtime/ilogbf/test1/paltest_ilogbf_test1 c_runtime/isalnum/test1/paltest_isalnum_test1 @@ -414,7 +393,6 @@ miscellaneous/SetEnvironmentVariableW/test3/paltest_setenvironmentvariablew_test miscellaneous/SetEnvironmentVariableW/test4/paltest_setenvironmentvariablew_test4 miscellaneous/SetLastError/test1/paltest_setlasterror_test1 miscellaneous/_i64tow/test1/paltest_i64tow_test1 -pal_specific/PAL_errno/test1/paltest_pal_errno_test1 pal_specific/PAL_GetUserTempDirectoryW/test1/paltest_pal_getusertempdirectoryw_test1 pal_specific/PAL_Initialize_Terminate/test1/paltest_pal_initialize_terminate_test1 pal_specific/PAL_Initialize_Terminate/test2/paltest_pal_initialize_terminate_test2 diff --git a/src/coreclr/pal/tests/palsuite/pal_specific/PAL_errno/test1/PAL_errno.cpp b/src/coreclr/pal/tests/palsuite/pal_specific/PAL_errno/test1/PAL_errno.cpp deleted file mode 100644 index 29f2da53b055b..0000000000000 --- a/src/coreclr/pal/tests/palsuite/pal_specific/PAL_errno/test1/PAL_errno.cpp +++ /dev/null @@ -1,52 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*============================================================= -** -** Source: pal_errno.c -** -** Purpose: Positive test the PAL_errno API. -** call PAL_errno to retrieve the pointer to -** the per-thread errno value. -** -** -**============================================================*/ -#include - -PALTEST(pal_specific_PAL_errno_test1_paltest_pal_errno_test1, "pal_specific/PAL_errno/test1/paltest_pal_errno_test1") -{ - int err; - FILE *pFile = NULL; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if( 0 != err) - { - return FAIL; - } - - /*Try to open a not-exist file to read to generate an error*/ - pFile = fopen( "no_exist_file_name", "r" ); - - if( NULL != pFile ) - { - Trace("\nFailed to call fopen to open a not exist for reading, " - "an error is expected, but no error occurred\n"); - - if( EOF == fclose( pFile ) ) - { - Trace("\nFailed to call fclose to close a file stream\n"); - } - Fail( "Test failed! fopen() Should not have worked!" ); - } - - /*retrieve the per-thread error value pointer*/ - if( 2 != errno ) - { - Fail("\nFailed to call PAL_errno API, this value is not correct." - " The correct value is ENOENT[2] ( No such file or directory.).\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/coreclr/pal/tests/palsuite/pal_specific/PAL_get_stderr/test1/PAL_get_stderr.cpp b/src/coreclr/pal/tests/palsuite/pal_specific/PAL_get_stderr/test1/PAL_get_stderr.cpp deleted file mode 100644 index 2377505158c65..0000000000000 --- a/src/coreclr/pal/tests/palsuite/pal_specific/PAL_get_stderr/test1/PAL_get_stderr.cpp +++ /dev/null @@ -1,51 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*============================================================= -** -** Source: pal_get_stderr.c -** -** Purpose: Positive test the PAL_get_stderr API. -** Call PAL_get_stderr to retrieve the PAL standard error -** output stream pointer. -** This test case should be run manually and automatically. -** - -** -**============================================================*/ -#include - -PALTEST(pal_specific_PAL_get_stderr_test1_paltest_pal_get_stderr_test1, "pal_specific/PAL_get_stderr/test1/paltest_pal_get_stderr_test1") -{ - int err; - FILE *pPAL_stderr = NULL; - const char *pMsg = "\nThis is a PAL_get_stderr test message, " - "not an error message!\n"; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /*retrieve the PAL standard error output stream pointer*/ - pPAL_stderr = PAL_get_stderr(); - - if(NULL == pPAL_stderr) - { - Fail("\nFailed to call PAL_get_stderr API, error code = %u\n", - GetLastError()); - } - - /*output a test message through PAL standard error stream*/ - err = fputs(pMsg, pPAL_stderr); - if(EOF == err) - { - Fail("\nFailed to call fputs to output message to PAL stdandard " - "error stream, error code=%u\n", GetLastError()); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/coreclr/pal/tests/palsuite/pal_specific/PAL_get_stdin/test1/PAL_get_stdin.cpp b/src/coreclr/pal/tests/palsuite/pal_specific/PAL_get_stdin/test1/PAL_get_stdin.cpp deleted file mode 100644 index 91d8a3a9a650e..0000000000000 --- a/src/coreclr/pal/tests/palsuite/pal_specific/PAL_get_stdin/test1/PAL_get_stdin.cpp +++ /dev/null @@ -1,67 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*============================================================= -** -** Source: pal_get_stdin.c -** -** Purpose: Positive test the PAL_get_stdout API. -** Call PAL_get_stdin to retrieve the PAL standard input -** stream pointer. -** This test case should be run manually. -** - -** -**============================================================*/ -#include - -PALTEST(pal_specific_PAL_get_stdin_test1_paltest_pal_get_stdin_test1, "pal_specific/PAL_get_stdin/test1/paltest_pal_get_stdin_test1") -{ - int err; - FILE *pPAL_stdin = NULL; - char Buffer[256]; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /*retrieve the PAL standard input stream pointer*/ - pPAL_stdin = PAL_get_stdin(); - if(NULL == pPAL_stdin) - { - Fail("\nFailed to call PAL_get_stdin API to retrieve the " - "PAL standard input stream pointer, " - "error code = %u\n", GetLastError()); - } - - /*zero the buffer*/ - memset(Buffer, 0, 256); - - printf("\nPlease input some words: (less than 255 characters)\n"); - - /*further test the input stream*/ - /*read message from the PAL standard input stream*/ - if(NULL == fgets(Buffer, 255, pPAL_stdin)) - { - Fail( "Failed to call fgets to get a string from PAL standard " - "input stream, error code=%u\n", GetLastError()); - } - else - { - if(1 == strlen(Buffer) && Buffer[0] == '\n') - { - printf("\nEmpty input!\n"); - } - else - { - printf("\nYour input words are:\n%s\n", Buffer); - } - } - - - PAL_Terminate(); - return PASS; -} diff --git a/src/coreclr/pal/tests/palsuite/pal_specific/PAL_get_stdout/test1/PAL_get_stdout.cpp b/src/coreclr/pal/tests/palsuite/pal_specific/PAL_get_stdout/test1/PAL_get_stdout.cpp deleted file mode 100644 index d891e9ac40abc..0000000000000 --- a/src/coreclr/pal/tests/palsuite/pal_specific/PAL_get_stdout/test1/PAL_get_stdout.cpp +++ /dev/null @@ -1,51 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*============================================================= -** -** Source: pal_get_stdout.c -** -** Purpose: Positive test the PAL_get_stdout API. -** Call PAL_get_stdout to retrieve the PAL standard output -** stream pointer. -** This test case should be run manually and automatically. -** - -** -**============================================================*/ -#include - -PALTEST(pal_specific_PAL_get_stdout_test1_paltest_pal_get_stdout_test1, "pal_specific/PAL_get_stdout/test1/paltest_pal_get_stdout_test1") -{ - int err; - FILE *pPAL_stdout = NULL; - const char *pMsg = "\nThis is a PAL_get_stdout test output message, " - "not an error message!\n"; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /*retrieve the PAL output stream pointer*/ - pPAL_stdout = PAL_get_stdout(); - if(NULL == pPAL_stdout) - { - Fail("\nFailed to call PAL_get_stdout API to retrieve the " - "standard PAL output stream pointer, error code=%u\n", - GetLastError()); - } - - /*output a test message through PAL standard output stream*/ - err = fputs(pMsg, pPAL_stdout); - if(EOF == err) - { - Fail("\nFailed to call fputs to output message to PAL stdandard " - "output stream, error code=%u\n", GetLastError()); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/coreclr/pal/tests/palsuite/paltestlist.txt b/src/coreclr/pal/tests/palsuite/paltestlist.txt index 716b647caec26..a8f7da9d31783 100644 --- a/src/coreclr/pal/tests/palsuite/paltestlist.txt +++ b/src/coreclr/pal/tests/palsuite/paltestlist.txt @@ -32,27 +32,13 @@ c_runtime/exp/test1/paltest_exp_test1 c_runtime/expf/test1/paltest_expf_test1 c_runtime/fabs/test1/paltest_fabs_test1 c_runtime/fabsf/test1/paltest_fabsf_test1 -c_runtime/fflush/test1/paltest_fflush_test1 -c_runtime/fgets/test1/paltest_fgets_test1 -c_runtime/fgets/test2/paltest_fgets_test2 -c_runtime/fgets/test3/paltest_fgets_test3 c_runtime/floor/test1/paltest_floor_test1 c_runtime/floorf/test1/paltest_floorf_test1 c_runtime/fma/test1/paltest_fma_test1 c_runtime/fmaf/test1/paltest_fmaf_test1 c_runtime/fmod/test1/paltest_fmod_test1 c_runtime/fmodf/test1/paltest_fmodf_test1 -c_runtime/fopen/test1/paltest_fopen_test1 -c_runtime/fopen/test2/paltest_fopen_test2 -c_runtime/fopen/test3/paltest_fopen_test3 -c_runtime/fopen/test4/paltest_fopen_test4 -c_runtime/fopen/test5/paltest_fopen_test5 -c_runtime/fopen/test6/paltest_fopen_test6 -c_runtime/fopen/test7/paltest_fopen_test7 -c_runtime/fputs/test1/paltest_fputs_test1 c_runtime/free/test1/paltest_free_test1 -c_runtime/fseek/test1/paltest_fseek_test1 -c_runtime/fwrite/test1/paltest_fwrite_test1 c_runtime/ilogb/test1/paltest_ilogb_test1 c_runtime/ilogbf/test1/paltest_ilogbf_test1 c_runtime/isalnum/test1/paltest_isalnum_test1 @@ -368,7 +354,6 @@ miscellaneous/SetEnvironmentVariableW/test3/paltest_setenvironmentvariablew_test miscellaneous/SetEnvironmentVariableW/test4/paltest_setenvironmentvariablew_test4 miscellaneous/SetLastError/test1/paltest_setlasterror_test1 miscellaneous/_i64tow/test1/paltest_i64tow_test1 -pal_specific/PAL_errno/test1/paltest_pal_errno_test1 pal_specific/PAL_Initialize_Terminate/test1/paltest_pal_initialize_terminate_test1 pal_specific/PAL_Initialize_Terminate/test2/paltest_pal_initialize_terminate_test2 samples/test1/paltest_samples_test1 diff --git a/src/coreclr/pal/tests/palsuite/threading/SignalObjectAndWait/SignalObjectAndWaitTest.cpp b/src/coreclr/pal/tests/palsuite/threading/SignalObjectAndWait/SignalObjectAndWaitTest.cpp index 5bdccd4dbd481..3601abb4b904b 100644 --- a/src/coreclr/pal/tests/palsuite/threading/SignalObjectAndWait/SignalObjectAndWaitTest.cpp +++ b/src/coreclr/pal/tests/palsuite/threading/SignalObjectAndWait/SignalObjectAndWaitTest.cpp @@ -399,8 +399,8 @@ PALTEST(threading_SignalObjectAndWait_paltest_signalobjectandwaittest, "threadin printf( "SignalObjectAndWaitTest - Assertion failure (line %d, signalable object type %d, waitable object type %d, wait result 0x%x, error code %u): '%s'\n", ex.lineNumber, - ex.signalableObjectType, - ex.waitableObjectType, + (int)ex.signalableObjectType, + (int)ex.waitableObjectType, ex.waitResult, ex.errorCode, ex.expression); diff --git a/src/coreclr/tools/StressLogAnalyzer/StressLogDump.cpp b/src/coreclr/tools/StressLogAnalyzer/StressLogDump.cpp index f3be8b8812218..49bf662c21dde 100644 --- a/src/coreclr/tools/StressLogAnalyzer/StressLogDump.cpp +++ b/src/coreclr/tools/StressLogAnalyzer/StressLogDump.cpp @@ -243,7 +243,7 @@ void formatOutput(struct IDebugDataSpaces* memCallBack, ___in FILE* file, __inou fprintf (file, " (%s", Symbol); if (Displacement) { - fprintf (file, "+%#llx", Displacement); + fprintf (file, "+%#llx", (unsigned long long)Displacement); } fprintf (file, ")"); } @@ -528,7 +528,7 @@ HRESULT StressLog::Dump(ULONG64 outProcLog, const char* fileName, struct IDebugD latestLog->readPtr = NULL; if (!bDoGcHist) { - fprintf(file, "------------ Last message from thread %llx -----------\n", latestLog->threadId); + fprintf(file, "------------ Last message from thread %llx -----------\n", (unsigned long long)latestLog->threadId); } } diff --git a/src/coreclr/utilcode/debug.cpp b/src/coreclr/utilcode/debug.cpp index 363ff6599bab3..9784bc71dc98e 100644 --- a/src/coreclr/utilcode/debug.cpp +++ b/src/coreclr/utilcode/debug.cpp @@ -20,9 +20,8 @@ #include "log.h" -extern "C" _CRTIMP int __cdecl _flushall(void); - #ifdef HOST_WINDOWS +extern "C" _CRTIMP int __cdecl _flushall(void); void CreateCrashDumpIfEnabled(bool stackoverflow = false); #endif @@ -51,7 +50,11 @@ static void DECLSPEC_NORETURN FailFastOnAssert() WRAPPER_NO_CONTRACT; // If we're calling this, we're well past caring about contract consistency! FlushLogging(); // make certain we get the last part of the log +#ifdef HOST_WINDOWS _flushall(); +#else + fflush(NULL); +#endif ShutdownLogging(); #ifdef HOST_WINDOWS @@ -254,7 +257,7 @@ bool _DbgBreakCheck( if (formattedMessages) { OutputDebugStringUtf8(formatBuffer); - fprintf(stderr, formatBuffer); + fprintf(stderr, "%s", formatBuffer); } else { diff --git a/src/coreclr/vm/pgo.cpp b/src/coreclr/vm/pgo.cpp index 20b060d2cb4a8..c42a2236b3b98 100644 --- a/src/coreclr/vm/pgo.cpp +++ b/src/coreclr/vm/pgo.cpp @@ -205,7 +205,7 @@ void PgoManager::WritePgoData() return; } - FILE* const pgoDataFile = _wfopen(fileName, W("w")); + FILE* const pgoDataFile = _wfopen(fileName, W("wb")); if (pgoDataFile == NULL) { @@ -238,7 +238,7 @@ void PgoManager::WritePgoData() unsigned lastOffset = 0; auto lambda = [data, pgoDataFile] (const ICorJitInfo::PgoInstrumentationSchema &schema) { - fprintf(pgoDataFile, s_RecordString, schema.InstrumentationKind, schema.ILOffset, schema.Count, schema.Other); + fprintf(pgoDataFile, s_RecordString, (unsigned int)schema.InstrumentationKind, schema.ILOffset, schema.Count, schema.Other); for (int32_t iEntry = 0; iEntry < schema.Count; iEntry++) { size_t entryOffset = schema.Offset + iEntry * InstrumentationKindToSize(schema.InstrumentationKind); @@ -367,7 +367,7 @@ void PgoManager::ReadPgoData() return; } - FILE* const pgoDataFile = _wfopen(fileName, W("r")); + FILE* const pgoDataFile = _wfopen(fileName, W("rb")); if (pgoDataFile == NULL) { From a7dd5516418cb428ab1f830f88d174d1db0c382b Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 9 Feb 2024 13:59:15 -0800 Subject: [PATCH 2/5] Abstract back out the standard streams so we can correctly reference the actual streams now before we can use the standard headers. --- .../dlls/mscordac/mscordac_unixexports.src | 4 +- src/coreclr/jit/compiler.cpp | 2 +- src/coreclr/pal/inc/pal.h | 38 ++++++++++++------- src/coreclr/pal/src/cruntime/misc.cpp | 29 ++++++++------ src/coreclr/pal/src/include/pal/palinternal.h | 2 +- 5 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/coreclr/dlls/mscordac/mscordac_unixexports.src b/src/coreclr/dlls/mscordac/mscordac_unixexports.src index 1eb94680cb6dd..6c34d51796ff1 100644 --- a/src/coreclr/dlls/mscordac/mscordac_unixexports.src +++ b/src/coreclr/dlls/mscordac/mscordac_unixexports.src @@ -29,8 +29,8 @@ nativeStringResourceTable_mscorrc #PAL_GetLogicalCpuCountFromOS #PAL_GetTotalCpuCount #PAL_GetUnwindInfoSize -#PAL_get_stdout -#PAL_get_stderr +#PAL_stdout +#PAL_stderr #PAL_GetApplicationGroupId #PAL_GetTransportName #PAL_GetCurrentThread diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index a4d15fe5706b3..9144759ead0fc 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -9088,7 +9088,7 @@ void JitTimer::PrintCsvMethodStats(Compiler* comp) { totCycles += m_info.m_cyclesByPhase[i]; } - fprintf(s_csvFile, "%llu,", m_info.m_cyclesByPhase[i]); + fprintf(s_csvFile, "%llu,", (unsigned long long)m_info.m_cyclesByPhase[i]); if ((JitConfig.JitMeasureIR() != 0) && PhaseReportsIRSize[i]) { diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index 8a0308b83a193..674b89fe0a476 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -4105,15 +4105,12 @@ PALIMPORT int remove(const char*); struct _FILE; -#ifndef SKIP_STD_FILE_DECLS -typedef struct _FILE FILE; -extern FILE * stdout; -extern FILE * stdin; -extern FILE * stderr; -#else +#ifdef DEFINE_DUMMY_FILE_TYPE #define FILE _PAL_FILE struct _PAL_FILE; -#endif // SKIP_STD_FILE_DECLS +#else +typedef _FILE FILE; +#endif // DEFINE_DUMMY_FILE_TYPE PALIMPORT int __cdecl fclose(FILE *); PALIMPORT int __cdecl fflush(FILE *); @@ -4129,15 +4126,28 @@ PALIMPORT int __cdecl ferror(FILE *); PALIMPORT FILE * __cdecl fopen(const char *, const char *); PALIMPORT int __cdecl setvbuf(FILE *stream, char *, int, size_t); -#ifdef SKIP_STD_FILE_DECLS -#undef FILE -#endif - -// We need a PAL shim for errno as it's not possible to replicate the errno definition from the standard library +// We need a PAL shim for errno and the standard streams as it's not possible to replicate these definition from the standard library // in all cases. Instead, we shim it and implement the PAL function where we can include the standard headers. // When we allow people to include the standard headers, then we can remove this. -PALIMPORT DLLEXPORT int * __cdecl PAL_errno(); + +PALIMPORT int * __cdecl PAL_errno(); #define errno (*PAL_errno()) + +// Only provide a prototype for the PAL forwarders for the standard streams if we are not including the standard headers. +#ifndef DEFINE_DUMMY_FILE_TYPE + +extern "C" PALIMPORT FILE* __cdecl PAL_stdout(); +extern "C" PALIMPORT FILE* __cdecl PAL_stdin(); +extern "C" PALIMPORT FILE* __cdecl PAL_stderr(); +#define stdout PAL_stdout() +#define stdin PAL_stdin() +#define stderr PAL_stderr() + +#endif + +#ifdef DEFINE_DUMMY_FILE_TYPE +#undef FILE +#endif #endif // PAL_STDCPP_COMPAT /* _TRUNCATE */ @@ -4177,7 +4187,7 @@ PALIMPORT errno_t __cdecl _wcslwr_s(WCHAR *, size_t sz); PALIMPORT DLLEXPORT errno_t __cdecl _i64tow_s(long long, WCHAR *, size_t, int); PALIMPORT int __cdecl _wtoi(const WCHAR *); -#ifndef SKIP_STD_FILE_DECLS +#ifndef DEFINE_DUMMY_FILE_TYPE PALIMPORT FILE * __cdecl _wfopen(const WCHAR *, const WCHAR *); #endif diff --git a/src/coreclr/pal/src/cruntime/misc.cpp b/src/coreclr/pal/src/cruntime/misc.cpp index 66b347bcf06f0..7eb70412cb1a7 100644 --- a/src/coreclr/pal/src/cruntime/misc.cpp +++ b/src/coreclr/pal/src/cruntime/misc.cpp @@ -110,22 +110,27 @@ __iscsym( int c ) } /*++ -Function : - - PAL_errno - - Returns the address of the errno. +PAL forwarders for standard macro headers. --*/ int * __cdecl PAL_errno() { - int *retval; - PERF_ENTRY(errno); - ENTRY( "PAL_errno( void )\n" ); - retval = (INT*)(&errno); - LOGEXIT("PAL_errno returns %p\n",retval); - PERF_EXIT(errno); - return retval; + return &errno; +} + +extern "C" FILE* __cdecl PAL_stdout() +{ + return stdout; +} + +extern "C" FILE* __cdecl PAL_stdin() +{ + return stdin; +} + +extern "C" FILE* __cdecl PAL_stderr() +{ + return stderr; } /*++ diff --git a/src/coreclr/pal/src/include/pal/palinternal.h b/src/coreclr/pal/src/include/pal/palinternal.h index 0166d6087450d..fd412c12f0c08 100644 --- a/src/coreclr/pal/src/include/pal/palinternal.h +++ b/src/coreclr/pal/src/include/pal/palinternal.h @@ -343,7 +343,7 @@ function_name() to call the system's implementation #define uintptr_t PAL_uintptr_t #define timeval PAL_timeval -#define SKIP_STD_FILE_DECLS +#define DEFINE_DUMMY_FILE_TYPE #include "pal.h" #include "palprivate.h" From 9dd3acd19198ff9fc46d61a6b8b52b3929dc174c Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 9 Feb 2024 15:51:38 -0800 Subject: [PATCH 3/5] Make sure we export the shims for errno/stdout/stdin/stderr as the DBI uses them. --- src/coreclr/pal/inc/pal.h | 8 ++++---- src/coreclr/pal/src/cruntime/misc.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index 674b89fe0a476..cfef66b57e304 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -4130,15 +4130,15 @@ PALIMPORT int __cdecl setvbuf(FILE *stream, char *, int, size_t); // in all cases. Instead, we shim it and implement the PAL function where we can include the standard headers. // When we allow people to include the standard headers, then we can remove this. -PALIMPORT int * __cdecl PAL_errno(); +PALIMPORT DLLEXPORT int * __cdecl PAL_errno(); #define errno (*PAL_errno()) // Only provide a prototype for the PAL forwarders for the standard streams if we are not including the standard headers. #ifndef DEFINE_DUMMY_FILE_TYPE -extern "C" PALIMPORT FILE* __cdecl PAL_stdout(); -extern "C" PALIMPORT FILE* __cdecl PAL_stdin(); -extern "C" PALIMPORT FILE* __cdecl PAL_stderr(); +extern "C" PALIMPORT DLLEXPORT FILE* __cdecl PAL_stdout(); +extern "C" PALIMPORT DLLEXPORT FILE* __cdecl PAL_stdin(); +extern "C" PALIMPORT DLLEXPORT FILE* __cdecl PAL_stderr(); #define stdout PAL_stdout() #define stdin PAL_stdin() #define stderr PAL_stderr() diff --git a/src/coreclr/pal/src/cruntime/misc.cpp b/src/coreclr/pal/src/cruntime/misc.cpp index 7eb70412cb1a7..d079cd0abc4d6 100644 --- a/src/coreclr/pal/src/cruntime/misc.cpp +++ b/src/coreclr/pal/src/cruntime/misc.cpp @@ -113,22 +113,22 @@ __iscsym( int c ) PAL forwarders for standard macro headers. --*/ -int * __cdecl PAL_errno() +PALIMPORT DLLEXPORT int * __cdecl PAL_errno() { return &errno; } -extern "C" FILE* __cdecl PAL_stdout() +extern "C" PALIMPORT DLLEXPORT FILE* __cdecl PAL_stdout() { return stdout; } -extern "C" FILE* __cdecl PAL_stdin() +extern "C" PALIMPORT DLLEXPORT FILE* __cdecl PAL_stdin() { return stdin; } -extern "C" FILE* __cdecl PAL_stderr() +extern "C" PALIMPORT DLLEXPORT FILE* __cdecl PAL_stderr() { return stderr; } From c1765cf6092a1ccbd7ecbf008948f84fc1df8f5b Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 9 Feb 2024 15:52:19 -0800 Subject: [PATCH 4/5] Fix another fprintf --- src/coreclr/jit/compiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index 9144759ead0fc..76aa831ac3b46 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -9101,7 +9101,7 @@ void JitTimer::PrintCsvMethodStats(Compiler* comp) fprintf(s_csvFile, "%u,", comp->info.compNativeCodeSize); fprintf(s_csvFile, "%zu,", comp->compInfoBlkSize); fprintf(s_csvFile, "%zu,", comp->compGetArenaAllocator()->getTotalBytesAllocated()); - fprintf(s_csvFile, "%llu,", m_info.m_totalCycles); + fprintf(s_csvFile, "%llu,", (unsigned long long)m_info.m_totalCycles); fprintf(s_csvFile, "%f\n", CachedCyclesPerSecond()); fflush(s_csvFile); From 1332b936ee7b55988e2170453ba7a5b3caabcce3 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Tue, 13 Feb 2024 00:50:09 +0000 Subject: [PATCH 5/5] Remove binary mode from APIs that compile against system headers and are Unix-only. --- src/coreclr/gc/unix/cgroup.cpp | 8 ++++---- src/coreclr/gc/unix/gcenv.unix.cpp | 6 +++--- src/coreclr/pal/src/misc/cgroup.cpp | 8 ++++---- src/coreclr/pal/src/thread/process.cpp | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/coreclr/gc/unix/cgroup.cpp b/src/coreclr/gc/unix/cgroup.cpp index b7b9c37ae5652..d2ad75bbf787b 100644 --- a/src/coreclr/gc/unix/cgroup.cpp +++ b/src/coreclr/gc/unix/cgroup.cpp @@ -213,7 +213,7 @@ class CGroup char *mountpath = nullptr; char *mountroot = nullptr; - FILE *mountinfofile = fopen(PROC_MOUNTINFO_FILENAME, "rb"); + FILE *mountinfofile = fopen(PROC_MOUNTINFO_FILENAME, "r"); if (mountinfofile == nullptr) goto done; @@ -302,7 +302,7 @@ class CGroup char *cgroup_path = nullptr; bool result = false; - FILE *cgroupfile = fopen(PROC_CGROUP_FILENAME, "rb"); + FILE *cgroupfile = fopen(PROC_CGROUP_FILENAME, "r"); if (cgroupfile == nullptr) goto done; @@ -388,7 +388,7 @@ class CGroup if (asprintf(&stat_filename, "%s%s", s_memory_cgroup_path, CGROUP_MEMORY_STAT_FILENAME) < 0) return false; - FILE *stat_file = fopen(stat_filename, "rb"); + FILE *stat_file = fopen(stat_filename, "r"); free(stat_filename); if (stat_file == nullptr) return false; @@ -625,7 +625,7 @@ bool GetPhysicalMemoryUsed(size_t* val) return true; // process resident set size. - FILE* file = fopen(PROC_STATM_FILENAME, "rb"); + FILE* file = fopen(PROC_STATM_FILENAME, "r"); if (file != nullptr && getline(&line, &linelen, file) != -1) { char* context = nullptr; diff --git a/src/coreclr/gc/unix/gcenv.unix.cpp b/src/coreclr/gc/unix/gcenv.unix.cpp index a6f3f0f098769..6f1a254a0528c 100644 --- a/src/coreclr/gc/unix/gcenv.unix.cpp +++ b/src/coreclr/gc/unix/gcenv.unix.cpp @@ -832,7 +832,7 @@ bool ReadMemoryValueFromFile(const char* filename, uint64_t* val) if (val == nullptr) goto done; - file = fopen(filename, "rb"); + file = fopen(filename, "r"); if (file == nullptr) goto done; @@ -1037,7 +1037,7 @@ static uint64_t GetMemorySizeMultiplier(char units) static bool ReadMemAvailable(uint64_t* memAvailable) { bool foundMemAvailable = false; - FILE* memInfoFile = fopen("/proc/meminfo", "rb"); + FILE* memInfoFile = fopen("/proc/meminfo", "r"); if (memInfoFile != NULL) { char *line = nullptr; @@ -1170,7 +1170,7 @@ static size_t GetCurrentVirtualMemorySize() char* line = nullptr; // process virtual memory size is reported in the first column of the /proc/self/statm - FILE* file = fopen("/proc/self/statm", "rb"); + FILE* file = fopen("/proc/self/statm", "r"); if (file != nullptr && getline(&line, &linelen, file) != -1) { // The first column of the /proc/self/statm contains the virtual memory size diff --git a/src/coreclr/pal/src/misc/cgroup.cpp b/src/coreclr/pal/src/misc/cgroup.cpp index d9916a923d333..ee3c0ae584392 100644 --- a/src/coreclr/pal/src/misc/cgroup.cpp +++ b/src/coreclr/pal/src/misc/cgroup.cpp @@ -179,7 +179,7 @@ class CGroup char *mountpath = nullptr; char *mountroot = nullptr; - FILE *mountinfofile = fopen(PROC_MOUNTINFO_FILENAME, "rb"); + FILE *mountinfofile = fopen(PROC_MOUNTINFO_FILENAME, "r"); if (mountinfofile == nullptr) goto done; @@ -267,7 +267,7 @@ class CGroup char *cgroup_path = nullptr; bool result = false; - FILE *cgroupfile = fopen(PROC_CGROUP_FILENAME, "rb"); + FILE *cgroupfile = fopen(PROC_CGROUP_FILENAME, "r"); if (cgroupfile == nullptr) goto done; @@ -384,7 +384,7 @@ class CGroup if (asprintf(&filename, "%s%s", s_cpu_cgroup_path, CGROUP2_CPU_MAX_FILENAME) < 0) return false; - file = fopen(filename, "rb"); + file = fopen(filename, "r"); if (file == nullptr) goto done; @@ -476,7 +476,7 @@ class CGroup if (val == nullptr) return false; - FILE* file = fopen(filename, "rb"); + FILE* file = fopen(filename, "r"); if (file == nullptr) goto done; diff --git a/src/coreclr/pal/src/thread/process.cpp b/src/coreclr/pal/src/thread/process.cpp index 0d516f3ed1232..b23eab001cca4 100644 --- a/src/coreclr/pal/src/thread/process.cpp +++ b/src/coreclr/pal/src/thread/process.cpp @@ -1690,7 +1690,7 @@ GetProcessIdDisambiguationKey(DWORD processId, UINT64 *disambiguationKey) snprintf(statFileName, sizeof(statFileName), "/proc/%d/stat", processId); _ASSERTE(chars > 0 && chars <= (int)sizeof(statFileName)); - FILE *statFile = fopen(statFileName, "rb"); + FILE *statFile = fopen(statFileName, "r"); if (statFile == nullptr) { TRACE("GetProcessIdDisambiguationKey: fopen() FAILED");