MCPcopy Create free account
hub / github.com/boostorg/filesystem / open_directory

Function open_directory

src/directory.cpp:121–163  ·  view source on GitHub ↗

Opens a directory file and returns a file descriptor. Returns a negative value in case of error.

Source from the content-addressed store, hash-verified

119
120//! Opens a directory file and returns a file descriptor. Returns a negative value in case of error.
121boost::scope::unique_fd open_directory(path const& p, directory_options opts, system::error_code& ec)
122{
123 ec.clear();
124
125 int flags = O_DIRECTORY | O_RDONLY | O_NONBLOCK | O_CLOEXEC;
126
127#if defined(BOOST_FILESYSTEM_HAS_FDOPENDIR_NOFOLLOW)
128 if ((opts & directory_options::_detail_no_follow) != directory_options::none)
129 flags |= O_NOFOLLOW;
130#endif
131
132 int res;
133 while (true)
134 {
135 res = ::open(p.c_str(), flags);
136 if (BOOST_UNLIKELY(res < 0))
137 {
138 const int err = errno;
139 if (err == EINTR)
140 continue;
141 ec = system::error_code(err, system::system_category());
142 return boost::scope::unique_fd();
143 }
144
145 break;
146 }
147
148#if defined(BOOST_FILESYSTEM_NO_O_CLOEXEC) && defined(FD_CLOEXEC)
149 boost::scope::unique_fd fd(res);
150
151 res = ::fcntl(fd.get(), F_SETFD, FD_CLOEXEC);
152 if (BOOST_UNLIKELY(res < 0))
153 {
154 const int err = errno;
155 ec = system::error_code(err, system::system_category());
156 return boost::scope::unique_fd();
157 }
158
159 return fd;
160#else
161 return boost::scope::unique_fd(res);
162#endif
163}
164
165#if defined(BOOST_FILESYSTEM_HAS_POSIX_AT_APIS)
166

Callers 1

dir_itr_createFunction · 0.85

Calls 3

clearMethod · 0.80
getMethod · 0.80
c_strMethod · 0.45

Tested by

no test coverage detected