2 #include "ace/OS_Memory.h"
4 #if defined (ACE_LACKS_ALPHASORT)
5 # include "ace/OS_NS_string.h"
6 #endif /* ACE_LACKS_ALPHASORT */
8 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
16 #if defined (ACE_HAS_DIRENT)
17 # if (defined (ACE_WIN32) || defined (ACE_MQX)) && defined (ACE_LACKS_CLOSEDIR)
18 ACE_OS::closedir_emulation (d);
19 delete [] d->directory_name_;
21 # elif defined (ACE_HAS_WCLOSEDIR) && defined (ACE_USES_WCHAR)
23 # else /* ACE_WIN32 && ACE_LACKS_CLOSEDIR */
25 # endif /* ACE_WIN32 && ACE_LACKS_CLOSEDIR */
27 #else /* ACE_HAS_DIRENT */
29 #endif /* ACE_HAS_DIRENT */
33 opendir (const ACE_TCHAR *filename)
35 #if defined (ACE_HAS_DIRENT)
36 # if (defined (ACE_WIN32) || defined(ACE_MQX)) && defined (ACE_LACKS_OPENDIR)
37 return ::ACE_OS::opendir_emulation (filename);
38 # elif defined (ACE_HAS_WOPENDIR) && defined (ACE_USES_WCHAR)
39 return ::wopendir (filename);
40 # elif defined (ACE_HAS_NONCONST_OPENDIR)
41 return ::opendir (const_cast<char *> (filename));
42 # else /* ! ACE_WIN32 && ACE_LACKS_OPENDIR */
43 return ::opendir (ACE_TEXT_ALWAYS_CHAR (filename));
44 # endif /* ACE_WIN32 && ACE_LACKS_OPENDIR */
46 ACE_UNUSED_ARG (filename);
47 ACE_NOTSUP_RETURN (0);
48 #endif /* ACE_HAS_DIRENT */
51 ACE_INLINE struct ACE_DIRENT *
54 #if defined (ACE_HAS_DIRENT)
55 # if (defined (ACE_WIN32) || defined (ACE_MQX)) && defined (ACE_LACKS_READDIR)
56 return ACE_OS::readdir_emulation (d);
57 # elif defined (ACE_HAS_WREADDIR) && defined (ACE_USES_WCHAR)
58 return ::wreaddir (d);
59 # else /* ACE_WIN32 && ACE_LACKS_READDIR */
61 # endif /* ACE_WIN32 && ACE_LACKS_READDIR */
64 ACE_NOTSUP_RETURN (0);
65 #endif /* ACE_HAS_DIRENT */
69 readdir_r (ACE_DIR *dirp,
70 struct ACE_DIRENT *entry,
71 struct ACE_DIRENT **result)
73 #if !defined (ACE_HAS_REENTRANT_FUNCTIONS)
74 ACE_UNUSED_ARG (entry);
75 // <result> has better not be 0!
76 *result = ACE_OS::readdir (dirp);
78 return 0; // Keep iterating
80 return 1; // Oops, some type of error!
81 #elif defined (ACE_HAS_DIRENT) && !defined (ACE_LACKS_READDIR_R)
82 # if defined (ACE_HAS_3_PARAM_READDIR_R)
83 return ::readdir_r (dirp, entry, result);
85 // <result> had better not be 0!
86 *result = ::readdir_r (dirp, entry);
89 #else /* ! ACE_HAS_DIRENT || ACE_LACKS_READDIR_R */
90 ACE_UNUSED_ARG (dirp);
91 ACE_UNUSED_ARG (entry);
92 ACE_UNUSED_ARG (result);
93 ACE_NOTSUP_RETURN (0);
95 #endif /* ACE_HAS_REENTRANT_FUNCTIONS */
99 rewinddir (ACE_DIR *d)
101 #if defined (ACE_HAS_DIRENT)
102 # if defined (ACE_HAS_WREWINDDIR) && defined (ACE_USES_WCHAR)
104 # elif !defined (ACE_LACKS_REWINDDIR)
105 ace_rewinddir_helper (d);
108 # endif /* !defined (ACE_LACKS_REWINDDIR) */
109 #endif /* ACE_HAS_DIRENT */
113 scandir (const ACE_TCHAR *dirname,
114 struct ACE_DIRENT **namelist[],
115 ACE_SCANDIR_SELECTOR selector,
116 ACE_SCANDIR_COMPARATOR comparator)
118 #if defined (ACE_HAS_SCANDIR)
119 return ::scandir (ACE_TEXT_ALWAYS_CHAR (dirname),
121 # if defined (ACE_SCANDIR_SEL_LACKS_CONST)
122 reinterpret_cast<ACE_SCANDIR_OS_SELECTOR> (selector),
125 # endif /* ACE_SCANDIR_SEL_LACKS_CONST */
126 # if defined (ACE_SCANDIR_CMP_USES_VOIDPTR) || \
127 defined (ACE_SCANDIR_CMP_USES_CONST_VOIDPTR)
128 reinterpret_cast<ACE_SCANDIR_OS_COMPARATOR> (comparator));
131 # endif /* ACE_SCANDIR_CMP_USES_VOIDPTR */
133 #else /* ! defined ( ACE_HAS_SCANDIR) */
134 return ACE_OS::scandir_emulation (dirname, namelist, selector, comparator);
135 #endif /* ACE_HAS_SCANDIR */
139 alphasort (const void *a, const void *b)
141 #if defined (ACE_LACKS_ALPHASORT)
142 return ACE_OS::strcmp ((*static_cast<const struct ACE_DIRENT * const *>(a))->d_name,
143 (*static_cast<const struct ACE_DIRENT * const *>(b))->d_name);
145 # if defined (ACE_SCANDIR_CMP_USES_VOIDPTR)
146 return ::alphasort (const_cast<void *>(a),
147 const_cast<void *>(b));
148 # elif defined (ACE_SCANDIR_CMP_USES_CONST_VOIDPTR)
149 return ::alphasort (a, b);
151 return ::alphasort ((const struct ACE_DIRENT **)a,
152 (const struct ACE_DIRENT **)b);
158 seekdir (ACE_DIR *d, long loc)
160 #if defined (ACE_HAS_DIRENT) && !defined (ACE_LACKS_SEEKDIR)
162 #else /* ! ACE_HAS_DIRENT || ACE_LACKS_SEEKDIR */
164 ACE_UNUSED_ARG (loc);
165 #endif /* ! ACE_HAS_DIRENT || ACE_LACKS_SEEKDIR */
171 #if defined (ACE_HAS_DIRENT) && !defined (ACE_LACKS_TELLDIR)
172 return ::telldir (d);
173 #else /* ! ACE_HAS_DIRENT || ACE_LACKS_TELLDIR */
175 ACE_NOTSUP_RETURN (-1);
176 #endif /* ! ACE_HAS_DIRENT || ACE_LACKS_TELLDIR */
181 ACE_END_VERSIONED_NAMESPACE_DECL