-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.h
58 lines (49 loc) · 1.38 KB
/
file.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* @file file.h
* @author Warren Mann (warren@nonvol.io)
* @brief File I/O operations.
* @version 0.1.0
* @date 2024-04-27
* @copyright Copyright (c) 2024
*/
#ifndef _FILE_H
#define _FILE_H
#include <stdio.h>
/**
* @brief Append the given string to the temporary file. The file is created if it
* does not exist.
* @param f The file to append to.
* @param s The string to append.
* @return 0 on success, 1 on failure.
*/
extern int file_append_tmp(FILE **f, const char *s);
/**
* @brief Create the given path. Programmatic version of `mkdir -p`.
* @param s The path to create.
* @return 0 on success, 1 on failure.
*/
extern int file_create_path(const char *s);
/**
* @brief Read the contents of the given file.
* @param filename The file to read.
* @return The contents of the file.
*/
extern char *file_read(const char *filename);
/**
* @brief Get the contents of the temporary file and close the file.
* @param f The file to read.
* @return The contents of the file or NULL on error
*/
extern char *file_read_tmp(FILE **f);
/**
* @brief Truncate the given file.
* @param filename The file to truncate.
*/
extern void file_truncate(const char *filename);
/**
* @brief Write the given data to the given file.
* @param filename The file to write to.
* @param data The data to write.
*/
extern void file_write(const char *filename, const char *data);
#endif // _FILE_H