Commit 6aa589e8 authored by Iván Matellanes's avatar Iván Matellanes Committed by Alexandre Julliard

msvcirt: Implement stdiobuf::seekoff.

parent 66ff2e3b
......@@ -1571,8 +1571,11 @@ int __thiscall stdiobuf_pbackfail(stdiobuf *this, int c)
DEFINE_THISCALL_WRAPPER(stdiobuf_seekoff, 16)
streampos __thiscall stdiobuf_seekoff(stdiobuf *this, streamoff offset, ios_seek_dir dir, int mode)
{
FIXME("(%p %d %d %d) stub\n", this, offset, dir, mode);
return EOF;
TRACE("(%p %d %d %d)\n", this, offset, dir, mode);
call_streambuf_overflow(&this->base, EOF);
if (fseek(this->file, offset, dir))
return EOF;
return ftell(this->file);
}
/* ?setrwbuf@stdiobuf@@QAEHHH@Z */
......
......@@ -210,6 +210,7 @@ static int (*__thiscall p_strstreambuf_underflow)(strstreambuf*);
static stdiobuf* (*__thiscall p_stdiobuf_file_ctor)(stdiobuf*, FILE*);
static void (*__thiscall p_stdiobuf_dtor)(stdiobuf*);
static int (*__thiscall p_stdiobuf_overflow)(stdiobuf*, int);
static streampos (*__thiscall p_stdiobuf_seekoff)(stdiobuf*, streamoff, ios_seek_dir, int);
static int (*__thiscall p_stdiobuf_setrwbuf)(stdiobuf*, int, int);
static int (*__thiscall p_stdiobuf_sync)(stdiobuf*);
static int (*__thiscall p_stdiobuf_underflow)(stdiobuf*);
......@@ -375,6 +376,7 @@ static BOOL init(void)
SET(p_stdiobuf_file_ctor, "??0stdiobuf@@QEAA@PEAU_iobuf@@@Z");
SET(p_stdiobuf_dtor, "??1stdiobuf@@UEAA@XZ");
SET(p_stdiobuf_overflow, "?overflow@stdiobuf@@UEAAHH@Z");
SET(p_stdiobuf_seekoff, "?seekoff@stdiobuf@@UEAAJJW4seek_dir@ios@@H@Z");
SET(p_stdiobuf_setrwbuf, "?setrwbuf@stdiobuf@@QEAAHHH@Z");
SET(p_stdiobuf_sync, "?sync@stdiobuf@@UEAAHXZ");
SET(p_stdiobuf_underflow, "?underflow@stdiobuf@@UEAAHXZ");
......@@ -460,6 +462,7 @@ static BOOL init(void)
SET(p_stdiobuf_file_ctor, "??0stdiobuf@@QAE@PAU_iobuf@@@Z");
SET(p_stdiobuf_dtor, "??1stdiobuf@@UAE@XZ");
SET(p_stdiobuf_overflow, "?overflow@stdiobuf@@UAEHH@Z");
SET(p_stdiobuf_seekoff, "?seekoff@stdiobuf@@UAEJJW4seek_dir@ios@@H@Z");
SET(p_stdiobuf_setrwbuf, "?setrwbuf@stdiobuf@@QAEHHH@Z");
SET(p_stdiobuf_sync, "?sync@stdiobuf@@UAEHXZ");
SET(p_stdiobuf_underflow, "?underflow@stdiobuf@@UAEHXZ");
......@@ -2048,6 +2051,63 @@ static void test_stdiobuf(void)
ok(ret == 0, "expected 0 got %d\n", ret);
ok(stb1.base.unbuffered == 1, "wrong unbuffered value, expected 1 got %d\n", stb1.base.unbuffered);
/* seekoff */
ret = (int) call_func4(p_stdiobuf_seekoff, &stb1, 0, SEEKDIR_beg, OPENMODE_in);
ok(ret == 0, "expected 0 got %d\n", ret);
stb1.base.unbuffered = 0;
ret = (int) call_func3(p_streambuf_xsputn, &stb1.base, "Never gonna say goodbye", 22);
ok(ret == 22, "expected 22 got %d\n", ret);
ret = (int) call_func4(p_stdiobuf_seekoff, &stb1, 5, SEEKDIR_beg, OPENMODE_in);
ok(ret == 5, "expected 5 got %d\n", ret);
ok(stb1.base.pptr == stb1.base.pbase + 22, "wrong put pointer, expected %p got %p\n", stb1.base.pbase + 22, stb1.base.pptr);
ret = (int) call_func4(p_stdiobuf_seekoff, &stb1, 300, SEEKDIR_beg, OPENMODE_in);
ok(ret == 300, "expected 300 got %d\n", ret);
ret = (int) call_func4(p_stdiobuf_seekoff, &stb1, -310, SEEKDIR_cur, OPENMODE_in);
ok(ret == EOF, "expected EOF got %d\n", ret);
stb1.base.eback = stb1.base.base;
stb1.base.gptr = stb1.base.egptr = stb1.base.pbase = stb1.base.base + 10;
ret = (int) call_func4(p_stdiobuf_seekoff, &stb1, -280, SEEKDIR_cur, OPENMODE_in);
ok(ret == 20, "expected 20 got %d\n", ret);
stb1.base.gptr = stb1.base.eback;
ret = (int) call_func4(p_stdiobuf_seekoff, &stb1, 80, SEEKDIR_cur, OPENMODE_in);
ok(ret == 100, "expected 100 got %d\n", ret);
ret = (int) call_func4(p_stdiobuf_seekoff, &stb1, 0, SEEKDIR_end, OPENMODE_in);
ok(ret == 49, "expected 49 got %d\n", ret);
ret = (int) call_func4(p_stdiobuf_seekoff, &stb1, 1, SEEKDIR_end, OPENMODE_in);
ok(ret == 50, "expected 50 got %d\n", ret);
ret = (int) call_func4(p_stdiobuf_seekoff, &stb1, -60, SEEKDIR_end, OPENMODE_in);
ok(ret == EOF, "expected EOF got %d\n", ret);
ret = (int) call_func4(p_stdiobuf_seekoff, &stb1, -20, SEEKDIR_end, OPENMODE_out);
ok(ret == 29, "expected 29 got %d\n", ret);
stb1.base.eback = stb1.base.gptr = stb1.base.egptr = NULL;
stb1.base.pptr = stb1.base.pbase;
stb1.base.unbuffered = 1;
ret = (int) call_func4(p_stdiobuf_seekoff, &stb2, 0, SEEKDIR_beg, OPENMODE_in);
ok(ret == 0, "expected 0 got %d\n", ret);
stb2.base.pptr += 10;
ret = (int) call_func4(p_stdiobuf_seekoff, &stb2, 20, SEEKDIR_beg, OPENMODE_in);
ok(ret == 20, "expected 20 got %d\n", ret);
ok(stb2.base.pptr == stb2.base.pbase + 10, "wrong put pointer, expected %p got %p\n", stb2.base.pbase + 10, stb2.base.pptr);
stb2.base.unbuffered = 0;
ret = (int) call_func4(p_stdiobuf_seekoff, &stb2, 10, SEEKDIR_cur, OPENMODE_in);
ok(ret == 40, "expected 40 got %d\n", ret);
ok(stb2.base.pptr == stb2.base.pbase, "wrong put pointer, expected %p got %p\n", stb2.base.pbase, stb2.base.pptr);
stb2.base.gptr = stb2.base.eback;
stb2.base.pptr += 5;
ret = (int) call_func4(p_stdiobuf_seekoff, &stb2, -50, SEEKDIR_cur, OPENMODE_in|OPENMODE_out);
ok(ret == EOF, "expected EOF got %d\n", ret);
ok(stb2.base.pptr == stb2.base.pbase, "wrong put pointer, expected %p got %p\n", stb2.base.pbase, stb2.base.pptr);
stb2.base.pbase = stb2.base.pptr = stb2.base.epptr = NULL;
ret = (int) call_func4(p_stdiobuf_seekoff, &stb2, 0, SEEKDIR_end, OPENMODE_in|OPENMODE_out);
ok(ret == 48, "expected 48 got %d\n", ret);
ok(stb2.base.pbase == stb2.base.base + 32, "wrong put pointer, expected %p got %p\n", stb2.base.base + 32, stb2.base.pbase);
ok(stb2.base.pptr == stb2.base.base + 32, "wrong put pointer, expected %p got %p\n", stb2.base.base + 32, stb2.base.pptr);
ok(stb2.base.epptr == stb2.base.ebuf, "wrong put pointer, expected %p got %p\n", stb2.base.ebuf, stb2.base.epptr);
ret = (int) call_func4(p_stdiobuf_seekoff, &stb2, -28, SEEKDIR_end, -1);
ok(ret == 20, "expected 20 got %d\n", ret);
stb2.base.gptr = stb2.base.egptr;
stb2.base.unbuffered = 1;
call_func1(p_stdiobuf_dtor, &stb1);
call_func1(p_stdiobuf_dtor, &stb2);
fclose(file1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment