fltk  1.3.5-source
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X.
  Fossies Dox: fltk-1.3.5-source.tar.bz2  ("inofficial" and yet experimental doxygen-generated source code documentation)  

File names and URI utility functions


#define FL_PATH_MAX   2048
#define fl_dirent_h_cyclic_include


typedef int() Fl_File_Sort_F(struct dirent **, struct dirent **)


const char * fl_filename_name (const char *filename)
const char * fl_filename_ext (const char *buf)
char * fl_filename_setext (char *to, int tolen, const char *ext)
int fl_filename_expand (char *to, int tolen, const char *from)
int fl_filename_absolute (char *to, int tolen, const char *from)
int fl_filename_relative (char *to, int tolen, const char *from)
int fl_filename_match (const char *name, const char *pattern)
int fl_filename_isdir (const char *name)
int fl_alphasort (struct dirent **, struct dirent **)
int fl_casealphasort (struct dirent **, struct dirent **)
int fl_casenumericsort (struct dirent **, struct dirent **)
int fl_numericsort (struct dirent **, struct dirent **)
int fl_open_uri (const char *uri, char *msg, int msglen)
void fl_decode_uri (char *uri)

Detailed Description

File names and URI functions defined in <FL/filename.H>

Macro Definition Documentation

◆ fl_dirent_h_cyclic_include

#define fl_dirent_h_cyclic_include

Definition at line 100 of file filename.H.


#define FL_PATH_MAX   2048

all path buffers should use this length

Definition at line 38 of file filename.H.

Typedef Documentation

◆ Fl_File_Sort_F

typedef int() Fl_File_Sort_F(struct dirent **, struct dirent **)

File sorting function.

See also

Definition at line 116 of file filename.H.

Function Documentation

◆ fl_alphasort()

int fl_alphasort ( struct dirent **  ,
struct dirent **   

Definition at line 37 of file filename_list.cxx.

◆ fl_casealphasort()

int fl_casealphasort ( struct dirent **  ,
struct dirent **   

Definition at line 41 of file filename_list.cxx.

◆ fl_casenumericsort()

int fl_casenumericsort ( struct dirent **  ,
struct dirent **   

◆ fl_decode_uri()

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.

Definition at line 253 of file fl_open_uri.cxx.

References last.

◆ fl_filename_absolute()

int fl_filename_absolute ( char *  to,
int  tolen,
const char *  from 

Makes a filename absolute from a relative filename.

#include <FL/filename.H>
fl_filename_absolute(out, sizeof(out), "foo.txt"); // out="/var/tmp/foo.txt"
fl_filename_absolute(out, sizeof(out), "./foo.txt"); // out="/var/tmp/foo.txt"
fl_filename_absolute(out, sizeof(out), "../log/messages"); // out="/var/log/messages"
[out]toresulting absolute filename
[in]tolensize of the absolute filename buffer
[in]fromrelative filename
0 if no change, non zero otherwise

Definition at line 56 of file filename_absolute.cxx.

References b, fl_getcwd(), isdirsep, start(), and strlcpy.

Referenced by Fl_File_Chooser::directory(), Fl_File_Chooser::fileNameCB(), update_history(), and Fl_File_Chooser::value().

◆ fl_filename_expand()

int fl_filename_expand ( char *  to,
int  tolen,
const char *  from 

Expands a filename containing shell variables and tilde (~). Currently handles these variants:

"~username" // if 'username' does not exist, result will be unchanged
"$VARNAME" // does NOT handle ${VARNAME}


#include <FL/filename.H>
fl_filename_expand(out, sizeof(out), "~fred/.cshrc"); // out="/usr/fred/.cshrc"
fl_filename_expand(out, sizeof(out), "~/.cshrc"); // out="/usr/<yourname>/.cshrc"
fl_filename_expand(out, sizeof(out), "$TMPDIR/foo.txt"); // out="/var/tmp/foo.txt"
[out]toresulting expanded filename
[in]tolensize of the expanded filename buffer
[in]fromfilename containing shell variables
0 if no change, non zero otherwise

Definition at line 63 of file filename_expand.cxx.

References fl_getenv(), isdirsep, pwd, start(), and strlcpy.

Referenced by Fl_File_Chooser::fileNameCB().

◆ fl_filename_ext()

const char* fl_filename_ext ( const char *  buf)

Gets the extensions of a filename.

#include <FL/filename.H>
const char *out;
out = fl_filename_ext("/some/path/foo.txt"); // result: ".txt"
out = fl_filename_ext("/some/path/foo"); // result: NULL
[in]bufthe filename to be parsed
a pointer to the extension (including '.') if any or NULL otherwise

Definition at line 34 of file filename_ext.cxx.

References buf, and p.

Referenced by fl_filename_setext(), Fl_File_Icon::load(), and Fluid_Image::write_static().

◆ fl_filename_isdir()

int fl_filename_isdir ( const char *  n)

Determines if a file exists and is a directory from its filename.

#include <FL/filename.H>
fl_filename_isdir("/etc"); // returns non-zero
fl_filename_isdir("/etc/hosts"); // returns 0
[in]nthe filename to parse
non zero if file exists and is a directory, zero otherwise

Definition at line 52 of file filename_isdir.cxx.

References FL_PATH_MAX, fl_stat(), isdirsep, and length.

Referenced by _fl_filename_isdir_quick(), extract_dir_from_path(), Fl_File_Chooser::fileNameCB(), Fl_File_Icon::find(), fl_filename_list(), load_kde_icons(), Fl_File_Chooser::update_preview(), and Fl_File_Chooser::value().

◆ fl_filename_match()

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:

  • * matches any sequence of 0 or more characters.
  • ? matches any single character.
  • [set] matches any character in the set. Set can contain any single characters, or a-z to represent a range. To match ] or - they must be the first characters. To match ^ or ! they must not be the first characters.
  • [^set] or [!set] matches any character not in the set.
  • {X|Y|Z} or {X,Y,Z} matches any one of the subexpressions literally.
  • \x quotes the character x so it has no special meaning.
  • x all other characters must be matched exactly.


#include <FL/filename.H>
[in]sthe string to check for a match
[in]pthe string pattern
non zero if the string matches the pattern

Definition at line 44 of file filename_match.cxx.

References last, and p.

Referenced by Fl_GTK_File_Chooser::custom_gtk_filter_function(), do_matching(), Fl_File_Icon::find(), Fl_Function_Type::has_signature(), Fl_File_Browser::load(), Fl_Plugin_Manager::loadAll(), and template_load().

◆ fl_filename_name()

const char* fl_filename_name ( const char *  filename)

Gets the file name from a path. Similar to basename(3), exceptions shown below.

#include <FL/filename.H>
const char *out;
out = fl_filename_name("/usr/lib"); // out="lib"
out = fl_filename_name("/usr/"); // out="" (basename(3) returns "usr" instead)
out = fl_filename_name("/usr"); // out="usr"
out = fl_filename_name("/"); // out="" (basename(3) returns "/" instead)
out = fl_filename_name("."); // out="."
out = fl_filename_name(".."); // out=".."
a pointer to the char after the last slash, or to filename if there is none.

Definition at line 2179 of file Fl_win32.cxx.

References name, and p.

Referenced by Fl_GTK_File_Chooser::changed_output_type(), Fl_GTK_File_Chooser::custom_gtk_filter_function(), Fl_File_Icon::find(), Fl_File_Chooser::fl_file_chooser(), Fl_GTK_File_Chooser::fl_gtk_chooser_wrapper(), fl_show_file_selector(), goto_source_dir(), Fl_Window::show(), update_sourceview_cb(), write_cb(), write_code(), Fluid_Image::write_static(), and write_strings_cb().

◆ fl_filename_relative()

int fl_filename_relative ( char *  to,
int  tolen,
const char *  from 

Makes a filename relative to the current working directory.

#include <FL/filename.H>
chdir("/var/tmp/somedir"); // set cwd to /var/tmp/somedir
char out[FL_PATH_MAX];
fl_filename_relative(out, sizeof(out), "/var/tmp/somedir/foo.txt"); // out="foo.txt", return=1
fl_filename_relative(out, sizeof(out), "/var/tmp/foo.txt"); // out="../foo.txt", return=1
fl_filename_relative(out, sizeof(out), "foo.txt"); // out="foo.txt", return=0 (no change)
fl_filename_relative(out, sizeof(out), "./foo.txt"); // out="./foo.txt", return=0 (no change)
fl_filename_relative(out, sizeof(out), "../foo.txt"); // out="../foo.txt", return=0 (no change)
[out]toresulting relative filename
[in]tolensize of the relative filename buffer
[in]fromabsolute filename
0 if no change, non zero otherwise

Definition at line 128 of file filename_absolute.cxx.

References fl_getcwd(), FL_PATH_MAX, and strlcpy.

Referenced by Fl_File_Chooser::fl_dir_chooser(), Fl_File_Chooser::fl_file_chooser(), load_history(), and update_history().

◆ fl_filename_setext()

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 ("").


#include <FL/filename.H>
char buf[FL_PATH_MAX] = "/path/myfile.cxx";
fl_filename_setext(buf, sizeof(buf), ".txt"); // buf[] becomes "/path/myfile.txt"
buf itself for calling convenience.

Definition at line 40 of file filename_setext.cxx.

References buf, buflen, fl_filename_ext(), and strlcpy.

Referenced by update_sourceview_cb(), write_cb(), and write_strings_cb().

◆ fl_numericsort()

int fl_numericsort ( struct dirent **  ,
struct dirent **   

◆ fl_open_uri()

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.

Platform Specific Issues: Windows
With "file:" based URIs on Windows, you may encounter issues with anchors being ignored. Example: "file:///c:/some/index.html#anchor" may open in the browser without the "#anchor" suffix. The behavior seems to vary across different Windows versions. Workaround: open a link to a separate html file that redirects to the desired "file:" URI.


#include <FL/filename.H>
char errmsg[512];
if ( !fl_open_uri("http://google.com/", errmsg, sizeof(errmsg)) ) {
char warnmsg[768];
sprintf(warnmsg, "Error: %s", errmsg);
uriThe URI to open
msgOptional buffer which contains the command or error message
msglenLength of optional buffer
1 on success, 0 on failure

Definition at line 98 of file fl_open_uri.cxx.

References command(), FL_PATH_MAX, NULL, path_find(), run_program(), snprintf, strlcat, and strlcpy.

Referenced by Fl_Help_View::load(), and show_help().

int fl_filename_relative(char *to, int tolen, const char *from)
Definition: filename_absolute.cxx:128
static char * buf
Definition: fl_encoding_mac_roman.cxx:76
int fl_filename_isdir(const char *name)
Definition: filename_isdir.cxx:52
#define FL_PATH_MAX
Definition: filename.H:38
const char * fl_filename_name(const char *filename)
Definition: Fl_win32.cxx:2179
int fl_filename_absolute(char *to, int tolen, const char *from)
Definition: filename_absolute.cxx:56
char * fl_filename_setext(char *to, int tolen, const char *ext)
Definition: filename_setext.cxx:40
int fl_filename_expand(char *to, int tolen, const char *from)
Definition: filename_expand.cxx:63
void fl_alert(const char *,...)
Definition: fl_ask.cxx:361
const char * fl_filename_ext(const char *buf)
Definition: filename_ext.cxx:34
int fl_open_uri(const char *uri, char *msg, int msglen)
Definition: fl_open_uri.cxx:98