From 8e24fad4e3d37d2dde03216db0b376e8a0557867 Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Wed, 25 Sep 2024 17:15:50 +0200 Subject: [PATCH] base: add memutil.h --- ortools/base/BUILD.bazel | 8 ++++++++ ortools/base/memutil.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 ortools/base/memutil.h diff --git a/ortools/base/BUILD.bazel b/ortools/base/BUILD.bazel index 0a3979cd7a..3a93dede6f 100644 --- a/ortools/base/BUILD.bazel +++ b/ortools/base/BUILD.bazel @@ -367,6 +367,14 @@ cc_library( deps = [], ) +cc_library( + name = "memutil", + hdrs = ["memutil.h"], + deps = [ + "@com_google_absl//absl/strings", + ], +) + cc_library( name = "murmur", hdrs = ["murmur.h"], diff --git a/ortools/base/memutil.h b/ortools/base/memutil.h new file mode 100644 index 0000000000..1d6fd87bae --- /dev/null +++ b/ortools/base/memutil.h @@ -0,0 +1,28 @@ +// Copyright 2010-2024 Google LLC +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef OR_TOOLS_BASE_MEMUTIL_H_ +#define OR_TOOLS_BASE_MEMUTIL_H_ + +#include "absl/strings/internal/memutil.h" + +namespace strings { +char* memdup(const char* s, size_t slen) { + void* copy; + if ((copy = malloc(slen)) == nullptr) return nullptr; + memcpy(copy, s, slen); + return reinterpret_cast(copy); +} +} // namespace strings + +#endif // OR_TOOLS_BASE_MEMUTIL_H_