| ARX 1.0 The next-generation open source augmented reality toolkit.

Loading...
Searching...
No Matches
file_utils.h
Go to the documentation of this file.
1/*
2 * file_utils.h
3 * artoolkitX
4 *
5 * This file is part of artoolkitX.
6 *
7 * artoolkitX is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * artoolkitX is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with artoolkitX. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * As a special exception, the copyright holders of this library give you
21 * permission to link this library with independent modules to produce an
22 * executable, regardless of the license terms of these independent modules, and to
23 * copy and distribute the resulting executable under terms of your choice,
24 * provided that you also meet, for each linked independent module, the terms and
25 * conditions of the license of that module. An independent module is a module
26 * which is neither derived from nor based on this library. If you modify this
27 * library, you may extend this exception to your version of the library, but you
28 * are not obligated to do so. If you do not wish to do so, delete this exception
29 * statement from your version.
30 *
31 * Copyright 2018 Realmax, Inc.
32 * Copyright 2015-2016 Daqri, LLC.
33 * Copyright 2013-2015 Daqri, LLC.
34 *
35 * Author(s): Philip Lamb, Dan Bell
36 *
37 */
38
39#ifndef __ARUtil_file_utils_h__
40#define __ARUtil_file_utils_h__
41
42#include <stddef.h>
43#include <stdint.h>
44#include <ARX/ARUtil/types.h>
45
46#ifdef __cplusplus
47 extern "C" {
48#endif
49
50// Test for existence of regular file like 'test -f [dir/]file'.
51// Returns 1 if file exists, 0 if not, or -1 in case of error and the error code in 'errno'.
52 ARUTIL_EXTERN int test_f(const char *file, const char *dir);
53
54// Test for existence of directory like 'test -d dir'.
55// Returns 1 if dir exists, 0 if not, or -1 in case of error and the error code in 'errno'.
56 ARUTIL_EXTERN int test_d(const char *dir);
57
58// Copy a single file (with overwriting in case of target file already existing) like 'cp -f source_file target_file'.
59// Returns 0 for success, -1 in case of error and the error code in 'errno'.
60 ARUTIL_EXTERN int cp_f(const char *source_file, const char *target_file);
61
62// Make directory like 'mkdir -p path'.
63// Returns 0 for success, -1 in case of error and the error code in 'errno'.
64 ARUTIL_EXTERN int mkdir_p(const char *path);
65
66// Remove path like 'rm -rf path'.
67// Returns 0 for success, -1 in case of error and the error code in 'errno'.
68 ARUTIL_EXTERN int rm_rf(const char *path);
69
70// Rename path like 'rn path newPath'.
71// Returns 0 for success, -1 in case of error and the error code in 'errno'.
72 ARUTIL_EXTERN int rn_f(const char *source_file, const char *target_file);
73
74// Unzip a zip file like 'unzip -o zipPathname -d outPath'.
75// Returns 0 in case of success, or error code < 0 in case of error (see unzip.h). If error code is -1, the error code is in 'errno'.
76 ARUTIL_EXTERN int unzip_od(const char *zipPathname, const char *outPath);
77
78// Zip a zip file like 'zip zipPathname -d fileNames'.
79// Returns 0 in case of success, or error code < 0 in case of error (see zip.h). If error code is -1, the error code is in 'errno'.
80 ARUTIL_EXTERN int zip_od(char *zipPathname, const char *baseFilePath, const char **fileNames, int totalFiles);
81
82// Get a file's size like 'stat -f "%z" file'
83 ARUTIL_EXTERN int64_t get_file_size(const char *file);
84
85// Read a file into a buffer like 'cat file', and appends a nul character so that the returned buffer
86// is always a valid C-string.
87// Returns pointer to heap-allocated buffer containing the file contents. The caller must call free()
88// on this value to dispose of the buffer. If bufSize_p is non-NULL, this will be filled with the
89// size in bytes of the returned buffer, including any trailing nul character.
90// In case of error, returns NULL and the error code in 'errno'.
91 ARUTIL_EXTERN char *cat(const char *file, size_t *bufSize_p);
92
93// Read a single character from the terminal without echo, like 'read -s -n 1'.
94 ARUTIL_EXTERN char read_sn1(void);
95
96// Set an environment variable for the current process,
97// like 'export name=val' (sh) or 'setenv name val' (csh).
98// Passing NULL for val will clear the export like 'export -n name' (sh) or 'unsetenv name' (csh).
99// Returns 0 in case of success, -1 in case of error and the error code in 'errno'.
100 ARUTIL_EXTERN int export_(const char *name, const char *val);
101
102// Take sha1 of a file and return as lowercase hex string plus nul-terminator in sha1String, like 'shasum -a 1 -b'.
103// Returns 0 in case of success, -1 in case of error and the error code in 'errno'.
104 ARUTIL_EXTERN int sha1(const char *filePath, char sha1String[41]);
105
106#ifdef __cplusplus
107}
108#endif
109#endif // !__ARUtil_file_utils_h__
sha1
ARUTIL_EXTERN int sha1(const char *filePath, char sha1String[41])
Definition: file_utils.c:812
mkdir_p
ARUTIL_EXTERN int mkdir_p(const char *path)
Definition: file_utils.c:252
test_d
ARUTIL_EXTERN int test_d(const char *dir)
Definition: file_utils.c:135
cp_f
ARUTIL_EXTERN int cp_f(const char *source_file, const char *target_file)
Definition: file_utils.c:162
read_sn1
ARUTIL_EXTERN char read_sn1(void)
Definition: file_utils.c:766
export_
ARUTIL_EXTERN int export_(const char *name, const char *val)
Definition: file_utils.c:798
rn_f
ARUTIL_EXTERN int rn_f(const char *source_file, const char *target_file)
Definition: file_utils.c:206
get_file_size
ARUTIL_EXTERN int64_t get_file_size(const char *file)
Definition: file_utils.c:720
zip_od
ARUTIL_EXTERN int zip_od(char *zipPathname, const char *baseFilePath, const char **fileNames, int totalFiles)
Definition: file_utils.c:613
cat
ARUTIL_EXTERN char * cat(const char *file, size_t *bufSize_p)
Definition: file_utils.c:729
unzip_od
ARUTIL_EXTERN int unzip_od(const char *zipPathname, const char *outPath)
Definition: file_utils.c:461
test_f
ARUTIL_EXTERN int test_f(const char *file, const char *dir)
Definition: file_utils.c:99
rm_rf
ARUTIL_EXTERN int rm_rf(const char *path)
Definition: file_utils.c:328
types.h
ARUTIL_EXTERN
#define ARUTIL_EXTERN
Definition: types.h:58