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
c870ac23
Commit
c870ac23
authored
Jul 15, 2008
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add sys.writefile; support for darwin only in this CL
SVN=127153
parent
e9a19438
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
3 deletions
+42
-3
sys.go
src/cmd/gc/sys.go
+2
-0
sysimport.c
src/cmd/gc/sysimport.c
+0
-0
runtime.h
src/runtime/runtime.h
+2
-1
sys_amd64_darwin.s
src/runtime/sys_amd64_darwin.s
+9
-0
sys_file.c
src/runtime/sys_file.c
+29
-2
No files found.
src/cmd/gc/sys.go
View file @
c870ac23
...
@@ -53,6 +53,7 @@ func gosched();
...
@@ -53,6 +53,7 @@ func gosched();
func
goexit
();
func
goexit
();
func
readfile
(
string
)
(
string
,
bool
);
// read file into string; boolean status
func
readfile
(
string
)
(
string
,
bool
);
// read file into string; boolean status
func
writefile
(
string
,
string
)
(
bool
);
// write string into file; boolean status
func
bytestorune
(
*
byte
,
int32
,
int32
)
(
int32
,
int32
);
// convert bytes to runes
func
bytestorune
(
*
byte
,
int32
,
int32
)
(
int32
,
int32
);
// convert bytes to runes
func
stringtorune
(
string
,
int32
,
int32
)
(
int32
,
int32
);
// convert bytes to runes
func
stringtorune
(
string
,
int32
,
int32
)
(
int32
,
int32
);
// convert bytes to runes
...
@@ -113,6 +114,7 @@ export
...
@@ -113,6 +114,7 @@ export
// files
// files
readfile
readfile
writefile
// runes and utf-8
// runes and utf-8
bytestorune
bytestorune
...
...
src/cmd/gc/sysimport.c
View file @
c870ac23
This diff is collapsed.
Click to expand it.
src/runtime/runtime.h
View file @
c870ac23
...
@@ -196,8 +196,9 @@ void* mal(uint32);
...
@@ -196,8 +196,9 @@ void* mal(uint32);
uint32
cmpstring
(
string
,
string
);
uint32
cmpstring
(
string
,
string
);
void
initsig
(
void
);
void
initsig
(
void
);
void
traceback
(
uint8
*
pc
,
uint8
*
sp
,
G
*
gp
);
void
traceback
(
uint8
*
pc
,
uint8
*
sp
,
G
*
gp
);
int32
open
(
byte
*
,
int32
);
int32
open
(
byte
*
,
int32
,
...
);
int32
read
(
int32
,
void
*
,
int32
);
int32
read
(
int32
,
void
*
,
int32
);
int32
write
(
int32
,
void
*
,
int32
);
void
close
(
int32
);
void
close
(
int32
);
int32
fstat
(
int32
,
void
*
);
int32
fstat
(
int32
,
void
*
);
...
...
src/runtime/sys_amd64_darwin.s
View file @
c870ac23
...
@@ -26,6 +26,7 @@ TEXT sys·write(SB),1,$-8
...
@@ -26,6 +26,7 @@ TEXT sys·write(SB),1,$-8
TEXT open(SB),1,$-8
TEXT open(SB),1,$-8
MOVQ 8(SP), DI
MOVQ 8(SP), DI
MOVL 16(SP), SI
MOVL 16(SP), SI
MOVL 20(SP), DX
MOVQ $0, R10
MOVQ $0, R10
MOVL $(0x2000000+5), AX // syscall entry
MOVL $(0x2000000+5), AX // syscall entry
SYSCALL
SYSCALL
...
@@ -52,6 +53,14 @@ TEXT read(SB),1,$-8
...
@@ -52,6 +53,14 @@ TEXT read(SB),1,$-8
SYSCALL
SYSCALL
RET
RET
TEXT write(SB),1,$-8
MOVL 8(SP), DI
MOVQ 16(SP), SI
MOVL 24(SP), DX
MOVL $(0x2000000+4), AX // syscall entry
SYSCALL
RET
TEXT sys·sigaction(SB),1,$-8
TEXT sys·sigaction(SB),1,$-8
MOVL 8(SP), DI // arg 1 sig
MOVL 8(SP), DI // arg 1 sig
MOVQ 16(SP), SI // arg 2 act
MOVQ 16(SP), SI // arg 2 act
...
...
src/runtime/sys_file.c
View file @
c870ac23
...
@@ -37,12 +37,39 @@ sys·readfile(string filein, string fileout, bool okout)
...
@@ -37,12 +37,39 @@ sys·readfile(string filein, string fileout, bool okout)
fileout
=
nil
;
fileout
=
nil
;
goto
close_out
;
goto
close_out
;
}
}
okout
=
1
;
okout
=
true
;
close_out
:
close_out
:
close
(
fd
);
close
(
fd
);
out
:
out
:
FLUSH
(
&
fileout
);
FLUSH
(
&
fileout
);
FLUSH
(
&
okout
);
FLUSH
(
&
okout
);
return
;
}
void
sys
·
writefile
(
string
filein
,
string
textin
,
bool
okout
)
{
int32
fd
;
byte
namebuf
[
256
];
okout
=
false
;
if
(
filein
==
nil
||
filein
->
len
>=
sizeof
(
namebuf
))
goto
out
;
mcpy
(
namebuf
,
filein
->
str
,
filein
->
len
);
namebuf
[
filein
->
len
]
=
'\0'
;
fd
=
open
(
namebuf
,
1
|
0x0200
,
0644
);
// open for write, create if non-existant (sic)
if
(
fd
<
0
)
goto
out
;
if
(
write
(
fd
,
textin
->
str
,
textin
->
len
)
!=
textin
->
len
)
{
goto
close_out
;
}
okout
=
true
;
close_out
:
close
(
fd
);
out
:
FLUSH
(
&
okout
);
}
}
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