filesystem_utils.h
Go to the documentation of this file.
1 /*
2 ** Copyright 2014-2016 The Earlham Institute
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 
24 #ifndef FILESYSTEM_H
25 #define FILESYSTEM_H
26 
27 #include <time.h>
28 
29 #include "typedefs.h"
30 #include "linked_list.h"
32 
33 
39 typedef struct FileInformation
40 {
43 
45  size_t fi_size;
47 
48 
49 
50 #ifdef __cplusplus
51  extern "C" {
52 #endif
53 
54 
55 
63 GRASSROOTS_UTIL_API void InitFileInformation (FileInformation *info_p);
64 
65 
75 GRASSROOTS_UTIL_API bool CalculateFileInformation (const char * const path_s, FileInformation *info_p);
76 
77 
88 GRASSROOTS_UTIL_API char *GetFilenameOnly (const char * const full_path_to_file_s);
89 
90 
101 GRASSROOTS_UTIL_API char *GetPathOnly (const char * const full_path_to_file_s);
102 
103 
118 GRASSROOTS_UTIL_API char *MakeFilename (const char * const path_s, const char * const filename_s);
119 
120 
121 
138 GRASSROOTS_UTIL_API bool DeterminePathAndFile (const char * const full_path_s, char ** const path_ss, char ** const filename_ss);
139 
140 
160 GRASSROOTS_UTIL_API char *SetFileExtension (const char * const filename_s, const char * const extension_s, bool replace_flag);
161 
162 
171 GRASSROOTS_UTIL_API void UsePlatformFileSeparator (char *value_s);
172 
173 
183 GRASSROOTS_UTIL_API bool IsPathValid (const char * const path_s);
184 
185 
195 GRASSROOTS_UTIL_API bool IsPathAbsolute (const char * const path_s);
196 
197 
209 GRASSROOTS_UTIL_API LinkedList *GetMatchingFiles (const char * const pattern_s, const bool full_path_flag);
210 
211 
222 GRASSROOTS_UTIL_API char GetFileSeparatorChar (void);
223 
224 
235 GRASSROOTS_UTIL_API const char *GetCurrentDirectoryString (void);
236 
237 
248 GRASSROOTS_UTIL_API const char *GetParentDirectory (void);
249 
250 
261 GRASSROOTS_UTIL_API const char *GetPluginPattern (void);
262 
263 
274 GRASSROOTS_UTIL_API bool EnsureDirectoryExists (const char * const path_s);
275 
276 
289 GRASSROOTS_UTIL_API bool CopyToNewFile (const char * const src_filename_s, const char * const dest_filename_s, void (*callback_fn) (void));
290 
291 
301 GRASSROOTS_UTIL_API bool SetCurrentWorkingDirectory (const char * const path_s);
302 
303 
311 GRASSROOTS_UTIL_API char *GetCurrentWorkingDirectory (void);
312 
313 
314 
323 GRASSROOTS_UTIL_API char *GetHomeDirectory (void);
324 
334 GRASSROOTS_UTIL_API bool IsDirectory (const char * const path_s);
335 
336 
346 GRASSROOTS_UTIL_API bool RemoveFile (const char * const path_s);
347 
348 
349 #ifdef __cplusplus
350 }
351 #endif
352 
353 #endif /* FILESYSTEM_H */
size_t fi_size
The size of the file in bytes.
Definition: filesystem_utils.h:45
bool RemoveFile(const char *const path_s)
Delete a file.
A datatype to hold a collection of metadata about a file.
Definition: filesystem_utils.h:39
void UsePlatformFileSeparator(char *value_s)
Replace any occurrences of // in a string with the platform-specific file separator.
time_t fi_last_modified
The timestamp of the last modification to a file.
Definition: filesystem_utils.h:42
bool CopyToNewFile(const char *const src_filename_s, const char *const dest_filename_s, void(*callback_fn)(void))
Copy the content of one file to another.
char * GetCurrentWorkingDirectory(void)
Get the current working directory.
bool IsDirectory(const char *const path_s)
Check whether the given path refers to a directory.
char GetFileSeparatorChar(void)
Get the platform-specific file separator.
bool SetCurrentWorkingDirectory(const char *const path_s)
Set the current working directory.
char * MakeFilename(const char *const path_s, const char *const filename_s)
Construct a filename.
const char * GetPluginPattern(void)
Get the platform-specific string for the a plugin.
A doubly-linked list.
char * GetPathOnly(const char *const full_path_to_file_s)
Get the path to the parent directory only from a given path.
A doubly-linked list that can be traversed in either direction.
Definition: linked_list.h:56
char * SetFileExtension(const char *const filename_s, const char *const extension_s, bool replace_flag)
Generate a new filename by adding an extension to a filename.
char * GetHomeDirectory(void)
Get the current user's home directory.
void InitFileInformation(FileInformation *info_p)
Initialise a FileInformation ready for use.
LinkedList * GetMatchingFiles(const char *const pattern_s, const bool full_path_flag)
Get files that match a given pattern.
bool EnsureDirectoryExists(const char *const path_s)
Makes sure that a given directory path exists.
bool CalculateFileInformation(const char *const path_s, FileInformation *info_p)
Calculate the FileInformation for a given filename.
bool IsPathValid(const char *const path_s)
Check whether a given file/directory exists.
bool DeterminePathAndFile(const char *const full_path_s, char **const path_ss, char **const filename_ss)
Extract the parent path and filename only from a given path.
bool IsPathAbsolute(const char *const path_s)
Check whether a given path is absolute.
const char * GetCurrentDirectoryString(void)
Get the platform-specific string for the current directory.
const char * GetParentDirectory(void)
Get the platform-specific string for the parent directory.
char * GetFilenameOnly(const char *const full_path_to_file_s)
Get the filename only from a given path.