summaryrefslogtreecommitdiff
path: root/src/lib/io/utils.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2009-06-01 19:00:07 -0700
committerRobert Griesemer <gri@golang.org>2009-06-01 19:00:07 -0700
commitad3bd653fed89b3d9ea879254243d7fdc764d342 (patch)
tree5ac92d346d82a47925b26afc2ae9a607402a5dc5 /src/lib/io/utils.go
parent3cac49d2f3f4f587869c270790324d010ede3830 (diff)
downloadgolang-ad3bd653fed89b3d9ea879254243d7fdc764d342.tar.gz
io.ReadFile
R=r,rsc DELTA=64 (63 added, 0 deleted, 1 changed) OCL=29702 CL=29702
Diffstat (limited to 'src/lib/io/utils.go')
-rw-r--r--src/lib/io/utils.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/lib/io/utils.go b/src/lib/io/utils.go
new file mode 100644
index 000000000..736097946
--- /dev/null
+++ b/src/lib/io/utils.go
@@ -0,0 +1,27 @@
+// 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.
+
+// Utility functions.
+
+package io
+
+import (
+ "io";
+ "os";
+)
+
+
+// ReadFile reads the file named by filename and returns
+// its contents if successful.
+//
+func ReadFile(filename string) ([]byte, os.Error) {
+ f, err := os.Open(filename, os.O_RDONLY, 0);
+ if err != nil {
+ return nil, err;
+ }
+ var b io.ByteBuffer;
+ _, err := io.Copy(f, &b);
+ f.Close();
+ return b.Data(), err;
+}