31 #include <gwenhywfar/directory.h>
32 #include <gwenhywfar/debug.h>
33 #include <gwenhywfar/path.h>
34 #include <gwenhywfar/buffer.h>
35 #include <gwenhywfar/text.h>
40 #ifdef HAVE_SYS_STAT_H
41 # include <sys/stat.h>
43 #include <sys/types.h>
59 #define DISABLE_DEBUGLOG
76 if (entry && isalpha(*entry)) {
81 if ( (len==2) && (entry[1] ==
':') ) {
91 if (strcasecmp(entry,
"..")==0) {
130 if (!S_ISREG(st.st_mode)) {
137 if (!S_ISDIR(st.st_mode)) {
170 fd=open(p, O_RDWR | O_CREAT | O_TRUNC,
180 fd=open(p, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
220 unsigned int flags) {
241 int transformDriveElement) {
248 if (transformDriveElement) {
251 if (p[2]==
'/' || p[2]==0) {
260 if (*p==
'/' || *p==
'\\') {
261 while (*p==
'/' || *p==
'\\')
281 const char *filePath,
300 "File \"%s\" found in folder \"%s\"",
319 const char *filePath,
338 "File \"%s\" found in folder \"%s\"",
361 tmp_dir = getenv (
"TMPDIR");
363 tmp_dir = getenv (
"TMP");
365 tmp_dir = getenv (
"TEMP");
375 strncpy (buffer, tmp_dir, size);
397 if (strcmp(buffer,
".")!=0 &&
398 strcmp(buffer,
"..")!=0 &&
434 if (strcmp(buffer,
".")!=0 &&
435 strcmp(buffer,
"..")!=0 &&
442 if (S_ISREG(st.st_mode))
444 else if (S_ISDIR(st.st_mode))
484 if (strcmp(buffer,
".")!=0 &&
485 strcmp(buffer,
"..")!=0 &&
492 if (S_ISREG(st.st_mode))
529 if (strcmp(buffer,
".")!=0 &&
530 strcmp(buffer,
"..")!=0 &&
537 if (S_ISDIR(st.st_mode))
578 if (strcmp(buffer,
".")!=0 &&
579 strcmp(buffer,
"..")!=0) {
584 if (S_ISDIR(st.st_mode))
626 if (getcwd(savedPwd,
sizeof(savedPwd)-1)==
NULL) {
637 if (getcwd(dataPwd,
sizeof(dataPwd)-1)==
NULL) {
641 dataPwd[
sizeof(dataPwd)-1]=0;
644 if (chdir(savedPwd)) {
void * GWEN_Path_Handle(const char *path, void *data, uint32_t flags, GWEN_PATHHANDLERPTR elementFunction)
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
int GWEN_Directory_GetAbsoluteFolderPath(const char *folder, GWEN_BUFFER *tbuf)
GWENHYWFAR_API void GWEN_Directory_free(GWEN_DIRECTORY *d)
struct GWEN_STRINGLISTENTRYSTRUCT GWEN_STRINGLISTENTRY
int GWEN_Directory_OsifyPath(const char *path, GWEN_BUFFER *pbuf, int transformDriveElement)
int GWEN_Directory_FindPathForFile(const GWEN_STRINGLIST *paths, const char *filePath, GWEN_BUFFER *fbuf)
#define GWEN_DIR_SEPARATOR_S
uint32_t GWEN_Buffer_GetUsedBytes(const GWEN_BUFFER *bf)
GWENHYWFAR_API int GWEN_Directory_Close(GWEN_DIRECTORY *d)
#define DBG_VERBOUS(dbg_logger, format, args...)
uint32_t GWEN_Buffer_GetPos(const GWEN_BUFFER *bf)
GWENHYWFAR_API GWEN_DIRECTORY * GWEN_Directory_new(void)
int GWEN_Directory_GetMatchingFilesRecursively(const char *folder, GWEN_STRINGLIST *sl, const char *mask)
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
GWEN_STRINGLISTENTRY * GWEN_StringList_FirstEntry(const GWEN_STRINGLIST *sl)
const char * GWEN_StringListEntry_Data(const GWEN_STRINGLISTENTRY *se)
struct GWEN_DIRECTORY GWEN_DIRECTORY
#define GWEN_DIR_FLAGS_PUBLIC_PATH
#define GWEN_PATH_FLAGS_LAST
void GWEN_StringList_free(GWEN_STRINGLIST *sl)
GWENHYWFAR_API int GWEN_Directory_Create(const char *path)
#define GWEN_PATH_FLAGS_NAMEMUSTNOTEXIST
#define GWEN_DIR_FLAGS_PUBLIC_NAME
int GWEN_StringList_AppendString(GWEN_STRINGLIST *sl, const char *s, int take, int checkDouble)
#define DBG_DEBUG(dbg_logger, format, args...)
int GWEN_Buffer_AppendBuffer(GWEN_BUFFER *bf, GWEN_BUFFER *sf)
int GWEN_Directory_GetTmpDirectory(char *buffer, unsigned int size)
int GWEN_Directory_FindFileInPaths(const GWEN_STRINGLIST *paths, const char *filePath, GWEN_BUFFER *fbuf)
#define GWEN_PATH_FLAGS_VARIABLE
struct GWEN_STRINGLISTSTRUCT GWEN_STRINGLIST
int GWEN_Buffer_AppendByte(GWEN_BUFFER *bf, char c)
int GWEN_Directory_GetDirEntries(const char *folder, GWEN_STRINGLIST *sl, const char *mask)
void GWEN_Buffer_free(GWEN_BUFFER *bf)
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
int GWEN_Directory_GetFileEntriesWithType(const char *folder, GWEN_STRINGLIST *sl, const char *mask)
int GWEN_Buffer_Crop(GWEN_BUFFER *bf, uint32_t pos, uint32_t l)
#define GWEN_PATH_FLAGS_CHECKROOT
unsigned int GWEN_StringList_Count(const GWEN_STRINGLIST *sl)
#define GWEN_PATH_FLAGS_PATHMUSTNOTEXIST
#define DBG_ERROR(dbg_logger, format, args...)
int GWEN_Directory_GetAllEntries(const char *folder, GWEN_STRINGLIST *sl, const char *mask)
int GWEN_Text_ComparePattern(const char *w, const char *p, int sensecase)
GWEN_STRINGLISTENTRY * GWEN_StringListEntry_Next(const GWEN_STRINGLISTENTRY *se)
#define GWEN_PATH_FLAGS_PATHMUSTEXIST
#define GWEN_ERROR_NOT_FOUND
GWENHYWFAR_API int GWEN_Directory_CreatePublic(const char *path)
#define DBG_INFO(dbg_logger, format, args...)
int GWEN_Directory_GetPath(const char *path, unsigned int flags)
int GWEN_Directory_GetFileEntries(const char *folder, GWEN_STRINGLIST *sl, const char *mask)
GWENHYWFAR_API int GWEN_Directory_Read(GWEN_DIRECTORY *d, char *buffer, unsigned int len)
GWEN_STRINGLIST * GWEN_StringList_new(void)
#define GWEN_PATH_FLAGS_NAMEMUSTEXIST
void * GWEN_Directory_HandlePathElement(const char *entry, void *data, unsigned int flags)
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
GWENHYWFAR_API int GWEN_Directory_Open(GWEN_DIRECTORY *d, const char *n)