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