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
289ff7d0
Commit
289ff7d0
authored
Jan 08, 2009
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache *os.Error values across all users.
R=rsc DELTA=27 (23 added, 0 deleted, 4 changed) OCL=22245 CL=22245
parent
eed3addb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
4 deletions
+27
-4
os_error.go
src/lib/os/os_error.go
+27
-4
No files found.
src/lib/os/os_error.go
View file @
289ff7d0
...
...
@@ -12,24 +12,47 @@ export type Error struct {
s
string
}
// Indexed by errno.
// If we worry about syscall speed (only relevant on failure), we could
// make it an array, but it's probably not important.
var
ErrorTab
=
make
(
map
[
int64
]
*
Error
);
// Table of all known errors in system. Use the same error string twice,
// get the same *os.Error.
var
ErrorStringTab
=
make
(
map
[
string
]
*
Error
);
// These functions contain a race if two goroutines add identical
// errors simultaneously but the consequences are unimportant.
// Allocate an Error objecct, but if it's been seen before, share that one.
export
func
NewError
(
s
string
)
*
Error
{
return
&
Error
{
s
}
if
s
==
""
{
return
nil
}
err
,
ok
:=
ErrorStringTab
[
s
];
if
ok
{
return
err
}
err
=
&
Error
{
s
};
ErrorStringTab
[
s
]
=
err
;
return
err
;
}
// Allocate an Error objecct, but if it's been seen before, share that one.
export
func
ErrnoToError
(
errno
int64
)
*
Error
{
if
errno
==
0
{
return
nil
}
// Quick lookup by errno.
err
,
ok
:=
ErrorTab
[
errno
];
if
ok
{
return
err
}
e
:
=
NewError
(
syscall
.
errstr
(
errno
));
ErrorTab
[
errno
]
=
e
;
return
e
;
e
rr
=
NewError
(
syscall
.
errstr
(
errno
));
ErrorTab
[
errno
]
=
e
rr
;
return
e
rr
;
}
export
var
(
ENONE
=
ErrnoToError
(
syscall
.
ENONE
);
EPERM
=
ErrnoToError
(
syscall
.
EPERM
);
...
...
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