diff --git a/exporters/otlp/src/otlp_file_client.cc b/exporters/otlp/src/otlp_file_client.cc index 09e97accdc..021035eb55 100644 --- a/exporters/otlp/src/otlp_file_client.cc +++ b/exporters/otlp/src/otlp_file_client.cc @@ -1,6 +1,8 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include + #include #include #include @@ -12,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -1028,13 +1029,13 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender MaybeRotateLog(data.size()); - std::shared_ptr out = OpenLogFile(true); + std::shared_ptr out = OpenLogFile(true); if (!out) { return; } - fwrite(data.data(), 1, data.size(), out.get()); + std::fwrite(data.data(), 1, data.size(), out.get()); { std::lock_guard lock_guard{file_->file_lock}; @@ -1042,7 +1043,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender file_->record_count += record_count; // Pipe file size always returns 0, we ignore the size limit of it. - auto written_size = ftell(out.get()); + auto written_size = std::ftell(out.get()); if (written_size >= 0) { file_->written_size = static_cast(written_size); @@ -1054,7 +1055,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender { file_->left_flush_record_count = options_.flush_count; - fflush(out.get()); + std::fflush(out.get()); file_->flushed_record_count.store(file_->record_count.load(std::memory_order_acquire), std::memory_order_release); @@ -1216,7 +1217,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender OpenLogFile(false); } - std::shared_ptr OpenLogFile(bool destroy_content) + std::shared_ptr OpenLogFile(bool destroy_content) { std::lock_guard lock_guard{file_->file_lock}; @@ -1238,8 +1239,6 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender } file_path[file_path_size] = 0; - std::shared_ptr of = std::make_shared(); - std::string directory_name = FileSystemUtil::DirName(file_path); if (!directory_name.empty()) { @@ -1294,10 +1293,10 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender << " failed with pattern: " << options_.file_pattern << hint); return nullptr; } - of = std::shared_ptr(new_file, fclose); + std::shared_ptr of = std::shared_ptr(new_file, fclose); - fseek(of.get(), 0, SEEK_END); - file_->written_size = static_cast(ftell(of.get())); + std::fseek(of.get(), 0, SEEK_END); + file_->written_size = static_cast(std::ftell(of.get())); file_->current_file = of; file_->last_checkpoint = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); @@ -1513,7 +1512,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender if (concurrency_file->current_file) { - fflush(concurrency_file->current_file.get()); + std::fflush(concurrency_file->current_file.get()); } concurrency_file->flushed_record_count.store(current_record_count, @@ -1568,7 +1567,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender std::size_t rotate_index; std::size_t written_size; std::size_t left_flush_record_count; - std::shared_ptr current_file; + std::shared_ptr current_file; std::mutex file_lock; std::time_t last_checkpoint; std::string file_path;