Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

OS_Dirent.inl

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // $Id: OS_Dirent.inl,v 1.1.1.3 2003/02/21 18:36:32 chad Exp $
00003 
00004 ACE_INLINE ACE_DIR *
00005 ACE_OS_Dirent::opendir (const ACE_TCHAR *filename)
00006 {
00007 #if defined (ACE_HAS_DIRENT)
00008 #  if defined (ACE_PSOS)
00009   // The pointer to the <ACE_DIR> buffer *must* be passed to
00010   // <ACE_OS_Dirent::closedir> to free it and avoid a memory leak.
00011   ACE_DIR *dir;
00012   u_long result;
00013   ACE_NEW_RETURN (dir, ACE_DIR, 0);
00014   result = ::open_dir (ACE_const_cast (ACE_TCHAR *,
00015                                        filename),
00016                        &dir->xdir);
00017   if (result == 0)
00018     return dir;
00019   else
00020     {
00021       errno = result;
00022       return 0;
00023     }
00024 #  else /* ! ACE_PSOS */
00025 #    if defined (ACE_WIN32)
00026   return ::ACE_OS_Dirent::opendir_emulation (filename);
00027 #    else /* ! ACE_WIN32 */
00028   // VxWorks' ::opendir () is declared with a non-const argument.
00029   return ::opendir (ACE_const_cast (ACE_TCHAR *, filename));
00030 #    endif /* ACE_WIN32 */
00031 #  endif /* ACE_PSOS */
00032 #else
00033   ACE_UNUSED_ARG (filename);
00034   ACE_NOTSUP_RETURN (0);
00035 #endif /* ACE_HAS_DIRENT */
00036 }
00037 
00038 ACE_INLINE void
00039 ACE_OS_Dirent::closedir (ACE_DIR *d)
00040 {
00041 #if defined (ACE_HAS_DIRENT)
00042 # if defined (ACE_PSOS)
00043 
00044   u_long result = ::close_dir (&(d->xdir));
00045   delete d;
00046   if (result != 0)
00047     errno = result;
00048 
00049 # else /* ! ACE_PSOS */
00050 
00051 #   if defined (ACE_WIN32)
00052   ACE_OS_Dirent::closedir_emulation (d);
00053   delete [] d->directory_name_;
00054   delete d;
00055 #   else /* ACE_WIN32 */
00056   ::closedir (d);
00057 #   endif /* ACE_WIN32 */
00058 
00059 # endif /* ACE_PSOS */
00060 #else /* ACE_HAS_DIRENT */
00061   ACE_UNUSED_ARG (d);
00062 #endif /* ACE_HAS_DIRENT */
00063 }
00064 
00065 ACE_INLINE struct dirent *
00066 ACE_OS_Dirent::readdir (ACE_DIR *d)
00067 {
00068 #if defined (ACE_HAS_DIRENT)
00069 #  if defined (ACE_PSOS)
00070 
00071   u_long result = ::read_dir (&d->xdir, &d->dirent);
00072   if (0 == result)
00073     return &d->dirent;
00074   else
00075     {
00076       errno = result;
00077       return 0;
00078     }
00079 
00080 #  else /* ! ACE_PSOS */
00081 #    if defined (ACE_WIN32)
00082   return ACE_OS_Dirent::readdir_emulation (d);
00083 #    else /* defined (ACE_WIN32) */
00084   return ::readdir (d);
00085 #    endif /* defined (ACE_WIN32) */
00086 #  endif /* ACE_PSOS */
00087 #else
00088   ACE_UNUSED_ARG (d);
00089   ACE_NOTSUP_RETURN (0);
00090 #endif /* ACE_HAS_DIRENT */
00091 }
00092 
00093 ACE_INLINE int
00094 ACE_OS_Dirent::readdir_r (ACE_DIR *dirp,
00095                           struct dirent *entry,
00096                           struct dirent **result)
00097 {
00098 #if !defined (ACE_HAS_REENTRANT_FUNCTIONS)
00099   ACE_UNUSED_ARG (entry);
00100   // <result> has better not be 0!
00101   *result = ACE_OS_Dirent::readdir (dirp);
00102   if (*result)
00103     return 0; // Keep iterating
00104   else
00105     return 1; // Oops, some type of error!
00106 #elif defined (ACE_HAS_DIRENT)  &&  !defined (ACE_LACKS_READDIR_R)
00107 #  if (defined (sun) && (defined (_POSIX_PTHREAD_SEMANTICS) || \
00108                         (_FILE_OFFSET_BITS == 64))) || \
00109       (!defined (sun) && (defined (ACE_HAS_PTHREADS_STD) || \
00110                          defined (ACE_HAS_PTHREADS_DRAFT7) || \
00111                          defined (__USE_POSIX) || \
00112                          defined (HPUX_11)))
00113 #    if defined (__GNUG__) && defined (DIGITAL_UNIX)
00114   return readdir_r (dirp, entry, result);
00115 #    else
00116   return ::readdir_r (dirp, entry, result);
00117 #    endif /* defined (__GNUG__) && defined (DIGITAL_UNIX) */
00118 #  else  /* ! POSIX.1c - this is draft 4 or draft 6 */
00119 #    if defined (HPUX_10)   /* But HP 10.x doesn't follow the draft either */
00120     *result = entry;
00121     return ::readdir_r (dirp, entry);
00122 #    else
00123     // <result> had better not be 0!
00124     *result = ::readdir_r (dirp, entry);
00125     return 0;
00126 #    endif /* HPUX_10 */
00127 #  endif /* ! POSIX.1c */
00128 #else  /* ! ACE_HAS_DIRENT  ||  ACE_LACKS_READDIR_R */
00129   ACE_UNUSED_ARG (dirp);
00130   ACE_UNUSED_ARG (entry);
00131   ACE_UNUSED_ARG (result);
00132   ACE_NOTSUP_RETURN (0);
00133 
00134 #endif /* ACE_HAS_REENTRANT_FUNCTIONS */
00135 }
00136 
00137 ACE_INLINE long
00138 ACE_OS_Dirent::telldir (ACE_DIR *d)
00139 {
00140 #if defined (ACE_HAS_DIRENT)  &&  !defined (ACE_LACKS_TELLDIR)
00141   return ::telldir (d);
00142 #else  /* ! ACE_HAS_DIRENT  ||  ACE_LACKS_TELLDIR */
00143   ACE_UNUSED_ARG (d);
00144   ACE_NOTSUP_RETURN (-1);
00145 #endif /* ! ACE_HAS_DIRENT  ||  ACE_LACKS_TELLDIR */
00146 }
00147 
00148 ACE_INLINE void
00149 ACE_OS_Dirent::seekdir (ACE_DIR *d, long loc)
00150 {
00151 #if defined (ACE_HAS_DIRENT)  &&  !defined (ACE_LACKS_SEEKDIR)
00152   ::seekdir (d, loc);
00153 #else  /* ! ACE_HAS_DIRENT  ||  ACE_LACKS_SEEKDIR */
00154   ACE_UNUSED_ARG (d);
00155   ACE_UNUSED_ARG (loc);
00156 #endif /* ! ACE_HAS_DIRENT  ||  ACE_LACKS_SEEKDIR */
00157 }
00158 
00159 ACE_INLINE void
00160 ACE_OS_Dirent::rewinddir (ACE_DIR *d)
00161 {
00162 #if defined (ACE_HAS_DIRENT)
00163 # if defined (ACE_LACKS_SEEKDIR)
00164 #  if defined (ACE_LACKS_REWINDDIR)
00165   ACE_UNUSED_ARG (d);
00166 #  else /* ! defined (ACE_LACKS_REWINDDIR) */
00167    ::rewinddir (d);
00168 #  endif /* ! defined (ACE_LACKS_REWINDDIR) */
00169 # else  /* ! ACE_LACKS_SEEKDIR */
00170     // We need to implement <rewinddir> using <seekdir> since it's often
00171     // defined as a macro...
00172    ::seekdir (d, long (0));
00173 # endif /* ! ACE_LACKS_SEEKDIR */
00174 #else
00175   ACE_UNUSED_ARG (d);
00176 #endif /* ACE_HAS_DIRENT */
00177 }
00178 
00179 ACE_INLINE int
00180 ACE_OS_Dirent::scandir (const ACE_TCHAR *dirname,
00181                         struct dirent **namelist[],
00182                         int (*selector)(const struct dirent *),
00183                         int (*comparator) (const struct dirent **f1,
00184                                            const struct dirent **f2))
00185 {
00186 #if defined (ACE_HAS_SCANDIR)
00187   return ::scandir (dirname, namelist, selector, comparator);
00188 #else /* ! defined ( ACE_HAS_SCANDIR) */
00189   return ACE_OS_Dirent::scandir_emulation (dirname, namelist, selector, comparator);
00190 #endif /* ACE_HAS_SCANDIR */
00191 }

Generated on Mon Jun 16 11:20:44 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002