1 /* $Id$
2  *  Provides compiler-independent types and functions to read directory contents
3  *
4  *  Copyright (C) 1998-1999
5  *
6  *  Matthias Tichy
7  *
8  *  Fido:     2:2433/1245 2:2433/1247 2:2432/605.14
9  *  Internet: mtt@tichy.de
10  *
11  *  Grimmestr. 12         Buchholzer Weg 4
12  *  33098 Paderborn       40472 Duesseldorf
13  *  Germany               Germany
14  *
15  *  Latest version may be foind on http://husky.sourceforge.net
16  *
17  *
18  * HUSKYLIB: common defines, types and functions for HUSKY
19  *
20  * This is part of The HUSKY Fidonet Software project:
21  * see http://husky.sourceforge.net for details
22  *
23  *
24  * HUSKYLIB is free software; you can redistribute it and/or
25  * modify it under the terms of the GNU Lesser General Public
26  * License as published by the Free Software Foundation; either
27  * version 2 of the License, or (at your option) any later version.
28  *
29  * HUSKYLIB is distributed in the hope that it will be useful,
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
32  * General Public License for more details.
33  *
34  * You should have received a copy of the GNU Lesser General Public
35  * License along with this library; see file COPYING. If not, write to the
36  * Free Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37  *
38  * See also http://www.gnu.org, license may be found here.
39  */
40 
41 #ifndef HUSKY_DIRLAYER_H
42 #define HUSKY_DIRLAYER_H
43 
44 /* standard headers */
45 #include <stdlib.h>
46 #include <string.h>
47 #include <sys/types.h>
48 
49 
50 /* huskylib: compiler.h */
51 #include "compiler.h"
52 
53 
54 /* compiler-dependent headers */
55 #ifdef HAS_DIRENT_H
56 #include <dirent.h>
57 #endif
58 
59 
60 /* huskylib headers */
61 #include "huskyext.h"
62 #include "ffind.h"
63 
64 
65 /***  Declarations & defines  ***********************************************/
66 
67 
68 #ifdef __MSVC__
69 #define NAME_MAX        _MAX_PATH
70 
71 #endif
72 
73 #if defined(__IBMC__) && !defined(__UNIX__)   /* only define it for IBM VisualAge C++ */
74 
75 #define INCL_DOSERRORS
76 #define INCL_DOSFILEMGR
77 #include <os2.h>
78 
79 #define NAME_MAX        255             /* maximum filename */
80 
81 /* File attribute constants for d_attr field */
82 
83 #define _A_NORMAL       0x00    /* Normal file - read/write permitted */
84 #define _A_RDONLY       0x01    /* Read-only file */
85 #define _A_HIDDEN       0x02    /* Hidden file */
86 #define _A_SYSTEM       0x04    /* System file */
87 #define _A_VOLID        0x08    /* Volume-ID entry */
88 #define _A_SUBDIR       0x10    /* Subdirectory */
89 #define _A_ARCH         0x20    /* Archive file */
90 
91 #endif
92 
93 #ifndef NAME_MAX
94 #define NAME_MAX        128     /* maximum filename */
95 #endif
96 
97 typedef struct husky_dirent {
98    char   d_attr;          /* file's attribute (DOS-based OS) */
99    /*  unsigned short int d_time;     */     /* file's time */
100    /*  unsigned short int d_date;     */     /* file's date */
101    long   d_size;              /* file's size */
102    char   d_name[NAME_MAX+1];  /* file's name */
103    char   d_mask[NAME_MAX+1];  /* file's search mask */
104 #ifdef HAS_DIRENT_H
105    DIR   *internal_DIR;       /* system/compiler DIR structure */
106 #else
107    FFIND *ff;       /* for FFindOpen()/FFindInfo()/FFindNext()/FFindClose() */
108    int    d_first;  /* flag for 1st time (set by husky_opendir(), reset by husky_readdir() */
109 #endif
110 } husky_DIR;
111 
112 /* The husky_opendir() function opens the directory named by filename,
113  * associates a directory stream with it and returns a pointer to be used
114  * to identify the directory stream in subsequent operations.  The pointer
115  * NULL is returned if filename cannot be accessed, or if it cannot malloc(3)
116  * enough memory to hold the whole thing.
117  */
118 HUSKYEXT husky_DIR* husky_opendir(const char*);
119 
120 /* The husky_readdir() function returns a pointer to the next file name in
121  * directory. husky_readdir() skips current and parent directory entries
122  * ("." & "..") for miltiplatform compatibility.
123  * It returns NULL upon reaching the end of the directory or detecting an
124  * invalid seekdir() operation.
125  */
126 HUSKYEXT char* husky_readdir(husky_DIR*);
127 
128 /* The husky_closedir() function closes the named directory stream and frees
129  * the structure associated with the dirp pointer, returning 0 on success.  On
130  * failure, -1 is returned and the global variable errno is set to indicate
131  * the error.
132  */
133 HUSKYEXT int  husky_closedir(husky_DIR*);
134 
135 /* The husky_rewinddir() function resets the position of the named directory
136  * stream to the beginning of the directory.
137  */
138 HUSKYEXT void  husky_rewinddir(husky_DIR* dir);
139 
140 #endif
141