diff --git a/dlls/msvcp90/ios.c b/dlls/msvcp90/ios.c index b1acb3f011..7759b72752 100644 --- a/dlls/msvcp90/ios.c +++ b/dlls/msvcp90/ios.c @@ -7737,25 +7737,23 @@ int __thiscall basic_istream_char_sync(basic_istream_char *this) DEFINE_THISCALL_WRAPPER(basic_istream_char_tellg, 8) fpos_int* __thiscall basic_istream_char_tellg(basic_istream_char *this, fpos_int *ret) { + basic_ios_char *base = basic_istream_char_get_basic_ios(this); + TRACE("(%p %p)\n", this, ret); - if(basic_istream_char_sentry_create(this, TRUE)) { - basic_ios_char *base = basic_istream_char_get_basic_ios(this); - if(!ios_base_fail(&base->base)) { - basic_streambuf_char_pubseekoff(basic_ios_char_rdbuf_get(base), - ret, 0, SEEKDIR_cur, OPENMODE_in); - basic_istream_char_sentry_destroy(this); - - if(ret->off==-1 && ret->pos==0 && ret->state==0) - basic_ios_char_setstate(base, IOSTATE_failbit); - return ret; - } + if(ios_base_fail(&base->base)) { + ret->off = -1; + ret->pos = 0; + ret->state = 0; + return ret; } - basic_istream_char_sentry_destroy(this); - ret->off = -1; - ret->pos = 0; - ret->state = 0; + basic_streambuf_char_pubseekoff(basic_ios_char_rdbuf_get(base), + ret, 0, SEEKDIR_cur, OPENMODE_in); + + if(ret->off==-1 && ret->pos==0 && ret->state==0) + basic_ios_char_setstate(base, IOSTATE_failbit); + return ret; } @@ -9019,25 +9017,22 @@ int __thiscall basic_istream_wchar_sync(basic_istream_wchar *this) DEFINE_THISCALL_WRAPPER(basic_istream_wchar_tellg, 8) fpos_int* __thiscall basic_istream_wchar_tellg(basic_istream_wchar *this, fpos_int *ret) { + basic_ios_wchar *base = basic_istream_wchar_get_basic_ios(this); + TRACE("(%p %p)\n", this, ret); - if(basic_istream_wchar_sentry_create(this, TRUE)) { - basic_ios_wchar *base = basic_istream_wchar_get_basic_ios(this); - if(!ios_base_fail(&base->base)) { - basic_streambuf_wchar_pubseekoff(basic_ios_wchar_rdbuf_get(base), - ret, 0, SEEKDIR_cur, OPENMODE_in); - basic_istream_wchar_sentry_destroy(this); - - if(ret->off==-1 && ret->pos==0 && ret->state==0) - basic_ios_wchar_setstate(base, IOSTATE_failbit); - return ret; - } + if(ios_base_fail(&base->base)) { + ret->off = -1; + ret->pos = 0; + ret->state = 0; + return ret; } - basic_istream_wchar_sentry_destroy(this); - ret->off = -1; - ret->pos = 0; - ret->state = 0; + basic_streambuf_wchar_pubseekoff(basic_ios_wchar_rdbuf_get(base), + ret, 0, SEEKDIR_cur, OPENMODE_in); + if(ret->off==-1 && ret->pos==0 && ret->state==0) + basic_ios_wchar_setstate(base, IOSTATE_failbit); + return ret; } diff --git a/dlls/msvcp90/tests/ios.c b/dlls/msvcp90/tests/ios.c index c184cdb586..867c190d54 100644 --- a/dlls/msvcp90/tests/ios.c +++ b/dlls/msvcp90/tests/ios.c @@ -365,6 +365,7 @@ static basic_istream_char* (*__thiscall p_basic_istream_char_ignore)(basic_istre static basic_istream_char* (*__thiscall p_basic_istream_char_seekg)(basic_istream_char*, streamoff, int); static basic_istream_char* (*__thiscall p_basic_istream_char_seekg_fpos)(basic_istream_char*, fpos_int); static int (*__thiscall p_basic_istream_char_peek)(basic_istream_char*); +static fpos_int* (*__thiscall p_basic_istream_char_tellg)(basic_istream_char*, fpos_int*); static basic_istream_wchar* (*__thiscall p_basic_istream_wchar_read_uint64)(basic_istream_wchar*, unsigned __int64*); static basic_istream_wchar* (*__thiscall p_basic_istream_wchar_read_double)(basic_istream_wchar*, double *); @@ -374,6 +375,7 @@ static basic_istream_wchar* (*__thiscall p_basic_istream_wchar_ignore)(basic_ist static basic_istream_wchar* (*__thiscall p_basic_istream_wchar_seekg)(basic_istream_wchar*, streamoff, int); static basic_istream_wchar* (*__thiscall p_basic_istream_wchar_seekg_fpos)(basic_istream_wchar*, fpos_int); static unsigned short (*__thiscall p_basic_istream_wchar_peek)(basic_istream_wchar*); +static fpos_int* (*__thiscall p_basic_istream_wchar_tellg)(basic_istream_wchar*, fpos_int*); /* ostream */ static basic_ostream_char* (*__thiscall p_basic_ostream_char_print_double)(basic_ostream_char*, double); @@ -417,6 +419,16 @@ static void __cdecl test_invalid_parameter_handler(const wchar_t *expression, invalid_parameter++; } +static inline const char* debugstr_longlong(ULONGLONG ll) +{ + static char string[17]; + if (sizeof(ll) > sizeof(unsigned long) && ll >> 32) + sprintf(string, "%lx%08lx", (unsigned long)(ll >> 32), (unsigned long)ll); + else + sprintf(string, "%lx", (unsigned long)ll); + return string; +} + /* Emulate a __thiscall */ #ifdef __i386__ @@ -544,6 +556,8 @@ static BOOL init(void) "?seekg@?$basic_istream@DU?$char_traits@D@std@@@std@@QEAAAEAV12@V?$fpos@H@2@@Z"); SET(p_basic_istream_char_peek, "?peek@?$basic_istream@DU?$char_traits@D@std@@@std@@QEAAHXZ"); + SET(p_basic_istream_char_tellg, + "?tellg@?$basic_istream@DU?$char_traits@D@std@@@std@@QEAA?AV?$fpos@H@2@XZ"); SET(p_basic_istream_wchar_read_uint64, "??5?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAAAEAV01@AEA_K@Z"); @@ -561,6 +575,8 @@ static BOOL init(void) "?seekg@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAAAEAV12@V?$fpos@H@2@@Z"); SET(p_basic_istream_wchar_peek, "?peek@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAAGXZ"); + SET(p_basic_istream_wchar_tellg, + "?tellg@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAA?AV?$fpos@H@2@XZ"); SET(p_basic_ostream_char_print_double, "??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@N@Z"); @@ -636,6 +652,8 @@ static BOOL init(void) "?seekg@?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV12@V?$fpos@H@2@@Z"); SET(p_basic_istream_char_peek, "?peek@?$basic_istream@DU?$char_traits@D@std@@@std@@QAEHXZ"); + SET(p_basic_istream_char_tellg, + "?tellg@?$basic_istream@DU?$char_traits@D@std@@@std@@QAE?AV?$fpos@H@2@XZ"); SET(p_basic_istream_wchar_read_uint64, "??5?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAEAAV01@AA_K@Z"); @@ -653,6 +671,8 @@ static BOOL init(void) "?seekg@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAEAAV12@V?$fpos@H@2@@Z"); SET(p_basic_istream_wchar_peek, "?peek@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAEGXZ"); + SET(p_basic_istream_wchar_tellg, + "?tellg@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAE?AV?$fpos@H@2@XZ"); SET(p_basic_ostream_char_print_double, "??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@N@Z"); @@ -1422,6 +1442,89 @@ static void test_istream_peek(void) } +static void test_istream_tellg(void) +{ + basic_stringstream_wchar wss; + basic_stringstream_char ss; + basic_string_wchar wstr; + basic_string_char str; + fpos_int spos, tpos, *rpos; + wchar_t wide[64]; + int i; + + struct _test_istream_tellg_fpos { + const char *str; + streamoff seekoff; + streamoff telloff; + } tests[] = { + /* empty strings */ + { "", -1, -1 }, /* tellg on defaults */ + { "", 0, -1 }, /* tellg after seek 0 */ + { "", 42, -1 }, /* tellg after seek beyond end */ + { "", -6, -1 }, /* tellg after seek beyond beg */ + + /* non-empty strings */ + { "ABCDEFGHIJ", -1, 0 }, + { "ABCDEFGHIJ", 3, 3 }, + { "ABCDEFGHIJ", 42, -1 }, + { "ABCDEFGHIJ", -6, -1 } + }; + + for(i=0; i