GRU - Generic Reusable Utilities
gru_path.h
Go to the documentation of this file.
1 /*
2  Copyright 2016 Otavio Rodolfo Piske
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  */
16 #ifndef GRU_PATH_H
17 #define GRU_PATH_H
18 
19 #include <fcntl.h>
20 #include <stdbool.h>
21 #include <string.h>
22 #if !defined(_WIN32) && !defined(_WIN64)
23 #include <unistd.h>
24 #else
25 #include <direct.h>
26 #include <io.h>
27 
28 #define R_OK 4
29 #define W_OK 2
30 #define mkdir(x, y) _mkdir(x)
31 #endif // !defined(_WIN32) && !defined(_WIN64)
32 
33 #include <sys/stat.h>
34 #include <sys/types.h>
35 
36 #include "common/gru_portable.h"
37 #include "common/gru_status.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 #ifndef FILE_SEPARATOR
44 #define FILE_SEPARATOR "/"
45 #endif
46 
47 typedef bool (*gru_path_cond_t)(const char *, gru_status_t *status);
48 
56 gru_export bool gru_path_exists(const char *filename, gru_status_t *status);
57 
65 gru_export bool gru_path_fexists(int fd, gru_status_t *status);
66 
74 gru_export bool gru_path_can_read_write(const char *filename, gru_status_t *status);
75 
84 gru_export bool gru_path_rename_cond(const char *filename,
85  gru_path_cond_t cond,
86  gru_status_t *status);
87 
95 gru_export bool gru_path_rename(const char *filename, gru_status_t *status);
96 
105 gru_export char *gru_path_format(const char *dir, const char *name, gru_status_t *status);
106 
114 gru_export bool gru_path_mkdir(const char *path, gru_status_t *status);
115 
123 gru_export bool gru_path_mkdirs(const char *path, gru_status_t *status);
124 
125 #ifdef __cplusplus
126 }
127 #endif
128 
129 #endif /* GRU_PATH_H */
gru_export bool gru_path_can_read_write(const char *filename, gru_status_t *status)
Checks whether can read/write a given file.
Definition: gru_path.c:59
gru_export bool gru_path_mkdirs(const char *path, gru_status_t *status)
Given a path, this function will recursively create directories.
Definition: gru_path.c:166
gru_export char * gru_path_format(const char *dir, const char *name, gru_status_t *status)
Formats a path.
Definition: gru_path.c:141
gru_export bool gru_path_rename(const char *filename, gru_status_t *status)
Renames a file.
Definition: gru_path.c:137
gru_export bool gru_path_rename_cond(const char *filename, gru_path_cond_t cond, gru_status_t *status)
Renames a file based on a condition.
Definition: gru_path.c:92
gru_export bool gru_path_exists(const char *filename, gru_status_t *status)
Checks whether a given file exists.
Definition: gru_path.c:19
gru_export bool gru_path_mkdir(const char *path, gru_status_t *status)
Create a directory.
Definition: gru_path.c:153
gru_export bool gru_path_fexists(int fd, gru_status_t *status)
Checks whether a given file exists based on it's file descriptor.
Definition: gru_path.c:39
bool(* gru_path_cond_t)(const char *, gru_status_t *status)
Definition: gru_path.h:47
#define gru_export
Definition: gru_portable.h:19
Status type.
Definition: gru_status.h:47