Imported Upstream version 1.2.0
[psensor-pkg-debian.git] / src / lib / pio.h
1 /*
2  *  Copyright (C) 2010-2016 jeanfi@gmail.com
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  *   02110-1301 USA
18  */
19
20 #ifndef _P_IO_H
21 #define _P_IO_H
22
23 #define P_IO_VER 6
24
25 /* Returns '1' if a given 'path' denotates a directory else returns
26  * 0
27  */
28 int is_dir(const char *path);
29
30 /* Returns '1' if a given 'path' denotates a file else returns
31  * 0
32  */
33 int is_file(const char *path);
34
35 /* Returns a normalized path */
36 char *path_normalize(const char *dpath);
37
38 /* Returns the null-terminated entries of a directory */
39 char **dir_list(const char *dpath, int (*filter) (const char *path));
40 void paths_free(char **paths);
41
42 char *path_append(const char *dir, const char *path);
43
44 /*
45  * Returns the size of a file.
46  * Returns '-1' if the size cannot be retrieved or not a file.
47  */
48 long file_get_size(const char *path);
49
50 /*
51  * Returns the content of a file.
52  * Returns 'NULL' if the file cannot be read or failed to allocate
53  * enough memory.
54  * Returns an empty string if the file exists but is empty.
55  */
56 char *file_get_content(const char *path);
57
58 enum file_copy_error {
59         FILE_COPY_ERROR_OPEN_SRC = 1,
60         FILE_COPY_ERROR_OPEN_DST,
61         FILE_COPY_ERROR_READ,
62         FILE_COPY_ERROR_WRITE,
63         FILE_COPY_ERROR_ALLOC_BUFFER
64 };
65
66 void file_copy_print_error(int code, const char *src, const char *dst);
67
68 /*
69  * Copy a file.
70  *
71  * Returns '0' if sucessfull, otherwise return the error code.
72  */
73 int file_copy(const char *src, const char *dst);
74
75 int dir_rcopy(const char *, const char *);
76
77 void mkdirs(const char *dirs, mode_t mode);
78
79 #endif