17310c0d0Sopenharmony_ci/*
27310c0d0Sopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
37310c0d0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
47310c0d0Sopenharmony_ci * you may not use this file except in compliance with the License.
57310c0d0Sopenharmony_ci * You may obtain a copy of the License at
67310c0d0Sopenharmony_ci *
77310c0d0Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
87310c0d0Sopenharmony_ci *
97310c0d0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
107310c0d0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
117310c0d0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
127310c0d0Sopenharmony_ci * See the License for the specific language governing permissions and
137310c0d0Sopenharmony_ci * limitations under the License.
147310c0d0Sopenharmony_ci */
157310c0d0Sopenharmony_ci#ifndef __HVB_UTIL_H_
167310c0d0Sopenharmony_ci#define __HVB_UTIL_H_
177310c0d0Sopenharmony_ci
187310c0d0Sopenharmony_ci#include <stddef.h>
197310c0d0Sopenharmony_ci#include "hvb_ops.h"
207310c0d0Sopenharmony_ci#include "hvb.h"
217310c0d0Sopenharmony_ci#include "hvb_sysdeps.h"
227310c0d0Sopenharmony_ci
237310c0d0Sopenharmony_ci#ifdef __cplusplus
247310c0d0Sopenharmony_ciextern "C"
257310c0d0Sopenharmony_ci{
267310c0d0Sopenharmony_ci#endif
277310c0d0Sopenharmony_ci
287310c0d0Sopenharmony_ci#define MAX_STRING_LEN         17
297310c0d0Sopenharmony_ci#define HVB_MAX_DIGITS_UINT64  32
307310c0d0Sopenharmony_ci
317310c0d0Sopenharmony_ci#ifndef NULL
327310c0d0Sopenharmony_ci#define NULL 0
337310c0d0Sopenharmony_ci#endif
347310c0d0Sopenharmony_ci
357310c0d0Sopenharmony_ci#ifdef offsetof
367310c0d0Sopenharmony_ci#define hvb_offsetof(type, member) offsetof(type, member)
377310c0d0Sopenharmony_ci#else
387310c0d0Sopenharmony_ci#define hvb_offsetof(type, member) ((size_t)&(((type *)0)->member))
397310c0d0Sopenharmony_ci#endif
407310c0d0Sopenharmony_ci
417310c0d0Sopenharmony_ci#define hvb_return_hvb_err_if_null(__ptr)                   \
427310c0d0Sopenharmony_ci    do {                                                       \
437310c0d0Sopenharmony_ci        if ((__ptr) == NULL) {                             \
447310c0d0Sopenharmony_ci            hvb_printv("error, %s is NULL\n", #__ptr, NULL); \
457310c0d0Sopenharmony_ci            return HVB_ERROR_INVALID_ARGUMENT;  \
467310c0d0Sopenharmony_ci        }                                                  \
477310c0d0Sopenharmony_ci    } while (0)
487310c0d0Sopenharmony_ci
497310c0d0Sopenharmony_ciuint64_t hvb_be64toh(uint64_t data);
507310c0d0Sopenharmony_ciuint64_t hvb_htobe64(uint64_t data);
517310c0d0Sopenharmony_ci
527310c0d0Sopenharmony_cichar *hvb_strdup(const char *str);
537310c0d0Sopenharmony_civoid *hvb_malloc(uint64_t size);
547310c0d0Sopenharmony_civoid *hvb_calloc(uint64_t size);
557310c0d0Sopenharmony_ci
567310c0d0Sopenharmony_ciuint64_t hvb_uint64_to_base10(uint64_t value, char digits[HVB_MAX_DIGITS_UINT64]);
577310c0d0Sopenharmony_cichar *hvb_bin2hex(const uint8_t *data, size_t data_len);
587310c0d0Sopenharmony_ci
597310c0d0Sopenharmony_cienum hvb_errno check_hvb_ops(struct hvb_ops *ops);
607310c0d0Sopenharmony_ci
617310c0d0Sopenharmony_ci#ifdef __cplusplus
627310c0d0Sopenharmony_ci}
637310c0d0Sopenharmony_ci#endif
647310c0d0Sopenharmony_ci
657310c0d0Sopenharmony_ci#endif