/*++ Function : ungetc See MSDN for more details. --*/ int _cdecl PAL_ungetc(int c, PAL_FILE * f) { INT nRetVal = 0; PERF_ENTRY(ungetc); ENTRY( "ungetc( %c, %p )\n", c, f ); _ASSERTE(f != NULL); #if UNGETC_NOT_RETURN_EOF /* On some Unix platform such as Solaris, ungetc does not return EOF on write-only file. */ if (f->bWriteOnlyMode) { nRetVal = EOF; } else #endif //UNGETC_NOT_RETURN_EOF { CLEARERR(f); nRetVal = ungetc( c, f->bsdFilePtr ); } LOGEXIT( "ungetc returning %d\n", nRetVal ); PERF_EXIT(ungetc); return nRetVal; }
/*++ 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; }
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); THREADMarkDiagnostic("PAL_fread"); 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++]=nChar; } } } } nReadBytes = i; } done: LOGEXIT( "fread returning size_t %d\n", nReadBytes ); PERF_EXIT(fread); return nReadBytes; }
/*-- Function : fputc See MSDN for more details. --*/ int _cdecl PAL_fputc(int c, PAL_FILE * f) { INT nRetVal = 0; PERF_ENTRY(fputc); ENTRY( "fputc( 0x%x (%c), %p )\n", c, c, f); _ASSERTE(f != NULL); CLEARERR(f); nRetVal = fputc( c, f->bsdFilePtr ); LOGEXIT( "fputc returning %d\n", nRetVal ); PERF_EXIT(fputc); return nRetVal; }
/*++ Function: _putw Writes an integer to a stream. Return Value _putw returns the value written. A return value of EOF may indicate an error. Because EOF is also a legitimate integer value, use ferror to verify an error. Parameters c Binary integer to be output file Pointer to FILE structure --*/ int __cdecl _putw(int c, PAL_FILE *f) { INT ret = 0; PERF_ENTRY(_putw); ENTRY("_putw (c=0x%x, f=%p)\n", c, f); _ASSERTE(f != NULL); CLEARERR(f); ret = putw(c, f->bsdFilePtr ); LOGEXIT( "returning %d\n", ret ); PERF_EXIT(_putw); return ret; }
/*++ Function: _getw Gets an integer from a stream. Return Value _getw returns the integer value read. A return value of EOF indicates either an error or end of file. However, because the EOF value is also a legitimate integer value, use feof or ferror to verify an end-of-file or error condition. Parameter file Pointer to FILE structure --*/ int __cdecl _getw(PAL_FILE *f) { INT ret = 0; PERF_ENTRY(_getw); ENTRY("_getw (f=%p)\n", f); _ASSERTE(f != NULL); CLEARERR(f); ret = getw( f->bsdFilePtr ); LOGEXIT( "returning %d\n", ret ); PERF_EXIT(_getw); return ret; }
/*++ 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 : 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; }