Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
d3a9ea6b
Commit
d3a9ea6b
authored
Nov 02, 2018
by
yinqiwen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make braft work in mac OSX, while braft replies on the interface DirReaderPosix's implemention
parent
a6ccc96a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
0 deletions
+94
-0
dir_reader_posix.h
src/butil/files/dir_reader_posix.h
+4
-0
dir_reader_unix.h
src/butil/files/dir_reader_unix.h
+90
-0
No files found.
src/butil/files/dir_reader_posix.h
View file @
d3a9ea6b
...
...
@@ -19,6 +19,8 @@
#if defined(OS_LINUX)
#include "butil/files/dir_reader_linux.h"
#elif defined(__APPLE__)
#include "butil/files/dir_reader_unix.h"
#else
#include "butil/files/dir_reader_fallback.h"
#endif
...
...
@@ -27,6 +29,8 @@ namespace butil {
#if defined(OS_LINUX)
typedef
DirReaderLinux
DirReaderPosix
;
#elif defined(__APPLE__)
typedef
DirReaderUnix
DirReaderPosix
;
#else
typedef
DirReaderFallback
DirReaderPosix
;
#endif
...
...
src/butil/files/dir_reader_unix.h
0 → 100644
View file @
d3a9ea6b
// Copyright (c) 2018 Baidu, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Authors: yinqiwen (yinqiwen@gmail.com)
#ifndef BUTIL_FILES_DIR_READER_UNIX_H_
#define BUTIL_FILES_DIR_READER_UNIX_H_
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <dirent.h>
#include "butil/logging.h"
#include "butil/posix/eintr_wrapper.h"
// See the comments in dir_reader_posix.h about this.
namespace
butil
{
class
DirReaderUnix
{
public
:
explicit
DirReaderUnix
(
const
char
*
directory_path
)
:
fd_
(
open
(
directory_path
,
O_RDONLY
|
O_DIRECTORY
)),
dir_
(
NULL
),
current_
(
NULL
)
{
dir_
=
fdopendir
(
fd_
);
}
~
DirReaderUnix
()
{
if
(
fd_
>=
0
)
{
if
(
IGNORE_EINTR
(
close
(
fd_
)))
RAW_LOG
(
ERROR
,
"Failed to close directory handle"
);
}
if
(
NULL
!=
dir_
)
{
closedir
(
dir_
);
}
}
bool
IsValid
()
const
{
return
fd_
>=
0
;
}
// Move to the next entry returning false if the iteration is complete.
bool
Next
()
{
int
err
=
readdir_r
(
dir_
,
&
entry_
,
&
current_
);
if
(
0
!=
err
||
NULL
==
current_
)
{
return
false
;
}
return
true
;
}
const
char
*
name
()
const
{
if
(
NULL
==
current_
)
return
NULL
;
return
current_
->
d_name
;
}
int
fd
()
const
{
return
fd_
;
}
static
bool
IsFallback
()
{
return
false
;
}
private
:
const
int
fd_
;
DIR
*
dir_
;
struct
dirent
entry_
;
struct
dirent
*
current_
;
};
}
// namespace butil
#endif // BUTIL_FILES_DIR_READER_LINUX_H_
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment