| 1 | /* Copyright (c) 2016, 2026, Oracle and/or its affiliates. |
| 2 | |
| 3 | This program is free software; you can redistribute it and/or modify |
| 4 | it under the terms of the GNU General Public License, version 2.0, |
| 5 | as published by the Free Software Foundation. |
| 6 | |
| 7 | This program is designed to work with certain software (including |
| 8 | but not limited to OpenSSL) that is licensed under separate terms, |
| 9 | as designated in a particular file or component or in included license |
| 10 | documentation. The authors of MySQL hereby grant you an additional |
| 11 | permission to link the program and your derivative works with the |
| 12 | separately licensed software that they have either included with |
| 13 | the program or referenced in the documentation. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU General Public License, version 2.0, for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
| 21 | along with this program; if not, write to the Free Software |
| 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 23 | |
| 24 | #include "unittest/gunit/keyring/buffered_file_io_10.h" |
| 25 | |
| 26 | #include <fcntl.h> |
| 27 | #include <mysql/psi/mysql_file.h> |
| 28 | |
| 29 | #include "my_io.h" |
| 30 | |
| 31 | namespace keyring { |
| 32 | bool Buffered_file_io_10::flush_to_file(PSI_file_key *file_key [[maybe_unused]], |
| 33 | const std::string *filename, |
| 34 | const Digest *) { |
| 35 | File file; |
| 36 | bool was_error = true; |
| 37 | file = mysql_file_open(*file_key, filename->c_str(), |
| 38 | O_TRUNC | O_WRONLY | O_CREAT, MYF(0)); |
| 39 | if (file >= 0 && |
| 40 | mysql_file_write( |
| 41 | file, reinterpret_cast<const uchar *>(file_version.c_str()), |
| 42 | file_version.length(), MYF(0)) == file_version.length() && |
| 43 | mysql_file_write(file, buffer.data, buffer.size, MYF(0)) == buffer.size && |
| 44 | mysql_file_write( |
| 45 | file, reinterpret_cast<const uchar *>(Checker::get_eofTAG().c_str()), |
| 46 | Checker::get_eofTAG().length(), |
| 47 | MYF(0)) == Checker::get_eofTAG().length() && |
| 48 | mysql_file_close(file, MYF(0)) >= 0) { |
| 49 | was_error = false; |
| 50 | } |
| 51 | buffer.free(); |
| 52 | return was_error; |
| 53 | } |
| 54 | |
| 55 | size_t Buffered_file_io_10::get_memory_needed_for_buffer() { |
| 56 | return memory_needed_for_buffer; |
| 57 | } |
| 58 | } // namespace keyring |