1 | /* $Id: dir.h 1 1970-01-01 00:00:00Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * InnoTek Portable Runtime - Internal Header for RTDir.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006 InnoTek Systemberatung GmbH
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * If you received this file as part of a commercial VirtualBox
|
---|
18 | * distribution, then only the terms of your commercial VirtualBox
|
---|
19 | * license agreement apply instead of the previous paragraph.
|
---|
20 | */
|
---|
21 |
|
---|
22 |
|
---|
23 | #ifndef __internal_dir_h__
|
---|
24 | #define __internal_dir_h__
|
---|
25 |
|
---|
26 | #include <iprt/cdefs.h>
|
---|
27 | #include <iprt/types.h>
|
---|
28 |
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Filter a the filename in the against a filter.
|
---|
32 | *
|
---|
33 | * @returns true if the name matches the filter.
|
---|
34 | * @returns false if the name doesn't match filter.
|
---|
35 | * @param pDir The directory handle.
|
---|
36 | * @param pszName The path to match to the filter.
|
---|
37 | */
|
---|
38 | typedef DECLCALLBACK(bool) FNRTDIRFILTER(PRTDIR pDir, const char *pszName);
|
---|
39 | /** Pointer to a filter function. */
|
---|
40 | typedef FNRTDIRFILTER *PFNRTDIRFILTER;
|
---|
41 |
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Open directory.
|
---|
45 | */
|
---|
46 | typedef struct RTDIR
|
---|
47 | {
|
---|
48 | /** Magic value, RTDIR_MAGIC. */
|
---|
49 | uint32_t u32Magic;
|
---|
50 | /** The type of filter that's to be applied to the directory listing. */
|
---|
51 | RTDIRFILTER enmFilter;
|
---|
52 | /** The filter function. */
|
---|
53 | PFNRTDIRFILTER pfnFilter;
|
---|
54 | /** The filter Code Point string.
|
---|
55 | * This is allocated in the same block as this structure. */
|
---|
56 | PRTUNICP puszFilter;
|
---|
57 | /** The number of Code Points in the filter string. */
|
---|
58 | size_t cucFilter;
|
---|
59 | /** The filter string.
|
---|
60 | * This is allocated in the same block as this structure, thus the const. */
|
---|
61 | const char *pszFilter;
|
---|
62 | /** The length of the filter string. */
|
---|
63 | unsigned cchFilter;
|
---|
64 | /** Normalized path to the directory including a trailing slash.
|
---|
65 | * We keep this around so we can query more information if required (posix).
|
---|
66 | * This is allocated in the same block as this structure, thus the const. */
|
---|
67 | const char *pszPath;
|
---|
68 | /** The length of the path. */
|
---|
69 | unsigned cchPath;
|
---|
70 | /** Set to indicate that the Data member contains unread data. */
|
---|
71 | bool fDataUnread;
|
---|
72 | #ifndef RT_DONT_CONVERT_FILENAMES
|
---|
73 | /** Pointer to the converted filename.
|
---|
74 | * This can be NULL. */
|
---|
75 | char *pszName;
|
---|
76 | /** The length of the converted filename. */
|
---|
77 | unsigned cchName;
|
---|
78 | #endif
|
---|
79 |
|
---|
80 | #ifdef __WIN__
|
---|
81 | /** Handle to the opened directory search. */
|
---|
82 | HANDLE hDir;
|
---|
83 | /** Find data buffer.
|
---|
84 | * fDataUnread indicates valid data. */
|
---|
85 | # ifdef RT_DONT_CONVERT_FILENAMES
|
---|
86 | WIN32_FIND_DATAA Data;
|
---|
87 | # else
|
---|
88 | WIN32_FIND_DATAW Data;
|
---|
89 | # endif
|
---|
90 |
|
---|
91 | #else /* 'POSIX': */
|
---|
92 | /** What opendir() returned. */
|
---|
93 | DIR *pDir;
|
---|
94 | /** Find data buffer.
|
---|
95 | * fDataUnread indicates valid data. */
|
---|
96 | struct dirent Data;
|
---|
97 | #endif
|
---|
98 | } RTDIR;
|
---|
99 |
|
---|
100 | /** The value of RTDIR::u32Magic. (Michael Ende) */
|
---|
101 | #define RTDIR_MAGIC 0x19291112
|
---|
102 | /** The value of RTDIR::u32Magic after RTDirClose(). */
|
---|
103 | #define RTDIR_MAGIC_DEAD 0x19950829
|
---|
104 |
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * Validates a directory handle.
|
---|
108 | * @returns true if valid.
|
---|
109 | * @returns false if valid after having bitched about it first.
|
---|
110 | */
|
---|
111 | DECLINLINE(bool) rtDirValidHandle(PRTDIR pDir)
|
---|
112 | {
|
---|
113 | AssertMsgReturn(VALID_PTR(pDir), ("%p\n", pDir), false);
|
---|
114 | AssertMsgReturn(pDir->u32Magic == RTDIR_MAGIC, ("%#RX32\n", pDir->u32Magic), false);
|
---|
115 | return true;
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * Initialize the OS specific part of the handle and open the directory.
|
---|
121 | * Called by rtDirOpenCommon().
|
---|
122 | *
|
---|
123 | * @returns IPRT status code.
|
---|
124 | * @param pDir The directory to open. The pszPath member contains the
|
---|
125 | * path to the directory.
|
---|
126 | * @param pszPathBuf Pointer to a RTPATH_MAX sized buffer containing pszPath.
|
---|
127 | * Find-first style systems can use this to setup the
|
---|
128 | * wildcard expression.
|
---|
129 | */
|
---|
130 | int rtOpenDirNative(PRTDIR pDir, char *pszPathBuf);
|
---|
131 |
|
---|
132 | #endif
|
---|