Mercurial > trustbridge
comparison common/listutil.c @ 769:44257ecdae6d
Make Read File public
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Thu, 10 Jul 2014 19:11:09 +0200 |
parents | aa48ea7ead1f |
children | 7861950f7637 |
comparison
equal
deleted
inserted
replaced
768:3f290ea49d45 | 769:44257ecdae6d |
---|---|
32 #include <polarssl/sha256.h> | 32 #include <polarssl/sha256.h> |
33 #pragma GCC diagnostic pop | 33 #pragma GCC diagnostic pop |
34 | 34 |
35 #define MAX_FILESIZE (MAX_LINE_LENGTH * MAX_LINES) | 35 #define MAX_FILESIZE (MAX_LINE_LENGTH * MAX_LINES) |
36 | 36 |
37 /** | |
38 * @brief Read a file into memory. | |
39 * | |
40 * The caller needs to free data | |
41 * | |
42 * @param[in] fileName Name of the file. | |
43 * @param[out] data the file content | |
44 * @param[out] size size in bytes of the file content. | |
45 * @param[in] max_size the maximum amount of bytes to read. | |
46 * | |
47 * @return 0 on success an error code otherwise. | |
48 */ | |
49 #define READ_FILE_UNREADABLE -1 | 37 #define READ_FILE_UNREADABLE -1 |
50 #define READ_FILE_TOO_LARGE -2 | 38 #define READ_FILE_TOO_LARGE -2 |
51 #define READ_FILE_NO_MEMORY -3 | 39 #define READ_FILE_NO_MEMORY -3 |
52 #define READ_FILE_READ_FAILED -4 | 40 #define READ_FILE_READ_FAILED -4 |
53 #define READ_FILE_INVALID_CALL -5 | 41 #define READ_FILE_INVALID_CALL -5 |
54 static int read_file(const char *file_name, char **data, size_t *size, | 42 int |
43 read_file(const char *file_name, char **data, size_t *size, | |
55 const size_t max_size) | 44 const size_t max_size) |
56 { | 45 { |
57 FILE *f; | 46 FILE *f; |
58 long file_size; | 47 long file_size; |
59 | 48 |