GRU - Generic Reusable Utilities
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
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 #define APPEND_SIZE_REMAP 64
44 
45 #ifndef FILE_SEPARATOR
46 #define FILE_SEPARATOR "/"
47 #endif
48 
49 typedef bool (*gru_path_cond_t)(const char *, gru_status_t *status);
50 
58 gru_export bool gru_path_exists(const char *filename, gru_status_t *status);
59 
67 gru_export bool gru_path_fexists(int fd, gru_status_t *status);
68 
76 gru_export bool gru_path_can_read_write(const char *filename, gru_status_t *status);
77 
87  const char *filename, gru_path_cond_t cond, gru_status_t *status);
88 
96 gru_export bool gru_path_rename(const char *filename, gru_status_t *status);
97 
106 gru_export char *gru_path_format(const char *dir, const char *name, gru_status_t *status);
107 
115 gru_export bool gru_path_mkdir(const char *path, gru_status_t *status);
116 
124 gru_export bool gru_path_mkdirs(const char *path, gru_status_t *status);
125 
126 #ifdef __cplusplus
127 }
128 #endif
129 
130 #endif /* GRU_PATH_H */
bool gru_path_fexists(int fd, gru_status_t *status)
Checks whether a given file exists based on it&#39;s file descriptor.
Definition: gru_path.c:39
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
bool gru_path_exists(const char *filename, gru_status_t *status)
Checks whether a given file exists.
Definition: gru_path.c:19
#define gru_export
Definition: gru_portable.h:19
bool gru_path_mkdirs(const char *path, gru_status_t *status)
Given a path, this function will recursively create directories.
Definition: gru_path.c:162
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
bool gru_path_rename(const char *filename, gru_status_t *status)
Renames a file.
Definition: gru_path.c:134
Status type.
Definition: gru_status.h:47
bool(* gru_path_cond_t)(const char *, gru_status_t *status)
Definition: gru_path.h:49
char * gru_path_format(const char *dir, const char *name, gru_status_t *status)
Formats a path.
Definition: gru_path.c:138
bool gru_path_mkdir(const char *path, gru_status_t *status)
Create a directory.
Definition: gru_path.c:149