Subversion Repositories QNX 8.QNX8 IFS tool

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
26 pmbaty 1
/* ACC -- Automatic Compiler Configuration
2
 
3
   Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
4
   All Rights Reserved.
5
 
6
   This software is a copyrighted work licensed under the terms of
7
   the GNU General Public License. Please consult the file "ACC_LICENSE"
8
   for details.
9
 
10
   Markus F.X.J. Oberhumer
11
   <markus@oberhumer.com>
12
   http://www.oberhumer.com/
13
 */
14
 
15
 
16
#define __ACCLIB_OPENDIR_CH_INCLUDED 1
17
#if !defined(ACCLIB_PUBLIC)
18
#  define ACCLIB_PUBLIC(r,f)    r __ACCLIB_FUNCNAME(f)
19
#endif
20
 
21
 
22
/*************************************************************************
23
// wrap <dirent.h>
24
**************************************************************************/
25
 
26
#if !defined(__ACCLIB_USE_OPENDIR)
27
#if (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_TOS || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
28
 
29
static int __ACCLIB_FUNCNAME(acc_opendir_init)(acc_dir_p f, const char* path, char* buf, size_t bufsize)
30
{
31
    size_t l; char* p;
32
    f->f_name[0] = 0; buf[0] = 0;
33
    l = strlen(path);
34
    if (l == 0 || bufsize <= 4 || l >= bufsize - 4)
35
        return -1;
36
    strcpy(buf, path); p = buf + l;
37
    if (p[-1] == ':' || p[-1] == '\\' || p[-1] == '/')
38
        strcpy(p, "*.*");
39
    else
40
        strcpy(p, "\\*.*");
41
    return 0;
42
}
43
 
44
#endif
45
#endif
46
 
47
 
48
#if defined(__ACCLIB_USE_OPENDIR)
49
 
50
ACCLIB_PUBLIC(int, acc_opendir) (acc_dir_p f, const char* path)
51
{
52
    f->u_dirp = opendir(path);
53
    if (!f->u_dirp)
54
        return -2;
55
    return __ACCLIB_FUNCNAME(acc_readdir)(f);
56
}
57
 
58
ACCLIB_PUBLIC(int, acc_readdir) (acc_dir_p f)
59
{
60
    const struct dirent* dp;
61
    f->f_name[0] = 0;
62
    if (!f->u_dirp)
63
        return -1;
64
    dp = (const struct dirent*) readdir((DIR*) f->u_dirp);
65
    if (!dp)
66
        return -1;
67
    if (!dp->d_name[0] || strlen(dp->d_name) >= sizeof(f->f_name))
68
        return -1;
69
    strcpy(f->f_name, dp->d_name);
70
#if (ACC_CC_WATCOMC)
71
    ACC_COMPILE_TIME_ASSERT(sizeof(f->f_name) >= sizeof(dp->d_name))
72
    f->f_time = dp->d_time;
73
    f->f_date = dp->d_date;
74
    f->f_size = dp->d_size;
75
#endif
76
    return 0;
77
}
78
 
79
ACCLIB_PUBLIC(int, acc_closedir) (acc_dir_p f)
80
{
81
    int r = -1;
82
    if (f->u_dirp)
83
        r = closedir((DIR*) f->u_dirp);
84
    f->u_dirp = 0;
85
    return r;
86
}
87
 
88
 
89
#elif (ACC_OS_WIN32 || ACC_OS_WIN64)
90
 
91
ACCLIB_PUBLIC(int, acc_opendir) (acc_dir_p f, const char* path)
92
{
93
    WIN32_FIND_DATAA d;
94
    HANDLE h;
95
    if (__ACCLIB_FUNCNAME(acc_opendir_init)(f, path, f->f_name, sizeof(f->f_name)) != 0)
96
        return -1;
97
    h = FindFirstFileA(f->f_name, &d);
98
    f->f_name[0] = 0;
99
    if ((f->u_handle = (acclib_handle_t) h) == -1)
100
        return -1;
101
    if (!d.cFileName[0] || strlen(d.cFileName) >= sizeof(f->f_name))
102
        return -1;
103
    strcpy(f->f_name, d.cFileName);
104
    f->f_attr = d.dwFileAttributes;
105
    f->f_size_high = d.nFileSizeHigh;
106
    f->f_size_low = d.nFileSizeLow;
107
    return 0;
108
}
109
 
110
ACCLIB_PUBLIC(int, acc_readdir) (acc_dir_p f)
111
{
112
    WIN32_FIND_DATAA d;
113
    f->f_name[0] = 0;
114
    if (f->u_handle == -1 || FindNextFileA((HANDLE) f->u_handle, &d) == 0)
115
        return -1;
116
    if (!d.cFileName[0] || strlen(d.cFileName) >= sizeof(f->f_name))
117
        return -1;
118
    strcpy(f->f_name, d.cFileName);
119
    f->f_attr = d.dwFileAttributes;
120
    f->f_size_high = d.nFileSizeHigh;
121
    f->f_size_low = d.nFileSizeLow;
122
    return 0;
123
}
124
 
