mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
add lib/os to standard build
break lib/os into multiple source files R=rsc DELTA=189 (178 added, 4 deleted, 7 changed) OCL=15149 CL=15152
This commit is contained in:
parent
c7ebfed655
commit
c80b06a54e
7 changed files with 197 additions and 11 deletions
|
|
@ -6,6 +6,10 @@
|
||||||
|
|
||||||
rm -f $GOROOT/pkg/*
|
rm -f $GOROOT/pkg/*
|
||||||
|
|
||||||
cd math
|
for i in os math
|
||||||
bash clean.bash
|
do
|
||||||
cd ..
|
cd $i
|
||||||
|
make nuke
|
||||||
|
cd ..
|
||||||
|
done
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,11 @@ do
|
||||||
6g -o $GOROOT/pkg/$base.6 $i
|
6g -o $GOROOT/pkg/$base.6 $i
|
||||||
done
|
done
|
||||||
|
|
||||||
echo; echo; echo %%%% making lib/math %%%%; echo
|
for i in os math
|
||||||
|
do
|
||||||
cd math
|
echo; echo; echo %%%% making lib/$i %%%%; echo
|
||||||
bash make.bash
|
cd $i
|
||||||
cd ..
|
make install
|
||||||
|
cd ..
|
||||||
|
done
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,20 @@ GC=$(O)g
|
||||||
PKG=$(GOROOT)/pkg/os.a
|
PKG=$(GOROOT)/pkg/os.a
|
||||||
|
|
||||||
O1=\
|
O1=\
|
||||||
os.$O
|
os_base.$O os_error.$O
|
||||||
|
O2=\
|
||||||
|
os_file.$O
|
||||||
|
|
||||||
install: $(PKG)
|
install: $(PKG)
|
||||||
|
|
||||||
$(PKG): a1
|
$(PKG): a1 a2
|
||||||
|
|
||||||
a1: $(O1)
|
a1: $(O1)
|
||||||
$(O)ar grc $(PKG) $(O1)
|
$(O)ar grc $(PKG) $(O1)
|
||||||
|
|
||||||
|
a2: $(O2)
|
||||||
|
$(O)ar grc $(PKG) $(O2)
|
||||||
|
|
||||||
nuke:
|
nuke:
|
||||||
rm -f *.$(O) *.a $(PKG)
|
rm -f *.$(O) *.a $(PKG)
|
||||||
|
|
||||||
|
|
|
||||||
18
src/lib/os/os_base.go
Normal file
18
src/lib/os/os_base.go
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
// Copyright 2009 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package os
|
||||||
|
|
||||||
|
// Support types and routines for OS library
|
||||||
|
|
||||||
|
export func StringToBytes(b *[]byte, s string) bool {
|
||||||
|
if len(s) >= len(b) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for i := 0; i < len(s); i++ {
|
||||||
|
b[i] = s[i]
|
||||||
|
}
|
||||||
|
b[len(s)] = '\000'; // not necessary - memory is zeroed - but be explicit
|
||||||
|
return true
|
||||||
|
}
|
||||||
76
src/lib/os/os_error.go
Normal file
76
src/lib/os/os_error.go
Normal file
|
|
@ -0,0 +1,76 @@
|
||||||
|
// Copyright 2009 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package os
|
||||||
|
|
||||||
|
import syscall "syscall"
|
||||||
|
|
||||||
|
// Errors are singleton structures. Use the Print()/String() methods to get their contents --
|
||||||
|
// they handle the nil (no error) case.
|
||||||
|
export type Error struct {
|
||||||
|
s string
|
||||||
|
}
|
||||||
|
|
||||||
|
var ErrorTab = new(map[int64] *Error);
|
||||||
|
|
||||||
|
export func ErrnoToError(errno int64) *Error {
|
||||||
|
if errno == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
err, ok := ErrorTab[errno]
|
||||||
|
if ok {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
e := new(Error);
|
||||||
|
e.s = syscall.errstr(errno);
|
||||||
|
ErrorTab[errno] = e;
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
export var (
|
||||||
|
ENONE = ErrnoToError(syscall.ENONE);
|
||||||
|
EPERM = ErrnoToError(syscall.EPERM);
|
||||||
|
ENOENT = ErrnoToError(syscall.ENOENT);
|
||||||
|
ESRCH = ErrnoToError(syscall.ESRCH);
|
||||||
|
EINTR = ErrnoToError(syscall.EINTR);
|
||||||
|
EIO = ErrnoToError(syscall.EIO);
|
||||||
|
ENXIO = ErrnoToError(syscall.ENXIO);
|
||||||
|
E2BIG = ErrnoToError(syscall.E2BIG);
|
||||||
|
ENOEXEC = ErrnoToError(syscall.ENOEXEC);
|
||||||
|
EBADF = ErrnoToError(syscall.EBADF);
|
||||||
|
ECHILD = ErrnoToError(syscall.ECHILD);
|
||||||
|
EDEADLK = ErrnoToError(syscall.EDEADLK);
|
||||||
|
ENOMEM = ErrnoToError(syscall.ENOMEM);
|
||||||
|
EACCES = ErrnoToError(syscall.EACCES);
|
||||||
|
EFAULT = ErrnoToError(syscall.EFAULT);
|
||||||
|
ENOTBLK = ErrnoToError(syscall.ENOTBLK);
|
||||||
|
EBUSY = ErrnoToError(syscall.EBUSY);
|
||||||
|
EEXIST = ErrnoToError(syscall.EEXIST);
|
||||||
|
EXDEV = ErrnoToError(syscall.EXDEV);
|
||||||
|
ENODEV = ErrnoToError(syscall.ENODEV);
|
||||||
|
ENOTDIR = ErrnoToError(syscall.ENOTDIR);
|
||||||
|
EISDIR = ErrnoToError(syscall.EISDIR);
|
||||||
|
EINVAL = ErrnoToError(syscall.EINVAL);
|
||||||
|
ENFILE = ErrnoToError(syscall.ENFILE);
|
||||||
|
EMFILE = ErrnoToError(syscall.EMFILE);
|
||||||
|
ENOTTY = ErrnoToError(syscall.ENOTTY);
|
||||||
|
ETXTBSY = ErrnoToError(syscall.ETXTBSY);
|
||||||
|
EFBIG = ErrnoToError(syscall.EFBIG);
|
||||||
|
ENOSPC = ErrnoToError(syscall.ENOSPC);
|
||||||
|
ESPIPE = ErrnoToError(syscall.ESPIPE);
|
||||||
|
EROFS = ErrnoToError(syscall.EROFS);
|
||||||
|
EMLINK = ErrnoToError(syscall.EMLINK);
|
||||||
|
EPIPE = ErrnoToError(syscall.EPIPE);
|
||||||
|
EDOM = ErrnoToError(syscall.EDOM);
|
||||||
|
ERANGE = ErrnoToError(syscall.ERANGE);
|
||||||
|
EAGAIN = ErrnoToError(syscall.EAGAIN);
|
||||||
|
)
|
||||||
|
const NoError = "No Error"
|
||||||
|
|
||||||
|
func (e *Error) String() string {
|
||||||
|
if e == nil {
|
||||||
|
return NoError
|
||||||
|
} else {
|
||||||
|
return e.s
|
||||||
|
}
|
||||||
|
}
|
||||||
74
src/lib/os/os_file.go
Normal file
74
src/lib/os/os_file.go
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
// Copyright 2009 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package os
|
||||||
|
|
||||||
|
import syscall "syscall"
|
||||||
|
import os "os"
|
||||||
|
|
||||||
|
// FDs are wrappers for file descriptors
|
||||||
|
export type FD struct {
|
||||||
|
fd int64
|
||||||
|
}
|
||||||
|
|
||||||
|
export func NewFD(fd int64) *FD {
|
||||||
|
if fd < 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
n := new(FD);
|
||||||
|
n.fd = fd;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
export var (
|
||||||
|
Stdin = NewFD(0);
|
||||||
|
Stdout = NewFD(1);
|
||||||
|
Stderr = NewFD(2);
|
||||||
|
)
|
||||||
|
|
||||||
|
export func Open(name string, mode int64, flags int64) (fd *FD, err *Error) {
|
||||||
|
var buf [512]byte;
|
||||||
|
if !StringToBytes(&buf, name) {
|
||||||
|
return nil, EINVAL
|
||||||
|
}
|
||||||
|
r, e := syscall.open(&buf[0], mode, flags);
|
||||||
|
return NewFD(r), ErrnoToError(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fd *FD) Close() *Error {
|
||||||
|
if fd == nil {
|
||||||
|
return EINVAL
|
||||||
|
}
|
||||||
|
r, e := syscall.close(fd.fd);
|
||||||
|
fd.fd = -1; // so it can't be closed again
|
||||||
|
return ErrnoToError(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fd *FD) Read(b *[]byte) (ret int64, err *Error) {
|
||||||
|
if fd == nil {
|
||||||
|
return -1, EINVAL
|
||||||
|
}
|
||||||
|
r, e := syscall.read(fd.fd, &b[0], int64(len(b)));
|
||||||
|
return r, ErrnoToError(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fd *FD) Write(b *[]byte) (ret int64, err *Error) {
|
||||||
|
if fd == nil {
|
||||||
|
return -1, EINVAL
|
||||||
|
}
|
||||||
|
r, e := syscall.write(fd.fd, &b[0], int64(len(b)));
|
||||||
|
return r, ErrnoToError(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fd *FD) WriteString(s string) (ret int64, err *Error) {
|
||||||
|
if fd == nil {
|
||||||
|
return -1, EINVAL
|
||||||
|
}
|
||||||
|
b := new([]byte, len(s)+1);
|
||||||
|
if !StringToBytes(b, s) {
|
||||||
|
return -1, EINVAL
|
||||||
|
}
|
||||||
|
r, e := syscall.write(fd.fd, &b[0], int64(len(s)));
|
||||||
|
return r, ErrnoToError(e)
|
||||||
|
}
|
||||||
|
|
@ -12,7 +12,7 @@ do
|
||||||
cd ..
|
cd ..
|
||||||
done
|
done
|
||||||
|
|
||||||
for i in cmd runtime lib
|
for i in cmd runtime
|
||||||
do
|
do
|
||||||
cd $i
|
cd $i
|
||||||
bash make.bash
|
bash make.bash
|
||||||
|
|
@ -27,3 +27,10 @@ do
|
||||||
make install
|
make install
|
||||||
cd ..
|
cd ..
|
||||||
done
|
done
|
||||||
|
|
||||||
|
for i in lib
|
||||||
|
do
|
||||||
|
cd $i
|
||||||
|
bash make.bash
|
||||||
|
cd ..
|
||||||
|
done
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue