FLTK 1.5.0
|
File names and URI functions defined in <FL/filename.H> More...
Macros | |
#define | FL_PATH_MAX 2048 |
all path buffers should use this length | |
Typedefs | |
typedef int() | Fl_File_Sort_F(struct dirent **, struct dirent **) |
File sorting function. More... | |
Functions | |
void | fl_decode_uri (char *uri) |
Decodes a URL-encoded string. More... | |
int | fl_filename_absolute (char *to, int tolen, const char *from) |
Makes a filename absolute from a relative filename to the current working directory. More... | |
int | fl_filename_absolute (char *to, int tolen, const char *from, const char *cwd) |
Concatenate the absolute path base with from to form the new absolute path in to . More... | |
std::string | fl_filename_absolute_str (const std::string &from) |
Makes a filename absolute from a filename relative to the current working directory. More... | |
std::string | fl_filename_absolute_str (const std::string &from, const std::string &base) |
Append the relative filename from to the absolute filename base to form the new absolute path. More... | |
int | fl_filename_expand (char *to, int tolen, const char *from) |
Expands a filename containing shell variables and tilde (~). More... | |
std::string | fl_filename_expand_str (const std::string &from) |
Expands a filename containing shell variables and tilde (~). More... | |
const char * | fl_filename_ext (const char *buf) |
Gets the extension of a filename. More... | |
std::string | fl_filename_ext_str (const std::string &filename) |
Return a new string that contains the filename extension. More... | |
void | fl_filename_free_list (struct dirent ***l, int n) |
Free the list of filenames that is generated by fl_filename_list(). More... | |
int | fl_filename_isdir (const char *name) |
Determines if a file exists and is a directory from its filename. More... | |
int | fl_filename_list (const char *d, struct dirent ***l, Fl_File_Sort_F *s=fl_numericsort) |
Portable and const-correct wrapper for the scandir() function. More... | |
int | fl_filename_match (const char *name, const char *pattern) |
Checks if a string s matches a pattern p . More... | |
const char * | fl_filename_name (const char *filename) |
Gets the file name from a path. More... | |
std::string | fl_filename_name_str (const std::string &filename) |
Return a new string that contains the name part of the filename. More... | |
std::string | fl_filename_path_str (const std::string &filename) |
Return a new string that contains the path part of the filename. More... | |
int | fl_filename_relative (char *to, int tolen, const char *from) |
Makes a filename relative to the current working directory. More... | |
int | fl_filename_relative (char *to, int tolen, const char *from, const char *cwd) |
Makes a filename relative to any other directory. More... | |
std::string | fl_filename_relative_str (const std::string &from) |
Makes a filename relative to the current working directory. More... | |
std::string | fl_filename_relative_str (const std::string &from, const std::string &base) |
Makes a filename relative to any directory. More... | |
char * | fl_filename_setext (char *to, int tolen, const char *ext) |
Replaces the extension in buf of max. More... | |
std::string | fl_filename_setext_str (const std::string &filename, const std::string &new_extension) |
Return a copy of the old filename with the new extension. More... | |
std::string | fl_getcwd_str () |
Cross-platform function to get the current working directory as a UTF-8 encoded value in an std::string. More... | |
int | fl_open_uri (const char *uri, char *msg, int msglen) |
Opens the specified Uniform Resource Identifier (URI). More... | |
File names and URI functions defined in <FL/filename.H>
typedef int() Fl_File_Sort_F(struct dirent **, struct dirent **) |
File sorting function.
void fl_decode_uri | ( | char * | uri | ) |
Decodes a URL-encoded string.
In a Uniform Resource Identifier (URI), all non-ASCII bytes and several others (e.g., '<', '', ' ') are URL-encoded using 3 bytes by "%XY" where XY is the hexadecimal value of the byte. This function decodes the URI restoring its original UTF-8 encoded content. Decoding is done in-place.
int fl_filename_absolute | ( | char * | to, |
int | tolen, | ||
const char * | from | ||
) |
Makes a filename absolute from a relative filename to the current working directory.
[out] | to | resulting absolute filename |
[in] | tolen | size of the absolute filename buffer |
[in] | from | relative filename |
int fl_filename_absolute | ( | char * | to, |
int | tolen, | ||
const char * | from, | ||
const char * | base | ||
) |
Concatenate the absolute path base
with from
to form the new absolute path in to
.
[out] | to | resulting absolute filename |
[in] | tolen | size of the absolute filename buffer |
[in] | from | relative filename |
[in] | base | from is relative to this absolute file path |
std::string fl_filename_absolute_str | ( | const std::string & | from | ) |
Makes a filename absolute from a filename relative to the current working directory.
[in] | from | relative filename |
std::string fl_filename_absolute_str | ( | const std::string & | from, |
const std::string & | base | ||
) |
Append the relative filename from
to the absolute filename base
to form the new absolute path.
[in] | from | relative filename |
[in] | base | from is relative to this absolute file path |
int fl_filename_expand | ( | char * | to, |
int | tolen, | ||
const char * | from | ||
) |
Expands a filename containing shell variables and tilde (~).
Currently handles these variants:
Examples:
[out] | to | resulting expanded filename |
[in] | tolen | size of the expanded filename buffer |
[in] | from | filename containing shell variables |
std::string fl_filename_expand_str | ( | const std::string & | from | ) |
Expands a filename containing shell variables and tilde (~).
[in] | from | file path and name |
const char * fl_filename_ext | ( | const char * | buf | ) |
Gets the extension of a filename.
[in] | buf | the filename to be parsed |
std::string fl_filename_ext_str | ( | const std::string & | filename | ) |
Return a new string that contains the filename extension.
[in] | filename | file path and name |
void fl_filename_free_list | ( | struct dirent *** | list, |
int | n | ||
) |
Free the list of filenames that is generated by fl_filename_list().
Free everything that was allocated by a previous call to fl_filename_list(). Use the return values as parameters for this function.
[in,out] | list | table containing the resulting directory listing |
[in] | n | number of entries in the list |
int fl_filename_isdir | ( | const char * | n | ) |
Determines if a file exists and is a directory from its filename.
[in] | n | the filename to parse |
int fl_filename_list | ( | const char * | d, |
dirent *** | list, | ||
Fl_File_Sort_F * | sort | ||
) |
Portable and const-correct wrapper for the scandir() function.
For each file in that directory a "dirent" structure is created. The only portable thing about a dirent is that dirent.d_name is the nul-terminated file name. A pointers array to these dirent's is created and a pointer to the array is returned in *list. The number of entries is given as a return value. If there is an error reading the directory a number less than zero is returned, and errno has the reason; errno does not work under Windows.
Include:
[in] | d | the name of the directory to list. It does not matter if it has a trailing slash. |
[out] | list | table containing the resulting directory listing |
[in] | sort | sorting functor:
|
int fl_filename_match | ( | const char * | s, |
const char * | p | ||
) |
Checks if a string s
matches a pattern p
.
The following syntax is used for the pattern:
Notes:
s
and p
are matched on a char/byte basis, not as UCS codepoints or UTF-8 sequences.Include:
[in] | s | the string to check for a match |
[in] | p | the string pattern |
const char * fl_filename_name | ( | const char * | filename | ) |
Gets the file name from a path.
Similar to basename(3), exceptions shown below.
filename
if there is none. std::string fl_filename_name_str | ( | const std::string & | filename | ) |
Return a new string that contains the name part of the filename.
[in] | filename | file path and name |
std::string fl_filename_path_str | ( | const std::string & | filename | ) |
Return a new string that contains the path part of the filename.
[in] | filename | file path and name |
int fl_filename_relative | ( | char * | to, |
int | tolen, | ||
const char * | from | ||
) |
Makes a filename relative to the current working directory.
Return the from path made relative to the working directory, similar to C++17 std::filesystem::path::lexically_relative
. This function can also be called with a fourth argument for a user supplied base directory path
These conversions are purely lexical. They do not check that the paths exist, do not follow symlinks, and do not access the filesystem at all.
Path arguments must be absolute (start at the root directory) and must not contain .
or ..
segments, or double separators. A single trailing separator is ok.
On Windows, path arguments must start with a drive name, e.g. c:\
. Windows network paths and other special paths starting with a double separator are not supported (\\cloud\drive\path
, \\?\
, etc.) . Separators can be \
and /
and will be preserved. Newly created separators are alway the forward slash /
.
On Windows and macOS, the path segment tests are case insensitive.
If the path can not be generated, from path is copied into the to buffer and 0 is returned.
[out] | to | resulting relative filename |
[in] | tolen | size of the relative filename buffer |
[in] | from | absolute filename |
int fl_filename_relative | ( | char * | to, |
int | tolen, | ||
const char * | from, | ||
const char * | base | ||
) |
Makes a filename relative to any other directory.
[out] | to | resulting relative filepath |
[in] | tolen | size of the relative filename buffer |
[in] | from | absolute filepath |
[in] | base | generate filepath relative to this absolute filepath |
std::string fl_filename_relative_str | ( | const std::string & | from | ) |
Makes a filename relative to the current working directory.
[in] | from | file path and name |
std::string fl_filename_relative_str | ( | const std::string & | from, |
const std::string & | base | ||
) |
Makes a filename relative to any directory.
[in] | from | file path and name |
[in] | base | relative to this absolute path |
char * fl_filename_setext | ( | char * | buf, |
int | buflen, | ||
const char * | ext | ||
) |
Replaces the extension in buf
of max.
size buflen
with the extension in ext
.
If there's no '.' in buf
, ext
is appended.
If ext
is NULL, behaves as if it were an empty string ("").
Example
std::string fl_filename_setext_str | ( | const std::string & | filename, |
const std::string & | new_extension | ||
) |
Return a copy of the old filename with the new extension.
[in] | filename | file path and name |
[in] | new_extension | new filename extension, starts with a '.' |
std::string fl_getcwd_str | ( | ) |
Cross-platform function to get the current working directory as a UTF-8 encoded value in an std::string.
int fl_open_uri | ( | const char * | uri, |
char * | msg, | ||
int | msglen | ||
) |
Opens the specified Uniform Resource Identifier (URI).
Uses an operating-system dependent program or interface. For URIs using the "ftp", "http", or "https" schemes, the system default web browser is used to open the URI, while "mailto" and "news" URIs are typically opened using the system default mail reader and "file" URIs are opened using the file system navigator.
On success, the (optional) msg buffer is filled with the command that was run to open the URI; on Windows, this will always be "open uri".
On failure, the msg buffer is filled with an English error message.
Example
uri | The URI to open |
msg | Optional buffer which contains the command or error message |
msglen | Length of optional buffer |