1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 // pos_type seekoff(off_type off, ios_base::seekdir way,
12 // ios_base::openmode which = ios_base::in | ios_base::out);
13 // pos_type seekpos(pos_type sp,
14 // ios_base::openmode which = ios_base::in | ios_base::out);
19 #include "test_macros.h"
25 typedef std::filebuf::pos_type pos_type
;
27 f
.pubsetbuf(buf
, sizeof(buf
));
28 assert(f
.open("seekoff.dat", std::ios_base::in
| std::ios_base::out
29 | std::ios_base::trunc
) != 0);
31 f
.sputn("abcdefghijklmnopqrstuvwxyz", 26);
32 LIBCPP_ASSERT(buf
[0] == 'v');
33 pos_type p
= f
.pubseekoff(-15, std::ios_base::cur
);
35 assert(f
.sgetc() == 'l');
36 f
.pubseekoff(0, std::ios_base::beg
);
37 assert(f
.sgetc() == 'a');
38 f
.pubseekoff(-1, std::ios_base::end
);
39 assert(f
.sgetc() == 'z');
40 assert(f
.pubseekpos(p
) == p
);
41 assert(f
.sgetc() == 'l');
43 std::remove("seekoff.dat");
45 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
48 typedef std::filebuf::pos_type pos_type
;
50 f
.pubsetbuf(buf
, sizeof(buf
)/sizeof(buf
[0]));
51 assert(f
.open("seekoff.dat", std::ios_base::in
| std::ios_base::out
52 | std::ios_base::trunc
) != 0);
54 f
.sputn(L
"abcdefghijklmnopqrstuvwxyz", 26);
55 LIBCPP_ASSERT(buf
[0] == L
'v');
56 pos_type p
= f
.pubseekoff(-15, std::ios_base::cur
);
58 assert(f
.sgetc() == L
'l');
59 f
.pubseekoff(0, std::ios_base::beg
);
60 assert(f
.sgetc() == L
'a');
61 f
.pubseekoff(-1, std::ios_base::end
);
62 assert(f
.sgetc() == L
'z');
63 assert(f
.pubseekpos(p
) == p
);
64 assert(f
.sgetc() == L
'l');
66 std::remove("seekoff.dat");