Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
08a073a1
Commit
08a073a1
authored
Nov 01, 2011
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
os: use error, io.EOF
R=r CC=golang-dev
https://golang.org/cl/5298073
parent
c06cf03f
Changes
30
Show whitespace changes
Inline
Side-by-side
Showing
30 changed files
with
233 additions
and
253 deletions
+233
-253
src/pkg/os/dir_plan9.go
src/pkg/os/dir_plan9.go
+10
-9
src/pkg/os/dir_unix.go
src/pkg/os/dir_unix.go
+3
-2
src/pkg/os/dir_windows.go
src/pkg/os/dir_windows.go
+1
-1
src/pkg/os/env_plan9.go
src/pkg/os/env_plan9.go
+4
-4
src/pkg/os/env_unix.go
src/pkg/os/env_unix.go
+6
-5
src/pkg/os/env_windows.go
src/pkg/os/env_windows.go
+4
-4
src/pkg/os/error.go
src/pkg/os/error.go
+4
-21
src/pkg/os/error_plan9.go
src/pkg/os/error_plan9.go
+3
-3
src/pkg/os/error_posix.go
src/pkg/os/error_posix.go
+44
-44
src/pkg/os/exec_plan9.go
src/pkg/os/exec_plan9.go
+11
-11
src/pkg/os/exec_posix.go
src/pkg/os/exec_posix.go
+6
-6
src/pkg/os/exec_unix.go
src/pkg/os/exec_unix.go
+7
-6
src/pkg/os/exec_windows.go
src/pkg/os/exec_windows.go
+4
-4
src/pkg/os/file.go
src/pkg/os/file.go
+26
-36
src/pkg/os/file_plan9.go
src/pkg/os/file_plan9.go
+21
-21
src/pkg/os/file_posix.go
src/pkg/os/file_posix.go
+20
-20
src/pkg/os/file_unix.go
src/pkg/os/file_unix.go
+12
-12
src/pkg/os/file_windows.go
src/pkg/os/file_windows.go
+13
-12
src/pkg/os/getwd.go
src/pkg/os/getwd.go
+1
-1
src/pkg/os/os_test.go
src/pkg/os/os_test.go
+13
-13
src/pkg/os/path.go
src/pkg/os/path.go
+6
-4
src/pkg/os/path_test.go
src/pkg/os/path_test.go
+1
-1
src/pkg/os/proc.go
src/pkg/os/proc.go
+1
-1
src/pkg/os/stat_plan9.go
src/pkg/os/stat_plan9.go
+3
-3
src/pkg/os/stat_windows.go
src/pkg/os/stat_windows.go
+3
-3
src/pkg/os/sys_bsd.go
src/pkg/os/sys_bsd.go
+1
-1
src/pkg/os/sys_linux.go
src/pkg/os/sys_linux.go
+1
-1
src/pkg/os/sys_plan9.go
src/pkg/os/sys_plan9.go
+1
-1
src/pkg/os/sys_windows.go
src/pkg/os/sys_windows.go
+1
-1
src/pkg/os/time.go
src/pkg/os/time.go
+2
-2
No files found.
src/pkg/os/dir_plan9.go
View file @
08a073a1
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
package
os
package
os
import
(
import
(
"io"
"syscall"
"syscall"
)
)
...
@@ -15,7 +16,7 @@ import (
...
@@ -15,7 +16,7 @@ import (
//
//
// If n > 0, Readdir returns at most n FileInfo structures. In this case, if
// If n > 0, Readdir returns at most n FileInfo structures. In this case, if
// Readdirnames returns an empty slice, it will return a non-nil error
// Readdirnames returns an empty slice, it will return a non-nil error
// explaining why. At the end of a directory, the error is
os
.EOF.
// explaining why. At the end of a directory, the error is
io
.EOF.
//
//
// If n <= 0, Readdir returns all the FileInfo from the directory in
// If n <= 0, Readdir returns all the FileInfo from the directory in
// a single slice. In this case, if Readdir succeeds (reads all
// a single slice. In this case, if Readdir succeeds (reads all
...
@@ -23,7 +24,7 @@ import (
...
@@ -23,7 +24,7 @@ import (
// nil os.Error. If it encounters an error before the end of the
// nil os.Error. If it encounters an error before the end of the
// directory, Readdir returns the FileInfo read until that point
// directory, Readdir returns the FileInfo read until that point
// and a non-nil error.
// and a non-nil error.
func
(
file
*
File
)
Readdir
(
n
int
)
(
fi
[]
FileInfo
,
err
E
rror
)
{
func
(
file
*
File
)
Readdir
(
n
int
)
(
fi
[]
FileInfo
,
err
e
rror
)
{
// If this file has no dirinfo, create one.
// If this file has no dirinfo, create one.
if
file
.
dirinfo
==
nil
{
if
file
.
dirinfo
==
nil
{
file
.
dirinfo
=
new
(
dirInfo
)
file
.
dirinfo
=
new
(
dirInfo
)
...
@@ -39,12 +40,12 @@ func (file *File) Readdir(n int) (fi []FileInfo, err Error) {
...
@@ -39,12 +40,12 @@ func (file *File) Readdir(n int) (fi []FileInfo, err Error) {
// Refill the buffer if necessary
// Refill the buffer if necessary
if
d
.
bufp
>=
d
.
nbuf
{
if
d
.
bufp
>=
d
.
nbuf
{
d
.
bufp
=
0
d
.
bufp
=
0
var
e
E
rror
var
e
e
rror
d
.
nbuf
,
e
=
file
.
Read
(
d
.
buf
[
:
])
d
.
nbuf
,
e
=
file
.
Read
(
d
.
buf
[
:
])
if
e
!=
nil
&&
e
!=
EOF
{
if
e
!=
nil
&&
e
!=
io
.
EOF
{
return
result
,
&
PathError
{
"readdir"
,
file
.
name
,
e
}
return
result
,
&
PathError
{
"readdir"
,
file
.
name
,
e
}
}
}
if
e
==
EOF
{
if
e
==
io
.
EOF
{
break
break
}
}
if
d
.
nbuf
<
syscall
.
STATFIXLEN
{
if
d
.
nbuf
<
syscall
.
STATFIXLEN
{
...
@@ -71,7 +72,7 @@ func (file *File) Readdir(n int) (fi []FileInfo, err Error) {
...
@@ -71,7 +72,7 @@ func (file *File) Readdir(n int) (fi []FileInfo, err Error) {
}
}
if
n
>=
0
&&
len
(
result
)
==
0
{
if
n
>=
0
&&
len
(
result
)
==
0
{
return
result
,
EOF
return
result
,
io
.
EOF
}
}
return
result
,
nil
return
result
,
nil
}
}
...
@@ -80,7 +81,7 @@ func (file *File) Readdir(n int) (fi []FileInfo, err Error) {
...
@@ -80,7 +81,7 @@ func (file *File) Readdir(n int) (fi []FileInfo, err Error) {
//
//
// If n > 0, Readdirnames returns at most n names. In this case, if
// If n > 0, Readdirnames returns at most n names. In this case, if
// Readdirnames returns an empty slice, it will return a non-nil error
// Readdirnames returns an empty slice, it will return a non-nil error
// explaining why. At the end of a directory, the error is
os
.EOF.
// explaining why. At the end of a directory, the error is
io
.EOF.
//
//
// If n <= 0, Readdirnames returns all the names from the directory in
// If n <= 0, Readdirnames returns all the names from the directory in
// a single slice. In this case, if Readdirnames succeeds (reads all
// a single slice. In this case, if Readdirnames succeeds (reads all
...
@@ -88,7 +89,7 @@ func (file *File) Readdir(n int) (fi []FileInfo, err Error) {
...
@@ -88,7 +89,7 @@ func (file *File) Readdir(n int) (fi []FileInfo, err Error) {
// nil os.Error. If it encounters an error before the end of the
// nil os.Error. If it encounters an error before the end of the
// directory, Readdirnames returns the names read until that point and
// directory, Readdirnames returns the names read until that point and
// a non-nil error.
// a non-nil error.
func
(
file
*
File
)
Readdirnames
(
n
int
)
(
names
[]
string
,
err
E
rror
)
{
func
(
file
*
File
)
Readdirnames
(
n
int
)
(
names
[]
string
,
err
e
rror
)
{
fi
,
err
:=
file
.
Readdir
(
n
)
fi
,
err
:=
file
.
Readdir
(
n
)
names
=
make
([]
string
,
len
(
fi
))
names
=
make
([]
string
,
len
(
fi
))
for
i
:=
range
fi
{
for
i
:=
range
fi
{
...
@@ -160,7 +161,7 @@ func pdir(b []byte, d *Dir) []byte {
...
@@ -160,7 +161,7 @@ func pdir(b []byte, d *Dir) []byte {
// UnmarshalDir reads a 9P Stat message from a 9P protocol message stored in b,
// UnmarshalDir reads a 9P Stat message from a 9P protocol message stored in b,
// returning the corresponding Dir struct.
// returning the corresponding Dir struct.
func
UnmarshalDir
(
b
[]
byte
)
(
d
*
Dir
,
err
E
rror
)
{
func
UnmarshalDir
(
b
[]
byte
)
(
d
*
Dir
,
err
e
rror
)
{
n
:=
uint16
(
0
)
n
:=
uint16
(
0
)
n
,
b
=
gbit16
(
b
)
n
,
b
=
gbit16
(
b
)
...
...
src/pkg/os/dir_unix.go
View file @
08a073a1
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
package
os
package
os
import
(
import
(
"io"
"syscall"
"syscall"
)
)
...
@@ -26,7 +27,7 @@ const (
...
@@ -26,7 +27,7 @@ const (
// nil os.Error. If it encounters an error before the end of the
// nil os.Error. If it encounters an error before the end of the
// directory, Readdirnames returns the names read until that point and
// directory, Readdirnames returns the names read until that point and
// a non-nil error.
// a non-nil error.
func
(
f
*
File
)
Readdirnames
(
n
int
)
(
names
[]
string
,
err
E
rror
)
{
func
(
f
*
File
)
Readdirnames
(
n
int
)
(
names
[]
string
,
err
e
rror
)
{
// If this file has no dirinfo, create one.
// If this file has no dirinfo, create one.
if
f
.
dirinfo
==
nil
{
if
f
.
dirinfo
==
nil
{
f
.
dirinfo
=
new
(
dirInfo
)
f
.
dirinfo
=
new
(
dirInfo
)
...
@@ -63,7 +64,7 @@ func (f *File) Readdirnames(n int) (names []string, err Error) {
...
@@ -63,7 +64,7 @@ func (f *File) Readdirnames(n int) (names []string, err Error) {
n
-=
nc
n
-=
nc
}
}
if
n
>=
0
&&
len
(
names
)
==
0
{
if
n
>=
0
&&
len
(
names
)
==
0
{
return
names
,
EOF
return
names
,
io
.
EOF
}
}
return
names
,
nil
return
names
,
nil
}
}
src/pkg/os/dir_windows.go
View file @
08a073a1
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
package
os
package
os
func
(
file
*
File
)
Readdirnames
(
n
int
)
(
names
[]
string
,
err
E
rror
)
{
func
(
file
*
File
)
Readdirnames
(
n
int
)
(
names
[]
string
,
err
e
rror
)
{
fis
,
err
:=
file
.
Readdir
(
n
)
fis
,
err
:=
file
.
Readdir
(
n
)
names
=
make
([]
string
,
len
(
fis
))
names
=
make
([]
string
,
len
(
fis
))
for
i
,
fi
:=
range
fis
{
for
i
,
fi
:=
range
fis
{
...
...
src/pkg/os/env_plan9.go
View file @
08a073a1
...
@@ -8,12 +8,12 @@ package os
...
@@ -8,12 +8,12 @@ package os
import
"syscall"
import
"syscall"
// ENOENV is the
E
rror indicating that an environment variable does not exist.
// ENOENV is the
e
rror indicating that an environment variable does not exist.
var
ENOENV
=
NewError
(
"no such environment variable"
)
var
ENOENV
=
NewError
(
"no such environment variable"
)
// Getenverror retrieves the value of the environment variable named by the key.
// Getenverror retrieves the value of the environment variable named by the key.
// It returns the value and an error, if any.
// It returns the value and an error, if any.
func
Getenverror
(
key
string
)
(
value
string
,
err
E
rror
)
{
func
Getenverror
(
key
string
)
(
value
string
,
err
e
rror
)
{
if
len
(
key
)
==
0
{
if
len
(
key
)
==
0
{
return
""
,
EINVAL
return
""
,
EINVAL
}
}
...
@@ -45,8 +45,8 @@ func Getenv(key string) string {
...
@@ -45,8 +45,8 @@ func Getenv(key string) string {
}
}
// Setenv sets the value of the environment variable named by the key.
// Setenv sets the value of the environment variable named by the key.
// It returns an
E
rror, if any.
// It returns an
e
rror, if any.
func
Setenv
(
key
,
value
string
)
E
rror
{
func
Setenv
(
key
,
value
string
)
e
rror
{
if
len
(
key
)
==
0
{
if
len
(
key
)
==
0
{
return
EINVAL
return
EINVAL
}
}
...
...
src/pkg/os/env_unix.go
View file @
08a073a1
...
@@ -9,11 +9,12 @@
...
@@ -9,11 +9,12 @@
package
os
package
os
import
(
import
(
"errors"
"sync"
"sync"
)
)
// ENOENV is the
E
rror indicating that an environment variable does not exist.
// ENOENV is the
e
rror indicating that an environment variable does not exist.
var
ENOENV
=
NewError
(
"no such environment variable"
)
var
ENOENV
=
errors
.
New
(
"no such environment variable"
)
var
env
map
[
string
]
string
var
env
map
[
string
]
string
var
once
sync
.
Once
var
once
sync
.
Once
...
@@ -34,7 +35,7 @@ var envLock sync.RWMutex
...
@@ -34,7 +35,7 @@ var envLock sync.RWMutex
// Getenverror retrieves the value of the environment variable named by the key.
// Getenverror retrieves the value of the environment variable named by the key.
// It returns the value and an error, if any.
// It returns the value and an error, if any.
func
Getenverror
(
key
string
)
(
value
string
,
err
E
rror
)
{
func
Getenverror
(
key
string
)
(
value
string
,
err
e
rror
)
{
once
.
Do
(
copyenv
)
once
.
Do
(
copyenv
)
if
len
(
key
)
==
0
{
if
len
(
key
)
==
0
{
...
@@ -59,8 +60,8 @@ func Getenv(key string) string {
...
@@ -59,8 +60,8 @@ func Getenv(key string) string {
}
}
// Setenv sets the value of the environment variable named by the key.
// Setenv sets the value of the environment variable named by the key.
// It returns an
E
rror, if any.
// It returns an
e
rror, if any.
func
Setenv
(
key
,
value
string
)
E
rror
{
func
Setenv
(
key
,
value
string
)
e
rror
{
once
.
Do
(
copyenv
)
once
.
Do
(
copyenv
)
if
len
(
key
)
==
0
{
if
len
(
key
)
==
0
{
return
EINVAL
return
EINVAL
...
...
src/pkg/os/env_windows.go
View file @
08a073a1
...
@@ -12,12 +12,12 @@ import (
...
@@ -12,12 +12,12 @@ import (
"unsafe"
"unsafe"
)
)
// ENOENV is the
E
rror indicating that an environment variable does not exist.
// ENOENV is the
e
rror indicating that an environment variable does not exist.
var
ENOENV
=
NewError
(
"no such environment variable"
)
var
ENOENV
=
NewError
(
"no such environment variable"
)
// Getenverror retrieves the value of the environment variable named by the key.
// Getenverror retrieves the value of the environment variable named by the key.
// It returns the value and an error, if any.
// It returns the value and an error, if any.
func
Getenverror
(
key
string
)
(
value
string
,
err
E
rror
)
{
func
Getenverror
(
key
string
)
(
value
string
,
err
e
rror
)
{
b
:=
make
([]
uint16
,
100
)
b
:=
make
([]
uint16
,
100
)
n
,
e
:=
syscall
.
GetEnvironmentVariable
(
syscall
.
StringToUTF16Ptr
(
key
),
&
b
[
0
],
uint32
(
len
(
b
)))
n
,
e
:=
syscall
.
GetEnvironmentVariable
(
syscall
.
StringToUTF16Ptr
(
key
),
&
b
[
0
],
uint32
(
len
(
b
)))
if
n
==
0
&&
e
==
syscall
.
ERROR_ENVVAR_NOT_FOUND
{
if
n
==
0
&&
e
==
syscall
.
ERROR_ENVVAR_NOT_FOUND
{
...
@@ -44,8 +44,8 @@ func Getenv(key string) string {
...
@@ -44,8 +44,8 @@ func Getenv(key string) string {
}
}
// Setenv sets the value of the environment variable named by the key.
// Setenv sets the value of the environment variable named by the key.
// It returns an
E
rror, if any.
// It returns an
e
rror, if any.
func
Setenv
(
key
,
value
string
)
E
rror
{
func
Setenv
(
key
,
value
string
)
e
rror
{
var
v
*
uint16
var
v
*
uint16
if
len
(
value
)
>
0
{
if
len
(
value
)
>
0
{
v
=
syscall
.
StringToUTF16Ptr
(
value
)
v
=
syscall
.
StringToUTF16Ptr
(
value
)
...
...
src/pkg/os/error.go
View file @
08a073a1
...
@@ -4,28 +4,11 @@
...
@@ -4,28 +4,11 @@
package
os
package
os
// An Error can represent any printable error condition.
type
Error
interface
{
String
()
string
}
// // errorString is a helper type used by NewError.
type
errorString
string
func
(
e
errorString
)
String
()
string
{
return
string
(
e
)
}
// Note: If the name of the function NewError changes,
// pkg/go/doc/doc.go should be adjusted since it hardwires
// this name in a heuristic.
// // NewError returns a new error with error.String() == s.
func
NewError
(
s
string
)
Error
{
return
errorString
(
s
)
}
// PathError records an error and the operation and file path that caused it.
// PathError records an error and the operation and file path that caused it.
type
PathError
struct
{
type
PathError
struct
{
Op
string
Op
string
Path
string
Path
string
Err
or
E
rror
Err
e
rror
}
}
func
(
e
*
PathError
)
String
()
string
{
return
e
.
Op
+
" "
+
e
.
Path
+
": "
+
e
.
Error
.
String
()
}
func
(
e
*
PathError
)
Error
()
string
{
return
e
.
Op
+
" "
+
e
.
Path
+
": "
+
e
.
Err
.
Error
()
}
src/pkg/os/error_plan9.go
View file @
08a073a1
...
@@ -12,16 +12,16 @@ type SyscallError struct {
...
@@ -12,16 +12,16 @@ type SyscallError struct {
Err
string
Err
string
}
}
func
(
e
*
SyscallError
)
String
()
string
{
return
e
.
Syscall
+
": "
+
e
.
Err
}
func
(
e
*
SyscallError
)
Error
()
string
{
return
e
.
Syscall
+
": "
+
e
.
Err
}
// Note: If the name of the function NewSyscallError changes,
// Note: If the name of the function NewSyscallError changes,
// pkg/go/doc/doc.go should be adjusted since it hardwires
// pkg/go/doc/doc.go should be adjusted since it hardwires
// this name in a heuristic.
// this name in a heuristic.
// NewSyscallError returns, as an
E
rror, a new SyscallError
// NewSyscallError returns, as an
e
rror, a new SyscallError
// with the given system call name and error details.
// with the given system call name and error details.
// As a convenience, if err is nil, NewSyscallError returns nil.
// As a convenience, if err is nil, NewSyscallError returns nil.
func
NewSyscallError
(
syscall
string
,
err
syscall
.
Error
)
E
rror
{
func
NewSyscallError
(
syscall
string
,
err
syscall
.
Error
)
e
rror
{
if
err
==
nil
{
if
err
==
nil
{
return
nil
return
nil
}
}
...
...
src/pkg/os/error_posix.go
View file @
08a073a1
...
@@ -9,10 +9,10 @@ package os
...
@@ -9,10 +9,10 @@ package os
import
syscall
"syscall"
import
syscall
"syscall"
// Errno is the Unix error number. Names such as EINVAL are simple
// Errno is the Unix error number. Names such as EINVAL are simple
// wrappers to convert the error number into an
E
rror.
// wrappers to convert the error number into an
e
rror.
type
Errno
int64
type
Errno
int64
func
(
e
Errno
)
String
()
string
{
return
syscall
.
Errstr
(
int
(
e
))
}
func
(
e
Errno
)
Error
()
string
{
return
syscall
.
Errstr
(
int
(
e
))
}
func
(
e
Errno
)
Temporary
()
bool
{
func
(
e
Errno
)
Temporary
()
bool
{
return
e
==
Errno
(
syscall
.
EINTR
)
||
e
==
Errno
(
syscall
.
EMFILE
)
||
e
.
Timeout
()
return
e
==
Errno
(
syscall
.
EINTR
)
||
e
==
Errno
(
syscall
.
EMFILE
)
||
e
.
Timeout
()
...
@@ -24,45 +24,45 @@ func (e Errno) Timeout() bool {
...
@@ -24,45 +24,45 @@ func (e Errno) Timeout() bool {
// Commonly known Unix errors.
// Commonly known Unix errors.
var
(
var
(
EPERM
E
rror
=
Errno
(
syscall
.
EPERM
)
EPERM
e
rror
=
Errno
(
syscall
.
EPERM
)
ENOENT
E
rror
=
Errno
(
syscall
.
ENOENT
)
ENOENT
e
rror
=
Errno
(
syscall
.
ENOENT
)
ESRCH
E
rror
=
Errno
(
syscall
.
ESRCH
)
ESRCH
e
rror
=
Errno
(
syscall
.
ESRCH
)
EINTR
E
rror
=
Errno
(
syscall
.
EINTR
)
EINTR
e
rror
=
Errno
(
syscall
.
EINTR
)
EIO
E
rror
=
Errno
(
syscall
.
EIO
)
EIO
e
rror
=
Errno
(
syscall
.
EIO
)
ENXIO
E
rror
=
Errno
(
syscall
.
ENXIO
)
ENXIO
e
rror
=
Errno
(
syscall
.
ENXIO
)
E2BIG
E
rror
=
Errno
(
syscall
.
E2BIG
)
E2BIG
e
rror
=
Errno
(
syscall
.
E2BIG
)
ENOEXEC
E
rror
=
Errno
(
syscall
.
ENOEXEC
)
ENOEXEC
e
rror
=
Errno
(
syscall
.
ENOEXEC
)
EBADF
E
rror
=
Errno
(
syscall
.
EBADF
)
EBADF
e
rror
=
Errno
(
syscall
.
EBADF
)
ECHILD
E
rror
=
Errno
(
syscall
.
ECHILD
)
ECHILD
e
rror
=
Errno
(
syscall
.
ECHILD
)
EDEADLK
E
rror
=
Errno
(
syscall
.
EDEADLK
)
EDEADLK
e
rror
=
Errno
(
syscall
.
EDEADLK
)
ENOMEM
E
rror
=
Errno
(
syscall
.
ENOMEM
)
ENOMEM
e
rror
=
Errno
(
syscall
.
ENOMEM
)
EACCES
E
rror
=
Errno
(
syscall
.
EACCES
)
EACCES
e
rror
=
Errno
(
syscall
.
EACCES
)
EFAULT
E
rror
=
Errno
(
syscall
.
EFAULT
)
EFAULT
e
rror
=
Errno
(
syscall
.
EFAULT
)
EBUSY
E
rror
=
Errno
(
syscall
.
EBUSY
)
EBUSY
e
rror
=
Errno
(
syscall
.
EBUSY
)
EEXIST
E
rror
=
Errno
(
syscall
.
EEXIST
)
EEXIST
e
rror
=
Errno
(
syscall
.
EEXIST
)
EXDEV
E
rror
=
Errno
(
syscall
.
EXDEV
)
EXDEV
e
rror
=
Errno
(
syscall
.
EXDEV
)
ENODEV
E
rror
=
Errno
(
syscall
.
ENODEV
)
ENODEV
e
rror
=
Errno
(
syscall
.
ENODEV
)
ENOTDIR
E
rror
=
Errno
(
syscall
.
ENOTDIR
)
ENOTDIR
e
rror
=
Errno
(
syscall
.
ENOTDIR
)
EISDIR
E
rror
=
Errno
(
syscall
.
EISDIR
)
EISDIR
e
rror
=
Errno
(
syscall
.
EISDIR
)
EINVAL
E
rror
=
Errno
(
syscall
.
EINVAL
)
EINVAL
e
rror
=
Errno
(
syscall
.
EINVAL
)
ENFILE
E
rror
=
Errno
(
syscall
.
ENFILE
)
ENFILE
e
rror
=
Errno
(
syscall
.
ENFILE
)
EMFILE
E
rror
=
Errno
(
syscall
.
EMFILE
)
EMFILE
e
rror
=
Errno
(
syscall
.
EMFILE
)
ENOTTY
E
rror
=
Errno
(
syscall
.
ENOTTY
)
ENOTTY
e
rror
=
Errno
(
syscall
.
ENOTTY
)
EFBIG
E
rror
=
Errno
(
syscall
.
EFBIG
)
EFBIG
e
rror
=
Errno
(
syscall
.
EFBIG
)
ENOSPC
E
rror
=
Errno
(
syscall
.
ENOSPC
)
ENOSPC
e
rror
=
Errno
(
syscall
.
ENOSPC
)
ESPIPE
E
rror
=
Errno
(
syscall
.
ESPIPE
)
ESPIPE
e
rror
=
Errno
(
syscall
.
ESPIPE
)
EROFS
E
rror
=
Errno
(
syscall
.
EROFS
)
EROFS
e
rror
=
Errno
(
syscall
.
EROFS
)
EMLINK
E
rror
=
Errno
(
syscall
.
EMLINK
)
EMLINK
e
rror
=
Errno
(
syscall
.
EMLINK
)
EPIPE
E
rror
=
Errno
(
syscall
.
EPIPE
)
EPIPE
e
rror
=
Errno
(
syscall
.
EPIPE
)
EAGAIN
E
rror
=
Errno
(
syscall
.
EAGAIN
)
EAGAIN
e
rror
=
Errno
(
syscall
.
EAGAIN
)
EDOM
E
rror
=
Errno
(
syscall
.
EDOM
)
EDOM
e
rror
=
Errno
(
syscall
.
EDOM
)
ERANGE
E
rror
=
Errno
(
syscall
.
ERANGE
)
ERANGE
e
rror
=
Errno
(
syscall
.
ERANGE
)
EADDRINUSE
E
rror
=
Errno
(
syscall
.
EADDRINUSE
)
EADDRINUSE
e
rror
=
Errno
(
syscall
.
EADDRINUSE
)
ECONNREFUSED
E
rror
=
Errno
(
syscall
.
ECONNREFUSED
)
ECONNREFUSED
e
rror
=
Errno
(
syscall
.
ECONNREFUSED
)
ENAMETOOLONG
E
rror
=
Errno
(
syscall
.
ENAMETOOLONG
)
ENAMETOOLONG
e
rror
=
Errno
(
syscall
.
ENAMETOOLONG
)
EAFNOSUPPORT
E
rror
=
Errno
(
syscall
.
EAFNOSUPPORT
)
EAFNOSUPPORT
e
rror
=
Errno
(
syscall
.
EAFNOSUPPORT
)
ETIMEDOUT
E
rror
=
Errno
(
syscall
.
ETIMEDOUT
)
ETIMEDOUT
e
rror
=
Errno
(
syscall
.
ETIMEDOUT
)
ENOTCONN
E
rror
=
Errno
(
syscall
.
ENOTCONN
)
ENOTCONN
e
rror
=
Errno
(
syscall
.
ENOTCONN
)
)
)
// SyscallError records an error from a specific system call.
// SyscallError records an error from a specific system call.
...
@@ -71,16 +71,16 @@ type SyscallError struct {
...
@@ -71,16 +71,16 @@ type SyscallError struct {
Errno
Errno
Errno
Errno
}
}
func
(
e
*
SyscallError
)
String
()
string
{
return
e
.
Syscall
+
": "
+
e
.
Errno
.
String
()
}
func
(
e
*
SyscallError
)
Error
()
string
{
return
e
.
Syscall
+
": "
+
e
.
Errno
.
Error
()
}
// Note: If the name of the function NewSyscallError changes,
// Note: If the name of the function NewSyscallError changes,
// pkg/go/doc/doc.go should be adjusted since it hardwires
// pkg/go/doc/doc.go should be adjusted since it hardwires
// this name in a heuristic.
// this name in a heuristic.
// NewSyscallError returns, as an
E
rror, a new SyscallError
// NewSyscallError returns, as an
e
rror, a new SyscallError
// with the given system call name and error details.
// with the given system call name and error details.
// As a convenience, if errno is 0, NewSyscallError returns nil.
// As a convenience, if errno is 0, NewSyscallError returns nil.
func
NewSyscallError
(
syscall
string
,
errno
int
)
E
rror
{
func
NewSyscallError
(
syscall
string
,
errno
int
)
e
rror
{
if
errno
==
0
{
if
errno
==
0
{
return
nil
return
nil
}
}
...
...
src/pkg/os/exec_plan9.go
View file @
08a073a1
...
@@ -11,7 +11,7 @@ import (
...
@@ -11,7 +11,7 @@ import (
// StartProcess starts a new process with the program, arguments and attributes
// StartProcess starts a new process with the program, arguments and attributes
// specified by name, argv and attr.
// specified by name, argv and attr.
func
StartProcess
(
name
string
,
argv
[]
string
,
attr
*
ProcAttr
)
(
p
*
Process
,
err
E
rror
)
{
func
StartProcess
(
name
string
,
argv
[]
string
,
attr
*
ProcAttr
)
(
p
*
Process
,
err
e
rror
)
{
sysattr
:=
&
syscall
.
ProcAttr
{
sysattr
:=
&
syscall
.
ProcAttr
{
Dir
:
attr
.
Dir
,
Dir
:
attr
.
Dir
,
Env
:
attr
.
Env
,
Env
:
attr
.
Env
,
...
@@ -45,7 +45,7 @@ func (note Plan9Note) String() string {
...
@@ -45,7 +45,7 @@ func (note Plan9Note) String() string {
return
string
(
note
)
return
string
(
note
)
}
}
func
(
p
*
Process
)
Signal
(
sig
Signal
)
E
rror
{
func
(
p
*
Process
)
Signal
(
sig
Signal
)
e
rror
{
if
p
.
done
{
if
p
.
done
{
return
NewError
(
"os: process already finished"
)
return
NewError
(
"os: process already finished"
)
}
}
...
@@ -60,7 +60,7 @@ func (p *Process) Signal(sig Signal) Error {
...
@@ -60,7 +60,7 @@ func (p *Process) Signal(sig Signal) Error {
}
}
// Kill causes the Process to exit immediately.
// Kill causes the Process to exit immediately.
func
(
p
*
Process
)
Kill
()
E
rror
{
func
(
p
*
Process
)
Kill
()
e
rror
{
f
,
e
:=
OpenFile
(
"/proc/"
+
itoa
(
p
.
Pid
)
+
"/ctl"
,
O_WRONLY
,
0
)
f
,
e
:=
OpenFile
(
"/proc/"
+
itoa
(
p
.
Pid
)
+
"/ctl"
,
O_WRONLY
,
0
)
if
iserror
(
e
)
{
if
iserror
(
e
)
{
return
NewSyscallError
(
"kill"
,
e
)
return
NewSyscallError
(
"kill"
,
e
)
...
@@ -72,9 +72,9 @@ func (p *Process) Kill() Error {
...
@@ -72,9 +72,9 @@ func (p *Process) Kill() Error {
// Exec replaces the current process with an execution of the
// Exec replaces the current process with an execution of the
// named binary, with arguments argv and environment envv.
// named binary, with arguments argv and environment envv.
// If successful, Exec never returns. If it fails, it returns an
E
rror.
// If successful, Exec never returns. If it fails, it returns an
e
rror.
// ForkExec is almost always a better way to execute a program.
// ForkExec is almost always a better way to execute a program.
func
Exec
(
name
string
,
argv
[]
string
,
envv
[]
string
)
E
rror
{
func
Exec
(
name
string
,
argv
[]
string
,
envv
[]
string
)
e
rror
{
e
:=
syscall
.
Exec
(
name
,
argv
,
envv
)
e
:=
syscall
.
Exec
(
name
,
argv
,
envv
)
if
iserror
(
e
)
{
if
iserror
(
e
)
{
return
&
PathError
{
"exec"
,
name
,
e
}
return
&
PathError
{
"exec"
,
name
,
e
}
...
@@ -89,9 +89,9 @@ type Waitmsg struct {
...
@@ -89,9 +89,9 @@ type Waitmsg struct {
}
}
// Wait waits for the Process to exit or stop, and then returns a
// Wait waits for the Process to exit or stop, and then returns a
// Waitmsg describing its status and an
E
rror, if any. The options
// Waitmsg describing its status and an
e
rror, if any. The options
// (WNOHANG etc.) affect the behavior of the Wait call.
// (WNOHANG etc.) affect the behavior of the Wait call.
func
(
p
*
Process
)
Wait
(
options
int
)
(
w
*
Waitmsg
,
err
E
rror
)
{
func
(
p
*
Process
)
Wait
(
options
int
)
(
w
*
Waitmsg
,
err
e
rror
)
{
var
waitmsg
syscall
.
Waitmsg
var
waitmsg
syscall
.
Waitmsg
if
p
.
Pid
==
-
1
{
if
p
.
Pid
==
-
1
{
...
@@ -115,11 +115,11 @@ func (p *Process) Wait(options int) (w *Waitmsg, err Error) {
...
@@ -115,11 +115,11 @@ func (p *Process) Wait(options int) (w *Waitmsg, err Error) {
}
}
// Wait waits for process pid to exit or stop, and then returns a
// Wait waits for process pid to exit or stop, and then returns a
// Waitmsg describing its status and an
E
rror, if any. The options
// Waitmsg describing its status and an
e
rror, if any. The options
// (WNOHANG etc.) affect the behavior of the Wait call.
// (WNOHANG etc.) affect the behavior of the Wait call.
// Wait is equivalent to calling FindProcess and then Wait
// Wait is equivalent to calling FindProcess and then Wait
// and Release on the result.
// and Release on the result.
func
Wait
(
pid
int
,
options
int
)
(
w
*
Waitmsg
,
err
E
rror
)
{
func
Wait
(
pid
int
,
options
int
)
(
w
*
Waitmsg
,
err
e
rror
)
{
p
,
e
:=
FindProcess
(
pid
)
p
,
e
:=
FindProcess
(
pid
)
if
e
!=
nil
{
if
e
!=
nil
{
return
nil
,
e
return
nil
,
e
...
@@ -129,7 +129,7 @@ func Wait(pid int, options int) (w *Waitmsg, err Error) {
...
@@ -129,7 +129,7 @@ func Wait(pid int, options int) (w *Waitmsg, err Error) {
}
}
// Release releases any resources associated with the Process.
// Release releases any resources associated with the Process.
func
(
p
*
Process
)
Release
()
E
rror
{
func
(
p
*
Process
)
Release
()
e
rror
{
// NOOP for Plan 9.
// NOOP for Plan 9.
p
.
Pid
=
-
1
p
.
Pid
=
-
1
// no need for a finalizer anymore
// no need for a finalizer anymore
...
@@ -140,7 +140,7 @@ func (p *Process) Release() Error {
...
@@ -140,7 +140,7 @@ func (p *Process) Release() Error {
// FindProcess looks for a running process by its pid.
// FindProcess looks for a running process by its pid.
// The Process it returns can be used to obtain information
// The Process it returns can be used to obtain information
// about the underlying operating system process.
// about the underlying operating system process.
func
FindProcess
(
pid
int
)
(
p
*
Process
,
err
E
rror
)
{
func
FindProcess
(
pid
int
)
(
p
*
Process
,
err
e
rror
)
{
// NOOP for Plan 9.
// NOOP for Plan 9.
return
newProcess
(
pid
,
0
),
nil
return
newProcess
(
pid
,
0
),
nil
}
}
...
...
src/pkg/os/exec_posix.go
View file @
08a073a1
...
@@ -26,7 +26,7 @@ func (sig UnixSignal) String() string {
...
@@ -26,7 +26,7 @@ func (sig UnixSignal) String() string {
//
//
// StartProcess is a low-level interface. The exec package provides
// StartProcess is a low-level interface. The exec package provides
// higher-level interfaces.
// higher-level interfaces.
func
StartProcess
(
name
string
,
argv
[]
string
,
attr
*
ProcAttr
)
(
p
*
Process
,
err
E
rror
)
{
func
StartProcess
(
name
string
,
argv
[]
string
,
attr
*
ProcAttr
)
(
p
*
Process
,
err
e
rror
)
{
sysattr
:=
&
syscall
.
ProcAttr
{
sysattr
:=
&
syscall
.
ProcAttr
{
Dir
:
attr
.
Dir
,
Dir
:
attr
.
Dir
,
Env
:
attr
.
Env
,
Env
:
attr
.
Env
,
...
@@ -47,17 +47,17 @@ func StartProcess(name string, argv []string, attr *ProcAttr) (p *Process, err E
...
@@ -47,17 +47,17 @@ func StartProcess(name string, argv []string, attr *ProcAttr) (p *Process, err E
}
}
// Kill causes the Process to exit immediately.
// Kill causes the Process to exit immediately.
func
(
p
*
Process
)
Kill
()
E
rror
{
func
(
p
*
Process
)
Kill
()
e
rror
{
return
p
.
Signal
(
SIGKILL
)
return
p
.
Signal
(
SIGKILL
)
}
}
// Exec replaces the current process with an execution of the
// Exec replaces the current process with an execution of the
// named binary, with arguments argv and environment envv.
// named binary, with arguments argv and environment envv.
// If successful, Exec never returns. If it fails, it returns an
E
rror.
// If successful, Exec never returns. If it fails, it returns an
e
rror.
//
//
// To run a child process, see StartProcess (for a low-level interface)
// To run a child process, see StartProcess (for a low-level interface)
// or the exec package (for higher-level interfaces).
// or the exec package (for higher-level interfaces).
func
Exec
(
name
string
,
argv
[]
string
,
envv
[]
string
)
E
rror
{
func
Exec
(
name
string
,
argv
[]
string
,
envv
[]
string
)
e
rror
{
if
envv
==
nil
{
if
envv
==
nil
{
envv
=
Environ
()
envv
=
Environ
()
}
}
...
@@ -83,11 +83,11 @@ type Waitmsg struct {
...
@@ -83,11 +83,11 @@ type Waitmsg struct {
}
}
// Wait waits for process pid to exit or stop, and then returns a
// Wait waits for process pid to exit or stop, and then returns a
// Waitmsg describing its status and an
E
rror, if any. The options
// Waitmsg describing its status and an
e
rror, if any. The options
// (WNOHANG etc.) affect the behavior of the Wait call.
// (WNOHANG etc.) affect the behavior of the Wait call.
// Wait is equivalent to calling FindProcess and then Wait
// Wait is equivalent to calling FindProcess and then Wait
// and Release on the result.
// and Release on the result.
func
Wait
(
pid
int
,
options
int
)
(
w
*
Waitmsg
,
err
E
rror
)
{
func
Wait
(
pid
int
,
options
int
)
(
w
*
Waitmsg
,
err
e
rror
)
{
p
,
e
:=
FindProcess
(
pid
)
p
,
e
:=
FindProcess
(
pid
)
if
e
!=
nil
{
if
e
!=
nil
{
return
nil
,
e
return
nil
,
e
...
...
src/pkg/os/exec_unix.go
View file @
08a073a1
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
package
os
package
os
import
(
import
(
"errors"
"runtime"
"runtime"
"syscall"
"syscall"
)
)
...
@@ -24,9 +25,9 @@ const (
...
@@ -24,9 +25,9 @@ const (
// the options
// the options
// Wait waits for the Process to exit or stop, and then returns a
// Wait waits for the Process to exit or stop, and then returns a
// Waitmsg describing its status and an
E
rror, if any. The options
// Waitmsg describing its status and an
e
rror, if any. The options
// (WNOHANG etc.) affect the behavior of the Wait call.
// (WNOHANG etc.) affect the behavior of the Wait call.
func
(
p
*
Process
)
Wait
(
options
int
)
(
w
*
Waitmsg
,
err
E
rror
)
{
func
(
p
*
Process
)
Wait
(
options
int
)
(
w
*
Waitmsg
,
err
e
rror
)
{
if
p
.
Pid
==
-
1
{
if
p
.
Pid
==
-
1
{
return
nil
,
EINVAL
return
nil
,
EINVAL
}
}
...
@@ -52,9 +53,9 @@ func (p *Process) Wait(options int) (w *Waitmsg, err Error) {
...
@@ -52,9 +53,9 @@ func (p *Process) Wait(options int) (w *Waitmsg, err Error) {
}
}
// Signal sends a signal to the Process.
// Signal sends a signal to the Process.
func
(
p
*
Process
)
Signal
(
sig
Signal
)
E
rror
{
func
(
p
*
Process
)
Signal
(
sig
Signal
)
e
rror
{
if
p
.
done
{
if
p
.
done
{
return
NewError
(
"os: process already finished"
)
return
errors
.
New
(
"os: process already finished"
)
}
}
if
e
:=
syscall
.
Kill
(
p
.
Pid
,
int
(
sig
.
(
UnixSignal
)));
e
!=
0
{
if
e
:=
syscall
.
Kill
(
p
.
Pid
,
int
(
sig
.
(
UnixSignal
)));
e
!=
0
{
return
Errno
(
e
)
return
Errno
(
e
)
...
@@ -63,7 +64,7 @@ func (p *Process) Signal(sig Signal) Error {
...
@@ -63,7 +64,7 @@ func (p *Process) Signal(sig Signal) Error {
}
}
// Release releases any resources associated with the Process.
// Release releases any resources associated with the Process.
func
(
p
*
Process
)
Release
()
E
rror
{
func
(
p
*
Process
)
Release
()
e
rror
{
// NOOP for unix.
// NOOP for unix.
p
.
Pid
=
-
1
p
.
Pid
=
-
1
// no need for a finalizer anymore
// no need for a finalizer anymore
...
@@ -74,7 +75,7 @@ func (p *Process) Release() Error {
...
@@ -74,7 +75,7 @@ func (p *Process) Release() Error {
// FindProcess looks for a running process by its pid.
// FindProcess looks for a running process by its pid.
// The Process it returns can be used to obtain information
// The Process it returns can be used to obtain information
// about the underlying operating system process.
// about the underlying operating system process.
func
FindProcess
(
pid
int
)
(
p
*
Process
,
err
E
rror
)
{
func
FindProcess
(
pid
int
)
(
p
*
Process
,
err
e
rror
)
{
// NOOP for unix.
// NOOP for unix.
return
newProcess
(
pid
,
0
),
nil
return
newProcess
(
pid
,
0
),
nil
}
}
src/pkg/os/exec_windows.go
View file @
08a073a1
...
@@ -9,7 +9,7 @@ import (
...
@@ -9,7 +9,7 @@ import (
"syscall"
"syscall"
)
)
func
(
p
*
Process
)
Wait
(
options
int
)
(
w
*
Waitmsg
,
err
E
rror
)
{
func
(
p
*
Process
)
Wait
(
options
int
)
(
w
*
Waitmsg
,
err
e
rror
)
{
s
,
e
:=
syscall
.
WaitForSingleObject
(
syscall
.
Handle
(
p
.
handle
),
syscall
.
INFINITE
)
s
,
e
:=
syscall
.
WaitForSingleObject
(
syscall
.
Handle
(
p
.
handle
),
syscall
.
INFINITE
)
switch
s
{
switch
s
{
case
syscall
.
WAIT_OBJECT_0
:
case
syscall
.
WAIT_OBJECT_0
:
...
@@ -29,7 +29,7 @@ func (p *Process) Wait(options int) (w *Waitmsg, err Error) {
...
@@ -29,7 +29,7 @@ func (p *Process) Wait(options int) (w *Waitmsg, err Error) {
}
}
// Signal sends a signal to the Process.
// Signal sends a signal to the Process.
func
(
p
*
Process
)
Signal
(
sig
Signal
)
E
rror
{
func
(
p
*
Process
)
Signal
(
sig
Signal
)
e
rror
{
if
p
.
done
{
if
p
.
done
{
return
NewError
(
"os: process already finished"
)
return
NewError
(
"os: process already finished"
)
}
}
...
@@ -41,7 +41,7 @@ func (p *Process) Signal(sig Signal) Error {
...
@@ -41,7 +41,7 @@ func (p *Process) Signal(sig Signal) Error {
return
Errno
(
syscall
.
EWINDOWS
)
return
Errno
(
syscall
.
EWINDOWS
)
}
}
func
(
p
*
Process
)
Release
()
E
rror
{
func
(
p
*
Process
)
Release
()
e
rror
{
if
p
.
handle
==
-
1
{
if
p
.
handle
==
-
1
{
return
EINVAL
return
EINVAL
}
}
...
@@ -55,7 +55,7 @@ func (p *Process) Release() Error {
...
@@ -55,7 +55,7 @@ func (p *Process) Release() Error {
return
nil
return
nil
}
}
func
FindProcess
(
pid
int
)
(
p
*
Process
,
err
E
rror
)
{
func
FindProcess
(
pid
int
)
(
p
*
Process
,
err
e
rror
)
{
const
da
=
syscall
.
STANDARD_RIGHTS_READ
|
const
da
=
syscall
.
STANDARD_RIGHTS_READ
|
syscall
.
PROCESS_QUERY_INFORMATION
|
syscall
.
SYNCHRONIZE
syscall
.
PROCESS_QUERY_INFORMATION
|
syscall
.
SYNCHRONIZE
h
,
e
:=
syscall
.
OpenProcess
(
da
,
false
,
uint32
(
pid
))
h
,
e
:=
syscall
.
OpenProcess
(
da
,
false
,
uint32
(
pid
))
...
...
src/pkg/os/file.go
View file @
08a073a1
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
package
os
package
os
import
(
import
(
"io"
"syscall"
"syscall"
)
)
...
@@ -47,21 +48,10 @@ const (
...
@@ -47,21 +48,10 @@ const (
SEEK_END
int
=
2
// seek relative to the end
SEEK_END
int
=
2
// seek relative to the end
)
)
type
eofError
int
func
(
eofError
)
String
()
string
{
return
"EOF"
}
// EOF is the Error returned by Read when no more input is available.
// Functions should return EOF only to signal a graceful end of input.
// If the EOF occurs unexpectedly in a structured data stream,
// the appropriate error is either io.ErrUnexpectedEOF or some other error
// giving more detail.
var
EOF
Error
=
eofError
(
0
)
// Read reads up to len(b) bytes from the File.
// Read reads up to len(b) bytes from the File.
// It returns the number of bytes read and an
E
rror, if any.
// It returns the number of bytes read and an
e
rror, if any.
// EOF is signaled by a zero count with err set to EOF.
// EOF is signaled by a zero count with err set to
io.
EOF.
func
(
file
*
File
)
Read
(
b
[]
byte
)
(
n
int
,
err
E
rror
)
{
func
(
file
*
File
)
Read
(
b
[]
byte
)
(
n
int
,
err
e
rror
)
{
if
file
==
nil
{
if
file
==
nil
{
return
0
,
EINVAL
return
0
,
EINVAL
}
}
...
@@ -70,7 +60,7 @@ func (file *File) Read(b []byte) (n int, err Error) {
...
@@ -70,7 +60,7 @@ func (file *File) Read(b []byte) (n int, err Error) {
n
=
0
n
=
0
}
}
if
n
==
0
&&
len
(
b
)
>
0
&&
!
iserror
(
e
)
{
if
n
==
0
&&
len
(
b
)
>
0
&&
!
iserror
(
e
)
{
return
0
,
EOF
return
0
,
io
.
EOF
}
}
if
iserror
(
e
)
{
if
iserror
(
e
)
{
err
=
&
PathError
{
"read"
,
file
.
name
,
Errno
(
e
)}
err
=
&
PathError
{
"read"
,
file
.
name
,
Errno
(
e
)}
...
@@ -79,17 +69,17 @@ func (file *File) Read(b []byte) (n int, err Error) {
...
@@ -79,17 +69,17 @@ func (file *File) Read(b []byte) (n int, err Error) {
}
}
// ReadAt reads len(b) bytes from the File starting at byte offset off.
// ReadAt reads len(b) bytes from the File starting at byte offset off.
// It returns the number of bytes read and the
E
rror, if any.
// It returns the number of bytes read and the
e
rror, if any.
// EOF is signaled by a zero count with err set to EOF.
// EOF is signaled by a zero count with err set to
io.
EOF.
// ReadAt always returns a non-nil
E
rror when n != len(b).
// ReadAt always returns a non-nil
e
rror when n != len(b).
func
(
file
*
File
)
ReadAt
(
b
[]
byte
,
off
int64
)
(
n
int
,
err
E
rror
)
{
func
(
file
*
File
)
ReadAt
(
b
[]
byte
,
off
int64
)
(
n
int
,
err
e
rror
)
{
if
file
==
nil
{
if
file
==
nil
{
return
0
,
EINVAL
return
0
,
EINVAL
}
}
for
len
(
b
)
>
0
{
for
len
(
b
)
>
0
{
m
,
e
:=
file
.
pread
(
b
,
off
)
m
,
e
:=
file
.
pread
(
b
,
off
)
if
m
==
0
&&
!
iserror
(
e
)
{
if
m
==
0
&&
!
iserror
(
e
)
{
return
n
,
EOF
return
n
,
io
.
EOF
}
}
if
iserror
(
e
)
{
if
iserror
(
e
)
{
err
=
&
PathError
{
"read"
,
file
.
name
,
Errno
(
e
)}
err
=
&
PathError
{
"read"
,
file
.
name
,
Errno
(
e
)}
...
@@ -103,9 +93,9 @@ func (file *File) ReadAt(b []byte, off int64) (n int, err Error) {
...
@@ -103,9 +93,9 @@ func (file *File) ReadAt(b []byte, off int64) (n int, err Error) {
}
}
// Write writes len(b) bytes to the File.
// Write writes len(b) bytes to the File.
// It returns the number of bytes written and an
E
rror, if any.
// It returns the number of bytes written and an
e
rror, if any.
// Write returns a non-nil
E
rror when n != len(b).
// Write returns a non-nil
e
rror when n != len(b).
func
(
file
*
File
)
Write
(
b
[]
byte
)
(
n
int
,
err
E
rror
)
{
func
(
file
*
File
)
Write
(
b
[]
byte
)
(
n
int
,
err
e
rror
)
{
if
file
==
nil
{
if
file
==
nil
{
return
0
,
EINVAL
return
0
,
EINVAL
}
}
...
@@ -123,9 +113,9 @@ func (file *File) Write(b []byte) (n int, err Error) {
...
@@ -123,9 +113,9 @@ func (file *File) Write(b []byte) (n int, err Error) {
}
}
// WriteAt writes len(b) bytes to the File starting at byte offset off.
// WriteAt writes len(b) bytes to the File starting at byte offset off.
// It returns the number of bytes written and an
E
rror, if any.
// It returns the number of bytes written and an
e
rror, if any.
// WriteAt returns a non-nil
E
rror when n != len(b).
// WriteAt returns a non-nil
e
rror when n != len(b).
func
(
file
*
File
)
WriteAt
(
b
[]
byte
,
off
int64
)
(
n
int
,
err
E
rror
)
{
func
(
file
*
File
)
WriteAt
(
b
[]
byte
,
off
int64
)
(
n
int
,
err
e
rror
)
{
if
file
==
nil
{
if
file
==
nil
{
return
0
,
EINVAL
return
0
,
EINVAL
}
}
...
@@ -145,8 +135,8 @@ func (file *File) WriteAt(b []byte, off int64) (n int, err Error) {
...
@@ -145,8 +135,8 @@ func (file *File) WriteAt(b []byte, off int64) (n int, err Error) {
// Seek sets the offset for the next Read or Write on file to offset, interpreted
// Seek sets the offset for the next Read or Write on file to offset, interpreted
// according to whence: 0 means relative to the origin of the file, 1 means
// according to whence: 0 means relative to the origin of the file, 1 means
// relative to the current offset, and 2 means relative to the end.
// relative to the current offset, and 2 means relative to the end.
// It returns the new offset and an
E
rror, if any.
// It returns the new offset and an
e
rror, if any.
func
(
file
*
File
)
Seek
(
offset
int64
,
whence
int
)
(
ret
int64
,
err
E
rror
)
{
func
(
file
*
File
)
Seek
(
offset
int64
,
whence
int
)
(
ret
int64
,
err
e
rror
)
{
r
,
e
:=
file
.
seek
(
offset
,
whence
)
r
,
e
:=
file
.
seek
(
offset
,
whence
)
if
!
iserror
(
e
)
&&
file
.
dirinfo
!=
nil
&&
r
!=
0
{
if
!
iserror
(
e
)
&&
file
.
dirinfo
!=
nil
&&
r
!=
0
{
e
=
syscall
.
EISDIR
e
=
syscall
.
EISDIR
...
@@ -159,7 +149,7 @@ func (file *File) Seek(offset int64, whence int) (ret int64, err Error) {
...
@@ -159,7 +149,7 @@ func (file *File) Seek(offset int64, whence int) (ret int64, err Error) {
// WriteString is like Write, but writes the contents of string s rather than
// WriteString is like Write, but writes the contents of string s rather than
// an array of bytes.
// an array of bytes.
func
(
file
*
File
)
WriteString
(
s
string
)
(
ret
int
,
err
E
rror
)
{
func
(
file
*
File
)
WriteString
(
s
string
)
(
ret
int
,
err
e
rror
)
{
if
file
==
nil
{
if
file
==
nil
{
return
0
,
EINVAL
return
0
,
EINVAL
}
}
...
@@ -168,7 +158,7 @@ func (file *File) WriteString(s string) (ret int, err Error) {
...
@@ -168,7 +158,7 @@ func (file *File) WriteString(s string) (ret int, err Error) {
// Mkdir creates a new directory with the specified name and permission bits.
// Mkdir creates a new directory with the specified name and permission bits.
// It returns an error, if any.
// It returns an error, if any.
func
Mkdir
(
name
string
,
perm
uint32
)
E
rror
{
func
Mkdir
(
name
string
,
perm
uint32
)
e
rror
{
e
:=
syscall
.
Mkdir
(
name
,
perm
)
e
:=
syscall
.
Mkdir
(
name
,
perm
)
if
iserror
(
e
)
{
if
iserror
(
e
)
{
return
&
PathError
{
"mkdir"
,
name
,
Errno
(
e
)}
return
&
PathError
{
"mkdir"
,
name
,
Errno
(
e
)}
...
@@ -177,7 +167,7 @@ func Mkdir(name string, perm uint32) Error {
...
@@ -177,7 +167,7 @@ func Mkdir(name string, perm uint32) Error {
}
}
// Chdir changes the current working directory to the named directory.
// Chdir changes the current working directory to the named directory.
func
Chdir
(
dir
string
)
E
rror
{
func
Chdir
(
dir
string
)
e
rror
{
if
e
:=
syscall
.
Chdir
(
dir
);
iserror
(
e
)
{
if
e
:=
syscall
.
Chdir
(
dir
);
iserror
(
e
)
{
return
&
PathError
{
"chdir"
,
dir
,
Errno
(
e
)}
return
&
PathError
{
"chdir"
,
dir
,
Errno
(
e
)}
}
}
...
@@ -186,7 +176,7 @@ func Chdir(dir string) Error {
...
@@ -186,7 +176,7 @@ func Chdir(dir string) Error {
// Chdir changes the current working directory to the file,
// Chdir changes the current working directory to the file,
// which must be a directory.
// which must be a directory.
func
(
f
*
File
)
Chdir
()
E
rror
{
func
(
f
*
File
)
Chdir
()
e
rror
{
if
e
:=
syscall
.
Fchdir
(
f
.
fd
);
iserror
(
e
)
{
if
e
:=
syscall
.
Fchdir
(
f
.
fd
);
iserror
(
e
)
{
return
&
PathError
{
"chdir"
,
f
.
name
,
Errno
(
e
)}
return
&
PathError
{
"chdir"
,
f
.
name
,
Errno
(
e
)}
}
}
...
@@ -196,8 +186,8 @@ func (f *File) Chdir() Error {
...
@@ -196,8 +186,8 @@ func (f *File) Chdir() Error {
// Open opens the named file for reading. If successful, methods on
// Open opens the named file for reading. If successful, methods on
// the returned file can be used for reading; the associated file
// the returned file can be used for reading; the associated file
// descriptor has mode O_RDONLY.
// descriptor has mode O_RDONLY.
// It returns the File and an
E
rror, if any.
// It returns the File and an
e
rror, if any.
func
Open
(
name
string
)
(
file
*
File
,
err
E
rror
)
{
func
Open
(
name
string
)
(
file
*
File
,
err
e
rror
)
{
return
OpenFile
(
name
,
O_RDONLY
,
0
)
return
OpenFile
(
name
,
O_RDONLY
,
0
)
}
}
...
@@ -205,7 +195,7 @@ func Open(name string) (file *File, err Error) {
...
@@ -205,7 +195,7 @@ func Open(name string) (file *File, err Error) {
// it if it already exists. If successful, methods on the returned
// it if it already exists. If successful, methods on the returned
// File can be used for I/O; the associated file descriptor has mode
// File can be used for I/O; the associated file descriptor has mode
// O_RDWR.
// O_RDWR.
// It returns the File and an
E
rror, if any.
// It returns the File and an
e
rror, if any.
func
Create
(
name
string
)
(
file
*
File
,
err
E
rror
)
{
func
Create
(
name
string
)
(
file
*
File
,
err
e
rror
)
{
return
OpenFile
(
name
,
O_RDWR
|
O_CREATE
|
O_TRUNC
,
0666
)
return
OpenFile
(
name
,
O_RDWR
|
O_CREATE
|
O_TRUNC
,
0666
)
}
}
src/pkg/os/file_plan9.go
View file @
08a073a1
...
@@ -52,8 +52,8 @@ const DevNull = "/dev/null"
...
@@ -52,8 +52,8 @@ const DevNull = "/dev/null"
// or Create instead. It opens the named file with specified flag
// or Create instead. It opens the named file with specified flag
// (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful,
// (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful,
// methods on the returned File can be used for I/O.
// methods on the returned File can be used for I/O.
// It returns the File and an
E
rror, if any.
// It returns the File and an
e
rror, if any.
func
OpenFile
(
name
string
,
flag
int
,
perm
uint32
)
(
file
*
File
,
err
E
rror
)
{
func
OpenFile
(
name
string
,
flag
int
,
perm
uint32
)
(
file
*
File
,
err
e
rror
)
{
var
(
var
(
fd
int
fd
int
e
syscall
.
Error
e
syscall
.
Error
...
@@ -108,12 +108,12 @@ func OpenFile(name string, flag int, perm uint32) (file *File, err Error) {
...
@@ -108,12 +108,12 @@ func OpenFile(name string, flag int, perm uint32) (file *File, err Error) {
}
}
// Close closes the File, rendering it unusable for I/O.
// Close closes the File, rendering it unusable for I/O.
// It returns an
E
rror, if any.
// It returns an
e
rror, if any.
func
(
file
*
File
)
Close
()
E
rror
{
func
(
file
*
File
)
Close
()
e
rror
{
if
file
==
nil
||
file
.
fd
<
0
{
if
file
==
nil
||
file
.
fd
<
0
{
return
Ebadfd
return
Ebadfd
}
}
var
err
E
rror
var
err
e
rror
syscall
.
ForkLock
.
RLock
()
syscall
.
ForkLock
.
RLock
()
if
e
:=
syscall
.
Close
(
file
.
fd
);
e
!=
nil
{
if
e
:=
syscall
.
Close
(
file
.
fd
);
e
!=
nil
{
err
=
&
PathError
{
"close"
,
file
.
name
,
e
}
err
=
&
PathError
{
"close"
,
file
.
name
,
e
}
...
@@ -128,7 +128,7 @@ func (file *File) Close() Error {
...
@@ -128,7 +128,7 @@ func (file *File) Close() Error {
// Stat returns the FileInfo structure describing file.
// Stat returns the FileInfo structure describing file.
// It returns the FileInfo and an error, if any.
// It returns the FileInfo and an error, if any.
func
(
f
*
File
)
Stat
()
(
fi
*
FileInfo
,
err
E
rror
)
{
func
(
f
*
File
)
Stat
()
(
fi
*
FileInfo
,
err
e
rror
)
{
d
,
err
:=
dirstat
(
f
)
d
,
err
:=
dirstat
(
f
)
if
iserror
(
err
)
{
if
iserror
(
err
)
{
return
nil
,
err
return
nil
,
err
...
@@ -138,7 +138,7 @@ func (f *File) Stat() (fi *FileInfo, err Error) {
...
@@ -138,7 +138,7 @@ func (f *File) Stat() (fi *FileInfo, err Error) {
// Truncate changes the size of the file.
// Truncate changes the size of the file.
// It does not change the I/O offset.
// It does not change the I/O offset.
func
(
f
*
File
)
Truncate
(
size
int64
)
E
rror
{
func
(
f
*
File
)
Truncate
(
size
int64
)
e
rror
{
var
d
Dir
var
d
Dir
d
.
Null
()
d
.
Null
()
...
@@ -151,7 +151,7 @@ func (f *File) Truncate(size int64) Error {
...
@@ -151,7 +151,7 @@ func (f *File) Truncate(size int64) Error {
}
}
// Chmod changes the mode of the file to mode.
// Chmod changes the mode of the file to mode.
func
(
f
*
File
)
Chmod
(
mode
uint32
)
E
rror
{
func
(
f
*
File
)
Chmod
(
mode
uint32
)
e
rror
{
var
d
Dir
var
d
Dir
var
mask
=
^
uint32
(
0777
)
var
mask
=
^
uint32
(
0777
)
...
@@ -171,7 +171,7 @@ func (f *File) Chmod(mode uint32) Error {
...
@@ -171,7 +171,7 @@ func (f *File) Chmod(mode uint32) Error {
// Sync commits the current contents of the file to stable storage.
// Sync commits the current contents of the file to stable storage.
// Typically, this means flushing the file system's in-memory copy
// Typically, this means flushing the file system's in-memory copy
// of recently written data to disk.
// of recently written data to disk.
func
(
f
*
File
)
Sync
()
(
err
E
rror
)
{
func
(
f
*
File
)
Sync
()
(
err
e
rror
)
{
if
f
==
nil
{
if
f
==
nil
{
return
EINVAL
return
EINVAL
}
}
...
@@ -220,7 +220,7 @@ func (f *File) seek(offset int64, whence int) (ret int64, err syscall.Error) {
...
@@ -220,7 +220,7 @@ func (f *File) seek(offset int64, whence int) (ret int64, err syscall.Error) {
// Truncate changes the size of the named file.
// Truncate changes the size of the named file.
// If the file is a symbolic link, it changes the size of the link's target.
// If the file is a symbolic link, it changes the size of the link's target.
func
Truncate
(
name
string
,
size
int64
)
E
rror
{
func
Truncate
(
name
string
,
size
int64
)
e
rror
{
var
d
Dir
var
d
Dir
d
.
Null
()
d
.
Null
()
...
@@ -233,7 +233,7 @@ func Truncate(name string, size int64) Error {
...
@@ -233,7 +233,7 @@ func Truncate(name string, size int64) Error {
}
}
// Remove removes the named file or directory.
// Remove removes the named file or directory.
func
Remove
(
name
string
)
E
rror
{
func
Remove
(
name
string
)
e
rror
{
if
e
:=
syscall
.
Remove
(
name
);
iserror
(
e
)
{
if
e
:=
syscall
.
Remove
(
name
);
iserror
(
e
)
{
return
&
PathError
{
"remove"
,
name
,
e
}
return
&
PathError
{
"remove"
,
name
,
e
}
}
}
...
@@ -241,7 +241,7 @@ func Remove(name string) Error {
...
@@ -241,7 +241,7 @@ func Remove(name string) Error {
}
}
// Rename renames a file.
// Rename renames a file.
func
Rename
(
oldname
,
newname
string
)
E
rror
{
func
Rename
(
oldname
,
newname
string
)
e
rror
{
var
d
Dir
var
d
Dir
d
.
Null
()
d
.
Null
()
...
@@ -254,7 +254,7 @@ func Rename(oldname, newname string) Error {
...
@@ -254,7 +254,7 @@ func Rename(oldname, newname string) Error {
}
}
// Chmod changes the mode of the named file to mode.
// Chmod changes the mode of the named file to mode.
func
Chmod
(
name
string
,
mode
uint32
)
E
rror
{
func
Chmod
(
name
string
,
mode
uint32
)
e
rror
{
var
d
Dir
var
d
Dir
var
mask
=
^
uint32
(
0777
)
var
mask
=
^
uint32
(
0777
)
...
@@ -277,7 +277,7 @@ func Chmod(name string, mode uint32) Error {
...
@@ -277,7 +277,7 @@ func Chmod(name string, mode uint32) Error {
// The argument times are in nanoseconds, although the underlying
// The argument times are in nanoseconds, although the underlying
// filesystem may truncate or round the values to a more
// filesystem may truncate or round the values to a more
// coarse time unit.
// coarse time unit.
func
Chtimes
(
name
string
,
atimeNs
int64
,
mtimeNs
int64
)
E
rror
{
func
Chtimes
(
name
string
,
atimeNs
int64
,
mtimeNs
int64
)
e
rror
{
var
d
Dir
var
d
Dir
d
.
Null
()
d
.
Null
()
...
@@ -290,7 +290,7 @@ func Chtimes(name string, atimeNs int64, mtimeNs int64) Error {
...
@@ -290,7 +290,7 @@ func Chtimes(name string, atimeNs int64, mtimeNs int64) Error {
return
nil
return
nil
}
}
func
Pipe
()
(
r
*
File
,
w
*
File
,
err
E
rror
)
{
func
Pipe
()
(
r
*
File
,
w
*
File
,
err
e
rror
)
{
var
p
[
2
]
int
var
p
[
2
]
int
syscall
.
ForkLock
.
RLock
()
syscall
.
ForkLock
.
RLock
()
...
@@ -306,26 +306,26 @@ func Pipe() (r *File, w *File, err Error) {
...
@@ -306,26 +306,26 @@ func Pipe() (r *File, w *File, err Error) {
// not supported on Plan 9
// not supported on Plan 9
// Link creates a hard link.
// Link creates a hard link.
func
Link
(
oldname
,
newname
string
)
E
rror
{
func
Link
(
oldname
,
newname
string
)
e
rror
{
return
EPLAN9
return
EPLAN9
}
}
func
Symlink
(
oldname
,
newname
string
)
E
rror
{
func
Symlink
(
oldname
,
newname
string
)
e
rror
{
return
EPLAN9
return
EPLAN9
}
}
func
Readlink
(
name
string
)
(
string
,
E
rror
)
{
func
Readlink
(
name
string
)
(
string
,
e
rror
)
{
return
""
,
EPLAN9
return
""
,
EPLAN9
}
}
func
Chown
(
name
string
,
uid
,
gid
int
)
E
rror
{
func
Chown
(
name
string
,
uid
,
gid
int
)
e
rror
{
return
EPLAN9
return
EPLAN9
}
}
func
Lchown
(
name
string
,
uid
,
gid
int
)
E
rror
{
func
Lchown
(
name
string
,
uid
,
gid
int
)
e
rror
{
return
EPLAN9
return
EPLAN9
}
}
func
(
f
*
File
)
Chown
(
uid
,
gid
int
)
E
rror
{
func
(
f
*
File
)
Chown
(
uid
,
gid
int
)
e
rror
{
return
EPLAN9
return
EPLAN9
}
}
src/pkg/os/file_posix.go
View file @
08a073a1
...
@@ -24,7 +24,7 @@ func epipecheck(file *File, e int) {
...
@@ -24,7 +24,7 @@ func epipecheck(file *File, e int) {
}
}
// Remove removes the named file or directory.
// Remove removes the named file or directory.
func
Remove
(
name
string
)
E
rror
{
func
Remove
(
name
string
)
e
rror
{
// System call interface forces us to know
// System call interface forces us to know
// whether name is a file or directory.
// whether name is a file or directory.
// Try both: it is cheaper on average than
// Try both: it is cheaper on average than
...
@@ -62,15 +62,15 @@ type LinkError struct {
...
@@ -62,15 +62,15 @@ type LinkError struct {
Op
string
Op
string
Old
string
Old
string
New
string
New
string
Err
or
E
rror
Err
e
rror
}
}
func
(
e
*
LinkError
)
String
()
string
{
func
(
e
*
LinkError
)
Error
()
string
{
return
e
.
Op
+
" "
+
e
.
Old
+
" "
+
e
.
New
+
": "
+
e
.
Err
or
.
String
()
return
e
.
Op
+
" "
+
e
.
Old
+
" "
+
e
.
New
+
": "
+
e
.
Err
.
Error
()
}
}
// Link creates a hard link.
// Link creates a hard link.
func
Link
(
oldname
,
newname
string
)
E
rror
{
func
Link
(
oldname
,
newname
string
)
e
rror
{
e
:=
syscall
.
Link
(
oldname
,
newname
)
e
:=
syscall
.
Link
(
oldname
,
newname
)
if
iserror
(
e
)
{
if
iserror
(
e
)
{
return
&
LinkError
{
"link"
,
oldname
,
newname
,
Errno
(
e
)}
return
&
LinkError
{
"link"
,
oldname
,
newname
,
Errno
(
e
)}
...
@@ -79,7 +79,7 @@ func Link(oldname, newname string) Error {
...
@@ -79,7 +79,7 @@ func Link(oldname, newname string) Error {
}
}
// Symlink creates a symbolic link.
// Symlink creates a symbolic link.
func
Symlink
(
oldname
,
newname
string
)
E
rror
{
func
Symlink
(
oldname
,
newname
string
)
e
rror
{
e
:=
syscall
.
Symlink
(
oldname
,
newname
)
e
:=
syscall
.
Symlink
(
oldname
,
newname
)
if
iserror
(
e
)
{
if
iserror
(
e
)
{
return
&
LinkError
{
"symlink"
,
oldname
,
newname
,
Errno
(
e
)}
return
&
LinkError
{
"symlink"
,
oldname
,
newname
,
Errno
(
e
)}
...
@@ -88,8 +88,8 @@ func Symlink(oldname, newname string) Error {
...
@@ -88,8 +88,8 @@ func Symlink(oldname, newname string) Error {
}
}
// Readlink reads the contents of a symbolic link: the destination of
// Readlink reads the contents of a symbolic link: the destination of
// the link. It returns the contents and an
E
rror, if any.
// the link. It returns the contents and an
e
rror, if any.
func
Readlink
(
name
string
)
(
string
,
E
rror
)
{
func
Readlink
(
name
string
)
(
string
,
e
rror
)
{
for
len
:=
128
;
;
len
*=
2
{
for
len
:=
128
;
;
len
*=
2
{
b
:=
make
([]
byte
,
len
)
b
:=
make
([]
byte
,
len
)
n
,
e
:=
syscall
.
Readlink
(
name
,
b
)
n
,
e
:=
syscall
.
Readlink
(
name
,
b
)
...
@@ -105,7 +105,7 @@ func Readlink(name string) (string, Error) {
...
@@ -105,7 +105,7 @@ func Readlink(name string) (string, Error) {
}
}
// Rename renames a file.
// Rename renames a file.
func
Rename
(
oldname
,
newname
string
)
E
rror
{
func
Rename
(
oldname
,
newname
string
)
e
rror
{
e
:=
syscall
.
Rename
(
oldname
,
newname
)
e
:=
syscall
.
Rename
(
oldname
,
newname
)
if
iserror
(
e
)
{
if
iserror
(
e
)
{
return
&
LinkError
{
"rename"
,
oldname
,
newname
,
Errno
(
e
)}
return
&
LinkError
{
"rename"
,
oldname
,
newname
,
Errno
(
e
)}
...
@@ -115,7 +115,7 @@ func Rename(oldname, newname string) Error {
...
@@ -115,7 +115,7 @@ func Rename(oldname, newname string) Error {
// Chmod changes the mode of the named file to mode.
// Chmod changes the mode of the named file to mode.
// If the file is a symbolic link, it changes the mode of the link's target.
// If the file is a symbolic link, it changes the mode of the link's target.
func
Chmod
(
name
string
,
mode
uint32
)
E
rror
{
func
Chmod
(
name
string
,
mode
uint32
)
e
rror
{
if
e
:=
syscall
.
Chmod
(
name
,
mode
);
iserror
(
e
)
{
if
e
:=
syscall
.
Chmod
(
name
,
mode
);
iserror
(
e
)
{
return
&
PathError
{
"chmod"
,
name
,
Errno
(
e
)}
return
&
PathError
{
"chmod"
,
name
,
Errno
(
e
)}
}
}
...
@@ -123,7 +123,7 @@ func Chmod(name string, mode uint32) Error {
...
@@ -123,7 +123,7 @@ func Chmod(name string, mode uint32) Error {
}
}
// Chmod changes the mode of the file to mode.
// Chmod changes the mode of the file to mode.
func
(
f
*
File
)
Chmod
(
mode
uint32
)
E
rror
{
func
(
f
*
File
)
Chmod
(
mode
uint32
)
e
rror
{
if
e
:=
syscall
.
Fchmod
(
f
.
fd
,
mode
);
iserror
(
e
)
{
if
e
:=
syscall
.
Fchmod
(
f
.
fd
,
mode
);
iserror
(
e
)
{
return
&
PathError
{
"chmod"
,
f
.
name
,
Errno
(
e
)}
return
&
PathError
{
"chmod"
,
f
.
name
,
Errno
(
e
)}
}
}
...
@@ -132,7 +132,7 @@ func (f *File) Chmod(mode uint32) Error {
...
@@ -132,7 +132,7 @@ func (f *File) Chmod(mode uint32) Error {
// Chown changes the numeric uid and gid of the named file.
// Chown changes the numeric uid and gid of the named file.
// If the file is a symbolic link, it changes the uid and gid of the link's target.
// If the file is a symbolic link, it changes the uid and gid of the link's target.
func
Chown
(
name
string
,
uid
,
gid
int
)
E
rror
{
func
Chown
(
name
string
,
uid
,
gid
int
)
e
rror
{
if
e
:=
syscall
.
Chown
(
name
,
uid
,
gid
);
iserror
(
e
)
{
if
e
:=
syscall
.
Chown
(
name
,
uid
,
gid
);
iserror
(
e
)
{
return
&
PathError
{
"chown"
,
name
,
Errno
(
e
)}
return
&
PathError
{
"chown"
,
name
,
Errno
(
e
)}
}
}
...
@@ -141,7 +141,7 @@ func Chown(name string, uid, gid int) Error {
...
@@ -141,7 +141,7 @@ func Chown(name string, uid, gid int) Error {
// Lchown changes the numeric uid and gid of the named file.
// Lchown changes the numeric uid and gid of the named file.
// If the file is a symbolic link, it changes the uid and gid of the link itself.
// If the file is a symbolic link, it changes the uid and gid of the link itself.
func
Lchown
(
name
string
,
uid
,
gid
int
)
E
rror
{
func
Lchown
(
name
string
,
uid
,
gid
int
)
e
rror
{
if
e
:=
syscall
.
Lchown
(
name
,
uid
,
gid
);
iserror
(
e
)
{
if
e
:=
syscall
.
Lchown
(
name
,
uid
,
gid
);
iserror
(
e
)
{
return
&
PathError
{
"lchown"
,
name
,
Errno
(
e
)}
return
&
PathError
{
"lchown"
,
name
,
Errno
(
e
)}
}
}
...
@@ -149,7 +149,7 @@ func Lchown(name string, uid, gid int) Error {
...
@@ -149,7 +149,7 @@ func Lchown(name string, uid, gid int) Error {
}
}
// Chown changes the numeric uid and gid of the named file.
// Chown changes the numeric uid and gid of the named file.
func
(
f
*
File
)
Chown
(
uid
,
gid
int
)
E
rror
{
func
(
f
*
File
)
Chown
(
uid
,
gid
int
)
e
rror
{
if
e
:=
syscall
.
Fchown
(
f
.
fd
,
uid
,
gid
);
iserror
(
e
)
{
if
e
:=
syscall
.
Fchown
(
f
.
fd
,
uid
,
gid
);
iserror
(
e
)
{
return
&
PathError
{
"chown"
,
f
.
name
,
Errno
(
e
)}
return
&
PathError
{
"chown"
,
f
.
name
,
Errno
(
e
)}
}
}
...
@@ -158,7 +158,7 @@ func (f *File) Chown(uid, gid int) Error {
...
@@ -158,7 +158,7 @@ func (f *File) Chown(uid, gid int) Error {
// Truncate changes the size of the file.
// Truncate changes the size of the file.
// It does not change the I/O offset.
// It does not change the I/O offset.
func
(
f
*
File
)
Truncate
(
size
int64
)
E
rror
{
func
(
f
*
File
)
Truncate
(
size
int64
)
e
rror
{
if
e
:=
syscall
.
Ftruncate
(
f
.
fd
,
size
);
iserror
(
e
)
{
if
e
:=
syscall
.
Ftruncate
(
f
.
fd
,
size
);
iserror
(
e
)
{
return
&
PathError
{
"truncate"
,
f
.
name
,
Errno
(
e
)}
return
&
PathError
{
"truncate"
,
f
.
name
,
Errno
(
e
)}
}
}
...
@@ -168,7 +168,7 @@ func (f *File) Truncate(size int64) Error {
...
@@ -168,7 +168,7 @@ func (f *File) Truncate(size int64) Error {
// Sync commits the current contents of the file to stable storage.
// Sync commits the current contents of the file to stable storage.
// Typically, this means flushing the file system's in-memory copy
// Typically, this means flushing the file system's in-memory copy
// of recently written data to disk.
// of recently written data to disk.
func
(
file
*
File
)
Sync
()
(
err
E
rror
)
{
func
(
file
*
File
)
Sync
()
(
err
e
rror
)
{
if
file
==
nil
{
if
file
==
nil
{
return
EINVAL
return
EINVAL
}
}
...
@@ -184,7 +184,7 @@ func (file *File) Sync() (err Error) {
...
@@ -184,7 +184,7 @@ func (file *File) Sync() (err Error) {
// The argument times are in nanoseconds, although the underlying
// The argument times are in nanoseconds, although the underlying
// filesystem may truncate or round the values to a more
// filesystem may truncate or round the values to a more
// coarse time unit.
// coarse time unit.
func
Chtimes
(
name
string
,
atime_ns
int64
,
mtime_ns
int64
)
E
rror
{
func
Chtimes
(
name
string
,
atime_ns
int64
,
mtime_ns
int64
)
e
rror
{
var
utimes
[
2
]
syscall
.
Timeval
var
utimes
[
2
]
syscall
.
Timeval
utimes
[
0
]
=
syscall
.
NsecToTimeval
(
atime_ns
)
utimes
[
0
]
=
syscall
.
NsecToTimeval
(
atime_ns
)
utimes
[
1
]
=
syscall
.
NsecToTimeval
(
mtime_ns
)
utimes
[
1
]
=
syscall
.
NsecToTimeval
(
mtime_ns
)
...
...
src/pkg/os/file_unix.go
View file @
08a073a1
...
@@ -52,8 +52,8 @@ const DevNull = "/dev/null"
...
@@ -52,8 +52,8 @@ const DevNull = "/dev/null"
// or Create instead. It opens the named file with specified flag
// or Create instead. It opens the named file with specified flag
// (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful,
// (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful,
// methods on the returned File can be used for I/O.
// methods on the returned File can be used for I/O.
// It returns the File and an
E
rror, if any.
// It returns the File and an
e
rror, if any.
func
OpenFile
(
name
string
,
flag
int
,
perm
uint32
)
(
file
*
File
,
err
E
rror
)
{
func
OpenFile
(
name
string
,
flag
int
,
perm
uint32
)
(
file
*
File
,
err
e
rror
)
{
r
,
e
:=
syscall
.
Open
(
name
,
flag
|
syscall
.
O_CLOEXEC
,
perm
)
r
,
e
:=
syscall
.
Open
(
name
,
flag
|
syscall
.
O_CLOEXEC
,
perm
)
if
e
!=
0
{
if
e
!=
0
{
return
nil
,
&
PathError
{
"open"
,
name
,
Errno
(
e
)}
return
nil
,
&
PathError
{
"open"
,
name
,
Errno
(
e
)}
...
@@ -69,12 +69,12 @@ func OpenFile(name string, flag int, perm uint32) (file *File, err Error) {
...
@@ -69,12 +69,12 @@ func OpenFile(name string, flag int, perm uint32) (file *File, err Error) {
}
}
// Close closes the File, rendering it unusable for I/O.
// Close closes the File, rendering it unusable for I/O.
// It returns an
E
rror, if any.
// It returns an
e
rror, if any.
func
(
file
*
File
)
Close
()
E
rror
{
func
(
file
*
File
)
Close
()
e
rror
{
if
file
==
nil
||
file
.
fd
<
0
{
if
file
==
nil
||
file
.
fd
<
0
{
return
EINVAL
return
EINVAL
}
}
var
err
E
rror
var
err
e
rror
if
e
:=
syscall
.
Close
(
file
.
fd
);
e
!=
0
{
if
e
:=
syscall
.
Close
(
file
.
fd
);
e
!=
0
{
err
=
&
PathError
{
"close"
,
file
.
name
,
Errno
(
e
)}
err
=
&
PathError
{
"close"
,
file
.
name
,
Errno
(
e
)}
}
}
...
@@ -87,7 +87,7 @@ func (file *File) Close() Error {
...
@@ -87,7 +87,7 @@ func (file *File) Close() Error {
// Stat returns the FileInfo structure describing file.
// Stat returns the FileInfo structure describing file.
// It returns the FileInfo and an error, if any.
// It returns the FileInfo and an error, if any.
func
(
file
*
File
)
Stat
()
(
fi
*
FileInfo
,
err
E
rror
)
{
func
(
file
*
File
)
Stat
()
(
fi
*
FileInfo
,
err
e
rror
)
{
var
stat
syscall
.
Stat_t
var
stat
syscall
.
Stat_t
e
:=
syscall
.
Fstat
(
file
.
fd
,
&
stat
)
e
:=
syscall
.
Fstat
(
file
.
fd
,
&
stat
)
if
e
!=
0
{
if
e
!=
0
{
...
@@ -101,7 +101,7 @@ func (file *File) Stat() (fi *FileInfo, err Error) {
...
@@ -101,7 +101,7 @@ func (file *File) Stat() (fi *FileInfo, err Error) {
// the file pointed at by the link and has fi.FollowedSymlink set to true.
// the file pointed at by the link and has fi.FollowedSymlink set to true.
// If name names an invalid symbolic link, the returned FileInfo describes
// If name names an invalid symbolic link, the returned FileInfo describes
// the link itself and has fi.FollowedSymlink set to false.
// the link itself and has fi.FollowedSymlink set to false.
func
Stat
(
name
string
)
(
fi
*
FileInfo
,
err
E
rror
)
{
func
Stat
(
name
string
)
(
fi
*
FileInfo
,
err
e
rror
)
{
var
lstat
,
stat
syscall
.
Stat_t
var
lstat
,
stat
syscall
.
Stat_t
e
:=
syscall
.
Lstat
(
name
,
&
lstat
)
e
:=
syscall
.
Lstat
(
name
,
&
lstat
)
if
iserror
(
e
)
{
if
iserror
(
e
)
{
...
@@ -120,7 +120,7 @@ func Stat(name string) (fi *FileInfo, err Error) {
...
@@ -120,7 +120,7 @@ func Stat(name string) (fi *FileInfo, err Error) {
// Lstat returns the FileInfo structure describing the named file and an
// Lstat returns the FileInfo structure describing the named file and an
// error, if any. If the file is a symbolic link, the returned FileInfo
// error, if any. If the file is a symbolic link, the returned FileInfo
// describes the symbolic link. Lstat makes no attempt to follow the link.
// describes the symbolic link. Lstat makes no attempt to follow the link.
func
Lstat
(
name
string
)
(
fi
*
FileInfo
,
err
E
rror
)
{
func
Lstat
(
name
string
)
(
fi
*
FileInfo
,
err
e
rror
)
{
var
stat
syscall
.
Stat_t
var
stat
syscall
.
Stat_t
e
:=
syscall
.
Lstat
(
name
,
&
stat
)
e
:=
syscall
.
Lstat
(
name
,
&
stat
)
if
iserror
(
e
)
{
if
iserror
(
e
)
{
...
@@ -144,7 +144,7 @@ func Lstat(name string) (fi *FileInfo, err Error) {
...
@@ -144,7 +144,7 @@ func Lstat(name string) (fi *FileInfo, err Error) {
// nil os.Error. If it encounters an error before the end of the
// nil os.Error. If it encounters an error before the end of the
// directory, Readdir returns the FileInfo read until that point
// directory, Readdir returns the FileInfo read until that point
// and a non-nil error.
// and a non-nil error.
func
(
file
*
File
)
Readdir
(
n
int
)
(
fi
[]
FileInfo
,
err
E
rror
)
{
func
(
file
*
File
)
Readdir
(
n
int
)
(
fi
[]
FileInfo
,
err
e
rror
)
{
dirname
:=
file
.
name
dirname
:=
file
.
name
if
dirname
==
""
{
if
dirname
==
""
{
dirname
=
"."
dirname
=
"."
...
@@ -198,7 +198,7 @@ func (f *File) seek(offset int64, whence int) (ret int64, err int) {
...
@@ -198,7 +198,7 @@ func (f *File) seek(offset int64, whence int) (ret int64, err int) {
// Truncate changes the size of the named file.
// Truncate changes the size of the named file.
// If the file is a symbolic link, it changes the size of the link's target.
// If the file is a symbolic link, it changes the size of the link's target.
func
Truncate
(
name
string
,
size
int64
)
E
rror
{
func
Truncate
(
name
string
,
size
int64
)
e
rror
{
if
e
:=
syscall
.
Truncate
(
name
,
size
);
e
!=
0
{
if
e
:=
syscall
.
Truncate
(
name
,
size
);
e
!=
0
{
return
&
PathError
{
"truncate"
,
name
,
Errno
(
e
)}
return
&
PathError
{
"truncate"
,
name
,
Errno
(
e
)}
}
}
...
@@ -224,8 +224,8 @@ func basename(name string) string {
...
@@ -224,8 +224,8 @@ func basename(name string) string {
}
}
// Pipe returns a connected pair of Files; reads from r return bytes written to w.
// Pipe returns a connected pair of Files; reads from r return bytes written to w.
// It returns the files and an
E
rror, if any.
// It returns the files and an
e
rror, if any.
func
Pipe
()
(
r
*
File
,
w
*
File
,
err
E
rror
)
{
func
Pipe
()
(
r
*
File
,
w
*
File
,
err
e
rror
)
{
var
p
[
2
]
int
var
p
[
2
]
int
// See ../syscall/exec.go for description of lock.
// See ../syscall/exec.go for description of lock.
...
...
src/pkg/os/file_windows.go
View file @
08a073a1
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
package
os
package
os
import
(
import
(
"io"
"runtime"
"runtime"
"sync"
"sync"
"syscall"
"syscall"
...
@@ -47,7 +48,7 @@ const DevNull = "NUL"
...
@@ -47,7 +48,7 @@ const DevNull = "NUL"
func
(
file
*
File
)
isdir
()
bool
{
return
file
!=
nil
&&
file
.
dirinfo
!=
nil
}
func
(
file
*
File
)
isdir
()
bool
{
return
file
!=
nil
&&
file
.
dirinfo
!=
nil
}
func
openFile
(
name
string
,
flag
int
,
perm
uint32
)
(
file
*
File
,
err
E
rror
)
{
func
openFile
(
name
string
,
flag
int
,
perm
uint32
)
(
file
*
File
,
err
e
rror
)
{
r
,
e
:=
syscall
.
Open
(
name
,
flag
|
syscall
.
O_CLOEXEC
,
perm
)
r
,
e
:=
syscall
.
Open
(
name
,
flag
|
syscall
.
O_CLOEXEC
,
perm
)
if
e
!=
0
{
if
e
!=
0
{
return
nil
,
&
PathError
{
"open"
,
name
,
Errno
(
e
)}
return
nil
,
&
PathError
{
"open"
,
name
,
Errno
(
e
)}
...
@@ -62,7 +63,7 @@ func openFile(name string, flag int, perm uint32) (file *File, err Error) {
...
@@ -62,7 +63,7 @@ func openFile(name string, flag int, perm uint32) (file *File, err Error) {
return
NewFile
(
r
,
name
),
nil
return
NewFile
(
r
,
name
),
nil
}
}
func
openDir
(
name
string
)
(
file
*
File
,
err
E
rror
)
{
func
openDir
(
name
string
)
(
file
*
File
,
err
e
rror
)
{
d
:=
new
(
dirInfo
)
d
:=
new
(
dirInfo
)
r
,
e
:=
syscall
.
FindFirstFile
(
syscall
.
StringToUTF16Ptr
(
name
+
`\*`
),
&
d
.
data
)
r
,
e
:=
syscall
.
FindFirstFile
(
syscall
.
StringToUTF16Ptr
(
name
+
`\*`
),
&
d
.
data
)
if
e
!=
0
{
if
e
!=
0
{
...
@@ -77,8 +78,8 @@ func openDir(name string) (file *File, err Error) {
...
@@ -77,8 +78,8 @@ func openDir(name string) (file *File, err Error) {
// or Create instead. It opens the named file with specified flag
// or Create instead. It opens the named file with specified flag
// (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful,
// (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful,
// methods on the returned File can be used for I/O.
// methods on the returned File can be used for I/O.
// It returns the File and an
E
rror, if any.
// It returns the File and an
e
rror, if any.
func
OpenFile
(
name
string
,
flag
int
,
perm
uint32
)
(
file
*
File
,
err
E
rror
)
{
func
OpenFile
(
name
string
,
flag
int
,
perm
uint32
)
(
file
*
File
,
err
e
rror
)
{
// TODO(brainman): not sure about my logic of assuming it is dir first, then fall back to file
// TODO(brainman): not sure about my logic of assuming it is dir first, then fall back to file
r
,
e
:=
openDir
(
name
)
r
,
e
:=
openDir
(
name
)
if
e
==
nil
{
if
e
==
nil
{
...
@@ -96,8 +97,8 @@ func OpenFile(name string, flag int, perm uint32) (file *File, err Error) {
...
@@ -96,8 +97,8 @@ func OpenFile(name string, flag int, perm uint32) (file *File, err Error) {
}
}
// Close closes the File, rendering it unusable for I/O.
// Close closes the File, rendering it unusable for I/O.
// It returns an
E
rror, if any.
// It returns an
e
rror, if any.
func
(
file
*
File
)
Close
()
E
rror
{
func
(
file
*
File
)
Close
()
e
rror
{
if
file
==
nil
||
file
.
fd
<
0
{
if
file
==
nil
||
file
.
fd
<
0
{
return
EINVAL
return
EINVAL
}
}
...
@@ -107,7 +108,7 @@ func (file *File) Close() Error {
...
@@ -107,7 +108,7 @@ func (file *File) Close() Error {
}
else
{
}
else
{
e
=
syscall
.
CloseHandle
(
syscall
.
Handle
(
file
.
fd
))
e
=
syscall
.
CloseHandle
(
syscall
.
Handle
(
file
.
fd
))
}
}
var
err
E
rror
var
err
e
rror
if
e
!=
0
{
if
e
!=
0
{
err
=
&
PathError
{
"close"
,
file
.
name
,
Errno
(
e
)}
err
=
&
PathError
{
"close"
,
file
.
name
,
Errno
(
e
)}
}
}
...
@@ -133,7 +134,7 @@ func (file *File) Close() Error {
...
@@ -133,7 +134,7 @@ func (file *File) Close() Error {
// nil os.Error. If it encounters an error before the end of the
// nil os.Error. If it encounters an error before the end of the
// directory, Readdir returns the FileInfo read until that point
// directory, Readdir returns the FileInfo read until that point
// and a non-nil error.
// and a non-nil error.
func
(
file
*
File
)
Readdir
(
n
int
)
(
fi
[]
FileInfo
,
err
E
rror
)
{
func
(
file
*
File
)
Readdir
(
n
int
)
(
fi
[]
FileInfo
,
err
e
rror
)
{
if
file
==
nil
||
file
.
fd
<
0
{
if
file
==
nil
||
file
.
fd
<
0
{
return
nil
,
EINVAL
return
nil
,
EINVAL
}
}
...
@@ -173,7 +174,7 @@ func (file *File) Readdir(n int) (fi []FileInfo, err Error) {
...
@@ -173,7 +174,7 @@ func (file *File) Readdir(n int) (fi []FileInfo, err Error) {
fi
=
append
(
fi
,
f
)
fi
=
append
(
fi
,
f
)
}
}
if
!
wantAll
&&
len
(
fi
)
==
0
{
if
!
wantAll
&&
len
(
fi
)
==
0
{
return
fi
,
EOF
return
fi
,
io
.
EOF
}
}
return
fi
,
nil
return
fi
,
nil
}
}
...
@@ -251,7 +252,7 @@ func (f *File) seek(offset int64, whence int) (ret int64, err int) {
...
@@ -251,7 +252,7 @@ func (f *File) seek(offset int64, whence int) (ret int64, err int) {
// Truncate changes the size of the named file.
// Truncate changes the size of the named file.
// If the file is a symbolic link, it changes the size of the link's target.
// If the file is a symbolic link, it changes the size of the link's target.
func
Truncate
(
name
string
,
size
int64
)
E
rror
{
func
Truncate
(
name
string
,
size
int64
)
e
rror
{
f
,
e
:=
OpenFile
(
name
,
O_WRONLY
|
O_CREATE
,
0666
)
f
,
e
:=
OpenFile
(
name
,
O_WRONLY
|
O_CREATE
,
0666
)
if
e
!=
nil
{
if
e
!=
nil
{
return
e
return
e
...
@@ -265,8 +266,8 @@ func Truncate(name string, size int64) Error {
...
@@ -265,8 +266,8 @@ func Truncate(name string, size int64) Error {
}
}
// Pipe returns a connected pair of Files; reads from r return bytes written to w.
// Pipe returns a connected pair of Files; reads from r return bytes written to w.
// It returns the files and an
E
rror, if any.
// It returns the files and an
e
rror, if any.
func
Pipe
()
(
r
*
File
,
w
*
File
,
err
E
rror
)
{
func
Pipe
()
(
r
*
File
,
w
*
File
,
err
e
rror
)
{
var
p
[
2
]
syscall
.
Handle
var
p
[
2
]
syscall
.
Handle
// See ../syscall/exec.go for description of lock.
// See ../syscall/exec.go for description of lock.
...
...
src/pkg/os/getwd.go
View file @
08a073a1
...
@@ -12,7 +12,7 @@ import (
...
@@ -12,7 +12,7 @@ import (
// current directory. If the current directory can be
// current directory. If the current directory can be
// reached via multiple paths (due to symbolic links),
// reached via multiple paths (due to symbolic links),
// Getwd may return any one of them.
// Getwd may return any one of them.
func
Getwd
()
(
string
,
E
rror
)
{
func
Getwd
()
(
string
,
e
rror
)
{
// If the operating system provides a Getwd call, use it.
// If the operating system provides a Getwd call, use it.
if
syscall
.
ImplementsGetwd
{
if
syscall
.
ImplementsGetwd
{
s
,
e
:=
syscall
.
Getwd
()
s
,
e
:=
syscall
.
Getwd
()
...
...
src/pkg/os/os_test.go
View file @
08a073a1
...
@@ -77,7 +77,7 @@ func size(name string, t *testing.T) int64 {
...
@@ -77,7 +77,7 @@ func size(name string, t *testing.T) int64 {
for
{
for
{
n
,
e
:=
file
.
Read
(
buf
[
0
:
])
n
,
e
:=
file
.
Read
(
buf
[
0
:
])
len
+=
n
len
+=
n
if
e
==
EOF
{
if
e
==
io
.
EOF
{
break
break
}
}
if
e
!=
nil
{
if
e
!=
nil
{
...
@@ -257,7 +257,7 @@ func smallReaddirnames(file *File, length int, t *testing.T) []string {
...
@@ -257,7 +257,7 @@ func smallReaddirnames(file *File, length int, t *testing.T) []string {
count
:=
0
count
:=
0
for
{
for
{
d
,
err
:=
file
.
Readdirnames
(
1
)
d
,
err
:=
file
.
Readdirnames
(
1
)
if
err
==
EOF
{
if
err
==
io
.
EOF
{
break
break
}
}
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -328,14 +328,14 @@ func TestReaddirNValues(t *testing.T) {
...
@@ -328,14 +328,14 @@ func TestReaddirNValues(t *testing.T) {
var
d
*
File
var
d
*
File
openDir
:=
func
()
{
openDir
:=
func
()
{
var
err
E
rror
var
err
e
rror
d
,
err
=
Open
(
dir
)
d
,
err
=
Open
(
dir
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Open directory: %v"
,
err
)
t
.
Fatalf
(
"Open directory: %v"
,
err
)
}
}
}
}
readDirExpect
:=
func
(
n
,
want
int
,
wantErr
E
rror
)
{
readDirExpect
:=
func
(
n
,
want
int
,
wantErr
e
rror
)
{
fi
,
err
:=
d
.
Readdir
(
n
)
fi
,
err
:=
d
.
Readdir
(
n
)
if
err
!=
wantErr
{
if
err
!=
wantErr
{
t
.
Fatalf
(
"Readdir of %d got error %v, want %v"
,
n
,
err
,
wantErr
)
t
.
Fatalf
(
"Readdir of %d got error %v, want %v"
,
n
,
err
,
wantErr
)
...
@@ -345,7 +345,7 @@ func TestReaddirNValues(t *testing.T) {
...
@@ -345,7 +345,7 @@ func TestReaddirNValues(t *testing.T) {
}
}
}
}
readDirNamesExpect
:=
func
(
n
,
want
int
,
wantErr
E
rror
)
{
readDirNamesExpect
:=
func
(
n
,
want
int
,
wantErr
e
rror
)
{
fi
,
err
:=
d
.
Readdirnames
(
n
)
fi
,
err
:=
d
.
Readdirnames
(
n
)
if
err
!=
wantErr
{
if
err
!=
wantErr
{
t
.
Fatalf
(
"Readdirnames of %d got error %v, want %v"
,
n
,
err
,
wantErr
)
t
.
Fatalf
(
"Readdirnames of %d got error %v, want %v"
,
n
,
err
,
wantErr
)
...
@@ -355,7 +355,7 @@ func TestReaddirNValues(t *testing.T) {
...
@@ -355,7 +355,7 @@ func TestReaddirNValues(t *testing.T) {
}
}
}
}
for
_
,
fn
:=
range
[]
func
(
int
,
int
,
E
rror
){
readDirExpect
,
readDirNamesExpect
}
{
for
_
,
fn
:=
range
[]
func
(
int
,
int
,
e
rror
){
readDirExpect
,
readDirNamesExpect
}
{
// Test the slurp case
// Test the slurp case
openDir
()
openDir
()
fn
(
0
,
105
,
nil
)
fn
(
0
,
105
,
nil
)
...
@@ -374,7 +374,7 @@ func TestReaddirNValues(t *testing.T) {
...
@@ -374,7 +374,7 @@ func TestReaddirNValues(t *testing.T) {
fn
(
1
,
1
,
nil
)
fn
(
1
,
1
,
nil
)
fn
(
2
,
2
,
nil
)
fn
(
2
,
2
,
nil
)
fn
(
105
,
102
,
nil
)
// and tests buffer >100 case
fn
(
105
,
102
,
nil
)
// and tests buffer >100 case
fn
(
3
,
0
,
EOF
)
fn
(
3
,
0
,
io
.
EOF
)
d
.
Close
()
d
.
Close
()
}
}
}
}
...
@@ -841,7 +841,7 @@ func TestSeek(t *testing.T) {
...
@@ -841,7 +841,7 @@ func TestSeek(t *testing.T) {
for
i
,
tt
:=
range
tests
{
for
i
,
tt
:=
range
tests
{
off
,
err
:=
f
.
Seek
(
tt
.
in
,
tt
.
whence
)
off
,
err
:=
f
.
Seek
(
tt
.
in
,
tt
.
whence
)
if
off
!=
tt
.
out
||
err
!=
nil
{
if
off
!=
tt
.
out
||
err
!=
nil
{
if
e
,
ok
:=
err
.
(
*
PathError
);
ok
&&
e
.
Err
or
==
EINVAL
&&
tt
.
out
>
1
<<
32
{
if
e
,
ok
:=
err
.
(
*
PathError
);
ok
&&
e
.
Err
==
EINVAL
&&
tt
.
out
>
1
<<
32
{
// Reiserfs rejects the big seeks.
// Reiserfs rejects the big seeks.
// http://code.google.com/p/go/issues/detail?id=91
// http://code.google.com/p/go/issues/detail?id=91
break
break
...
@@ -854,7 +854,7 @@ func TestSeek(t *testing.T) {
...
@@ -854,7 +854,7 @@ func TestSeek(t *testing.T) {
type
openErrorTest
struct
{
type
openErrorTest
struct
{
path
string
path
string
mode
int
mode
int
error
E
rror
error
e
rror
}
}
var
openErrorTests
=
[]
openErrorTest
{
var
openErrorTests
=
[]
openErrorTest
{
...
@@ -887,15 +887,15 @@ func TestOpenError(t *testing.T) {
...
@@ -887,15 +887,15 @@ func TestOpenError(t *testing.T) {
if
!
ok
{
if
!
ok
{
t
.
Errorf
(
"Open(%q, %d) returns error of %T type; want *os.PathError"
,
tt
.
path
,
tt
.
mode
,
err
)
t
.
Errorf
(
"Open(%q, %d) returns error of %T type; want *os.PathError"
,
tt
.
path
,
tt
.
mode
,
err
)
}
}
if
perr
.
Err
or
!=
tt
.
error
{
if
perr
.
Err
!=
tt
.
error
{
if
syscall
.
OS
==
"plan9"
{
if
syscall
.
OS
==
"plan9"
{
syscallErrStr
:=
perr
.
Err
or
.
String
()
syscallErrStr
:=
perr
.
Err
.
Error
()
expectedErrStr
:=
strings
.
Replace
(
tt
.
error
.
String
(),
"file "
,
""
,
1
)
expectedErrStr
:=
strings
.
Replace
(
tt
.
error
.
Error
(),
"file "
,
""
,
1
)
if
!
strings
.
HasSuffix
(
syscallErrStr
,
expectedErrStr
)
{
if
!
strings
.
HasSuffix
(
syscallErrStr
,
expectedErrStr
)
{
t
.
Errorf
(
"Open(%q, %d) = _, %q; want suffix %q"
,
tt
.
path
,
tt
.
mode
,
syscallErrStr
,
expectedErrStr
)
t
.
Errorf
(
"Open(%q, %d) = _, %q; want suffix %q"
,
tt
.
path
,
tt
.
mode
,
syscallErrStr
,
expectedErrStr
)
}
}
}
else
{
}
else
{
t
.
Errorf
(
"Open(%q, %d) = _, %q; want %q"
,
tt
.
path
,
tt
.
mode
,
perr
.
Err
or
.
String
(),
tt
.
error
.
String
())
t
.
Errorf
(
"Open(%q, %d) = _, %q; want %q"
,
tt
.
path
,
tt
.
mode
,
perr
.
Err
.
Error
(),
tt
.
error
.
Error
())
}
}
}
}
}
}
...
...
src/pkg/os/path.go
View file @
08a073a1
...
@@ -4,6 +4,8 @@
...
@@ -4,6 +4,8 @@
package
os
package
os
import
"io"
// MkdirAll creates a directory named path,
// MkdirAll creates a directory named path,
// along with any necessary parents, and returns nil,
// along with any necessary parents, and returns nil,
// or else returns an error.
// or else returns an error.
...
@@ -11,7 +13,7 @@ package os
...
@@ -11,7 +13,7 @@ package os
// directories that MkdirAll creates.
// directories that MkdirAll creates.
// If path is already a directory, MkdirAll does nothing
// If path is already a directory, MkdirAll does nothing
// and returns nil.
// and returns nil.
func
MkdirAll
(
path
string
,
perm
uint32
)
E
rror
{
func
MkdirAll
(
path
string
,
perm
uint32
)
e
rror
{
// If path exists, stop with success or error.
// If path exists, stop with success or error.
dir
,
err
:=
Stat
(
path
)
dir
,
err
:=
Stat
(
path
)
if
err
==
nil
{
if
err
==
nil
{
...
@@ -58,7 +60,7 @@ func MkdirAll(path string, perm uint32) Error {
...
@@ -58,7 +60,7 @@ func MkdirAll(path string, perm uint32) Error {
// It removes everything it can but returns the first error
// It removes everything it can but returns the first error
// it encounters. If the path does not exist, RemoveAll
// it encounters. If the path does not exist, RemoveAll
// returns nil (no error).
// returns nil (no error).
func
RemoveAll
(
path
string
)
E
rror
{
func
RemoveAll
(
path
string
)
e
rror
{
// Simple case: if Remove works, we're done.
// Simple case: if Remove works, we're done.
err
:=
Remove
(
path
)
err
:=
Remove
(
path
)
if
err
==
nil
{
if
err
==
nil
{
...
@@ -68,7 +70,7 @@ func RemoveAll(path string) Error {
...
@@ -68,7 +70,7 @@ func RemoveAll(path string) Error {
// Otherwise, is this a directory we need to recurse into?
// Otherwise, is this a directory we need to recurse into?
dir
,
serr
:=
Lstat
(
path
)
dir
,
serr
:=
Lstat
(
path
)
if
serr
!=
nil
{
if
serr
!=
nil
{
if
serr
,
ok
:=
serr
.
(
*
PathError
);
ok
&&
(
serr
.
Err
or
==
ENOENT
||
serr
.
Erro
r
==
ENOTDIR
)
{
if
serr
,
ok
:=
serr
.
(
*
PathError
);
ok
&&
(
serr
.
Err
==
ENOENT
||
serr
.
Er
r
==
ENOTDIR
)
{
return
nil
return
nil
}
}
return
serr
return
serr
...
@@ -94,7 +96,7 @@ func RemoveAll(path string) Error {
...
@@ -94,7 +96,7 @@ func RemoveAll(path string) Error {
err
=
err1
err
=
err1
}
}
}
}
if
err1
==
EOF
{
if
err1
==
io
.
EOF
{
break
break
}
}
// If Readdirnames returned an error, use it.
// If Readdirnames returned an error, use it.
...
...
src/pkg/os/path_test.go
View file @
08a073a1
...
@@ -199,7 +199,7 @@ func TestMkdirAllAtSlash(t *testing.T) {
...
@@ -199,7 +199,7 @@ func TestMkdirAllAtSlash(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
pathErr
,
ok
:=
err
.
(
*
PathError
)
pathErr
,
ok
:=
err
.
(
*
PathError
)
// common for users not to be able to write to /
// common for users not to be able to write to /
if
ok
&&
pathErr
.
Err
or
==
EACCES
{
if
ok
&&
pathErr
.
Err
==
EACCES
{
return
return
}
}
t
.
Fatalf
(
`MkdirAll "/_go_os_test/dir": %v`
,
err
)
t
.
Fatalf
(
`MkdirAll "/_go_os_test/dir": %v`
,
err
)
...
...
src/pkg/os/proc.go
View file @
08a073a1
...
@@ -24,7 +24,7 @@ func Getgid() int { return syscall.Getgid() }
...
@@ -24,7 +24,7 @@ func Getgid() int { return syscall.Getgid() }
func
Getegid
()
int
{
return
syscall
.
Getegid
()
}
func
Getegid
()
int
{
return
syscall
.
Getegid
()
}
// Getgroups returns a list of the numeric ids of groups that the caller belongs to.
// Getgroups returns a list of the numeric ids of groups that the caller belongs to.
func
Getgroups
()
([]
int
,
E
rror
)
{
func
Getgroups
()
([]
int
,
e
rror
)
{
gids
,
e
:=
syscall
.
Getgroups
()
gids
,
e
:=
syscall
.
Getgroups
()
return
gids
,
NewSyscallError
(
"getgroups"
,
e
)
return
gids
,
NewSyscallError
(
"getgroups"
,
e
)
}
}
...
...
src/pkg/os/stat_plan9.go
View file @
08a073a1
...
@@ -26,7 +26,7 @@ func fileInfoFromStat(fi *FileInfo, d *Dir) *FileInfo {
...
@@ -26,7 +26,7 @@ func fileInfoFromStat(fi *FileInfo, d *Dir) *FileInfo {
}
}
// arg is an open *File or a path string.
// arg is an open *File or a path string.
func
dirstat
(
arg
interface
{})
(
d
*
Dir
,
err
E
rror
)
{
func
dirstat
(
arg
interface
{})
(
d
*
Dir
,
err
e
rror
)
{
var
name
string
var
name
string
nd
:=
syscall
.
STATFIXLEN
+
16
*
4
nd
:=
syscall
.
STATFIXLEN
+
16
*
4
...
@@ -70,7 +70,7 @@ func dirstat(arg interface{}) (d *Dir, err Error) {
...
@@ -70,7 +70,7 @@ func dirstat(arg interface{}) (d *Dir, err Error) {
}
}
// Stat returns a FileInfo structure describing the named file and an error, if any.
// Stat returns a FileInfo structure describing the named file and an error, if any.
func
Stat
(
name
string
)
(
fi
*
FileInfo
,
err
E
rror
)
{
func
Stat
(
name
string
)
(
fi
*
FileInfo
,
err
e
rror
)
{
d
,
err
:=
dirstat
(
name
)
d
,
err
:=
dirstat
(
name
)
if
iserror
(
err
)
{
if
iserror
(
err
)
{
return
nil
,
err
return
nil
,
err
...
@@ -81,7 +81,7 @@ func Stat(name string) (fi *FileInfo, err Error) {
...
@@ -81,7 +81,7 @@ func Stat(name string) (fi *FileInfo, err Error) {
// Lstat returns the FileInfo structure describing the named file and an
// Lstat returns the FileInfo structure describing the named file and an
// error, if any. If the file is a symbolic link (though Plan 9 does not have symbolic links),
// error, if any. If the file is a symbolic link (though Plan 9 does not have symbolic links),
// the returned FileInfo describes the symbolic link. Lstat makes no attempt to follow the link.
// the returned FileInfo describes the symbolic link. Lstat makes no attempt to follow the link.
func
Lstat
(
name
string
)
(
fi
*
FileInfo
,
err
E
rror
)
{
func
Lstat
(
name
string
)
(
fi
*
FileInfo
,
err
e
rror
)
{
d
,
err
:=
dirstat
(
name
)
d
,
err
:=
dirstat
(
name
)
if
iserror
(
err
)
{
if
iserror
(
err
)
{
return
nil
,
err
return
nil
,
err
...
...
src/pkg/os/stat_windows.go
View file @
08a073a1
...
@@ -11,7 +11,7 @@ import (
...
@@ -11,7 +11,7 @@ import (
// Stat returns the FileInfo structure describing file.
// Stat returns the FileInfo structure describing file.
// It returns the FileInfo and an error, if any.
// It returns the FileInfo and an error, if any.
func
(
file
*
File
)
Stat
()
(
fi
*
FileInfo
,
err
E
rror
)
{
func
(
file
*
File
)
Stat
()
(
fi
*
FileInfo
,
err
e
rror
)
{
if
file
==
nil
||
file
.
fd
<
0
{
if
file
==
nil
||
file
.
fd
<
0
{
return
nil
,
EINVAL
return
nil
,
EINVAL
}
}
...
@@ -32,7 +32,7 @@ func (file *File) Stat() (fi *FileInfo, err Error) {
...
@@ -32,7 +32,7 @@ func (file *File) Stat() (fi *FileInfo, err Error) {
// the file pointed at by the link and has fi.FollowedSymlink set to true.
// the file pointed at by the link and has fi.FollowedSymlink set to true.
// If name names an invalid symbolic link, the returned FileInfo describes
// If name names an invalid symbolic link, the returned FileInfo describes
// the link itself and has fi.FollowedSymlink set to false.
// the link itself and has fi.FollowedSymlink set to false.
func
Stat
(
name
string
)
(
fi
*
FileInfo
,
err
E
rror
)
{
func
Stat
(
name
string
)
(
fi
*
FileInfo
,
err
e
rror
)
{
if
len
(
name
)
==
0
{
if
len
(
name
)
==
0
{
return
nil
,
&
PathError
{
"Stat"
,
name
,
Errno
(
syscall
.
ERROR_PATH_NOT_FOUND
)}
return
nil
,
&
PathError
{
"Stat"
,
name
,
Errno
(
syscall
.
ERROR_PATH_NOT_FOUND
)}
}
}
...
@@ -47,7 +47,7 @@ func Stat(name string) (fi *FileInfo, err Error) {
...
@@ -47,7 +47,7 @@ func Stat(name string) (fi *FileInfo, err Error) {
// Lstat returns the FileInfo structure describing the named file and an
// Lstat returns the FileInfo structure describing the named file and an
// error, if any. If the file is a symbolic link, the returned FileInfo
// error, if any. If the file is a symbolic link, the returned FileInfo
// describes the symbolic link. Lstat makes no attempt to follow the link.
// describes the symbolic link. Lstat makes no attempt to follow the link.
func
Lstat
(
name
string
)
(
fi
*
FileInfo
,
err
E
rror
)
{
func
Lstat
(
name
string
)
(
fi
*
FileInfo
,
err
e
rror
)
{
// No links on Windows
// No links on Windows
return
Stat
(
name
)
return
Stat
(
name
)
}
}
...
...
src/pkg/os/sys_bsd.go
View file @
08a073a1
...
@@ -11,7 +11,7 @@ package os
...
@@ -11,7 +11,7 @@ package os
import
"syscall"
import
"syscall"
func
Hostname
()
(
name
string
,
err
E
rror
)
{
func
Hostname
()
(
name
string
,
err
e
rror
)
{
var
errno
int
var
errno
int
name
,
errno
=
syscall
.
Sysctl
(
"kern.hostname"
)
name
,
errno
=
syscall
.
Sysctl
(
"kern.hostname"
)
if
errno
!=
0
{
if
errno
!=
0
{
...
...
src/pkg/os/sys_linux.go
View file @
08a073a1
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
package
os
package
os
// Hostname returns the host name reported by the kernel.
// Hostname returns the host name reported by the kernel.
func
Hostname
()
(
name
string
,
err
E
rror
)
{
func
Hostname
()
(
name
string
,
err
e
rror
)
{
f
,
err
:=
Open
(
"/proc/sys/kernel/hostname"
)
f
,
err
:=
Open
(
"/proc/sys/kernel/hostname"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
...
...
src/pkg/os/sys_plan9.go
View file @
08a073a1
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
package
os
package
os
func
Hostname
()
(
name
string
,
err
E
rror
)
{
func
Hostname
()
(
name
string
,
err
e
rror
)
{
f
,
err
:=
Open
(
"#c/sysname"
)
f
,
err
:=
Open
(
"#c/sysname"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
...
...
src/pkg/os/sys_windows.go
View file @
08a073a1
...
@@ -6,7 +6,7 @@ package os
...
@@ -6,7 +6,7 @@ package os
import
"syscall"
import
"syscall"
func
Hostname
()
(
name
string
,
err
E
rror
)
{
func
Hostname
()
(
name
string
,
err
e
rror
)
{
s
,
e
:=
syscall
.
ComputerName
()
s
,
e
:=
syscall
.
ComputerName
()
if
e
!=
0
{
if
e
!=
0
{
return
""
,
NewSyscallError
(
"ComputerName"
,
e
)
return
""
,
NewSyscallError
(
"ComputerName"
,
e
)
...
...
src/pkg/os/time.go
View file @
08a073a1
...
@@ -7,10 +7,10 @@ package os
...
@@ -7,10 +7,10 @@ package os
import
"syscall"
import
"syscall"
// Time returns the current time, in whole seconds and
// Time returns the current time, in whole seconds and
// fractional nanoseconds, plus an
E
rror if any. The current
// fractional nanoseconds, plus an
e
rror if any. The current
// time is thus 1e9*sec+nsec, in nanoseconds. The zero of
// time is thus 1e9*sec+nsec, in nanoseconds. The zero of
// time is the Unix epoch.
// time is the Unix epoch.
func
Time
()
(
sec
int64
,
nsec
int64
,
err
E
rror
)
{
func
Time
()
(
sec
int64
,
nsec
int64
,
err
e
rror
)
{
var
tv
syscall
.
Timeval
var
tv
syscall
.
Timeval
if
e
:=
syscall
.
Gettimeofday
(
&
tv
);
iserror
(
e
)
{
if
e
:=
syscall
.
Gettimeofday
(
&
tv
);
iserror
(
e
)
{
return
0
,
0
,
NewSyscallError
(
"gettimeofday"
,
e
)
return
0
,
0
,
NewSyscallError
(
"gettimeofday"
,
e
)
...
...
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