Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert fstream.seekp(0, ios::cur) change #3841

Merged
merged 2 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion stl/inc/__msvc_filebuf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,8 @@ class basic_filebuf : public basic_streambuf<_Elem, _Traits> { // stream buffer
_Off -= static_cast<off_type>(sizeof(_Elem)); // back up over _Elem bytes
}

if (!_Myfile || !_Endwrite() || _CSTD _fseeki64(_Myfile, _Off, _Way) != 0
if (!_Myfile || !_Endwrite()
|| ((_Off != 0 || _Way != ios_base::cur) && _CSTD _fseeki64(_Myfile, _Off, _Way) != 0)
|| _CSTD fgetpos(_Myfile, &_Fileposition) != 0) {
return pos_type{off_type{-1}}; // report failure
}
Expand Down
2 changes: 1 addition & 1 deletion tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,10 @@ tests\GH_003022_substr_allocator
tests\GH_003105_piecewise_densities
tests\GH_003119_error_category_ctor
tests\GH_003246_cmath_narrowing
tests\GH_003572_fstream_seekp_0_cur
tests\GH_003617_vectorized_meow_element
tests\GH_003676_format_large_hh_mm_ss_values
tests\GH_003735_char_traits_signatures
tests\GH_003840_tellg_when_reading_lf_file_in_text_mode
tests\LWG2381_num_get_floating_point
tests\LWG2597_complex_branch_cut
tests\LWG3018_shared_ptr_function
Expand Down
47 changes: 0 additions & 47 deletions tests/std/tests/GH_003572_fstream_seekp_0_cur/test.cpp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\usual_matrix.lst
RUNALL_INCLUDE ..\usual_17_matrix.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <cassert>
#include <filesystem>
#include <fstream>
#include <ios>
#include <string>

#include "temp_file_name.hpp"

using namespace std;

void test(const string& temp_file_name_str, const ios_base::openmode mode) {
filesystem::remove(temp_file_name_str);

{
ofstream out{temp_file_name_str, mode};
out << "Line A\n";
out << "Line B\n";
out << "Line C\n";
}

{
ifstream in{temp_file_name_str};
string line;

assert(getline(in, line));
assert(line == "Line A");
(void) in.tellg();

assert(getline(in, line));
assert(line == "Line B");
(void) in.tellg();

assert(getline(in, line));
assert(line == "Line C");
(void) in.tellg();

assert(!getline(in, line));
}

filesystem::remove(temp_file_name_str);
}

int main() {
const string temp_file_name_str = temp_file_name();

test(temp_file_name_str, ios_base::out);
test(temp_file_name_str, ios_base::binary);
}