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
79d94d50
Commit
79d94d50
authored
Nov 19, 2008
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Copyn
R=rsc DELTA=34 (34 added, 0 deleted, 0 changed) OCL=19541 CL=19545
parent
23bd1298
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
0 deletions
+34
-0
io.go
src/lib/io.go
+34
-0
No files found.
src/lib/io.go
View file @
79d94d50
...
...
@@ -76,3 +76,37 @@ export func MakeFullReader(fd Read) Read {
}
return
&
FullRead
{
fd
}
}
// Copies n bytes (or until EOF is reached) from src to dst.
// Returns the number of bytes copied and the error, if any.
export
func
Copyn
(
src
Read
,
dst
Write
,
n
int
)
(
c
int
,
err
*
os
.
Error
)
{
buf
:=
new
([]
byte
,
32
*
1024
);
// BUG 6g crashes on non-pointer array slices
c
=
0
;
for
c
<
n
{
l
:=
n
-
c
;
if
l
>
len
(
buf
)
{
l
=
len
(
buf
)
}
nr
,
er
:=
src
.
Read
(
buf
[
0
:
l
]);
if
nr
>
0
{
nw
,
ew
:=
dst
.
Write
(
buf
[
0
:
nr
]);
if
nw
!=
nr
||
ew
!=
nil
{
c
+=
nw
;
if
ew
==
nil
{
ew
=
os
.
EIO
}
err
=
ew
;
break
;
}
c
+=
nr
;
}
if
er
!=
nil
{
err
=
er
;
break
;
}
if
nr
==
0
{
break
;
}
}
return
c
,
err
}
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