Author: akhaldi
Date: Sun May 11 10:45:02 2014
New Revision: 63226
URL:
http://svn.reactos.org/svn/reactos?rev=63226&view=rev
Log:
[CRT]
* Update _ftelli64()
* Fixes a couple msvcrt tests.
CORE-8080
Modified:
trunk/reactos/lib/sdk/crt/stdio/file.c
Modified: trunk/reactos/lib/sdk/crt/stdio/file.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/stdio/file.c?r…
==============================================================================
--- trunk/reactos/lib/sdk/crt/stdio/file.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/stdio/file.c [iso-8859-1] Sun May 11 10:45:02 2014
@@ -83,6 +83,7 @@
/* values for wxflag in file descriptor */
#define WX_OPEN 0x01
#define WX_ATEOF 0x02
+#define WX_READNL 0x04 /* read started with \n */
#define WX_READEOF 0x04 /* like ATEOF, but for underlying file rather than buffer
*/
#define WX_READCR 0x08 /* underlying file is at \r */
#define WX_DONTINHERIT 0x10
@@ -2894,13 +2895,79 @@
*/
__int64 CDECL _ftelli64(FILE* file)
{
- /* TODO: just call fgetpos and return lower half of result */
- int off=0;
__int64 pos;
_lock_file(file);
pos = _telli64(file->_file);
if(pos == -1) {
+ _unlock_file(file);
+ return -1;
+ }
+ if(file->_bufsiz) {
+ if(file->_flag & _IOWRT) {
+ pos += file->_ptr - file->_base;
+
+ if(get_ioinfo(file->_file)->wxflag & WX_TEXT) {
+ char *p;
+
+ for(p=file->_base; p<file->_ptr; p++)
+ if(*p == '\n')
+ pos++;
+ }
+ } else if(!file->_cnt) { /* nothing to do */
+ } else if(_lseeki64(file->_file, 0, SEEK_END)==pos) {
+ int i;
+
+ pos -= file->_cnt;
+ if(get_ioinfo(file->_file)->wxflag & WX_TEXT) {
+ for(i=0; i<file->_cnt; i++)
+ if(file->_ptr[i] == '\n')
+ pos--;
+ }
+ } else {
+ char *p;
+
+ if(_lseeki64(file->_file, pos, SEEK_SET) != pos) {
+ _unlock_file(file);
+ return -1;
+ }
+
+ pos -= file->_bufsiz;
+ pos += file->_ptr - file->_base;
+
+ if(get_ioinfo(file->_file)->wxflag & WX_TEXT) {
+ if(get_ioinfo(file->_file)->wxflag & WX_READNL)
+ pos--;
+
+ for(p=file->_base; p<file->_ptr; p++)
+ if(*p == '\n')
+ pos++;
+ }
+ }
+ }
+
+ _unlock_file(file);
+ return pos;
+}
+
+/*********************************************************************
+ * ftell (MSVCRT.@)
+ */
+LONG CDECL ftell(FILE* file)
+{
+ return (LONG)_ftelli64(file);
+}
+
+/*********************************************************************
+ * fgetpos (MSVCRT.@)
+ */
+int CDECL fgetpos(FILE* file, fpos_t *pos)
+{
+ int off=0;
+
+ _lock_file(file);
+ *pos = _lseeki64(file->_file,0,SEEK_CUR);
+ if(*pos == -1) {
_unlock_file(file);
return -1;
}
@@ -2922,50 +2989,6 @@
}
}
}
-
- _unlock_file(file);
- return off + pos;
-}
-
-/*********************************************************************
- * ftell (MSVCRT.@)
- */
-LONG CDECL ftell(FILE* file)
-{
- return (LONG)_ftelli64(file);
-}
-
-/*********************************************************************
- * fgetpos (MSVCRT.@)
- */
-int CDECL fgetpos(FILE* file, fpos_t *pos)
-{
- int off=0;
-
- _lock_file(file);
- *pos = _lseeki64(file->_file,0,SEEK_CUR);
- if(*pos == -1) {
- _unlock_file(file);
- return -1;
- }
- if(file->_bufsiz) {
- if( file->_flag & _IOWRT ) {
- off = file->_ptr - file->_base;
- } else {
- off = -file->_cnt;
- if (get_ioinfo(file->_file)->wxflag & WX_TEXT) {
- /* Black magic correction for CR removal */
- int i;
- for (i=0; i<file->_cnt; i++) {
- if (file->_ptr[i] == '\n')
- off--;
- }
- /* Black magic when reading CR at buffer boundary*/
- if(get_ioinfo(file->_file)->wxflag & WX_READCR)
- off--;
- }
- }
- }
*pos += off;
_unlock_file(file);
return 0;