1 /** @file de/findfile.h Win32-style native file finding.
2  *
3  * @author Copyright &copy; 2004-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
4  * @author Copyright &copy; 2007-2013 Daniel Swanson <danij@dengine.net>
5  *
6  * @par License
7  * GPL: http://www.gnu.org/licenses/gpl.html
8  *
9  * <small>This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by the
11  * Free Software Foundation; either version 2 of the License, or (at your
12  * option) any later version. This program is distributed in the hope that it
13  * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15  * Public License for more details. You should have received a copy of the GNU
16  * General Public License along with this program; if not, write to the Free
17  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18  * 02110-1301 USA</small>
19  */
20 
21 #ifndef LIBDENG_FILESYS_FILEFINDER_H
22 #define LIBDENG_FILESYS_FILEFINDER_H
23 
24 #include "types.h"
25 #include "str.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 /// @addtogroup legacy
32 /// @{
33 
34 // File attributes.
35 #define A_SUBDIR                0x1
36 #define A_RDONLY                0x2
37 #define A_HIDDEN                0x4
38 #define A_ARCH                  0x8
39 
40 typedef struct finddata_s {
41     void *finddata;
42 #if defined(UNIX)
43     long date;
44     long time;
45     long size;
46 #else
47     time_t date;
48     time_t time;
49     size_t size;
50 #endif
51     ddstring_t name; // UTF-8 encoded
52     long attrib;
53 } FindData;
54 
55 /**
56  * Initializes the file finder and locates the first matching file.
57  * Directory names end in a directory separator character.
58  *
59  * @param findData  File finder.
60  * @param pattern   File path pattern to find.
61  *
62  * @return  @c 0, if successful. If non-zero is returned, there were no
63  * matching files.
64  */
65 DENG_PUBLIC int FindFile_FindFirst(FindData *findData, char const *pattern);
66 
67 /**
68  * Finds the next matching file. Directory names end in a directory
69  * separator character.
70  *
71  * @param findData  File finder.
72  *
73  * @return  @c 0, if successful. If non-zero is returned, there were no
74  * matching files.
75  */
76 DENG_PUBLIC int FindFile_FindNext(FindData *findData);
77 
78 /**
79  * This must be called after the file finding operation has been concluded.
80  * Releases memory allocated for file finding.
81  *
82  * @param findData  File finder to release.
83  */
84 DENG_PUBLIC void FindFile_Finish(FindData *findData);
85 
86 #ifdef UNIX
87 
88 /**
89  * Convert the given path to an absolute path. This behaves like the Win32 @c
90  * _fullpath function. Do not use this in newly written code; it is intened for
91  * supporting legacy code.
92  *
93  * @param full      Buffer where to write the full/absolute path.
94  * @param original  Path to convert.
95  * @param len       Length of the @a full buffer.
96  */
97 DENG_PUBLIC char* _fullpath(char* full, const char* original, int len);
98 
99 /**
100  * Split a path into components. This behaves like the Win32 @c _splitpath
101  * function. Do not use this in newly written code; it is intended for
102  * supporting legacy code.
103  *
104  * @param path   Path to split.
105  * @param drive  Drive letter.
106  * @param dir    Path.
107  * @param name   File name.
108  * @param ext    File extension.
109  */
110 DENG_PUBLIC void _splitpath(const char* path, char* drive, char* dir, char* name, char* ext);
111 
112 #endif // UNIX
113 
114 /// @}
115 
116 #ifdef __cplusplus
117 } // extern "C"
118 #endif
119 
120 #endif /* LIBDENG_FILESYS_FILEFINDER_H */
121