1 /*
2 *
3 * Copyright (C) 2012-2018 by C.H. Huang
4 * plushuang.tw@gmail.com
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 * ---
21 *
22 * In addition, as a special exception, the copyright holders give
23 * permission to link the code of portions of this program with the
24 * OpenSSL library under certain conditions as described in each
25 * individual source file, and distribute linked combinations
26 * including the two.
27 * You must obey the GNU Lesser General Public License in all respects
28 * for all of the code used other than OpenSSL. If you modify
29 * file(s) with this exception, you may extend this exception to your
30 * version of the file(s), but you are not obligated to do so. If you
31 * do not wish to do so, delete this exception statement from your
32 * version. If you delete this exception statement from all source
33 * files in the program, then also delete it here.
34 *
35 */
36
37 #ifndef UG_FILE_UTIL_H
38 #define UG_FILE_UTIL_H
39
40 #ifdef HAVE_CONFIG_H
41 #include <config.h>
42 #endif
43
44 #ifdef HAVE_GLIB
45 #include <glib.h>
ug_data_get_registry(void)46 #endif
47
48 #if !(defined _WIN32 || defined _WIN64)
49 #include <sys/types.h>
50 #include <dirent.h> // opendir(), closedir(), readdir()
51 #endif
52
53 #include <time.h>
54 #include <UgList.h>
55
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59
60 // ----------------------------------------------------------------------------
61 // UgDir
62
63 #if defined HAVE_GLIB
64 typedef GDir UgDir;
65 # define ug_dir_open(p) g_dir_open(p, 0, NULL)
66 # define ug_dir_close g_dir_close
67 # define ug_dir_rewind g_dir_rewind
68 # define ug_dir_read g_dir_read_name
69 #elif defined _WIN32 || defined _WIN64
70 typedef struct UgDir UgDir;
71 UgDir* ug_dir_open (const char* path_utf8);
72 void ug_dir_close (UgDir* udir);
73 void ug_dir_rewind (UgDir* udir);
74 const char* ug_dir_read (UgDir* udir);
75 #else
76 typedef DIR UgDir;
77 # define ug_dir_open opendir
78 # define ug_dir_close closedir
79 # define ug_dir_rewind rewinddir
80 const char* ug_dir_read (UgDir* udir);
81 #endif
82
83
84 // ----------------------------------------------------------------------------
85 // Time
86
87 // Change the modified time of file
88 int ug_modify_file_time (const char *file_utf8, time_t mod_time);
89
90 // ----------------------------------------------------------------------------
91 // file & directory functions
92
93 int ug_file_is_exist (const char* file_utf8);
94 int ug_file_is_dir (const char* file_utf8);
95
96 // return -1 if error
97 #if defined _WIN32 || defined _WIN64 || defined HAVE_GLIB || defined USE__ANDROID__SAF
98 int ug_create_dir (const char *dir_utf8);
99 int ug_delete_dir (const char *dir_utf8);
100 #else
101 # define ug_create_dir(dir) mkdir(dir,0755)
102 # define ug_delete_dir rmdir
103 #endif
104
105 // return -1 if error
106 int ug_create_dir_all (const char* dir_utf8, int len);
107 //int ug_delete_dir_all (const char* dir_utf8, int len);
108
109 // ----------------------------------------------------------------------------
110 // File I/O
111
112 // return -1 if error
113 int ug_file_copy (const char *src_file_utf8, const char *dest_file_utf8);
114 // return number of lines
115 int ug_file_get_lines (const char* filename_utf8, UgList* list);
116
117 #ifdef __cplusplus
118 }
119 #endif
ug_data_find(UgData * data,const UgGroupDataInfo * key,int * index)120
121 #endif // End of UG_FILE_UTIL_H
122
123