libcmutils 0.6.5
Multi-platform C99 utility library
Loading...
Searching...
No Matches
CMUTIL_File Struct Reference

A file or directory object. More...

Data Fields

CMUTIL_String *(* GetContents )(const CMUTIL_File *file)
 Get the contents of the file as a string.
 
CMBool(* Delete )(const CMUTIL_File *file)
 Delete the file.
 
CMBool(* IsFile )(const CMUTIL_File *file)
 Check if the file is a regular file.
 
CMBool(* IsDirectory )(const CMUTIL_File *file)
 Check if the file is a directory.
 
CMBool(* IsExists )(const CMUTIL_File *file)
 Check if the file exists.
 
long(* Length )(const CMUTIL_File *file)
 Get the length of the file in bytes.
 
const char *(* GetName )(const CMUTIL_File *file)
 Get the name of the file or directory.
 
const char *(* GetFullPath )(const CMUTIL_File *file)
 Get the full path of the file or directory.
 
time_t(* ModifiedTime )(const CMUTIL_File *file)
 Get the last modified time of the file.
 
CMUTIL_FileList *(* Children )(const CMUTIL_File *file)
 Get a list of all children files and directories.
 
CMUTIL_FileList *(* Find )(const CMUTIL_File *file, const char *pattern, CMBool recursive)
 Find all children whose name is matched with the given pattern.
 
CMUTIL_FileStream *(* CreateStream )(const CMUTIL_File *file, CMFileOpenMode mode)
 Create a file stream for reading or writing the file.
 
void(* Destroy )(CMUTIL_File *file)
 Destroy the file or directory object and free its resources.
 

Detailed Description

A file or directory object.

Field Documentation

◆ GetContents

CMUTIL_String *(* CMUTIL_File::GetContents) (const CMUTIL_File *file)

Get the contents of the file as a string.

Parameters
fileA pointer to the CMUTIL_File object.
Returns
A pointer to a CMUTIL_String object containing the file contents, or NULL on failure.

◆ Delete

CMBool(* CMUTIL_File::Delete) (const CMUTIL_File *file)

Delete the file.

Parameters
fileA pointer to the CMUTIL_File object.
Returns
CMTrue on success, CMFalse on failure.

◆ IsFile

CMBool(* CMUTIL_File::IsFile) (const CMUTIL_File *file)

Check if the file is a regular file.

Parameters
fileA pointer to the CMUTIL_File object.
Returns
CMTrue if the file is a regular file, CMFalse otherwise.

◆ IsDirectory

CMBool(* CMUTIL_File::IsDirectory) (const CMUTIL_File *file)

Check if the file is a directory.

Parameters
fileA pointer to the CMUTIL_File object.
Returns
CMTrue if the file is a directory, CMFalse otherwise.

◆ IsExists

CMBool(* CMUTIL_File::IsExists) (const CMUTIL_File *file)

Check if the file exists.

Parameters
fileA pointer to the CMUTIL_File object.
Returns
CMTrue if the file exists, CMFalse otherwise.

◆ Length

long(* CMUTIL_File::Length) (const CMUTIL_File *file)

Get the length of the file in bytes.

Parameters
fileA pointer to the CMUTIL_File object.
Returns
The length of the file in bytes, or -1 on failure.

◆ GetName

const char *(* CMUTIL_File::GetName) (const CMUTIL_File *file)

Get the name of the file or directory.

Parameters
fileA pointer to the CMUTIL_File object.
Returns
A pointer to a C-style string containing the name of the file or directory.

◆ GetFullPath

const char *(* CMUTIL_File::GetFullPath) (const CMUTIL_File *file)

Get the full path of the file or directory.

Parameters
fileA pointer to the CMUTIL_File object.
Returns
A pointer to a C-style string containing the full path of the file or directory.

◆ ModifiedTime

time_t(* CMUTIL_File::ModifiedTime) (const CMUTIL_File *file)

Get the last modified time of the file.

Parameters
fileA pointer to the CMUTIL_File object.
Returns
The last modified time of the file as a time_t value.

◆ Children

CMUTIL_FileList *(* CMUTIL_File::Children) (const CMUTIL_File *file)

Get a list of all children files and directories.

Parameters
fileA pointer to the CMUTIL_File object representing a directory.
Returns
A pointer to a CMUTIL_FileList object containing all children files and directories. The caller is responsible for freeing the returned object.

◆ Find

CMUTIL_FileList *(* CMUTIL_File::Find) (const CMUTIL_File *file, const char *pattern, CMBool recursive)

