xref: /wlan-dirver/qca-wifi-host-cmn/qdf/inc/qdf_file.h (revision 2f4b444fb7e689b83a4ab0e7b3b38f0bf4def8e0)
1 /*
2  * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /**
20  * DOC: Thin filesystem API abstractions
21  */
22 
23 #ifndef __QDF_FILE_H
24 #define __QDF_FILE_H
25 
26 #include "qdf_status.h"
27 
28 /**
29  * qdf_file_read() - read the entire contents of a file
30  * @path: the full path of the file to read
31  * @out_buf: double pointer for referring to the file contents buffer
32  *
33  * This API allocates a new, null-terminated buffer containing the contents of
34  * the file at @path. On success, @out_buf points to this new buffer, otherwise
35  * @out_buf is set to NULL.
36  *
37  * Consumers must free the allocated buffer by calling qdf_file_buf_free().
38  *
39  * Return: QDF_STATUS
40  */
41 QDF_STATUS qdf_file_read(const char *path, char **out_buf);
42 
43 /**
44  * qdf_file_buf_free() - free a previously allocated file buffer
45  * @file_buf: pointer to the file buffer to free
46  *
47  * This API is used in conjunction with qdf_file_read().
48  *
49  * Return: None
50  */
51 void qdf_file_buf_free(char *file_buf);
52 
53 #ifdef QCA_WIFI_MODULE_PARAMS_FROM_INI
54 /**
55  * qdf_module_param_file_read() - read the entire contents of a file
56  * @path: the full path of the file to read
57  * @out_buf: double pointer for referring to the file contents buffer
58  *
59  * This API allocates a new buffer before qdf_mem_init() is being called.
60  * Thus, this API helps to allocate memory which is being used before qdf
61  * memory tracking framework is available. Buffer is null-terminated,
62  * containing the contents of the file at @path. On success, @out_buf
63  * points to this new buffer, otherwise @out_buf is set to NULL.
64  *
65  * Consumers must free the allocated buffer by calling
66  * qdf_module_param_file_free().
67  *
68  * Return: QDF_STATUS
69  */
70 
71 QDF_STATUS qdf_module_param_file_read(const char *path, char **out_buf);
72 
73 /**
74  * qdf_module_param_file_free() - free a previously allocated file buffer
75  * @file_buf: pointer to the file buffer to free. The buffer allocated in
76  * qdf_module_param_file_read is not tracked by qdf framework.
77  *
78  * This API is used in conjunction with qdf_module_param_file_read().
79  *
80  * Return: None
81  */
82 void qdf_module_param_file_free(char *file_buf);
83 #else
84 static inline
85 QDF_STATUS qdf_module_param_file_read(const char *path, char **out_buf)
86 {
87 	return QDF_STATUS_E_INVAL;
88 }
89 
90 static inline
91 void qdf_module_param_file_free(char *file_buf)
92 {
93 }
94 #endif
95 #endif /* __QDF_FILE_H */
96 
97