Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
08a073a1
Commit
08a073a1
authored
Nov 02, 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
Hide whitespace changes
Inline
Side-by-side
Showing
30 changed files
with
233 additions
and
253 deletions
+233
-253
dir_plan9.go
src/pkg/os/dir_plan9.go
+10
-9
dir_unix.go
src/pkg/os/dir_unix.go
+3
-2
dir_windows.go
src/pkg/os/dir_windows.go
+1
-1
env_plan9.go
src/pkg/os/env_plan9.go
+4
-4
env_unix.go
src/pkg/os/env_unix.go
+6
-5
env_windows.go
src/pkg/os/env_windows.go
+4
-4
error.go
src/pkg/os/error.go
+4
-21
error_plan9.go
src/pkg/os/error_plan9.go
+3
-3
error_posix.go
src/pkg/os/error_posix.go
+44
-44
exec_plan9.go
src/pkg/os/exec_plan9.go
+11
-11
exec_posix.go
src/pkg/os/exec_posix.go
+6
-6
exec_unix.go
src/pkg/os/exec_unix.go
+7
-6
exec_windows.go
src/pkg/os/exec_windows.go
+4
-4
file.go
src/pkg/os/file.go
+26
-36
file_plan9.go
src/pkg/os/file_plan9.go
+21
-21
file_posix.go
src/pkg/os/file_posix.go
+20
-20
file_unix.go
src/pkg/os/file_unix.go
+12
-12
file_windows.go
src/pkg/os/file_windows.go
+13
-12
getwd.go
src/pkg/os/getwd.go
+1
-1
os_test.go
src/pkg/os/os_test.go
+13
-13
path.go
src/pkg/os/path.go
+6
-4
path_test.go
src/pkg/os/path_test.go
+1
-1
proc.go
src/pkg/os/proc.go
+1
-1
stat_plan9.go
src/pkg/os/stat_plan9.go
+3
-3
stat_windows.go
src/pkg/os/stat_windows.go
+3
-3
sys_bsd.go
src/pkg/os/sys_bsd.go
+1
-1
sys_linux.go
src/pkg/os/sys_linux.go
+1
-1
sys_plan9.go
src/pkg/os/sys_plan9.go
+1
-1
sys_windows.go
src/pkg/os/sys_windows.go
+1
-1
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 @@
package
os
import
(
"io"
"syscall"
)
...
...
@@ -15,7 +16,7 @@ import (
//
// 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
// 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
// a single slice. In this case, if Readdir succeeds (reads all
...
...
@@ -23,7 +24,7 @@ import (
// nil os.Error. If it encounters an error before the end of the
// directory, Readdir returns the FileInfo read until that point
// 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
file
.
dirinfo
==
nil
{
file
.
dirinfo
=
new
(
dirInfo
)
...
...
@@ -39,12 +40,12 @@ func (file *File) Readdir(n int) (fi []FileInfo, err Error) {
// Refill the buffer if necessary
if
d
.
bufp
>=
d
.
nbuf
{
d
.
bufp
=
0
var
e
E
rror
var
e
e
rror
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
}
}
if
e
==
EOF
{
if
e
==
io
.
EOF
{
break
}
if
d
.
nbuf
<
syscall
.
STATFIXLEN
{
...
...
@@ -71,7 +72,7 @@ func (file *File) Readdir(n int) (fi []FileInfo, err Error) {
}
if
n
>=
0
&&
len
(
result
)
==
0
{
return
result
,
EOF
return
result
,
io
.
EOF
}
return
result
,
nil
}
...
...
@@ -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
// 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
// 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) {
// nil os.Error. If it encounters an error before the end of the
// directory, Readdirnames returns the names read until that point and
// 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
)
names
=
make
([]
string
,
len
(
fi
))
for
i
:=
range
fi
{
...
...
@@ -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,
// 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
,
b
=
gbit16
(
b
)
...
...
src/pkg/os/dir_unix.go
View file @
08a073a1
...
...
@@ -7,6 +7,7 @@
package
os
import
(
"io"
"syscall"
)
...
...
@@ -26,7 +27,7 @@ const (
// nil os.Error. If it encounters an error before the end of the
// directory, Readdirnames returns the names read until that point and
// 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
f
.
dirinfo
==
nil
{
f
.
dirinfo
=
new
(
dirInfo
)
...
...
@@ -63,7 +64,7 @@ func (f *File) Readdirnames(n int) (names []string, err Error) {
n
-=
nc
}
if
n
>=
0
&&
len
(
names
)
==
0
{
return
names
,
EOF
return
names
,
io
.
EOF
}
return
names
,
nil
}
src/pkg/os/dir_windows.go
View file @
08a073a1
...
...
@@ -4,7 +4,7 @@
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
)
names
=
make
([]
string
,
len
(
fis
))
for
i
,
fi
:=
range
fis
{
...
...
src/pkg/os/env_plan9.go
View file @
08a073a1
...
...
@@ -8,12 +8,12 @@ package os
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"
)
// Getenverror retrieves the value of the environment variable named by the key.
// 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
{
return
""
,
EINVAL
}
...
...
@@ -45,8 +45,8 @@ func Getenv(key string) string {
}
// Setenv sets the value of the environment variable named by the key.
// It returns an
E
rror, if any.
func
Setenv
(
key
,
value
string
)
E
rror
{
// It returns an
e
rror, if any.
func
Setenv
(
key
,
value
string
)
e
rror
{
if
len
(
key
)
==
0
{
return
EINVAL
}
...
...
src/pkg/os/env_unix.go
View file @
08a073a1
...
...
@@ -9,11 +9,12 @@
package
os
import
(
"errors"
"sync"
)
// ENOENV is the
E
rror indicating that an environment variable does not exist.
var
ENOENV
=
NewError
(
"no such environment variable"
)
// ENOENV is the
e
rror indicating that an environment variable does not exist.
var
ENOENV
=
errors
.
New
(
"no such environment variable"
)
var
env
map
[
string
]
string
var
once
sync
.
Once
...
...
@@ -34,7 +35,7 @@ var envLock sync.RWMutex
// Getenverror retrieves the value of the environment variable named by the key.
// 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
)
if
len
(
key
)
==
0
{
...
...
@@ -59,8 +60,8 @@ func Getenv(key string) string {
}
// Setenv sets the value of the environment variable named by the key.
// It returns an
E
rror, if any.
func
Setenv
(
key
,
value
string
)
E
rror
{
// It returns an
e
rror, if any.
func
Setenv
(
key
,
value
string
)
e
rror
{
once
.
Do
(
copyenv
)
if
len
(
key
)
==
0
{
return
EINVAL
...
...
src/pkg/os/env_windows.go
View file @
08a073a1
...
...
@@ -12,12 +12,12 @@ import (
"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"
)
// Getenverror retrieves the value of the environment variable named by the key.
// 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
)
n
,
e
:=
syscall
.
GetEnvironmentVariable
(
syscall
.
StringToUTF16Ptr
(
key
),
&
b
[
0
],
uint32
(
len
(
b
)))
if
n
==
0
&&
e
==
syscall
.
ERROR_ENVVAR_NOT_FOUND
{
...
...
@@ -44,8 +44,8 @@ func Getenv(key string) string {
}
// Setenv sets the value of the environment variable named by the key.
// It returns an
E
rror, if any.
func
Setenv
(
key
,
value
string
)
E
rror
{
// It returns an
e
rror, if any.
func
Setenv
(
key
,
value
string
)
e
rror
{
var
v
*
uint16
if
len
(
value
)
>
0
{
v
=
syscall
.
StringToUTF16Ptr
(
value
)
...
...
src/pkg/os/error.go
View file @
08a073a1
...
...
@@ -4,28 +4,11 @@
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.
type
PathError
struct
{
Op
string
Path
string
Err
or
E
rror
Op
string
Path
string
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 {
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,
// pkg/go/doc/doc.go should be adjusted since it hardwires
// 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.
// 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
{
return
nil
}
...
...
src/pkg/os/error_posix.go
View file @
08a073a1
...
...
@@ -9,10 +9,10 @@ package os
import
syscall
"syscall"
// 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
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
{
return
e
==
Errno
(
syscall
.
EINTR
)
||
e
==
Errno
(
syscall
.
EMFILE
)
||
e
.
Timeout
()
...
...
@@ -24,45 +24,45 @@ func (e Errno) Timeout() bool {
// Commonly known Unix errors.
var
(
EPERM
E
rror
=
Errno
(
syscall
.
EPERM
)
ENOENT
E
rror
=
Errno
(
syscall
.
ENOENT
)
ESRCH
E
rror
=
Errno
(
syscall
.
ESRCH
)
EINTR
E
rror
=
Errno
(
syscall
.
EINTR
)
EIO
E
rror
=
Errno
(
syscall
.
EIO
)
ENXIO
E
rror
=
Errno
(
syscall
.
ENXIO
)
E2BIG
E
rror
=
Errno
(
syscall
.
E2BIG
)
ENOEXEC
E
rror
=
Errno
(
syscall
.
ENOEXEC
)
EBADF
E
rror
=
Errno
(
syscall
.
EBADF
)
ECHILD
E
rror
=
Errno
(
syscall
.
ECHILD
)
EDEADLK
E
rror
=
Errno
(
syscall
.
EDEADLK
)
ENOMEM
E
rror
=
Errno
(
syscall
.
ENOMEM
)
EACCES
E
rror
=
Errno
(
syscall
.
EACCES
)
EFAULT
E
rror
=
Errno
(
syscall
.
EFAULT
)
EBUSY
E
rror
=
Errno
(
syscall
.
EBUSY
)
EEXIST
E
rror
=
Errno
(
syscall
.
EEXIST
)
EXDEV
E
rror
=
Errno
(
syscall
.
EXDEV
)
ENODEV
E
rror
=
Errno
(
syscall
.
ENODEV
)
ENOTDIR
E
rror
=
Errno
(
syscall
.
ENOTDIR
)
EISDIR
E
rror
=
Errno
(
syscall
.
EISDIR
)
EINVAL
E
rror
=
Errno
(
syscall
.
EINVAL
)
ENFILE
E
rror
=
Errno
(
syscall
.
ENFILE
)
EMFILE
E
rror
=
Errno
(
syscall
.
EMFILE
)
ENOTTY
E
rror
=
Errno
(
syscall
.
ENOTTY
)
EFBIG
E
rror
=
Errno
(
syscall
.
EFBIG
)
ENOSPC
E
rror
=
Errno
(
syscall
.
ENOSPC
)
ESPIPE
E
rror
=
Errno
(
syscall
.
ESPIPE
)
EROFS
E
rror
=
Errno
(
syscall
.
EROFS
)
EMLINK
E
rror
=
Errno
(
syscall
.
EMLINK
)
EPIPE
E
rror
=
Errno
(
syscall
.
EPIPE
)
EAGAIN
E
rror
=
Errno
(
syscall
.
EAGAIN
)
EDOM
E
rror
=
Errno
(
syscall
.
EDOM
)
ERANGE
E
rror
=
Errno
(
syscall
.
ERANGE
)
EADDRINUSE
E
rror
=
Errno
(
syscall
.
EADDRINUSE
)
ECONNREFUSED
E
rror
=
Errno
(
syscall
.
ECONNREFUSED
)
ENAMETOOLONG
E
rror
=
Errno
(
syscall
.
ENAMETOOLONG
)
EAFNOSUPPORT
E
rror
=
Errno
(
syscall
.
EAFNOSUPPORT
)
ETIMEDOUT
E
rror
=
Errno
(
syscall
.
ETIMEDOUT
)
ENOTCONN
E
rror
=
Errno
(
syscall
.
ENOTCONN
)
EPERM
e
rror
=
Errno
(
syscall
.
EPERM
)
ENOENT
e
rror
=
Errno
(
syscall
.
ENOENT
)
ESRCH
e
rror
=
Errno
(
syscall
.
ESRCH
)
EINTR
e
rror
=
Errno
(
syscall
.
EINTR
)
EIO
e
rror
=
Errno
(
syscall
.
EIO
)
ENXIO
e
rror
=
Errno
(
syscall
.
ENXIO
)
E2BIG
e
rror
=
Errno
(
syscall
.
E2BIG
)
ENOEXEC
e
rror
=
Errno
(
syscall
.
ENOEXEC
)
EBADF
e
rror
=
Errno
(
syscall
.
EBADF
)
ECHILD
e
rror
=
Errno
(
syscall
.
ECHILD
)
EDEADLK
e
rror
=
Errno
(
syscall
.
EDEADLK
)
ENOMEM
e
rror
=
Errno
(
syscall
.
ENOMEM
)
EACCES
e
rror
=
Errno
(
syscall
.
EACCES
)
EFAULT
e
rror
=
Errno
(
syscall
.
EFAULT
)
EBUSY
e
rror
=
Errno
(
syscall
.
EBUSY
)
EEXIST
e
rror
=
Errno
(
syscall
.
EEXIST
)
EXDEV
e
rror
=
Errno
(
syscall
.
EXDEV
)
ENODEV
e
rror
=
Errno
(
syscall
.
ENODEV
)
ENOTDIR
e
rror
=
Errno
(
syscall
.
ENOTDIR
)
EISDIR
e
rror
=
Errno
(
syscall
.
EISDIR
)
EINVAL
e
rror
=
Errno
(
syscall
.
EINVAL
)
ENFILE
e
rror
=
Errno
(
syscall
.
ENFILE
)
EMFILE
e
rror
=
Errno
(
syscall
.
EMFILE
)
ENOTTY
e
rror
=
Errno
(
syscall
.
ENOTTY
)
EFBIG
e
rror
=
Errno
(
syscall
.
EFBIG
)
ENOSPC
e
rror
=
Errno
(
syscall
.
ENOSPC
)
ESPIPE
e
rror
=
Errno
(
syscall
.
ESPIPE
)
EROFS
e
rror
=
Errno
(
syscall
.
EROFS
)
EMLINK
e
rror
=
Errno
(
syscall
.
EMLINK
)
EPIPE
e
rror
=
Errno
(
syscall
.
EPIPE
)
EAGAIN
e
rror
=
Errno
(
syscall
.
EAGAIN
)
EDOM
e
rror
=
Errno
(
syscall
.
EDOM
)
ERANGE
e
rror
=
Errno
(
syscall
.
ERANGE
)
EADDRINUSE
e
rror
=
Errno
(
syscall
.
EADDRINUSE
)
ECONNREFUSED
e
rror
=
Errno
(
syscall
.
ECONNREFUSED
)
ENAMETOOLONG
e
rror
=
Errno
(
syscall
.
ENAMETOOLONG
)
EAFNOSUPPORT
e
rror
=
Errno
(
syscall
.
EAFNOSUPPORT
)
ETIMEDOUT
e
rror
=
Errno
(
syscall
.
ETIMEDOUT
)
ENOTCONN
e
rror
=
Errno
(
syscall
.
ENOTCONN
)
)
// SyscallError records an error from a specific system call.
...
...
@@ -71,16 +71,16 @@ type SyscallError struct {
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,
// pkg/go/doc/doc.go should be adjusted since it hardwires
// 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.
// 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
{
return
nil
}
...
...
src/pkg/os/exec_plan9.go
View file @
08a073a1
...
...
@@ -11,7 +11,7 @@ import (
// StartProcess starts a new process with the program, arguments and attributes
// 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
{
Dir
:
attr
.
Dir
,
Env
:
attr
.
Env
,
...
...
@@ -45,7 +45,7 @@ func (note Plan9Note) String() string {
return
string
(
note
)
}
func
(
p
*
Process
)
Signal
(
sig
Signal
)
E
rror
{
func
(
p
*
Process
)
Signal
(
sig
Signal
)
e
rror
{
if
p
.
done
{
return
NewError
(
"os: process already finished"
)
}
...
...
@@ -60,7 +60,7 @@ func (p *Process) Signal(sig Signal) Error {
}
// 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
)
if
iserror
(
e
)
{
return
NewSyscallError
(
"kill"
,
e
)
...
...
@@ -72,9 +72,9 @@ func (p *Process) Kill() Error {
// Exec replaces the current process with an execution of the
// 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.
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
)
if
iserror
(
e
)
{
return
&
PathError
{
"exec"
,
name
,
e
}
...
...
@@ -89,9 +89,9 @@ type Waitmsg struct {
}
// 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.
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
if
p
.
Pid
==
-
1
{
...
...
@@ -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
// 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.
// Wait is equivalent to calling FindProcess and then Wait
// 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
)
if
e
!=
nil
{
return
nil
,
e
...
...
@@ -129,7 +129,7 @@ func Wait(pid int, options int) (w *Waitmsg, err Error) {
}
// Release releases any resources associated with the Process.
func
(
p
*
Process
)
Release
()
E
rror
{
func
(
p
*
Process
)
Release
()
e
rror
{
// NOOP for Plan 9.
p
.
Pid
=
-
1
// no need for a finalizer anymore
...
...
@@ -140,7 +140,7 @@ func (p *Process) Release() Error {
// FindProcess looks for a running process by its pid.
// The Process it returns can be used to obtain information
// 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.
return
newProcess
(
pid
,
0
),
nil
}
...
...
src/pkg/os/exec_posix.go
View file @
08a073a1
...
...
@@ -26,7 +26,7 @@ func (sig UnixSignal) String() string {
//
// StartProcess is a low-level interface. The exec package provides
// 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
{
Dir
:
attr
.
Dir
,
Env
:
attr
.
Env
,
...
...
@@ -47,17 +47,17 @@ func StartProcess(name string, argv []string, attr *ProcAttr) (p *Process, err E
}
// Kill causes the Process to exit immediately.
func
(
p
*
Process
)
Kill
()
E
rror
{
func
(
p
*
Process
)
Kill
()
e
rror
{
return
p
.
Signal
(
SIGKILL
)
}
// Exec replaces the current process with an execution of the
// 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)
// 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
{
envv
=
Environ
()
}
...
...
@@ -83,11 +83,11 @@ type Waitmsg struct {
}
// 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.
// Wait is equivalent to calling FindProcess and then Wait
// 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
)
if
e
!=
nil
{
return
nil
,
e
...
...
src/pkg/os/exec_unix.go
View file @
08a073a1
...
...
@@ -7,6 +7,7 @@
package
os
import
(
"errors"
"runtime"
"syscall"
)
...
...
@@ -24,9 +25,9 @@ const (
// the options
// 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.
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
{
return
nil
,
EINVAL
}
...
...
@@ -52,9 +53,9 @@ func (p *Process) Wait(options int) (w *Waitmsg, err Error) {
}
// 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
{
return
NewError
(
"os: process already finished"
)
return
errors
.
New
(
"os: process already finished"
)
}
if
e
:=
syscall
.
Kill
(
p
.
Pid
,
int
(
sig
.
(
UnixSignal
)));
e
!=
0
{
return
Errno
(
e
)
...
...
@@ -63,7 +64,7 @@ func (p *Process) Signal(sig Signal) Error {
}
// Release releases any resources associated with the Process.
func
(
p
*
Process
)
Release
()
E
rror
{
func
(
p
*
Process
)
Release
()
e
rror
{
// NOOP for unix.
p
.
Pid
=
-
1
// no need for a finalizer anymore
...
...
@@ -74,7 +75,7 @@ func (p *Process) Release() Error {
// FindProcess looks for a running process by its pid.
// The Process it returns can be used to obtain information
// 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.
return
newProcess
(
pid
,
0
),
nil
}
src/pkg/os/exec_windows.go
View file @
08a073a1
...
...
@@ -9,7 +9,7 @@ import (
"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
)
switch
s
{
case
syscall
.
WAIT_OBJECT_0
:
...
...
@@ -29,7 +29,7 @@ func (p *Process) Wait(options int) (w *Waitmsg, err Error) {
}
// 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
{
return
NewError
(
"os: process already finished"
)
}
...
...
@@ -41,7 +41,7 @@ func (p *Process) Signal(sig Signal) Error {
return
Errno
(
syscall
.
EWINDOWS
)
}
func
(
p
*
Process
)
Release
()
E
rror
{
func
(
p
*
Process
)
Release
()
e
rror
{
if
p
.
handle
==
-
1
{
return
EINVAL
}
...
...
@@ -55,7 +55,7 @@ func (p *Process) Release() Error {
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
|
syscall
.
PROCESS_QUERY_INFORMATION
|
syscall
.
SYNCHRONIZE
h
,
e
:=
syscall
.
OpenProcess
(
da
,
false
,
uint32
(
pid
))
...
...
src/pkg/os/file.go
View file @
08a073a1
...
...
@@ -9,6 +9,7 @@
package
os
import
(
"io"
"syscall"
)
...
...
@@ -47,21 +48,10 @@ const (
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.
// 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.
func
(
file
*
File
)
Read
(
b
[]
byte
)
(
n
int
,
err
E
rror
)
{
// It returns the number of bytes read and an
e
rror, if any.
// EOF is signaled by a zero count with err set to
io.
EOF.
func
(
file
*
File
)
Read
(
b
[]
byte
)
(
n
int
,
err
e
rror
)
{
if
file
==
nil
{
return
0
,
EINVAL
}
...
...
@@ -70,7 +60,7 @@ func (file *File) Read(b []byte) (n int, err Error) {
n
=
0
}
if
n
==
0
&&
len
(
b
)
>
0
&&
!
iserror
(
e
)
{
return
0
,
EOF
return
0
,
io
.
EOF
}
if
iserror
(
e
)
{
err
=
&
PathError
{
"read"
,
file
.
name
,
Errno
(
e
)}
...
...
@@ -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.
// 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.
// 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
)
{
// It returns the number of bytes read and the
e
rror, if any.
// 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).
func
(
file
*
File
)
ReadAt
(
b
[]
byte
,
off
int64
)
(
n
int
,
err
e
rror
)
{
if
file
==
nil
{
return
0
,
EINVAL
}
for
len
(
b
)
>
0
{
m
,
e
:=
file
.
pread
(
b
,
off
)
if
m
==
0
&&
!
iserror
(
e
)
{
return
n
,
EOF
return
n
,
io
.
EOF
}
if
iserror
(
e
)
{
err
=
&
PathError
{
"read"
,
file
.
name
,
Errno
(
e
)}
...
...
@@ -103,9 +93,9 @@ func (file *File) ReadAt(b []byte, off int64) (n int, err Error) {
}
// Write writes len(b) bytes to the File.
// It returns the number of bytes written and an
E
rror, if any.
// Write returns a non-nil
E
rror when n != len(b).
func
(
file
*
File
)
Write
(
b
[]
byte
)
(
n
int
,
err
E
rror
)
{
// It returns the number of bytes written and an
e
rror, if any.
// Write returns a non-nil
e
rror when n != len(b).
func
(
file
*
File
)
Write
(
b
[]
byte
)
(
n
int
,
err
e
rror
)
{
if
file
==
nil
{
return
0
,
EINVAL
}
...
...
@@ -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.
// It returns the number of bytes written and an
E
rror, if any.
// WriteAt returns a non-nil
E
rror when n != len(b).
func
(
file
*
File
)
WriteAt
(
b
[]
byte
,
off
int64
)
(
n
int
,
err
E
rror
)
{
// It returns the number of bytes written and an
e
rror, if any.
// WriteAt returns a non-nil
e
rror when n != len(b).
func
(
file
*
File
)
WriteAt
(
b
[]
byte
,
off
int64
)
(
n
int
,
err
e
rror
)
{
if
file
==
nil
{
return
0
,
EINVAL
}
...
...
@@ -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
// 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.
// It returns the new offset and an
E
rror, if any.
func
(
file
*
File
)
Seek
(
offset
int64
,
whence
int
)
(
ret
int64
,
err
E
rror
)
{
// It returns the new offset and an
e
rror, if any.
func
(
file
*
File
)
Seek
(
offset
int64
,
whence
int
)
(
ret
int64
,
err
e
rror
)
{
r
,
e
:=
file
.
seek
(
offset
,
whence
)
if
!
iserror
(
e
)
&&
file
.
dirinfo
!=
nil
&&
r
!=
0
{
e
=
syscall
.
EISDIR
...
...
@@ -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
// 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
{
return
0
,
EINVAL
}
...
...
@@ -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.
// 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
)
if
iserror
(
e
)
{
return
&
PathError
{
"mkdir"
,
name
,
Errno
(
e
)}
...
...
@@ -177,7 +167,7 @@ func Mkdir(name string, perm uint32) Error {
}
// 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
)
{
return
&
PathError
{
"chdir"
,
dir
,
Errno
(
e
)}
}
...
...
@@ -186,7 +176,7 @@ func Chdir(dir string) Error {
// Chdir changes the current working directory to the file,
// 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
)
{
return
&
PathError
{
"chdir"
,
f
.
name
,
Errno
(
e
)}
}
...
...
@@ -196,8 +186,8 @@ func (f *File) Chdir() Error {
// Open opens the named file for reading. If successful, methods on
// the returned file can be used for reading; the associated file
// descriptor has mode O_RDONLY.
// It returns the File and an
E
rror, if any.
func
Open
(
name
string
)
(
file
*
File
,
err
E
rror
)
{
// It returns the File and an
e
rror, if any.
func
Open
(
name
string
)
(
file
*
File
,
err
e
rror
)
{
return
OpenFile
(
name
,
O_RDONLY
,
0
)
}
...
...
@@ -205,7 +195,7 @@ func Open(name string) (file *File, err Error) {
// it if it already exists. If successful, methods on the returned
// File can be used for I/O; the associated file descriptor has mode
// O_RDWR.
// It returns the File and an
E
rror, if any.
func
Create
(
name
string
)
(
file
*
File
,
err
E
rror
)
{
// It returns the File and an
e
rror, if any.
func
Create
(
name
string
)
(
file
*
File
,
err
e
rror
)
{
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"
// or Create instead. It opens the named file with specified flag
// (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful,
// methods on the returned File can be used for I/O.
// It returns the File and an
E
rror, if any.
func
OpenFile
(
name
string
,
flag
int
,
perm
uint32
)
(
file
*
File
,
err
E
rror
)
{
// It returns the File and an
e
rror, if any.
func
OpenFile
(
name
string
,
flag
int
,
perm
uint32
)
(
file
*
File
,
err
e
rror
)
{
var
(
fd
int
e
syscall
.
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.
// It returns an
E
rror, if any.
func
(
file
*
File
)
Close
()
E
rror
{
// It returns an
e
rror, if any.
func
(
file
*
File
)
Close
()
e
rror
{
if
file
==
nil
||
file
.
fd
<
0
{
return
Ebadfd
}
var
err
E
rror
var
err
e
rror
syscall
.
ForkLock
.
RLock
()
if
e
:=
syscall
.
Close
(
file
.
fd
);
e
!=
nil
{
err
=
&
PathError
{
"close"
,
file
.
name
,
e
}
...
...
@@ -128,7 +128,7 @@ func (file *File) Close() Error {
// Stat returns the FileInfo structure describing file.
// 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
)
if
iserror
(
err
)
{
return
nil
,
err
...
...
@@ -138,7 +138,7 @@ func (f *File) Stat() (fi *FileInfo, err Error) {
// Truncate changes the size of the file.
// 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
d
.
Null
()
...
...
@@ -151,7 +151,7 @@ func (f *File) Truncate(size int64) Error {
}
// 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
mask
=
^
uint32
(
0777
)
...
...
@@ -171,7 +171,7 @@ func (f *File) Chmod(mode uint32) Error {
// Sync commits the current contents of the file to stable storage.
// Typically, this means flushing the file system's in-memory copy
// of recently written data to disk.
func
(
f
*
File
)
Sync
()
(
err
E
rror
)
{
func
(
f
*
File
)
Sync
()
(
err
e
rror
)
{
if
f
==
nil
{
return
EINVAL
}
...
...
@@ -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.
// 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
d
.
Null
()
...
...
@@ -233,7 +233,7 @@ func Truncate(name string, size int64) Error {
}
// 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
)
{
return
&
PathError
{
"remove"
,
name
,
e
}
}
...
...
@@ -241,7 +241,7 @@ func Remove(name string) Error {
}
// Rename renames a file.
func
Rename
(
oldname
,
newname
string
)
E
rror
{
func
Rename
(
oldname
,
newname
string
)
e
rror
{
var
d
Dir
d
.
Null
()
...
...
@@ -254,7 +254,7 @@ func Rename(oldname, newname string) Error {
}
// 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
mask
=
^
uint32
(
0777
)
...
...
@@ -277,7 +277,7 @@ func Chmod(name string, mode uint32) Error {
// The argument times are in nanoseconds, although the underlying
// filesystem may truncate or round the values to a more
// 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
d
.
Null
()
...
...
@@ -290,7 +290,7 @@ func Chtimes(name string, atimeNs int64, mtimeNs int64) Error {
return
nil
}
func
Pipe
()
(
r
*
File
,
w
*
File
,
err
E
rror
)
{
func
Pipe
()
(
r
*
File
,
w
*
File
,
err
e
rror
)
{
var
p
[
2
]
int
syscall
.
ForkLock
.
RLock
()
...
...
@@ -306,26 +306,26 @@ func Pipe() (r *File, w *File, err Error) {
// not supported on Plan 9
// Link creates a hard link.
func
Link
(
oldname
,
newname
string
)
E
rror
{
func
Link
(
oldname
,
newname
string
)
e
rror
{
return
EPLAN9
}
func
Symlink
(
oldname
,
newname
string
)
E
rror
{
func
Symlink
(
oldname
,
newname
string
)
e
rror
{
return
EPLAN9
}
func
Readlink
(
name
string
)
(
string
,
E
rror
)
{
func
Readlink
(
name
string
)
(
string
,
e
rror
)
{
return
""
,
EPLAN9
}
func
Chown
(
name
string
,
uid
,
gid
int
)
E
rror
{
func
Chown
(
name
string
,
uid
,
gid
int
)
e
rror
{
return
EPLAN9
}
func
Lchown
(
name
string
,
uid
,
gid
int
)
E
rror
{
func
Lchown
(
name
string
,
uid
,
gid
int
)
e
rror
{
return
EPLAN9
}
func
(
f
*
File
)
Chown
(
uid
,
gid
int
)
E
rror
{
func
(
f
*
File
)
Chown
(
uid
,
gid
int
)
e
rror
{
return
EPLAN9
}
src/pkg/os/file_posix.go
View file @
08a073a1
...
...
@@ -24,7 +24,7 @@ func epipecheck(file *File, e int) {
}
// 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
// whether name is a file or directory.
// Try both: it is cheaper on average than
...
...
@@ -59,18 +59,18 @@ func Remove(name string) Error {
// LinkError records an error during a link or symlink or rename
// system call and the paths that caused it.
type
LinkError
struct
{
Op
string
Old
string
New
string
Err
or
E
rror
Op
string
Old
string
New
string
Err
e
rror
}
func
(
e
*
LinkError
)
String
()
string
{
return
e
.
Op
+
" "
+
e
.
Old
+
" "
+
e
.
New
+
": "
+
e
.
Err
or
.
String
()
func
(
e
*
LinkError
)
Error
()
string
{
return
e
.
Op
+
" "
+
e
.
Old
+
" "
+
e
.
New
+
": "
+
e
.
Err
.
Error
()
}
// Link creates a hard link.
func
Link
(
oldname
,
newname
string
)
E
rror
{
func
Link
(
oldname
,
newname
string
)
e
rror
{
e
:=
syscall
.
Link
(
oldname
,
newname
)
if
iserror
(
e
)
{
return
&
LinkError
{
"link"
,
oldname
,
newname
,
Errno
(
e
)}
...
...
@@ -79,7 +79,7 @@ func Link(oldname, newname string) Error {
}
// Symlink creates a symbolic link.
func
Symlink
(
oldname
,
newname
string
)
E
rror
{
func
Symlink
(
oldname
,
newname
string
)
e
rror
{
e
:=
syscall
.
Symlink
(
oldname
,
newname
)
if
iserror
(
e
)
{
return
&
LinkError
{
"symlink"
,
oldname
,
newname
,
Errno
(
e
)}
...
...
@@ -88,8 +88,8 @@ func Symlink(oldname, newname string) Error {
}
// Readlink reads the contents of a symbolic link: the destination of
// the link. It returns the contents and an
E
rror, if any.
func
Readlink
(
name
string
)
(
string
,
E
rror
)
{
// the link. It returns the contents and an
e
rror, if any.
func
Readlink
(
name
string
)
(
string
,
e
rror
)
{
for
len
:=
128
;
;
len
*=
2
{
b
:=
make
([]
byte
,
len
)
n
,
e
:=
syscall
.
Readlink
(
name
,
b
)
...
...
@@ -105,7 +105,7 @@ func Readlink(name string) (string, Error) {
}
// Rename renames a file.
func
Rename
(
oldname
,
newname
string
)
E
rror
{
func
Rename
(
oldname
,
newname
string
)
e
rror
{
e
:=
syscall
.
Rename
(
oldname
,
newname
)
if
iserror
(
e
)
{
return
&
LinkError
{
"rename"
,
oldname
,
newname
,
Errno
(
e
)}
...
...
@@ -115,7 +115,7 @@ func Rename(oldname, newname string) Error {
// 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.
func
Chmod
(
name
string
,
mode
uint32
)
E
rror
{
func
Chmod
(
name
string
,
mode
uint32
)
e
rror
{
if
e
:=
syscall
.
Chmod
(
name
,
mode
);
iserror
(
e
)
{
return
&
PathError
{
"chmod"
,
name
,
Errno
(
e
)}
}
...
...
@@ -123,7 +123,7 @@ func Chmod(name string, mode uint32) Error {
}
// 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
)
{
return
&
PathError
{
"chmod"
,
f
.
name
,
Errno
(
e
)}
}
...
...
@@ -132,7 +132,7 @@ func (f *File) Chmod(mode uint32) Error {
// 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.
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
)
{
return
&
PathError
{
"chown"
,
name
,
Errno
(
e
)}
}
...
...
@@ -141,7 +141,7 @@ func Chown(name string, uid, gid int) Error {
// 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.
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
)
{
return
&
PathError
{
"lchown"
,
name
,
Errno
(
e
)}
}
...
...
@@ -149,7 +149,7 @@ func Lchown(name string, uid, gid int) Error {
}
// 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
)
{
return
&
PathError
{
"chown"
,
f
.
name
,
Errno
(
e
)}
}
...
...
@@ -158,7 +158,7 @@ func (f *File) Chown(uid, gid int) Error {
// Truncate changes the size of the file.
// 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
)
{
return
&
PathError
{
"truncate"
,
f
.
name
,
Errno
(
e
)}
}
...
...
@@ -168,7 +168,7 @@ func (f *File) Truncate(size int64) Error {
// Sync commits the current contents of the file to stable storage.
// Typically, this means flushing the file system's in-memory copy
// of recently written data to disk.
func
(
file
*
File
)
Sync
()
(
err
E
rror
)
{
func
(
file
*
File
)
Sync
()
(
err
e
rror
)
{
if
file
==
nil
{
return
EINVAL
}
...
...
@@ -184,7 +184,7 @@ func (file *File) Sync() (err Error) {
// The argument times are in nanoseconds, although the underlying
// filesystem may truncate or round the values to a more
// 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
utimes
[
0
]
=
syscall
.
NsecToTimeval
(
atime_ns
)
utimes
[
1
]
=
syscall
.
NsecToTimeval
(
mtime_ns
)
...
...
src/pkg/os/file_unix.go
View file @
08a073a1
...
...
@@ -52,8 +52,8 @@ const DevNull = "/dev/null"
// or Create instead. It opens the named file with specified flag
// (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful,
// methods on the returned File can be used for I/O.
// It returns the File and an
E
rror, if any.
func
OpenFile
(
name
string
,
flag
int
,
perm
uint32
)
(
file
*
File
,
err
E
rror
)
{
// It returns the File and an
e
rror, if any.
func
OpenFile
(
name
string
,
flag
int
,
perm
uint32
)
(
file
*
File
,
err
e
rror
)
{
r
,
e
:=
syscall
.
Open
(
name
,
flag
|
syscall
.
O_CLOEXEC
,
perm
)
if
e
!=
0
{
return
nil
,
&
PathError
{
"open"
,
name
,
Errno
(
e
)}
...
...
@@ -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.
// It returns an
E
rror, if any.
func
(
file
*
File
)
Close
()
E
rror
{
// It returns an
e
rror, if any.
func
(
file
*
File
)
Close
()
e
rror
{
if
file
==
nil
||
file
.
fd
<
0
{
return
EINVAL
}
var
err
E
rror
var
err
e
rror
if
e
:=
syscall
.
Close
(
file
.
fd
);
e
!=
0
{
err
=
&
PathError
{
"close"
,
file
.
name
,
Errno
(
e
)}
}
...
...
@@ -87,7 +87,7 @@ func (file *File) Close() Error {
// Stat returns the FileInfo structure describing file.
// 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
e
:=
syscall
.
Fstat
(
file
.
fd
,
&
stat
)
if
e
!=
0
{
...
...
@@ -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.
// If name names an invalid symbolic link, the returned FileInfo describes
// 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
e
:=
syscall
.
Lstat
(
name
,
&
lstat
)
if
iserror
(
e
)
{
...
...
@@ -120,7 +120,7 @@ func Stat(name string) (fi *FileInfo, err Error) {
// Lstat returns the FileInfo structure describing the named file and an
// 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.
func
Lstat
(
name
string
)
(
fi
*
FileInfo
,
err
E
rror
)
{
func
Lstat
(
name
string
)
(
fi
*
FileInfo
,
err
e
rror
)
{
var
stat
syscall
.
Stat_t
e
:=
syscall
.
Lstat
(
name
,
&
stat
)
if
iserror
(
e
)
{
...
...
@@ -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
// directory, Readdir returns the FileInfo read until that point
// 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
if
dirname
==
""
{
dirname
=
"."
...
...
@@ -198,7 +198,7 @@ func (f *File) seek(offset int64, whence int) (ret int64, err int) {
// Truncate changes the size of the named file.
// 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
{
return
&
PathError
{
"truncate"
,
name
,
Errno
(
e
)}
}
...
...
@@ -224,8 +224,8 @@ func basename(name string) string {
}
// 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.
func
Pipe
()
(
r
*
File
,
w
*
File
,
err
E
rror
)
{
// It returns the files and an
e
rror, if any.
func
Pipe
()
(
r
*
File
,
w
*
File
,
err
e
rror
)
{
var
p
[
2
]
int
// See ../syscall/exec.go for description of lock.
...
...
src/pkg/os/file_windows.go
View file @
08a073a1
...
...
@@ -5,6 +5,7 @@
package
os
import
(
"io"
"runtime"
"sync"
"syscall"
...
...
@@ -47,7 +48,7 @@ const DevNull = "NUL"
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
)
if
e
!=
0
{
return
nil
,
&
PathError
{
"open"
,
name
,
Errno
(
e
)}
...
...
@@ -62,7 +63,7 @@ func openFile(name string, flag int, perm uint32) (file *File, err Error) {
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
)
r
,
e
:=
syscall
.
FindFirstFile
(
syscall
.
StringToUTF16Ptr
(
name
+
`\*`
),
&
d
.
data
)
if
e
!=
0
{
...
...
@@ -77,8 +78,8 @@ func openDir(name string) (file *File, err Error) {
// or Create instead. It opens the named file with specified flag
// (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful,
// methods on the returned File can be used for I/O.
// It returns the File and an
E
rror, if any.
func
OpenFile
(
name
string
,
flag
int
,
perm
uint32
)
(
file
*
File
,
err
E
rror
)
{
// It returns the File and an
e
rror, if any.
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
r
,
e
:=
openDir
(
name
)
if
e
==
nil
{
...
...
@@ -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.
// It returns an
E
rror, if any.
func
(
file
*
File
)
Close
()
E
rror
{
// It returns an
e
rror, if any.
func
(
file
*
File
)
Close
()
e
rror
{
if
file
==
nil
||
file
.
fd
<
0
{
return
EINVAL
}
...
...
@@ -107,7 +108,7 @@ func (file *File) Close() Error {
}
else
{
e
=
syscall
.
CloseHandle
(
syscall
.
Handle
(
file
.
fd
))
}
var
err
E
rror
var
err
e
rror
if
e
!=
0
{
err
=
&
PathError
{
"close"
,
file
.
name
,
Errno
(
e
)}
}
...
...
@@ -133,7 +134,7 @@ func (file *File) Close() Error {
// nil os.Error. If it encounters an error before the end of the
// directory, Readdir returns the FileInfo read until that point
// 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
{
return
nil
,
EINVAL
}
...
...
@@ -173,7 +174,7 @@ func (file *File) Readdir(n int) (fi []FileInfo, err Error) {
fi
=
append
(
fi
,
f
)
}
if
!
wantAll
&&
len
(
fi
)
==
0
{
return
fi
,
EOF
return
fi
,
io
.
EOF
}
return
fi
,
nil
}
...
...
@@ -251,7 +252,7 @@ func (f *File) seek(offset int64, whence int) (ret int64, err int) {
// Truncate changes the size of the named file.
// 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
)
if
e
!=
nil
{
return
e
...
...
@@ -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.
// It returns the files and an
E
rror, if any.
func
Pipe
()
(
r
*
File
,
w
*
File
,
err
E
rror
)
{
// It returns the files and an
e
rror, if any.
func
Pipe
()
(
r
*
File
,
w
*
File
,
err
e
rror
)
{
var
p
[
2
]
syscall
.
Handle
// See ../syscall/exec.go for description of lock.
...
...
src/pkg/os/getwd.go
View file @
08a073a1
...
...
@@ -12,7 +12,7 @@ import (
// current directory. If the current directory can be
// reached via multiple paths (due to symbolic links),
// 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
syscall
.
ImplementsGetwd
{
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 {
for
{
n
,
e
:=
file
.
Read
(
buf
[
0
:
])
len
+=
n
if
e
==
EOF
{
if
e
==
io
.
EOF
{
break
}
if
e
!=
nil
{
...
...
@@ -257,7 +257,7 @@ func smallReaddirnames(file *File, length int, t *testing.T) []string {
count
:=
0
for
{
d
,
err
:=
file
.
Readdirnames
(
1
)
if
err
==
EOF
{
if
err
==
io
.
EOF
{
break
}
if
err
!=
nil
{
...
...
@@ -328,14 +328,14 @@ func TestReaddirNValues(t *testing.T) {
var
d
*
File
openDir
:=
func
()
{
var
err
E
rror
var
err
e
rror
d
,
err
=
Open
(
dir
)
if
err
!=
nil
{
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
)
if
err
!=
wantErr
{
t
.
Fatalf
(
"Readdir of %d got error %v, want %v"
,
n
,
err
,
wantErr
)
...
...
@@ -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
)
if
err
!=
wantErr
{
t
.
Fatalf
(
"Readdirnames of %d got error %v, want %v"
,
n
,
err
,
wantErr
)
...
...
@@ -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
openDir
()
fn
(
0
,
105
,
nil
)
...
...
@@ -374,7 +374,7 @@ func TestReaddirNValues(t *testing.T) {
fn
(
1
,
1
,
nil
)
fn
(
2
,
2
,
nil
)
fn
(
105
,
102
,
nil
)
// and tests buffer >100 case
fn
(
3
,
0
,
EOF
)
fn
(
3
,
0
,
io
.
EOF
)
d
.
Close
()
}
}
...
...
@@ -841,7 +841,7 @@ func TestSeek(t *testing.T) {
for
i
,
tt
:=
range
tests
{
off
,
err
:=
f
.
Seek
(
tt
.
in
,
tt
.
whence
)
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.
// http://code.google.com/p/go/issues/detail?id=91
break
...
...
@@ -854,7 +854,7 @@ func TestSeek(t *testing.T) {
type
openErrorTest
struct
{
path
string
mode
int
error
E
rror
error
e
rror
}
var
openErrorTests
=
[]
openErrorTest
{
...
...
@@ -887,15 +887,15 @@ func TestOpenError(t *testing.T) {
if
!
ok
{
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"
{
syscallErrStr
:=
perr
.
Err
or
.
String
()
expectedErrStr
:=
strings
.
Replace
(
tt
.
error
.
String
(),
"file "
,
""
,
1
)
syscallErrStr
:=
perr
.
Err
.
Error
()
expectedErrStr
:=
strings
.
Replace
(
tt
.
error
.
Error
(),
"file "
,
""
,
1
)
if
!
strings
.
HasSuffix
(
syscallErrStr
,
expectedErrStr
)
{
t
.
Errorf
(
"Open(%q, %d) = _, %q; want suffix %q"
,
tt
.
path
,
tt
.
mode
,
syscallErrStr
,
expectedErrStr
)
}
}
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 @@
package
os
import
"io"
// MkdirAll creates a directory named path,
// along with any necessary parents, and returns nil,
// or else returns an error.
...
...
@@ -11,7 +13,7 @@ package os
// directories that MkdirAll creates.
// If path is already a directory, MkdirAll does nothing
// 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.
dir
,
err
:=
Stat
(
path
)
if
err
==
nil
{
...
...
@@ -58,7 +60,7 @@ func MkdirAll(path string, perm uint32) Error {
// It removes everything it can but returns the first error
// it encounters. If the path does not exist, RemoveAll
// returns nil (no error).
func
RemoveAll
(
path
string
)
E
rror
{
func
RemoveAll
(
path
string
)
e
rror
{
// Simple case: if Remove works, we're done.
err
:=
Remove
(
path
)
if
err
==
nil
{
...
...
@@ -68,7 +70,7 @@ func RemoveAll(path string) Error {
// Otherwise, is this a directory we need to recurse into?
dir
,
serr
:=
Lstat
(
path
)
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
serr
...
...
@@ -94,7 +96,7 @@ func RemoveAll(path string) Error {
err
=
err1
}
}
if
err1
==
EOF
{
if
err1
==
io
.
EOF
{
break
}
// 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) {
if
err
!=
nil
{
pathErr
,
ok
:=
err
.
(
*
PathError
)
// common for users not to be able to write to /
if
ok
&&
pathErr
.
Err
or
==
EACCES
{
if
ok
&&
pathErr
.
Err
==
EACCES
{
return
}
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() }
func
Getegid
()
int
{
return
syscall
.
Getegid
()
}
// 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
()
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 {
}
// 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
nd
:=
syscall
.
STATFIXLEN
+
16
*
4
...
...
@@ -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.
func
Stat
(
name
string
)
(
fi
*
FileInfo
,
err
E
rror
)
{
func
Stat
(
name
string
)
(
fi
*
FileInfo
,
err
e
rror
)
{
d
,
err
:=
dirstat
(
name
)
if
iserror
(
err
)
{
return
nil
,
err
...
...
@@ -81,7 +81,7 @@ func Stat(name string) (fi *FileInfo, err Error) {
// 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),
// 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
)
if
iserror
(
err
)
{
return
nil
,
err
...
...
src/pkg/os/stat_windows.go
View file @
08a073a1
...
...
@@ -11,7 +11,7 @@ import (
// Stat returns the FileInfo structure describing file.
// 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
{
return
nil
,
EINVAL
}
...
...
@@ -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.
// If name names an invalid symbolic link, the returned FileInfo describes
// 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
{
return
nil
,
&
PathError
{
"Stat"
,
name
,
Errno
(
syscall
.
ERROR_PATH_NOT_FOUND
)}
}
...
...
@@ -47,7 +47,7 @@ func Stat(name string) (fi *FileInfo, err Error) {
// Lstat returns the FileInfo structure describing the named file and an
// 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.
func
Lstat
(
name
string
)
(
fi
*
FileInfo
,
err
E
rror
)
{
func
Lstat
(
name
string
)
(
fi
*
FileInfo
,
err
e
rror
)
{
// No links on Windows
return
Stat
(
name
)
}
...
...
src/pkg/os/sys_bsd.go
View file @
08a073a1
...
...
@@ -11,7 +11,7 @@ package os
import
"syscall"
func
Hostname
()
(
name
string
,
err
E
rror
)
{
func
Hostname
()
(
name
string
,
err
e
rror
)
{
var
errno
int
name
,
errno
=
syscall
.
Sysctl
(
"kern.hostname"
)
if
errno
!=
0
{
...
...
src/pkg/os/sys_linux.go
View file @
08a073a1
...
...
@@ -7,7 +7,7 @@
package
os
// 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"
)
if
err
!=
nil
{
return
""
,
err
...
...
src/pkg/os/sys_plan9.go
View file @
08a073a1
...
...
@@ -6,7 +6,7 @@
package
os
func
Hostname
()
(
name
string
,
err
E
rror
)
{
func
Hostname
()
(
name
string
,
err
e
rror
)
{
f
,
err
:=
Open
(
"#c/sysname"
)
if
err
!=
nil
{
return
""
,
err
...
...
src/pkg/os/sys_windows.go
View file @
08a073a1
...
...
@@ -6,7 +6,7 @@ package os
import
"syscall"
func
Hostname
()
(
name
string
,
err
E
rror
)
{
func
Hostname
()
(
name
string
,
err
e
rror
)
{
s
,
e
:=
syscall
.
ComputerName
()
if
e
!=
0
{
return
""
,
NewSyscallError
(
"ComputerName"
,
e
)
...
...
src/pkg/os/time.go
View file @
08a073a1
...
...
@@ -7,10 +7,10 @@ package os
import
"syscall"
// 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 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
if
e
:=
syscall
.
Gettimeofday
(
&
tv
);
iserror
(
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