125
ACCLIB_PUBLIC(int, acc_closedir) (acc_dir_p f)
126
{
127
    int r = -1;
128
    if (f->u_handle != -1)
129
        r = FindClose((HANDLE) f->u_handle);
130
    f->u_handle = -1;
131
    return r;
132
}
133
 
134
 
135
#elif (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_WIN16)
136
 
137
ACCLIB_PUBLIC(int, acc_opendir) (acc_dir_p f, const char* path)
138
{
139
    char tmp[ACC_FN_PATH_MAX+1];
140
    int r;
141
    f->u_dirp = 0;
142
    if (__ACCLIB_FUNCNAME(acc_opendir_init)(f, path, tmp, sizeof(tmp)) != 0)
143
        return -1;
144
#if (ACC_CC_AZTECC || ACC_CC_PACIFICC)
145
    r = -1;
146
#elif (ACC_CC_BORLANDC || ACC_CC_TURBOC)
147
    r = findfirst(tmp, (struct ffblk*) f->u_dta, FA_HIDDEN|FA_SYSTEM|FA_RDONLY|FA_DIREC);
148
#else
149
    r = _dos_findfirst(tmp, _A_HIDDEN|_A_SYSTEM|_A_RDONLY|_A_SUBDIR, (struct find_t*) f->u_dta);
150
#endif
151
    if (r != 0) f->f_name[0] = 0;
152
    if (!f->f_name[0]) return -1;
153
    f->u_dirp = 1;
154
    return 0;
155
}
156
 
157
ACCLIB_PUBLIC(int, acc_readdir) (acc_dir_p f)
158
{
159
    int r;
160
    f->f_name[0] = 0;
161
    if (!f->u_dirp)
162
        return -1;
163
#if (ACC_CC_AZTECC || ACC_CC_PACIFICC)
164
    r = -1;
165
#elif (ACC_CC_BORLANDC || ACC_CC_TURBOC)
166
    r = findnext((struct ffblk*) f->u_dta);
167
#else
168
    r = _dos_findnext((struct find_t*) f->u_dta);
169
#endif
170
    if (r != 0) f->f_name[0] = 0;
171
    if (!f->f_name[0]) return -1;
172
    return 0;
173
}
174
 
175
ACCLIB_PUBLIC(int, acc_closedir) (acc_dir_p f)
176
{
177
    ACC_COMPILE_TIME_ASSERT(sizeof(*f) == 44);
178
    f->f_name[0] = 0;
179
    f->u_dirp = 0;
180
    return 0;
181
}
182
 
183
 
184
#elif (ACC_OS_TOS)
185
 
186
ACCLIB_PUBLIC(int, acc_opendir) (acc_dir_p f, const char* path)
187
{
188
    char tmp[ACC_FN_PATH_MAX+1];
189
    int r;
190
    DTA* olddta;
191
    f->u_dirp = 0;
192
    if (__ACCLIB_FUNCNAME(acc_opendir_init)(f, path, tmp, sizeof(tmp)) != 0)
193
        return -1;
194
    olddta = Fgetdta();
195
    Fsetdta((DTA*) f->u_dta);
196
    r = Fsfirst(tmp, FA_HIDDEN|FA_SYSTEM|FA_READONLY|FA_SUBDIR);
197
    Fsetdta(olddta);
198
    if (r != 0) f->f_name[0] = 0;
199
    if (!f->f_name[0]) return -1;
200
    f->u_dirp = 1;
201
    return 0;
202
}
203
 
204
ACCLIB_PUBLIC(int, acc_readdir) (acc_dir_p f)
205
{
206
    int r;
207
    DTA* olddta;
208
    f->f_name[0] = 0;
209
    if (!f->u_dirp)
210
        return -1;
211
    olddta = Fgetdta();
212
    Fsetdta((DTA*) f->u_dta);
213
    r = Fsnext();
214
    Fsetdta(olddta);
215
    if (r != 0) f->f_name[0] = 0;
216
    if (!f->f_name[0]) return -1;
217
    return 0;
218
}
219
 
220
ACCLIB_PUBLIC(int, acc_closedir) (acc_dir_p f)
221
{
222
    ACC_COMPILE_TIME_ASSERT(sizeof(*f) == 44);
223
    f->f_name[0] = 0;
224
    f->u_dirp = 0;
225
    return 0;
226
}
227
 
228
 
229
#else
230
 
231
ACCLIB_PUBLIC(int, acc_opendir) (acc_dir_p f, const char* path)
232
{
233
    ACC_UNUSED(path);
234
    f->f_name[0] = 0;
235
    return -3;
236
}
237
 
238
ACCLIB_PUBLIC(int, acc_readdir) (acc_dir_p f)
239
{
240
    f->f_name[0] = 0;
241
    return -1;
242
}
243
 
244
ACCLIB_PUBLIC(int, acc_closedir) (acc_dir_p f)
245
{
246
    f->u_dirp = 0;
247
    return -1;
248
}
249
 
250
#endif
251
 
252
 
253
/*
254
vi:ts=4:et
255
*/