clibcni/src/utils.h

73 lines
2.4 KiB
C
Raw Normal View History

2019-09-30 10:35:21 -04:00
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.
* clibcni licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
2019-09-30 10:35:21 -04:00
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
2019-09-30 10:35:21 -04:00
* Author: tanyifeng
* Create: 2019-04-25
* Description: provide util function definition
*********************************************************************************/
#ifndef CLIBCNI_UTILS_H
#define CLIBCNI_UTILS_H
2019-09-30 10:35:21 -04:00
#include <unistd.h>
#include <string.h>
#include <inttypes.h>
#include <stdbool.h>
#define CLIBCNI_BUFFER_SIZE 4096
2019-09-30 10:35:21 -04:00
#define MB (1 * 1024 * 1024)
#define CLIBCNI_NUMSTRLEN64_MAXLEN 21
2019-09-30 10:35:21 -04:00
#define CLIBCNI_DEFAULT_SECURE_DIRECTORY_MODE 0750
2019-09-30 10:35:21 -04:00
#if __WORDSIZE == 64
/* current max user memory for 64-machine is 2^47 B */
#define CLIBCNI_MAX_MEMORY_SIZE ((size_t)1 << 47)
#else
/* current max user memory for 32-machine is 2^31 B */
#define CLIBCNI_MAX_MEMORY_SIZE ((size_t)1 << 31)
#endif
bool clibcni_is_null_or_empty(const char *str);
2019-09-30 10:35:21 -04:00
size_t clibcni_util_array_len(const char * const *array);
2019-09-30 10:35:21 -04:00
void clibcni_util_free_array(char **array);
2019-09-30 10:35:21 -04:00
void *clibcni_util_smart_calloc_s(size_t count, size_t unit_size);
void *clibcni_util_common_calloc_s(size_t size);
2019-09-30 10:35:21 -04:00
ssize_t clibcni_util_write_nointr(int fd, const void *buf, size_t count);
2019-09-30 10:35:21 -04:00
ssize_t clibcni_util_read_nointr(int fd, void *buf, size_t count);
2019-09-30 10:35:21 -04:00
char *clibcni_util_string_join(const char *sep, const char * const *parts, size_t len);
2019-09-30 10:35:21 -04:00
char *clibcni_util_uint8_join(const char *sep, const char *type, const uint8_t *parts, size_t len);
2019-09-30 10:35:21 -04:00
int clibcni_util_safe_uint(const char *numstr, unsigned int *converted);
2019-09-30 10:35:21 -04:00
bool clibcni_util_dir_exists(const char *path);
2019-09-30 10:35:21 -04:00
int clibcni_util_grow_array(char ***orig_array, size_t *orig_capacity, size_t size, size_t increment);
2019-09-30 10:35:21 -04:00
char *clibcni_util_strdup_s(const char *src);
2019-09-30 10:35:21 -04:00
int clibcni_util_validate_absolute_path(const char *path);
2019-09-30 10:35:21 -04:00
int clibcni_util_validate_name(const char *name);
2019-09-30 10:35:21 -04:00
int clibcni_util_open(const char *filename, unsigned int flags, mode_t mode);
2019-09-30 10:35:21 -04:00
int clibcni_util_build_dir(const char *name);
2019-09-30 10:35:21 -04:00
#endif