blob: f603c2d17db7850cf949aa0cba041027b2a224b5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
//
// "$Id$"
//
// Definition of Apple Darwin system driver.
//
// Copyright 1998-2017 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
// http://www.fltk.org/COPYING.php
//
// Please report all bugs and problems on the following page:
//
// http://www.fltk.org/str.php
//
#include <config.h>
#include "Fl_Posix_System_Driver.H"
#include "../../flstring.h"
#include <FL/Fl_File_Browser.H>
#include <FL/Fl_File_Icon.H>
#include <FL/filename.H>
#include <FL/Fl.H>
#include <locale.h>
#include <stdio.h>
#if HAVE_DLFCN_H
# include <dlfcn.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <pwd.h>
#include <unistd.h>
#include <time.h>
#if defined(HAVE_LIBZ)
# include <zlib.h>
#endif
//
// Define missing POSIX/XPG4 macros as needed...
//
#ifndef S_ISDIR
# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
#endif /* !S_ISDIR */
void *Fl_Posix_System_Driver::dlopen(const char *filename)
{
#if HAVE_DLSYM
return ::dlopen(filename, RTLD_LAZY);
#endif
return NULL;
}
int Fl_Posix_System_Driver::file_type(const char *filename)
{
int filetype;
struct stat fileinfo; // Information on file
if (!::stat(filename, &fileinfo))
{
if (S_ISDIR(fileinfo.st_mode))
filetype = Fl_File_Icon::DIRECTORY;
# ifdef S_ISFIFO
else if (S_ISFIFO(fileinfo.st_mode))
filetype = Fl_File_Icon::FIFO;
# endif // S_ISFIFO
# if defined(S_ISCHR) && defined(S_ISBLK)
else if (S_ISCHR(fileinfo.st_mode) || S_ISBLK(fileinfo.st_mode))
filetype = Fl_File_Icon::DEVICE;
# endif // S_ISCHR && S_ISBLK
# ifdef S_ISLNK
else if (S_ISLNK(fileinfo.st_mode))
filetype = Fl_File_Icon::LINK;
# endif // S_ISLNK
else
filetype = Fl_File_Icon::PLAIN;
}
else
filetype = Fl_File_Icon::PLAIN;
return filetype;
}
const char *Fl_Posix_System_Driver::getpwnam(const char *login) {
struct passwd *pwd;
pwd = ::getpwnam(login);
return pwd ? pwd->pw_dir : NULL;
}
void Fl_Posix_System_Driver::gettime(time_t *sec, int *usec) {
struct timeval tv;
gettimeofday(&tv, NULL);
*sec = tv.tv_sec;
*usec = tv.tv_usec;
}
void* Fl_Posix_System_Driver::gzopen(const char *fname, const char *mode) {
#if defined(HAVE_LIBZ)
FILE *in = fl_fopen(fname, mode);
if (!in) return NULL;
int fd = dup(fileno(in));
fclose(in);
return gzdopen(fd, mode);
#else
return NULL;
#endif
}
//
// End of "$Id$".
//
|