gwenhywfar  5.11.1beta
Macros | Typedefs | Functions
directory.h File Reference

This file contains the directory handling module. More...

#include <gwenhywfar/gwenhywfarapi.h>
#include <gwenhywfar/buffer.h>
#include <gwenhywfar/stringlist.h>

Go to the source code of this file.

Macros

#define GWEN_DIR_FLAGS_PUBLIC_NAME   0x00020000
 
#define GWEN_DIR_FLAGS_PUBLIC_PATH   0x00010000
 

Typedefs

typedef struct GWEN_DIRECTORY GWEN_DIRECTORY
 

Functions

GWENHYWFAR_API int GWEN_Directory_Close (GWEN_DIRECTORY *d)
 
GWENHYWFAR_API int GWEN_Directory_Create (const char *path)
 
GWENHYWFAR_API int GWEN_Directory_CreatePublic (const char *path)
 
GWENHYWFAR_API int GWEN_Directory_FindFileInPaths (const GWEN_STRINGLIST *paths, const char *filePath, GWEN_BUFFER *fbuf)
 
GWENHYWFAR_API int GWEN_Directory_FindPathForFile (const GWEN_STRINGLIST *paths, const char *filePath, GWEN_BUFFER *fbuf)
 
GWENHYWFAR_API void GWEN_Directory_free (GWEN_DIRECTORY *d)
 
GWENHYWFAR_API int GWEN_Directory_GetAbsoluteFolderPath (const char *folder, GWEN_BUFFER *tbuf)
 
GWENHYWFAR_API int GWEN_Directory_GetAllEntries (const char *folder, GWEN_STRINGLIST *sl, const char *mask)
 
GWENHYWFAR_API int GWEN_Directory_GetDirEntries (const char *folder, GWEN_STRINGLIST *sl, const char *mask)
 
GWENHYWFAR_API int GWEN_Directory_GetFileEntries (const char *folder, GWEN_STRINGLIST *sl, const char *mask)
 
GWENHYWFAR_API int GWEN_Directory_GetFileEntriesWithType (const char *folder, GWEN_STRINGLIST *sl, const char *mask)
 
GWENHYWFAR_API int GWEN_Directory_GetHomeDirectory (char *buffer, unsigned int size)
 
GWENHYWFAR_API int GWEN_Directory_GetMatchingFilesRecursively (const char *folder, GWEN_STRINGLIST *sl, const char *mask)
 
GWENHYWFAR_API int GWEN_Directory_GetPath (const char *path, unsigned int flags)
 
GWENHYWFAR_API int GWEN_Directory_GetPrefixDirectory (char *buffer, unsigned int size)
 
GWENHYWFAR_API int GWEN_Directory_GetTmpDirectory (char *buffer, unsigned int size)
 
GWENHYWFAR_API GWEN_DIRECTORYGWEN_Directory_new (void)
 
GWENHYWFAR_API int GWEN_Directory_Open (GWEN_DIRECTORY *d, const char *n)
 
GWENHYWFAR_API int GWEN_Directory_OsifyPath (const char *path, GWEN_BUFFER *pbuf, int transformDriveElement)
 
GWENHYWFAR_API int GWEN_Directory_Read (GWEN_DIRECTORY *d, char *buffer, unsigned int len)
 
GWENHYWFAR_API int GWEN_Directory_Rewind (GWEN_DIRECTORY *d)
 

Detailed Description

This file contains the directory handling module.

Definition in file directory.h.

Macro Definition Documentation

◆ GWEN_DIR_FLAGS_PUBLIC_NAME

#define GWEN_DIR_FLAGS_PUBLIC_NAME   0x00020000

Definition at line 61 of file directory.h.

◆ GWEN_DIR_FLAGS_PUBLIC_PATH

#define GWEN_DIR_FLAGS_PUBLIC_PATH   0x00010000

Definition at line 60 of file directory.h.

Typedef Documentation

◆ GWEN_DIRECTORY

Definition at line 1 of file directory.h.

Function Documentation

◆ GWEN_Directory_Close()

GWENHYWFAR_API int GWEN_Directory_Close ( GWEN_DIRECTORY d)

Closes a previously opened directory.

Author
Martin Preussmarti.nosp@m.n@li.nosp@m.bchip.nosp@m.card.nosp@m..de
Returns
0 if ok, !=0 on error
Parameters
dpointer to a directory data structure. This should be created by calling GWEN_Directory_new().

◆ GWEN_Directory_Create()

GWENHYWFAR_API int GWEN_Directory_Create ( const char *  path)

Creates a directory.

◆ GWEN_Directory_CreatePublic()

GWENHYWFAR_API int GWEN_Directory_CreatePublic ( const char *  path)

Creates a public directory (a folder which can be listed and entered by anyone)

◆ GWEN_Directory_FindFileInPaths()

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

◆ GWEN_Directory_FindPathForFile()

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

◆ GWEN_Directory_free()

GWENHYWFAR_API void GWEN_Directory_free ( GWEN_DIRECTORY d)

Destructor

◆ GWEN_Directory_GetAbsoluteFolderPath()

GWENHYWFAR_API 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

◆ GWEN_Directory_GetAllEntries()

GWENHYWFAR_API 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)

◆ GWEN_Directory_GetDirEntries()

GWENHYWFAR_API 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)

◆ GWEN_Directory_GetFileEntries()

GWENHYWFAR_API 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)

◆ GWEN_Directory_GetFileEntriesWithType()

GWENHYWFAR_API 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)

◆ GWEN_Directory_GetHomeDirectory()

GWENHYWFAR_API int GWEN_Directory_GetHomeDirectory ( char *  buffer,
unsigned int  size 
)

Gets the current user's home directory and copies it into the given buffer.

On Unix, this looks up the passwd entry of the current user, similar to glib's g_get_home_dir(). Watch out: The environment variable "HOME" is not used, not even as a fallback if there is no passwd entry (different from g_get_home_dir()).

On Windows, this looks up the environment variable "HOME", then "USERPROFILE", then the Windows system directory. This behaviour is identical to glib's g_get_home_dir(). Watch out: In the normal non-mingw/msys environment, only "USERPROFILE" is set, e.g. to "c:\Documents\Yourusername". But if this function is called from within msys, then msys itself has set "HOME" to a different value, e.g. to "c:\msys\1.0\home\yourusername". In effect, your program will see a different home directory when run from within msys compared to without msys. This is weird, but it is identical to the glib behaviour and hence we leave it at that.

Returns
0 if ok, !=0 on error

◆ GWEN_Directory_GetMatchingFilesRecursively()

GWENHYWFAR_API 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)

◆ GWEN_Directory_GetPath()

GWENHYWFAR_API int GWEN_Directory_GetPath ( const char *  path,
unsigned int  flags 
)

Gets a file path. It uses Paths to either create or check for the existence of a given path.

Returns
0 if ok, !=0 on error
Parameters
pathpath to inspect
flagsflags, please see GWEN_PATH_FLAGS_PATHMUSTEXIST et. al.

◆ GWEN_Directory_GetPrefixDirectory()

GWENHYWFAR_API int GWEN_Directory_GetPrefixDirectory ( char *  buffer,
unsigned int  size 
)

Gets the prefix to which the calling executable was installed, e.g. if the executable was installed using prefix "/usr" then the binary itself will be in "/usr/bin". In this case this function will return the directory name "/usr". Please note that this function only looks at the folder at which the calling exectuable is located when this function is called, so if you move the binary to another place then the result will be different.

◆ GWEN_Directory_GetTmpDirectory()

GWENHYWFAR_API 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

◆ GWEN_Directory_new()

GWENHYWFAR_API GWEN_DIRECTORY* GWEN_Directory_new ( void  )

Constructor.

◆ GWEN_Directory_Open()

GWENHYWFAR_API int GWEN_Directory_Open ( GWEN_DIRECTORY d,
const char *  n 
)

Opens a directory. This allows calling "Directory_Read" to succeed.

Author
Martin Preussmarti.nosp@m.n@li.nosp@m.bchip.nosp@m.card.nosp@m..de
Returns
0 if ok, !=0 on error (e.g. if no such directory exists; see opendir(3) and errno for the detailed error)
Parameters
dpointer to a directory data structure. This should be created by calling GWEN_Directory_new().
npath and name of the directory to open

◆ GWEN_Directory_OsifyPath()

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

Takes a path and translates it into a path that the running platform can understand. This is needed for unix paths used on Windows. If transformDriveElement is !=0 on Windows platforms and the first element of the path is "/x" (with x being [a..z,A..Z]) then this element is translated into the corresponding drive letter sequence (x:). Slashes and backslashes are transformed as needed by the running platform. Duplicate slashes/backslashed are removed.

Parameters
pathpath to translate
pbufbuffer to which the path is appended
transformDriveElemensee above (ignored on non-win32 platforms)

◆ GWEN_Directory_Read()

GWENHYWFAR_API int GWEN_Directory_Read ( GWEN_DIRECTORY d,
char *  buffer,
unsigned int  len 
)

Reads the next entry from a directory and stores the name of that entry in the given buffer. The entry returned is relative to the open directory.

Author
Martin Preussmarti.nosp@m.n@li.nosp@m.bchip.nosp@m.card.nosp@m..de
Returns
0 if ok, !=0 on error
Parameters
dpointer to a directory data structure. This should be created by calling GWEN_Directory_new().
bufferpointer to a buffer to receive the name
lensize of the buffer

◆ GWEN_Directory_Rewind()

GWENHYWFAR_API int GWEN_Directory_Rewind ( GWEN_DIRECTORY d)

Rewinds the internal pointers, so that the next call to

Author
Martin Preussmarti.nosp@m.n@li.nosp@m.bchip.nosp@m.card.nosp@m..de GWEN_Directory_Read will return the first entry of the open directory.
Returns
0 if ok, !=0 on error
Parameters
dpointer to a directory data structure. This should be created by calling GWEN_Directory_new().