*/
unsigned int _PDCLIB_filemode( char const * const mode )
{
+ if(!mode) return 0;
+
unsigned rc = 0;
switch ( mode[0] )
{
TESTCASE( ( fh = tmpfile() ) != NULL );
TESTCASE( fgetpos( fh, &pos1 ) == 0 );
TESTCASE( fwrite( teststring, 1, strlen( teststring ), fh ) == strlen( teststring ) );
+ TESTCASE( (size_t)ftell( fh ) == strlen( teststring ) );
TESTCASE( fgetpos( fh, &pos2 ) == 0 );
TESTCASE( fsetpos( fh, &pos1 ) == 0 );
TESTCASE( ftell( fh ) == 0 );
const char * _PDCLIB_restrict mode )
{
int imode = _PDCLIB_filemode( mode );
+
+ if( imode == 0 || filename == NULL )
+ return NULL;
+
_PDCLIB_fd_t fd = _PDCLIB_open( filename, imode );
if(fd == _PDCLIB_NOHANDLE) {
return NULL;
_PDCLIB_errno = _PDCLIB_ERANGE;
return -1;
}
- return (long int)( stream->pos.offset - ( ( (int)stream->bufend - (int)stream->bufidx ) + stream->ungetidx ) );
+ long int res = ( stream->pos.offset - ( ( (int)stream->bufend - (int)stream->bufidx ) + stream->ungetidx ) );
+ return res;
}
#endif
BOOL res = WriteFile( stream->handle, stream->buffer + written,
toWrite, &justWrote, NULL);
written += justWrote;
+ stream->pos.offset += justWrote;
if(!res) {
stream->status |=_PDCLIB_ERRORFLAG;
#include <errno.h>
#ifndef REGTEST
#include <_PDCLIB_glue.h>
+#include <windows.h>
+extern void _PDCLIB_w32errno( void );
_PDCLIB_int64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, _PDCLIB_int64_t offset, int whence )
{
- errno = ENOTSUP;
- return EOF;
+ LARGE_INTEGER liOffset;
+ liOffset.QuadPart = offset;
+ BOOL rv = SetFilePointerEx( stream->handle, liOffset, &liOffset, whence );
+ if(!rv) {
+ _PDCLIB_w32errno();
+ return EOF;
+ }
+ stream->pos.offset = liOffset.QuadPart;
+ return liOffset.QuadPart;
}
#endif
/* The values of SEEK_SET, SEEK_CUR and SEEK_END, used by fseek().
Since at least one platform (POSIX) uses the same symbols for its own "seek"
function, we use whatever the host defines (if it does define them).
+
+ Win32 note: Must match Win32 API values (FILE_BEGIN/FILE_CURRENT/FILE_END)
*/
#define _PDCLIB_SEEK_SET 0
#define _PDCLIB_SEEK_CUR 1