NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
utils.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021-2023 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
26 #ifndef COMMON_UTILS_H_
27 #define COMMON_UTILS_H_
28 
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <stdint.h>
32 #include <unistd.h>
33 
34 #include <doca_error.h>
35 #include <doca_types.h>
36 
37 #ifndef MIN
38 #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) /* Return the minimum value between X and Y */
39 #endif
40 
41 #ifndef MAX
42 #define MAX(X, Y) (((X) > (Y)) ? (X) : (Y)) /* Return the maximum value between X and Y */
43 #endif
44 
45 /*
46  * Prints DOCA SDK and runtime versions
47  *
48  * @param [in]: unused
49  * @doca_config [in]: unused
50  * @return: the function exit with EXIT_SUCCESS
51  */
52 doca_error_t sdk_version_callback(void *param, void *doca_config);
53 
54 /*
55  * Read the entire content of a file into a buffer
56  *
57  * @path [in]: file path
58  * @out_bytes [out]: file data buffer
59  * @out_bytes_len [out]: file length
60  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
61  */
62 doca_error_t read_file(char const *path, char **out_bytes, size_t *out_bytes_len);
63 
64 /*
65  * Init a uint16_t array with linear number start from zero
66  *
67  * @array [in]: pointer to array to init
68  * @n [in]: number of element to init
69  */
70 void linear_array_init_u16(uint16_t *array, uint16_t n);
71 
72 #ifdef DOCA_USE_LIBBSD
73 
74 #include <bsd/string.h>
75 
76 #else
77 
78 #ifndef strlcpy
79 
80 /*
81  * This method wraps our implementation of strlcpy when libbsd is missing
82  * @dst [in]: destination string
83  * @src [in]: source string
84  * @size [in]: size, in bytes, of the destination buffer
85  * @return: total length of the string (src) we tried to create
86  */
87 size_t strlcpy(char *dst, const char *src, size_t size);
88 
89 #endif /* strlcpy */
90 
91 #ifndef strlcat
92 
93 /*
94  * This method wraps our implementation of strlcat when libbsd is missing
95  * @dst [in]: destination string
96  * @src [in]: source string
97  * @size [in]: size, in bytes, of the destination buffer
98  * @return: total length of the string (src) we tried to create
99  */
100 size_t strlcat(char *dst, const char *src, size_t size);
101 
102 #endif /* strlcat */
103 
104 #endif /* DOCA_USE_LIBBSD */
105 
106 #endif /* COMMON_UTILS_H_ */
char path[MAX_PATH_LEN+1]
static uint64_t *restrict src
Definition: dpaintrin.h:230
enum doca_error doca_error_t
DOCA API return codes.
size_t strlcat(char *dst, const char *src, size_t size)
Definition: utils.c:144
doca_error_t read_file(char const *path, char **out_bytes, size_t *out_bytes_len)
Definition: utils.c:56
size_t strlcpy(char *dst, const char *src, size_t size)
Definition: utils.c:123
doca_error_t sdk_version_callback(void *param, void *doca_config)
Definition: utils.c:41
void linear_array_init_u16(uint16_t *array, uint16_t n)
Definition: utils.c:109