1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_DIR_READER_LINUX_H_
6 #define BASE_DIR_READER_LINUX_H_
12 #include <sys/syscall.h>
15 #include "base/logging.h"
16 #include "base/eintr_wrapper.h"
18 // See the comments in dir_reader_posix.h about this.
25 unsigned short d_reclen
;
30 class DirReaderLinux
{
32 explicit DirReaderLinux(const char* directory_path
)
33 : fd_(open(directory_path
, O_RDONLY
| O_DIRECTORY
)),
36 memset(buf_
, 0, sizeof(buf_
));
41 if (HANDLE_EINTR(close(fd_
)))
42 RAW_LOG(ERROR
, "Failed to close directory handle");
46 bool IsValid() const {
50 // Move to the next entry returning false if the iteration is complete.
53 linux_dirent
* dirent
= reinterpret_cast<linux_dirent
*>(&buf_
[offset_
]);
54 offset_
+= dirent
->d_reclen
;
60 const int r
= syscall(__NR_getdents64
, fd_
, buf_
, sizeof(buf_
));
64 DPLOG(FATAL
) << "getdents64 returned an error: " << errno
;
72 const char* name() const {
76 const linux_dirent
* dirent
=
77 reinterpret_cast<const linux_dirent
*>(&buf_
[offset_
]);
78 return dirent
->d_name
;
85 static bool IsFallback() {
91 unsigned char buf_
[512];
92 size_t offset_
, size_
;
94 DISALLOW_COPY_AND_ASSIGN(DirReaderLinux
);
99 #endif // BASE_DIR_READER_LINUX_H_