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)
filename_isdir.cxx
Go to the documentation of this file.
1
//
2
// "$Id$"
3
//
4
// Directory detection routines for the Fast Light Tool Kit (FLTK).
5
//
6
// Copyright 1998-2010 by Bill Spitzak and others.
7
//
8
// This library is free software. Distribution and use rights are outlined in
9
// the file "COPYING" which should have been included with this file. If this
10
// file is missing or damaged, see the license at:
11
//
12
// http://www.fltk.org/COPYING.php
13
//
14
// Please report all bugs and problems on the following page:
15
//
16
// http://www.fltk.org/str.php
17
//
18
19
// Used by fl_file_chooser
20
21
#include "
flstring.h
"
22
#include <sys/types.h>
23
#include <sys/stat.h>
24
#include <ctype.h>
25
#include <
FL/filename.H
>
26
#include <
FL/fl_utf8.h
>
27
28
29
#if defined(WIN32) || defined(__EMX__) && !defined(__CYGWIN__)
30
static
inline
int
isdirsep
(
char
c) {
return
c==
'/'
|| c==
'\\'
;}
31
#else
32
#define isdirsep(c) ((c)=='/')
33
#endif
34
35
int
_fl_filename_isdir_quick
(
const
char
* n) {
36
// Do a quick optimization for filenames with a trailing slash...
37
if
(*n &&
isdirsep
(n[strlen(n) - 1]))
return
1;
38
return
fl_filename_isdir
(n);
39
}
40
52
int
fl_filename_isdir
(
const
char
* n) {
53
struct
stat s;
54
char
fn[
FL_PATH_MAX
];
55
int
length
;
56
57
length
= (int) strlen(n);
58
59
#ifdef WIN32
60
// This workaround brought to you by the fine folks at Microsoft!
61
// (read lots of sarcasm in that...)
62
if
(
length
< (
int
)(
sizeof
(fn) - 1)) {
63
if
(
length
< 4 && isalpha(n[0]) && n[1] ==
':'
&&
64
(
isdirsep
(n[2]) || !n[2])) {
65
// Always use D:/ for drive letters
66
fn[0] = n[0];
67
strcpy(fn + 1,
":/"
);
68
n = fn;
69
}
else
if
(
length
> 0 &&
isdirsep
(n[
length
- 1])) {
70
// Strip trailing slash from name...
71
length
--;
72
memcpy(fn, n,
length
);
73
fn[
length
] =
'\0'
;
74
n = fn;
75
}
76
}
77
#else
78
// Matt: Just in case, we strip the slash for other operating
79
// systems as well, avoid bugs by sloppy implementations
80
// of "stat".
81
if
(
length
> 1 &&
isdirsep
(n[
length
- 1])) {
82
length
--;
83
memcpy(fn, n,
length
);
84
fn[
length
] =
'\0'
;
85
n = fn;
86
}
87
#endif
88
89
return
!
fl_stat
(n, &s) && (s.st_mode&0170000)==0040000;
90
}
91
92
//
93
// End of "$Id$".
94
//
filename.H
fl_filename_isdir
int fl_filename_isdir(const char *n)
Definition:
filename_isdir.cxx:52
fl_utf8.h
header for Unicode and UTF-8 character handling
FL_PATH_MAX
#define FL_PATH_MAX
Definition:
filename.H:38
isdirsep
#define isdirsep(c)
Definition:
filename_isdir.cxx:32
fl_stat
int fl_stat(const char *path, struct stat *buffer)
Definition:
fl_utf8.cxx:669
_fl_filename_isdir_quick
int _fl_filename_isdir_quick(const char *n)
Definition:
filename_isdir.cxx:35
flstring.h
length
png_uint_32 length
Definition:
png.c:2173
src
filename_isdir.cxx
Generated by
1.8.16