summaryrefslogtreecommitdiff
path: root/src/lib/os/file.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-05-15 14:11:24 -0700
committerRuss Cox <rsc@golang.org>2009-05-15 14:11:24 -0700
commit0ba6e1dc3cf14ba32446f2877097a18f2448f58f (patch)
tree5a901abf7c202d84926a001bc0482a98f3784775 /src/lib/os/file.go
parent12ea0da0dfcff4d601e29bb77467f5a8a06024c7 (diff)
downloadgolang-0ba6e1dc3cf14ba32446f2877097a18f2448f58f.tar.gz
os: MkdirAll, RemoveAll, Chmod, Chown, Truncate, Getgroups.
Getuid, etc drop their errors -- they cannot error R=r DELTA=605 (547 added, 12 deleted, 46 changed) OCL=28919 CL=28929
Diffstat (limited to 'src/lib/os/file.go')
-rw-r--r--src/lib/os/file.go60
1 files changed, 54 insertions, 6 deletions
diff --git a/src/lib/os/file.go b/src/lib/os/file.go
index 19706e3df..d65807326 100644
--- a/src/lib/os/file.go
+++ b/src/lib/os/file.go
@@ -315,23 +315,23 @@ func Remove(name string) Error {
}
// Link creates a hard link.
-func Link(oldpath, newpath string) Error {
- r, e := syscall.Link(oldpath, newpath);
+func Link(oldname, newname string) Error {
+ r, e := syscall.Link(oldname, newname);
return ErrnoToError(e);
}
// Symlink creates a symbolic link.
-func Symlink(oldpath, newpath string) Error {
- r, e := syscall.Symlink(oldpath, newpath);
+func Symlink(oldname, newname string) Error {
+ r, e := syscall.Symlink(oldname, newname);
return ErrnoToError(e);
}
// Readlink reads the contents of a symbolic link: the destination of
// the link. It returns the contents and an Error, if any.
-func Readlink(path string) (string, Error) {
+func Readlink(name string) (string, Error) {
for len := int64(128); ; len *= 2 {
b := make([]byte, len);
- r, e := syscall.Readlink(path, &b[0], len);
+ r, e := syscall.Readlink(name, &b[0], len);
if r == -1 {
return "", ErrnoToError(e);
} else if r < len {
@@ -341,3 +341,51 @@ func Readlink(path string) (string, Error) {
// Silence 6g.
return "", nil;
}
+
+// Chmod changes the mode of the named file to mode.
+// If the file is a symbolic link, it changes the uid and gid of the link's target.
+func Chmod(name string, mode int) Error {
+ r, e := syscall.Chmod(name, int64(mode));
+ return ErrnoToError(e);
+}
+
+// Chmod changes the mode of the file to mode.
+func (f *File) Chmod(mode int) Error {
+ r, e := syscall.Fchmod(f.fd, int64(mode));
+ return ErrnoToError(e);
+}
+
+// Chown changes the numeric uid and gid of the named file.
+// If the file is a symbolic link, it changes the uid and gid of the link's target.
+func Chown(name string, uid, gid int) Error {
+ r, e := syscall.Chown(name, int64(uid), int64(gid));
+ return ErrnoToError(e);
+}
+
+// Lchown changes the numeric uid and gid of the named file.
+// If the file is a symbolic link, it changes the uid and gid of the link itself.
+func Lchown(name string, uid, gid int) Error {
+ r, e := syscall.Lchown(name, int64(uid), int64(gid));
+ return ErrnoToError(e);
+}
+
+// Chown changes the numeric uid and gid of the named file.
+func (f *File) Chown(uid, gid int) Error {
+ r, e := syscall.Fchown(f.fd, int64(uid), int64(gid));
+ return ErrnoToError(e);
+}
+
+// Truncate changes the size of the named file.
+// If the file is a symbolic link, it changes the size of the link's target.
+func Truncate(name string, size int64) Error {
+ r, e := syscall.Truncate(name, size);
+ return ErrnoToError(e);
+}
+
+// Truncate changes the size of the file.
+// It does not change the I/O offset.
+func (f *File) Truncate(size int64) Error {
+ r, e := syscall.Ftruncate(f.fd, size);
+ return ErrnoToError(e);
+}
+