2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef BACKUP_MANAGER_SERVER_INCLUDE_BKUP_UTIL_H_
18 #define BACKUP_MANAGER_SERVER_INCLUDE_BKUP_UTIL_H_
24 static inline size_t BkupStrlcpy(char *dst, const char *src, size_t siz) {
25 size_t ret = strlen(src);
32 if (siz) { // LCOV_EXCL_BR_LINE 6:double check
33 size_t len = (ret >= siz) ? siz - 1 : ret; // LCOV_EXCL_BR_LINE 11:unexpected branch
34 memcpy(dst, src, len);
40 static inline char *BkupAnonMmap(size_t size) {
41 char *map = static_cast<char *>(mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0));
45 static inline uint64_t BkupTimerReal(void) {
47 if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts) != -1) { // LCOV_EXCL_BR_LINE 5:clock_gettime's error case.
48 return (uint64_t)ts.tv_sec * 1000000000 + ts.tv_nsec;
53 #endif // BACKUP_MANAGER_SERVER_INCLUDE_BKUP_UTIL_H_