Find all children whose name is matched with the given pattern.

Filename patterns are composed of regular (printable) characters which may comprise a filename as well as special pattern matching characters:

  • . - Matches a period (.). Note that a period in a filename is not treated any differently than any other character.

  • ? - Any. Matches any single character except '/' or '\'.

  • * - Closure. Matches zero or more occurences of any characters other than '/' or '\'. Leading '*' characters are allowed.

  • SUB - Substitute (^Z). Similar to '*', this matches zero or more occurences of any characters other than '/', '\', or '.'. Leading '^Z' characters are allowed.

  • [ab] - Set. Matches the single character 'a' or 'b'. If the dash '-' character is to be included, it must immediately follow the opening bracket '['. If the closing bracket ']' character is to be included, it must be preceded by a quote '‘’.

  • [a-z] - Range. Matches a single character in the range 'a' to 'z'. Ranges and sets may be combined within the same set of brackets.

  • [!R] - Exclusive range. Matches a single character not in the range 'R'. If range 'R' includes the dash '-' character, the dash must immediately follow the caret '!'.

  • ! - Not. Makes the following pattern (up to the next '/') match any filename except those what it would normally match.

  • / - Path separator (UNIX and DOS). Matches a '/' or '\' pathname (directory) separator. Multiple separators are treated like a single separator. A leading separator indicates an absolute pathname.

  • \ - Path separator (DOS). Same as the '/' character. Note that this character must be escaped if used within string constants ("\\"). <li>\ - Quote (UNIX).</li> Makes the next character a regular (nonspecial) character. Note that to match the quote character itself, it must be quoted. Note that this character must be escaped if used within string constants ("\").

  • ` - Quote (DOS). Makes the next character a regular (nonspecial) character. Note that to match the quote character itself, it must be quoted.

Upper and lower case alphabetic characters are considered identical, i.e., 'a' and 'A' match each other. (What constitutes a lowercase letter depends on the current locale settings.)

Spaces and control characters are treated as normal characters.
Examples
The following patterns in the left column will match the filenames in the middle column and will not match filenames in the right column:

     Pattern     Will Match                      Will Not Match
     -------     ----------                      --------------
     a           a (only)                        (anything else)
     a.          a. (only)                       (anything else)
     a?c         abc, acc, arc, a.c              a, ac, abbc
     a*c         ac, abc, abbc, acc, a.c         a, ab, acb, bac
     a*          a, ab, abb, a., a.b             b, ba
     *           a, ab, abb, a., .foo, a.foo     (nothing)
     *.          a., ab., abb., a.foo.           a, ab, a.foo, .foo
     *.*         a., a.b, ah.bc.foo              a
     ^Z          a, ab, abb                      a., .foo, a.foo
     ^Z.         a., ab., abb.                   a, .foo, a.foo
     ^Z.*        a, a., .foo, a.foo              ab, abb
     *2.c        2.c, 12.c, foo2.c, foo.12.c     2x.c
     a[b-z]c     abc, acc, azc (only)            (anything else)
     [ab0-9]x    ax, bx, 0x, 9x                  zx
     a[-.]b      a-b, a.b (only)                 (anything else)
     a[!a-z]b    a0b, a.b, aaab, azb, aa0b
     a[!-b]x     a0x, a+x, acx                   a-x, abx, axxx
     a[-!b]x     a-x, a!x, abx (only)            (anything else)
     a[`]]x      a]x (only)                      (anything else)
     a``x        a`x (only)                      (anything else)
     oh`!        oh! (only)                      (anything else)
     is`?it      is?it (only)                    (anything else)
     !a?c        a, ac, ab, abb, acb, a.foo      abc, a.c, azc
Parameters
fileA pointer to the CMUTIL_File object representing a directory.
patternThe filename pattern to match.
recursiveWhether to search recursively in subdirectories.
Returns
A pointer to a CMUTIL_FileList object containing all matched files and directories.

◆ CreateStream

CMUTIL_FileStream *(* CMUTIL_File::CreateStream) (const CMUTIL_File *file, CMFileOpenMode mode)

Create a file stream for reading or writing the file.

Parameters
fileA pointer to the CMUTIL_File object.
modeThe file open mode (read, write, append).
Returns
A pointer to the newly created CMUTIL_FileStream object, or NULL on failure.

◆ Destroy

void(* CMUTIL_File::Destroy) (CMUTIL_File *file)

Destroy the file or directory object and free its resources.

Parameters
fileA pointer to the CMUTIL_File object to be destroyed.

The documentation for this struct was generated from the following file: