Loading...
Searching...
No Matches
cs_file.h
1/*
2 * Copyright (c) 2014-2018 Cesanta Software Limited
3 * All rights reserved
4 *
5 * Licensed under the Apache License, Version 2.0 (the ""License"");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an ""AS IS"" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef CS_COMMON_CS_FILE_H_
19#define CS_COMMON_CS_FILE_H_
20
21#include "platform.h"
22
23#ifdef __cplusplus
24extern "C" {
25#endif /* __cplusplus */
26
27/*
28 * Read whole file `path` in memory. It is responsibility of the caller
29 * to `free()` allocated memory. File content is guaranteed to be
30 * '\0'-terminated. File size is returned in `size` variable, which does not
31 * count terminating `\0`.
32 * Return: allocated memory, or NULL on error.
33 */
34char *cs_read_file(const char *path, size_t *size);
35
36#ifdef CS_MMAP
37/*
38 * Only on platforms which support mmapping: mmap file `path` to the returned
39 * address. File size is written to `*size`.
40 */
41char *cs_mmap_file(const char *path, size_t *size);
42#endif
43
44#ifdef __cplusplus
45}
46#endif /* __cplusplus */
47
48#endif /* CS_COMMON_CS_FILE_H_ */