XRootD
Loading...
Searching...
No Matches
XrdSysDir Class Reference

#include <XrdSysDir.hh>

+ Collaboration diagram for XrdSysDir:

Public Member Functions

 XrdSysDir (const char *path)
 
virtual ~XrdSysDir ()
 
bool isValid ()
 
int lastError ()
 
char * nextEntry ()
 

Detailed Description

Definition at line 48 of file XrdSysDir.hh.

Constructor & Destructor Documentation

◆ XrdSysDir()

XrdSysDir::XrdSysDir ( const char *  path)

Definition at line 51 of file XrdSysDir.cc.

52{
53 // Constructor. Initialize a directory handle for 'path'.
54 // Use isValid() to check the result of this operation, and lastError()
55 // to get the last error code, if any.
56
57 lasterr = 0; dhandle = 0;
58 if (path && strlen(path) > 0) {
59#if !defined(WINDOWS)
60 dhandle = (void *) opendir(path);
61 if (!dhandle)
62 lasterr = errno;
63#else
64 WIN32_FIND_DATA filedata;
65 dhandle = (void *) ::FindFirstFile(path, &filedata);
66 if ((HANDLE)dhandle == INVALID_HANDLE_VALUE) {
67 lasterr = EINVAL;
68 dhandle = 0;
69 }
70 else if (!(filedata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
71 lasterr = ENOTDIR;
72 dhandle = 0;
73 }
74#endif
75 } else
76 // Invalid argument
77 lasterr = EINVAL;
78}
#define opendir(a)
Definition XrdPosix.hh:73

References opendir.

◆ ~XrdSysDir()

XrdSysDir::~XrdSysDir ( )
virtual

Definition at line 81 of file XrdSysDir.cc.

82{
83 // Destructor.
84
85 if (dhandle) {
86#if !defined(WINDOWS)
87 closedir((DIR *)dhandle);
88#else
89 ::FindClose((HANDLE)dhandle);
90#endif
91 }
92}
#define closedir(a)
Definition XrdPosix.hh:45

References closedir.

Member Function Documentation

◆ isValid()

bool XrdSysDir::isValid ( )
inline

Definition at line 54 of file XrdSysDir.hh.

54{ return (dhandle ? 1 : 0); }

◆ lastError()

int XrdSysDir::lastError ( )
inline

Definition at line 55 of file XrdSysDir.hh.

55{ return lasterr; }

◆ nextEntry()

char * XrdSysDir::nextEntry ( )

Definition at line 95 of file XrdSysDir.cc.

96{
97 // Get next entry in directory structure.
98 // Return 0 if no more entries or error. In the latter case
99 // the error code can be retrieved via lastError().
100
101 char *dent = 0;
102
103 lasterr = 0;
104 if (!dhandle) {
105 lasterr = EINVAL;
106 return dent;
107 }
108
109#if !defined(WINDOWS)
110 struct dirent *ent = readdir((DIR *)dhandle);
111 if (!ent) {
112 if (errno == EBADF)
113 lasterr = errno;
114 } else {
115 dent = (char *) ent->d_name;
116 }
117#else
118 WIN32_FIND_DATA filedata;
119 if (::FindNextFile((HANDLE)dhandle, &filedata)) {
120 dent = (char *) filedata.cFileName;
121 } else {
122 if (::GetLastError() != ERROR_NO_MORE_FILES)
123 lasterr = EBADF;
124 }
125#endif
126 // Done
127 return dent;
128}
#define readdir(a)
Definition XrdPosix.hh:81

References readdir.


The documentation for this class was generated from the following files: