Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
riscv-gcc-1
Overview
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
riscv-gcc-1
Commits
4d901dd7
Commit
4d901dd7
authored
Dec 06, 2012
by
Ian Lance Taylor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
os: Clean up directory reading code.
From-SVN: r194237
parent
d6981042
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
24 deletions
+41
-24
libgo/go/os/dir.go
+34
-22
libgo/go/os/file_unix.go
+7
-2
No files found.
libgo/go/os/dir.go
View file @
4d901dd7
...
...
@@ -6,6 +6,7 @@ package os
import
(
"io"
"sync/atomic"
"syscall"
"unsafe"
)
...
...
@@ -29,27 +30,42 @@ func clen(n []byte) int {
return
len
(
n
)
}
var
elen
int
var
nameMax
int32
func
(
file
*
File
)
readdirnames
(
n
int
)
(
names
[]
string
,
err
error
)
{
if
elen
==
0
{
var
dummy
syscall
.
Dirent
elen
=
(
int
(
unsafe
.
Offsetof
(
dummy
.
Name
))
+
libc_pathconf
(
syscall
.
StringBytePtr
(
file
.
name
),
syscall
.
PC_NAME_MAX
)
+
1
)
}
if
file
.
dirinfo
==
nil
{
file
.
dirinfo
=
new
(
dirInfo
)
file
.
dirinfo
.
buf
=
make
([]
byte
,
elen
)
p
:=
syscall
.
StringBytePtr
(
file
.
name
)
p
,
err
:=
syscall
.
BytePtrFromString
(
file
.
name
)
if
err
!=
nil
{
return
nil
,
err
}
elen
:=
int
(
atomic
.
LoadInt32
(
&
nameMax
))
if
elen
==
0
{
syscall
.
Entersyscall
()
plen
:=
libc_pathconf
(
p
,
syscall
.
PC_NAME_MAX
)
syscall
.
Exitsyscall
()
if
plen
<
1024
{
plen
=
1024
}
var
dummy
syscall
.
Dirent
elen
=
int
(
unsafe
.
Offsetof
(
dummy
.
Name
))
+
plen
+
1
atomic
.
StoreInt32
(
&
nameMax
,
int32
(
elen
))
}
syscall
.
Entersyscall
()
r
:=
libc_opendir
(
p
)
errno
:=
syscall
.
GetErrno
()
syscall
.
Exitsyscall
()
if
r
==
nil
{
return
nil
,
&
PathError
{
"opendir"
,
file
.
name
,
errno
}
}
file
.
dirinfo
=
new
(
dirInfo
)
file
.
dirinfo
.
buf
=
make
([]
byte
,
elen
)
file
.
dirinfo
.
dir
=
r
}
entry
_d
irent
:=
(
*
syscall
.
Dirent
)(
unsafe
.
Pointer
(
&
file
.
dirinfo
.
buf
[
0
]))
entry
D
irent
:=
(
*
syscall
.
Dirent
)(
unsafe
.
Pointer
(
&
file
.
dirinfo
.
buf
[
0
]))
size
:=
n
if
size
<=
0
{
...
...
@@ -59,24 +75,20 @@ func (file *File) readdirnames(n int) (names []string, err error) {
names
=
make
([]
string
,
0
,
size
)
// Empty with room to grow.
dir
:=
file
.
dirinfo
.
dir
if
dir
==
nil
{
return
names
,
NewSyscallError
(
"opendir"
,
syscall
.
GetErrno
())
}
for
n
!=
0
{
var
resul
t
*
syscall
.
Dirent
pr
:=
&
resul
t
var
diren
t
*
syscall
.
Dirent
pr
:=
&
diren
t
syscall
.
Entersyscall
()
i
:=
libc_readdir_r
(
dir
,
entry_d
irent
,
pr
)
i
:=
libc_readdir_r
(
file
.
dirinfo
.
dir
,
entryD
irent
,
pr
)
syscall
.
Exitsyscall
()
if
i
!=
0
{
return
names
,
NewSyscallError
(
"readdir_r"
,
i
)
}
if
resul
t
==
nil
{
if
diren
t
==
nil
{
break
// EOF
}
var
name
=
string
(
result
.
Name
[
0
:
clen
(
result
.
Name
[
0
:
])])
bytes
:=
(
*
[
10000
]
byte
)(
unsafe
.
Pointer
(
&
dirent
.
Name
[
0
]))
var
name
=
string
(
bytes
[
0
:
clen
(
bytes
[
:
])])
if
name
==
"."
||
name
==
".."
{
// Useless names
continue
}
...
...
libgo/go/os/file_unix.go
View file @
4d901dd7
...
...
@@ -108,8 +108,13 @@ func (file *file) close() error {
}
if
file
.
dirinfo
!=
nil
{
if
libc_closedir
(
file
.
dirinfo
.
dir
)
<
0
&&
err
==
nil
{
err
=
&
PathError
{
"closedir"
,
file
.
name
,
syscall
.
GetErrno
()}
syscall
.
Entersyscall
()
i
:=
libc_closedir
(
file
.
dirinfo
.
dir
)
errno
:=
syscall
.
GetErrno
()
syscall
.
Exitsyscall
()
file
.
dirinfo
=
nil
if
i
<
0
&&
err
==
nil
{
err
=
&
PathError
{
"closedir"
,
file
.
name
,
errno
}
}
}
...
...
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