gwenhywfar 5.14.1
directory_all.c File Reference
#include <gwenhywfar/directory.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/path.h>
#include <gwenhywfar/buffer.h>
#include <gwenhywfar/text.h>
#include <sys/types.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <stdlib.h>
#include <ctype.h>
Include dependency graph for directory_all.c:

Go to the source code of this file.

Macros

#define DIRSEP   "/"
#define DISABLE_DEBUGLOG

Functions

int GWEN_Directory_FindFileInPaths (const GWEN_STRINGLIST *paths, const char *filePath, GWEN_BUFFER *fbuf)
int GWEN_Directory_FindPathForFile (const GWEN_STRINGLIST *paths, const char *filePath, GWEN_BUFFER *fbuf)
int GWEN_Directory_GetAbsoluteFolderPath (const char *folder, GWEN_BUFFER *tbuf)
int GWEN_Directory_GetAllEntries (const char *folder, GWEN_STRINGLIST *sl, const char *mask)
int GWEN_Directory_GetDirEntries (const char *folder, GWEN_STRINGLIST *sl, const char *mask)
int GWEN_Directory_GetFileEntries (const char *folder, GWEN_STRINGLIST *sl, const char *mask)
int GWEN_Directory_GetFileEntriesWithType (const char *folder, GWEN_STRINGLIST *sl, const char *mask)
int GWEN_Directory_GetMatchingFilesRecursively (const char *folder, GWEN_STRINGLIST *sl, const char *mask)
int GWEN_Directory_GetPath (const char *path, unsigned int flags)
int GWEN_Directory_GetTmpDirectory (char *buffer, unsigned int size)
static void * GWEN_Directory_HandlePathElement (const char *entry, void *data, unsigned int flags)
int GWEN_Directory_OsifyPath (const char *path, GWEN_BUFFER *pbuf, GWEN_UNUSED int transformDriveElement)

Macro Definition Documentation

◆ DIRSEP

#define DIRSEP   "/"

Definition at line 56 of file directory_all.c.

◆ DISABLE_DEBUGLOG

#define DISABLE_DEBUGLOG

Definition at line 59 of file directory_all.c.

Function Documentation

◆ GWEN_Directory_FindFileInPaths()

◆ GWEN_Directory_FindPathForFile()

int GWEN_Directory_FindPathForFile ( const GWEN_STRINGLIST * paths,
const char * filePath,
GWEN_BUFFER * fbuf )

◆ GWEN_Directory_GetAbsoluteFolderPath()

int GWEN_Directory_GetAbsoluteFolderPath ( const char * folder,
GWEN_BUFFER * tbuf )

This function determines the absolute path og the given folder and returns it in the given buffer. It uses a combination of getcwd() and chdir() to get the result. This function should return with the current working directory effectively unchanged.

Returns
0 if ok, error code otherwise
Parameters
folderfolder for which to retrieve the absolute path
tbufbuffer to receive the result

Definition at line 652 of file directory_all.c.

References DBG_ERROR, GWEN_Buffer_AppendString(), GWEN_ERROR_IO, GWEN_LOGDOMAIN, and NULL.

Referenced by _makeAbsolutePaths(), and GWB_Builder_AddAbsFileNameToBuffer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Directory_GetAllEntries()

int GWEN_Directory_GetAllEntries ( const char * folder,
GWEN_STRINGLIST * sl,
const char * mask )

This function reads all entries of the given folder and stores them in the given string list if they match a mask.

The entries added to the string list are the names returned by the operating systems. They do not contain the full path.

Parameters
folderfolder to inspect
slstring list to add new entries to
maskif omitted, all entries match (wildcards and jokers allowed)

Definition at line 407 of file directory_all.c.

References DBG_INFO, GWEN_Directory_Close(), GWEN_Directory_free(), GWEN_Directory_new(), GWEN_Directory_Open(), GWEN_Directory_Read(), GWEN_LOGDOMAIN, GWEN_StringList_AppendString(), GWEN_Text_ComparePattern(), and NULL.

Here is the call graph for this function:

◆ GWEN_Directory_GetDirEntries()

int GWEN_Directory_GetDirEntries ( const char * folder,
GWEN_STRINGLIST * sl,
const char * mask )

This function does the same as GWEN_Directory_GetAllEntries, but it only adds folder entries.

Parameters
folderfolder to inspect
slstring list to add new entries to
maskif omitted, all entries match (wildcards and jokers allowed)

Definition at line 536 of file directory_all.c.

References DBG_INFO, GWEN_Buffer_AppendString(), GWEN_Buffer_Crop(), GWEN_Buffer_GetPos(), GWEN_Buffer_GetStart(), GWEN_Buffer_new(), GWEN_DIR_SEPARATOR_S, GWEN_Directory_Close(), GWEN_Directory_free(), GWEN_Directory_new(), GWEN_Directory_Open(), GWEN_Directory_Read(), GWEN_LOGDOMAIN, GWEN_StringList_AppendString(), GWEN_Text_ComparePattern(), and NULL.

Referenced by GWEN_ConfigMgrDir_ListGroups().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Directory_GetFileEntries()

int GWEN_Directory_GetFileEntries ( const char * folder,
GWEN_STRINGLIST * sl,
const char * mask )

This function does the same as GWEN_Directory_GetAllEntries, but it only adds file entries.

Parameters
folderfolder to inspect
slstring list to add new entries to
maskif omitted, all entries match (wildcards and jokers allowed)

Definition at line 490 of file directory_all.c.

References DBG_INFO, GWEN_Buffer_AppendString(), GWEN_Buffer_Crop(), GWEN_Buffer_free(), GWEN_Buffer_GetPos(), GWEN_Buffer_GetStart(), GWEN_Buffer_new(), GWEN_DIR_SEPARATOR_S, GWEN_Directory_Close(), GWEN_Directory_free(), GWEN_Directory_new(), GWEN_Directory_Open(), GWEN_Directory_Read(), GWEN_LOGDOMAIN, GWEN_StringList_AppendString(), GWEN_Text_ComparePattern(), and NULL.

Referenced by GWEN_ConfigMgrDir_ListSubGroups(), and GWEN_LoadPluginDescrsByType().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Directory_GetFileEntriesWithType()

int GWEN_Directory_GetFileEntriesWithType ( const char * folder,
GWEN_STRINGLIST * sl,
const char * mask )

This function does the same as GWEN_Directory_GetAllEntries, but in addition a entry type indicator is prepended to the entries added to the string list. Known indicators are:

  • d: entry is a directory
  • f: entry is a file
  • ?: entry type is unknown
Parameters
folderfolder to inspect
slstring list to add new entries to
maskif omitted, all entries match (wildcards and jokers allowed)

Definition at line 438 of file directory_all.c.

References DBG_INFO, GWEN_Buffer_AppendString(), GWEN_Buffer_Crop(), GWEN_Buffer_GetPos(), GWEN_Buffer_GetStart(), GWEN_Buffer_new(), GWEN_DIR_SEPARATOR_S, GWEN_Directory_Close(), GWEN_Directory_free(), GWEN_Directory_new(), GWEN_Directory_Open(), GWEN_Directory_Read(), GWEN_LOGDOMAIN, GWEN_StringList_AppendString(), GWEN_Text_ComparePattern(), and NULL.

Referenced by GWEN_MDigest__HashFileTree().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Directory_GetMatchingFilesRecursively()

int GWEN_Directory_GetMatchingFilesRecursively ( const char * folder,
GWEN_STRINGLIST * sl,
const char * mask )

This function adds all matching files to the given string list recursively. Each entry of the stringlist starts with the given folder, so if that argument is an absolute path all stringlist entries will be absolute paths.

Parameters
folderfolder to inspect (including sub-folders)
slstring list to add new entries to
maskif omitted, all entries match (wildcards and jokers allowed)

Definition at line 581 of file directory_all.c.

References DBG_INFO, GWEN_Buffer_AppendString(), GWEN_Buffer_Crop(), GWEN_Buffer_free(), GWEN_Buffer_GetPos(), GWEN_Buffer_GetStart(), GWEN_Buffer_new(), GWEN_DIR_SEPARATOR_S, GWEN_Directory_Close(), GWEN_Directory_free(), GWEN_Directory_GetMatchingFilesRecursively(), GWEN_Directory_new(), GWEN_Directory_Open(), GWEN_Directory_Read(), GWEN_LOGDOMAIN, GWEN_StringList_AppendString(), GWEN_StringList_Count(), GWEN_StringList_FirstEntry(), GWEN_StringList_free(), GWEN_StringList_new(), GWEN_StringListEntry_Data(), GWEN_StringListEntry_Next(), GWEN_Text_ComparePattern(), and NULL.

Referenced by GWB_GBuilderDescr_ReadAll(), GWEN_Directory_GetMatchingFilesRecursively(), and GWEN_PathManager_GetMatchingFilesRecursively().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Directory_GetPath()

◆ GWEN_Directory_GetTmpDirectory()

int GWEN_Directory_GetTmpDirectory ( char * buffer,
unsigned int size )

Gets the directory to use for temporary files and copies it into the given buffer.

This is found from inspecting the environment variables TMPDIR, TMP, and TEMP in that order. If none of those are defined, "/tmp" is returned on UNIX and "C:\" on Windows. This is similar to glib's g_get_tmp_dir().

Returns
0 if ok, !=0 on error

Definition at line 381 of file directory_all.c.

Referenced by check_directory().

Here is the caller graph for this function:

◆ GWEN_Directory_HandlePathElement()

◆ GWEN_Directory_OsifyPath()

int GWEN_Directory_OsifyPath ( const char * path,
GWEN_BUFFER * pbuf,
GWEN_UNUSED int transformDriveElement )

Definition at line 259 of file directory_all.c.

References GWEN_Buffer_AppendByte(), and GWEN_UNUSED.

Here is the call graph for this function: