plibsys 0.0.5
pdir.h File Reference

Filesystem interface. More...

#include <pmacros.h>
#include <ptypes.h>
#include <perror.h>

Go to the source code of this file.

Data Structures

struct  PDirEntry_
 Structure with directory entry information. More...
 

Typedefs

typedef struct PDir_ PDir
 Directory opaque data structure.
 
typedef enum PDirEntryType_ PDirEntryType
 Directory entry types.
 
typedef struct PDirEntry_ PDirEntry
 Structure with directory entry information.
 

Enumerations

enum  PDirEntryType_ { P_DIR_ENTRY_TYPE_DIR = 1 , P_DIR_ENTRY_TYPE_FILE = 2 , P_DIR_ENTRY_TYPE_OTHER = 3 }
 Directory entry types. More...
 

Functions

P_LIB_API PDirp_dir_new (const pchar *path, PError **error)
 Creates a new PDir object.
 
P_LIB_API pboolean p_dir_create (const pchar *path, pint mode, PError **error)
 Creates a new directory on a filesystem.
 
P_LIB_API pboolean p_dir_remove (const pchar *path, PError **error)
 Removes an empty directory.
 
P_LIB_API pboolean p_dir_is_exists (const pchar *path)
 Checks whether a directory exists or not.
 
P_LIB_API pcharp_dir_get_path (const PDir *dir)
 Gets the original directory path used to create a PDir object.
 
P_LIB_API PDirEntryp_dir_get_next_entry (PDir *dir, PError **error)
 Gets the next directory entry info.
 
P_LIB_API pboolean p_dir_rewind (PDir *dir, PError **error)
 Resets a directory entry pointer.
 
P_LIB_API void p_dir_entry_free (PDirEntry *entry)
 Frees PDirEntry object.
 
P_LIB_API void p_dir_free (PDir *dir)
 Frees PDir object.
 

Detailed Description

Filesystem interface.

Author
Alexander Saprykin

A traditional filesystem can be presented as a combination of directories and files within a defined hierarchy. A directory contains the so called entries: files and other directories. PDir allows to iterate through these entries without reading their contents, thus building a filesystem hierarchy tree.

Think of this module as an interface to the well-known dirent API.

First you need to open a directory for iterating through its content entries using p_dir_new(). After that every next entry inside the directory can be read with the p_dir_get_next_entry() call until it returns NULL (though it's better to check an error code to be sure no error occurred).

Also some directory manipulation routines are provided to create, remove and check existance.

Definition in file pdir.h.

Typedef Documentation

◆ PDir

typedef struct PDir_ PDir

Directory opaque data structure.

Definition at line 61 of file pdir.h.

Enumeration Type Documentation

◆ PDirEntryType_

Directory entry types.

Enumerator
P_DIR_ENTRY_TYPE_DIR 

Directory.


P_DIR_ENTRY_TYPE_FILE 

File.


P_DIR_ENTRY_TYPE_OTHER 

Other.


Definition at line 64 of file pdir.h.

Function Documentation

◆ p_dir_create()

P_LIB_API pboolean p_dir_create ( const pchar * path,
pint mode,
PError ** error )

Creates a new directory on a filesystem.

Parameters
pathDirectory path.
modeDirectory permissions to use, ignored on Windows.
[out]errorError report object, NULL to ignore.
Returns
TRUE in case of success, FALSE otherwise.
Since
0.0.1
Note
Call returns TRUE if the directory path is already exists.
On OpenVMS operating system it creates intermediate directories as well.

◆ p_dir_entry_free()

P_LIB_API void p_dir_entry_free ( PDirEntry * entry)

Frees PDirEntry object.

Parameters
entryPDirEntry to free.
Since
0.0.1

◆ p_dir_free()

P_LIB_API void p_dir_free ( PDir * dir)

Frees PDir object.

Parameters
dirPDir to free.
Since
0.0.1

◆ p_dir_get_next_entry()

P_LIB_API PDirEntry * p_dir_get_next_entry ( PDir * dir,
PError ** error )

Gets the next directory entry info.

Parameters
dirDirectory to get the next entry from.
[out]errorError report object, NULL to ignore.
Returns
Info for the next entry in case of success, NULL otherwise.
Since
0.0.1

Caller takes ownership of the returned object. Use p_dir_entry_free() to free memory of the directory entry after usage.

An error is set only if it is occurred. You should check the error object for P_ERROR_IO_NO_MORE code.

◆ p_dir_get_path()

P_LIB_API pchar * p_dir_get_path ( const PDir * dir)

Gets the original directory path used to create a PDir object.

Parameters
dirPDir object to retrieve the path from.
Returns
The directory path in case of success, NULL otherwise.
Since
0.0.1

Caller takes ownership of the returned string. Use p_free() to free memory after usage.

◆ p_dir_is_exists()

P_LIB_API pboolean p_dir_is_exists ( const pchar * path)

Checks whether a directory exists or not.

Parameters
pathDirectory path.
Returns
TRUE in case of success, FALSE otherwise.
Since
0.0.1

◆ p_dir_new()

P_LIB_API PDir * p_dir_new ( const pchar * path,
PError ** error )

Creates a new PDir object.

Parameters
pathDirectory path.
Returns
Pointer to a newly created PDir object in case of success, NULL otherwise.
Parameters
[out]errorError report object, NULL to ignore.
Since
0.0.1
Note
If you want to create a new directory on a filesystem, use p_dir_create() instead.

◆ p_dir_remove()

P_LIB_API pboolean p_dir_remove ( const pchar * path,
PError ** error )

Removes an empty directory.

Parameters
pathDirectory path to remove.
[out]errorError report object, NULL to ignore.
Returns
TRUE in case of success, FALSE otherwise.
Since
0.0.1

The directory path should be empty to be removed successfully.

◆ p_dir_rewind()

P_LIB_API pboolean p_dir_rewind ( PDir * dir,
PError ** error )

Resets a directory entry pointer.

Parameters
dirDirectory to reset the entry pointer.
[out]errorError report object, NULL to ignore.
Returns
TRUE in case of success, FALSE otherwise.
Since
0.0.1