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
c870ac23
Commit
c870ac23
authored
Jul 14, 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
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
156 additions
and
112 deletions
+156
-112
src/cmd/gc/sys.go
src/cmd/gc/sys.go
+2
-0
src/cmd/gc/sysimport.c
src/cmd/gc/sysimport.c
+114
-109
src/runtime/runtime.h
src/runtime/runtime.h
+2
-1
src/runtime/sys_amd64_darwin.s
src/runtime/sys_amd64_darwin.s
+9
-0
src/runtime/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();
func
goexit
();
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
stringtorune
(
string
,
int32
,
int32
)
(
int32
,
int32
);
// convert bytes to runes
...
...
@@ -113,6 +114,7 @@ export
// files
readfile
writefile
// runes and utf-8
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);
uint32
cmpstring
(
string
,
string
);
void
initsig
(
void
);
void
traceback
(
uint8
*
pc
,
uint8
*
sp
,
G
*
gp
);
int32
open
(
byte
*
,
int32
);
int32
open
(
byte
*
,
int32
,
...
);
int32
read
(
int32
,
void
*
,
int32
);
int32
write
(
int32
,
void
*
,
int32
);
void
close
(
int32
);
int32
fstat
(
int32
,
void
*
);
...
...
src/runtime/sys_amd64_darwin.s
View file @
c870ac23
...
...
@@ -26,6 +26,7 @@ TEXT sys·write(SB),1,$-8
TEXT
open
(
SB
),1,$-8
MOVQ
8
(
SP
),
DI
MOVL
16
(
SP
),
SI
MOVL
20
(
SP
),
DX
MOVQ
$
0
,
R10
MOVL
$
(
0x2000000
+
5
),
AX
//
syscall
entry
SYSCALL
...
...
@@ -52,6 +53,14 @@ TEXT read(SB),1,$-8
SYSCALL
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
MOVL
8
(
SP
),
DI
//
arg
1
sig
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)
fileout
=
nil
;
goto
close_out
;
}
okout
=
1
;
okout
=
true
;
close_out:
close
(
fd
);
out:
FLUSH
(
&
fileout
);
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