diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-04-28 10:35:15 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-04-28 10:35:15 +0200 |
commit | c1ba1a0fec4aed430709030f98a3bdb90bfeea16 (patch) | |
tree | 3df18657e50a0313ed6defcda30e4474cb28a467 /doc | |
parent | 7b15ed9ef455b6b66c6b376898a88aef5d6a9970 (diff) | |
download | golang-c1ba1a0fec4aed430709030f98a3bdb90bfeea16.tar.gz |
Imported Upstream version 2011.04.27upstream/2011.04.27
Diffstat (limited to 'doc')
-rw-r--r-- | doc/all.css | 2 | ||||
-rw-r--r-- | doc/devel/release.html | 133 | ||||
-rw-r--r-- | doc/effective_go.html | 4 | ||||
-rw-r--r-- | doc/go_spec.html | 19 | ||||
-rw-r--r-- | doc/go_tutorial.html | 165 | ||||
-rw-r--r-- | doc/go_tutorial.txt | 24 | ||||
-rw-r--r-- | doc/godocs.js | 11 | ||||
-rw-r--r-- | doc/install.html | 2 | ||||
-rw-r--r-- | doc/progs/cat.go | 3 | ||||
-rw-r--r-- | doc/progs/cat_rot13.go | 3 | ||||
-rw-r--r-- | doc/progs/file.go | 17 | ||||
-rw-r--r-- | doc/progs/helloworld3.go | 2 | ||||
-rw-r--r-- | doc/progs/sieve.go | 2 | ||||
-rw-r--r-- | doc/progs/sieve1.go | 2 |
14 files changed, 300 insertions, 89 deletions
diff --git a/doc/all.css b/doc/all.css index b1d55cf25..dd00d1adb 100644 --- a/doc/all.css +++ b/doc/all.css @@ -96,7 +96,7 @@ h1#title { color: #999; } #search { - width: 100px; + width: 120px; margin-left: 0.5em; } #search.inactive { diff --git a/doc/devel/release.html b/doc/devel/release.html index f75cbf24f..0b70f030b 100644 --- a/doc/devel/release.html +++ b/doc/devel/release.html @@ -5,6 +5,139 @@ <p>This page summarizes the changes between tagged releases of Go. For full details, see the <a href="http://code.google.com/p/go/source/list">Mercurial change log</a>.</p> +<h3 id="2011-04-27">2011-04-27</h3> + +<pre> +This release includes revisions to the reflect package to make it more +efficient, after last the weekly’s major API update. If your code uses reflect +it may require further changes, not all of which can be made automatically by +gofix. For the full details of the change, see + http://codereview.appspot.com/4435042 +Also, the Typeof and NewValue functions have been renamed to TypeOf and ValueOf. + +Other changes: +* 5c: make alignment rules match 5g, just like 6c matches 6g. +* 8g, 8l: fix "set but not used" gcc error (thanks Fazlul Shahriar). +* all-qemu.bash: remove DISABLE_NET_TESTS. +* build: remove DISABLE_NET_TESTS. +* builder: build multiple targets in parallel. +* cgo: avoid "incompatible pointer type" warning (thanks Albert Strasheim). +* codereview: add 'hg undo' command, various other fixes. +* compress/flate: dictionary support. +* compress/zlib: add FDICT flag in Reader/Writer (thanks Ross Light). +* container/heap: fix circular dependency in test. +* crypto/openpgp: better handling of keyrings. +* crypto/rsa: support > 3 primes. +* crypto/tls: add server-side OCSP stapling support. +* crypto/x509: memorize chain building. +* crypto: move certificate verification into x509. +* dashboard: build most recent revision first. +* doc: mention make version in install.html. +* expvar: add Func for functions that return values that are JSON marshalable. +* fmt: decrease recursion depth in tests to permit them to run under gccgo, + tweak the doc for %U. +* gc: allow complex types to be receiver types (thanks Robert Hencke), + correct handling of unexported method names in embedded interfaces, + explain why invalid receiver types are invalid, + fix copy([]int, string) error message (thanks Quan Yong Zhai), + fix 'invalid recursive type' error (thanks Lorenzo Stoakes), + many bug fixes. +* go spec: attempt at clarifying language for "append", + for map types, mention indexing operations. +* go/types: update for export data format change. +* gob: fix handling of indirect receivers for GobDecoders, + fix trivial bug in map marshaling, + have errorf always prefix the message with "gob: ", + test case for indirection to large field, + use new Implements and AssignableTo methods in reflect, + when decoding a string, allocate a string, not a []byte. +* gobuilder: permit builders of the form goos-goarch-foo, + respect MAKEFLAGS if provided (thanks Dave Cheney). +* godoc: use "search" input type for search box (thanks Dmitry Chestnykh). +* gofix: add support for reflect rename. +* gofmt: add -d (diff) (thanks David Crawshaw), + don't crash when rewriting nil interfaces in AST, + exclude test case that doesn't compile w/o errors, + gofmt test harness bug fix. +* goinstall: support GOPATH; building and installing outside the Go tree, + support building executable commands. +* gopack: fix prefix bug, + preserve safe flag when not adding unsafe objects to archive. +* gotest: add timing, respect $GOARCH, + generate gofmt-compliant code. +* http/cgi: copy some PATH environment variables to child, + improve Location response handling, + pass some default environment variables. +* http/fcgi: new package (thanks Evan Shaw). +* http: add NewRequest helper, + add MultipartForm, ParseMultipartForm, and FormFile to Request, + be clear when failing to connect to a proxy, + bug fixes and new tests, + consume request bodies before replying, + don't quote Set-Cookie Domain and Path (thanks Petar Maymounkov), + fix IP confusion in TestServerTimeouts, + handler timeout support, + ServerConn, ClientConn: add real Close (thanks Petar Maymounkov), + make Client redirect policy configurable, + put a limit on POST size, + reverse proxy handler. +* image/jpeg: add an encoder, + decode to a YCbCr image instead of an RGBA image. +* ioutil: add Discard. +* json: keep track of error offset in SyntaxError. +* ld: defend against some broken object files, + do not emit empty dwarf pe sections (thanks Alex Brainman), + fix 6l -d on Mac, diagnose invalid use of -d, + fix Plan 9 symbol table (thanks Anthony Martin), + remove MachoLoad limit. +* make: prevent rm provoking 'text file busy' errors (thanks Lorenzo Stoakes). +* mime/multipart: add ReadForm for parsing multipart forms, + limit line length to prevent abuse. +* mime: RFC 2231 continuation / non-ASCII support, + bunch more tests, few minor parsing fixes. +* misc/goplay: fix Tab and Shift+Enter in Firefox (thanks Dmitry Chestnykh). +* net: disable one more external network test, + fix EAI_BADFLAGS error on freebsd (thanks Mikio Hara), + fix ParseIP (thanks Quan Yong Zhai), + fix dialgoogle_test.go (thanks Quan Yong Zhai), + try /etc/hosts before loading DNS config (thanks Dmitry Chestnykh), + use C library resolver on FreeBSD, Linux, OS X / amd64, 386. +* os/user: new package to look up users. +* os: Open with O_APPEND|O_CREATE to append on Windows (thanks Alex Brainman), + fix race in ReadAt/WriteAt on Windows (thanks Alex Brainman), + turn EPIPE exit into panic. +* rc/env.bash: fix to build on windows under msys (thanks Joe Poirier). +* reflect: allow Slice of arrays, + fix Copy of arrays (thanks Gustavo Niemeyer), + require package qualifiers to match during interface check, + add Type.Implements, Type.AssignableTo, Value.CallSlice, + make Set match Go. +* rpc: allow the first argument of a method to be a value rather than a pointer, + run benchmarks over HTTP as well as direct network connections. +* run.bash: remove redundant rebuilds. +* runtime/plan9: warning remediation for Plan 9 (thanks Lucio De Re), +* runtime: many bug fixes, + fix GOMAXPROCS vs garbage collection bug (thanks Dmitriy Vyukov), + fix mkversion to output valid path separators (thanks Peter Mundy), + more graceful out-of-memory crash, + require package qualifiers to match during interface check, + skip functions with no lines when building src line table, + turn "too many EPIPE" into real SIGPIPE. +* src/pkg: make package doc comments consistently start with "Package foo". +* syscall: Madvise and Mprotect for Linux (thanks Albert Strasheim), + Mlock, Munlock, Mlockall, Munlockall on Linux (thanks Albert Strasheim), + add BPF support for darwin/386, darwin/amd64 (thanks Mikio Hara), + correct Windows CreateProcess input parameters (thanks Alex Brainman), + fix Ftruncate under linux/arm5 (thanks Dave Cheney), + permit StartProcess to hide the executed program on windows (thanks Vincent Vanackere). +* test/bench: update timings; moving to new machine. +* time: support Irix 6 location for zoneinfo files. +* tutorial: modernize the definition and use of Open, + replace the forever loops with finite counts in sieve programs. +* websocket: include *http.Request in websocket.Conn. +* xml: Parser hook for non-UTF-8 charset converters. +</pre> + <h3 id="2011-04-13">2011-04-13</h3> <pre> diff --git a/doc/effective_go.html b/doc/effective_go.html index 27bfd1bf5..a7e6b7bdf 100644 --- a/doc/effective_go.html +++ b/doc/effective_go.html @@ -159,7 +159,7 @@ should set up the detailed documentation that follows. <pre> /* - The regexp package implements a simple library for + Package regexp implements a simple library for regular expressions. The syntax of the regular expressions accepted is: @@ -186,7 +186,7 @@ If the package is simple, the package comment can be brief. </p> <pre> -// The path package implements utility routines for +// Package path implements utility routines for // manipulating slash-separated filename paths. </pre> diff --git a/doc/go_spec.html b/doc/go_spec.html index f8fe5974a..886f89d12 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,5 +1,5 @@ <!-- title The Go Programming Language Specification --> -<!-- subtitle Version of Apr 5, 2011 --> +<!-- subtitle Version of Apr 22, 2011 --> <!-- TODO @@ -1155,8 +1155,9 @@ map [string] interface {} The number of map elements is called its length. For a map <code>m</code>, it can be discovered using the built-in function <a href="#Length_and_capacity"><code>len(m)</code></a> -and may change during execution. Values may be added and removed -during execution using special forms of <a href="#Assignments">assignment</a>. +and may change during execution. Elements may be added and removed +during execution using special forms of <a href="#Assignments">assignment</a>; +and they may be accessed with <a href="#Indexes">index</a> expressions. </p> <p> A new, empty map value is made using the built-in @@ -4541,13 +4542,14 @@ Two built-in functions assist in common slice operations. <p> The function <code>append</code> appends zero or more values <code>x</code> -to a slice <code>s</code> and returns the resulting slice, with the same type -as s. Each value must be <a href="#Assignability">assignable</a> to the slice's -element type. +to <code>s</code> of type <code>S</code>, which must be a slice type, and +returns the resulting slice, also of type <code>S</code>. +Each value <code>x</code> must be <a href="#Assignability">assignable</a> to +the <a href="#Slice_types">element type</a> of <code>S</code>. </p> <pre class="grammar"> -append(s S, x ...T) S // S is assignable to []T +append(s S, x ...T) S // T is the element type of S </pre> <p> @@ -4562,6 +4564,9 @@ s0 := []int{0, 0} s1 := append(s0, 2) // append a single element s1 == []int{0, 0, 2} s2 := append(s1, 3, 5, 7) // append multiple elements s2 == []int{0, 0, 2, 3, 5, 7} s3 := append(s2, s0...) // append a slice s3 == []int{0, 0, 2, 3, 5, 7, 0, 0} + +var t []interface{} +t = append(t, 42, 3.1415, "foo") t == []interface{}{42, 3.1415, "foo"} </pre> <p> diff --git a/doc/go_tutorial.html b/doc/go_tutorial.html index e3d946f8d..c87254ecb 100644 --- a/doc/go_tutorial.html +++ b/doc/go_tutorial.html @@ -474,8 +474,8 @@ assigned to a variable. <p> <h2>An I/O Package</h2> <p> -Next we'll look at a simple package for doing file I/O with the usual -sort of open/close/read/write interface. Here's the start of <code>file.go</code>: +Next we'll look at a simple package for doing file I/O with an +open/close/read/write interface. Here's the start of <code>file.go</code>: <p> <pre> <!-- progs/file.go /package/ /^}/ --> 05 package file @@ -554,10 +554,10 @@ We can use the factory to construct some familiar, exported variables of type <c </pre> <p> The <code>newFile</code> function was not exported because it's internal. The proper, -exported factory to use is <code>Open</code>: +exported factory to use is <code>OpenFile</code> (we'll explain that name in a moment): <p> -<pre> <!-- progs/file.go /func.Open/ /^}/ --> -30 func Open(name string, mode int, perm uint32) (file *File, err os.Error) { +<pre> <!-- progs/file.go /func.OpenFile/ /^}/ --> +30 func OpenFile(name string, mode int, perm uint32) (file *File, err os.Error) { 31 r, e := syscall.Open(name, mode, perm) 32 if e != 0 { 33 err = os.Errno(e) @@ -566,7 +566,7 @@ exported factory to use is <code>Open</code>: 36 } </pre> <p> -There are a number of new things in these few lines. First, <code>Open</code> returns +There are a number of new things in these few lines. First, <code>OpenFile</code> returns multiple values, a <code>File</code> and an error (more about errors in a moment). We declare the multi-value return as a parenthesized list of declarations; syntactically @@ -585,6 +585,35 @@ consistent error handling throughout Go code. In <code>Open</code> we use a conversion to translate Unix's integer <code>errno</code> value into the integer type <code>os.Errno</code>, which implements <code>os.Error</code>. <p> +Why <code>OpenFile</code> and not <code>Open</code>? To mimic Go's <code>os</code> package, which +our exercise is emulating. The <code>os</code> package takes the opportunity +to make the two commonest cases - open for read and create for +write - the simplest, just <code>Open</code> and <code>Create</code>. <code>OpenFile</code> is the +general case, analogous to the Unix system call <code>Open</code>. Here is +the implementation of our <code>Open</code> and <code>Create</code>; they're trivial +wrappers that eliminate common errors by capturing +the tricky standard arguments to open and, especially, to create a file: +<p> +<pre> <!-- progs/file.go /^const/ /^}/ --> +38 const ( +39 O_RDONLY = syscall.O_RDONLY +40 O_RDWR = syscall.O_RDWR +41 O_CREATE = syscall.O_CREAT +42 O_TRUNC = syscall.O_TRUNC +43 ) +<p> +45 func Open(name string) (file *File, err os.Error) { +46 return OpenFile(name, O_RDONLY, 0) +47 } +</pre> +<p> +<pre> <!-- progs/file.go /func.Create/ /^}/ --> +49 func Create(name string) (file *File, err os.Error) { +50 return OpenFile(name, O_RDWR|O_CREATE|O_TRUNC, 0666) +51 } +</pre> +<p> +Back to our main story. Now that we can build <code>Files</code>, we can write methods for them. To declare a method of a type, we define a function to have an explicit receiver of that type, placed @@ -592,43 +621,43 @@ in parentheses before the function name. Here are some methods for <code>*File</ each of which declares a receiver variable <code>file</code>. <p> <pre> <!-- progs/file.go /Close/ END --> -38 func (file *File) Close() os.Error { -39 if file == nil { -40 return os.EINVAL -41 } -42 e := syscall.Close(file.fd) -43 file.fd = -1 // so it can't be closed again -44 if e != 0 { -45 return os.Errno(e) -46 } -47 return nil -48 } -<p> -50 func (file *File) Read(b []byte) (ret int, err os.Error) { -51 if file == nil { -52 return -1, os.EINVAL -53 } -54 r, e := syscall.Read(file.fd, b) -55 if e != 0 { -56 err = os.Errno(e) -57 } -58 return int(r), err -59 } -<p> -61 func (file *File) Write(b []byte) (ret int, err os.Error) { -62 if file == nil { -63 return -1, os.EINVAL -64 } -65 r, e := syscall.Write(file.fd, b) -66 if e != 0 { -67 err = os.Errno(e) +53 func (file *File) Close() os.Error { +54 if file == nil { +55 return os.EINVAL +56 } +57 e := syscall.Close(file.fd) +58 file.fd = -1 // so it can't be closed again +59 if e != 0 { +60 return os.Errno(e) +61 } +62 return nil +63 } +<p> +65 func (file *File) Read(b []byte) (ret int, err os.Error) { +66 if file == nil { +67 return -1, os.EINVAL 68 } -69 return int(r), err -70 } -<p> -72 func (file *File) String() string { -73 return file.name +69 r, e := syscall.Read(file.fd, b) +70 if e != 0 { +71 err = os.Errno(e) +72 } +73 return int(r), err 74 } +<p> +76 func (file *File) Write(b []byte) (ret int, err os.Error) { +77 if file == nil { +78 return -1, os.EINVAL +79 } +80 r, e := syscall.Write(file.fd, b) +81 if e != 0 { +82 err = os.Errno(e) +83 } +84 return int(r), err +85 } +<p> +87 func (file *File) String() string { +88 return file.name +89 } </pre> <p> There is no implicit <code>this</code> and the receiver variable must be used to access @@ -658,7 +687,7 @@ We can now use our new package: 13 func main() { 14 hello := []byte("hello, world\n") 15 file.Stdout.Write(hello) -16 f, err := file.Open("/does/not/exist", 0, 0) +16 f, err := file.Open("/does/not/exist") 17 if f == nil { 18 fmt.Printf("can't open file; err=%s\n", err.String()) 19 os.Exit(1) @@ -712,26 +741,27 @@ Building on the <code>file</code> package, here's a simple version of the Unix u 24 case nr > 0: 25 if nw, ew := file.Stdout.Write(buf[0:nr]); nw != nr { 26 fmt.Fprintf(os.Stderr, "cat: error writing from %s: %s\n", f.String(), ew.String()) -27 } -28 } -29 } -30 } +27 os.Exit(1) +28 } +29 } +30 } +31 } <p> -32 func main() { -33 flag.Parse() // Scans the arg list and sets up flags -34 if flag.NArg() == 0 { -35 cat(file.Stdin) -36 } -37 for i := 0; i < flag.NArg(); i++ { -38 f, err := file.Open(flag.Arg(i), 0, 0) -39 if f == nil { -40 fmt.Fprintf(os.Stderr, "cat: can't open %s: error %s\n", flag.Arg(i), err) -41 os.Exit(1) -42 } -43 cat(f) -44 f.Close() -45 } -46 } +33 func main() { +34 flag.Parse() // Scans the arg list and sets up flags +35 if flag.NArg() == 0 { +36 cat(file.Stdin) +37 } +38 for i := 0; i < flag.NArg(); i++ { +39 f, err := file.Open(flag.Arg(i)) +40 if f == nil { +41 fmt.Fprintf(os.Stderr, "cat: can't open %s: error %s\n", flag.Arg(i), err) +42 os.Exit(1) +43 } +44 cat(f) +45 f.Close() +46 } +47 } </pre> <p> By now this should be easy to follow, but the <code>switch</code> statement introduces some @@ -829,10 +859,11 @@ and use it from within a mostly unchanged <code>cat()</code> function: 67 nw, ew := file.Stdout.Write(buf[0:nr]) 68 if nw != nr { 69 fmt.Fprintf(os.Stderr, "cat: error writing from %s: %s\n", r.String(), ew.String()) -70 } -71 } -72 } -73 } +70 os.Exit(1) +71 } +72 } +73 } +74 } </pre> <p> (We could also do the wrapping in <code>main</code> and leave <code>cat()</code> mostly alone, except @@ -1209,7 +1240,7 @@ together: 28 func main() { 29 ch := make(chan int) // Create a new channel. 30 go generate(ch) // Start generate() as a goroutine. -31 for { +31 for i := 0; i < 100; i++ { // Print the first hundred primes. 32 prime := <-ch 33 fmt.Println(prime) 34 ch1 := make(chan int) @@ -1289,7 +1320,7 @@ Now <code>main</code>'s interface to the prime sieve is a channel of primes: <pre> <!-- progs/sieve1.go /func.main/ /^}/ --> 46 func main() { 47 primes := sieve() -48 for { +48 for i := 0; i < 100; i++ { // Print the first hundred primes. 49 fmt.Println(<-primes) 50 } 51 } diff --git a/doc/go_tutorial.txt b/doc/go_tutorial.txt index 2b2a0cda1..ab02baf2c 100644 --- a/doc/go_tutorial.txt +++ b/doc/go_tutorial.txt @@ -384,8 +384,8 @@ assigned to a variable. An I/O Package ---- -Next we'll look at a simple package for doing file I/O with the usual -sort of open/close/read/write interface. Here's the start of "file.go": +Next we'll look at a simple package for doing file I/O with an +open/close/read/write interface. Here's the start of "file.go": --PROG progs/file.go /package/ /^}/ @@ -437,11 +437,11 @@ We can use the factory to construct some familiar, exported variables of type "* --PROG progs/file.go /var/ /^.$/ The "newFile" function was not exported because it's internal. The proper, -exported factory to use is "Open": +exported factory to use is "OpenFile" (we'll explain that name in a moment): ---PROG progs/file.go /func.Open/ /^}/ +--PROG progs/file.go /func.OpenFile/ /^}/ -There are a number of new things in these few lines. First, "Open" returns +There are a number of new things in these few lines. First, "OpenFile" returns multiple values, a "File" and an error (more about errors in a moment). We declare the multi-value return as a parenthesized list of declarations; syntactically @@ -460,6 +460,20 @@ consistent error handling throughout Go code. In "Open" we use a conversion to translate Unix's integer "errno" value into the integer type "os.Errno", which implements "os.Error". +Why "OpenFile" and not "Open"? To mimic Go's "os" package, which +our exercise is emulating. The "os" package takes the opportunity +to make the two commonest cases - open for read and create for +write - the simplest, just "Open" and "Create". "OpenFile" is the +general case, analogous to the Unix system call "Open". Here is +the implementation of our "Open" and "Create"; they're trivial +wrappers that eliminate common errors by capturing +the tricky standard arguments to open and, especially, to create a file: + +--PROG progs/file.go /^const/ /^}/ + +--PROG progs/file.go /func.Create/ /^}/ + +Back to our main story. Now that we can build "Files", we can write methods for them. To declare a method of a type, we define a function to have an explicit receiver of that type, placed diff --git a/doc/godocs.js b/doc/godocs.js index 8b451547d..2b3ab065f 100644 --- a/doc/godocs.js +++ b/doc/godocs.js @@ -34,7 +34,18 @@ function godocs_bindSearchEvents() { search.className = ""; } } + function restoreInactive() { + if (search.value != "") { + return; + } + if (search.type != "search") { + search.value = search.getAttribute("placeholder"); + } + search.className = "inactive"; + } + restoreInactive(); bindEvent(search, 'focus', clearInactive); + bindEvent(search, 'blur', restoreInactive); } /* Generates a table of contents: looks for h2 and h3 elements and generates diff --git a/doc/install.html b/doc/install.html index 843e0645f..b98941691 100644 --- a/doc/install.html +++ b/doc/install.html @@ -80,7 +80,7 @@ To build it, you need these programs installed: <li>GCC, <li>the standard C libraries, <li>the parser generator Bison, -<li><tt>make</tt>, +<li>GNU <tt>make</tt> (version 3.81 or later), <li><tt>awk</tt>, and <li>the text editor <tt>ed</tt>. </ul> diff --git a/doc/progs/cat.go b/doc/progs/cat.go index 697e5f786..9f0b8d4a3 100644 --- a/doc/progs/cat.go +++ b/doc/progs/cat.go @@ -24,6 +24,7 @@ func cat(f *file.File) { case nr > 0: if nw, ew := file.Stdout.Write(buf[0:nr]); nw != nr { fmt.Fprintf(os.Stderr, "cat: error writing from %s: %s\n", f.String(), ew.String()) + os.Exit(1) } } } @@ -35,7 +36,7 @@ func main() { cat(file.Stdin) } for i := 0; i < flag.NArg(); i++ { - f, err := file.Open(flag.Arg(i), 0, 0) + f, err := file.Open(flag.Arg(i)) if f == nil { fmt.Fprintf(os.Stderr, "cat: can't open %s: error %s\n", flag.Arg(i), err) os.Exit(1) diff --git a/doc/progs/cat_rot13.go b/doc/progs/cat_rot13.go index 03fc02259..0eefe7cfc 100644 --- a/doc/progs/cat_rot13.go +++ b/doc/progs/cat_rot13.go @@ -67,6 +67,7 @@ func cat(r reader) { nw, ew := file.Stdout.Write(buf[0:nr]) if nw != nr { fmt.Fprintf(os.Stderr, "cat: error writing from %s: %s\n", r.String(), ew.String()) + os.Exit(1) } } } @@ -78,7 +79,7 @@ func main() { cat(file.Stdin) } for i := 0; i < flag.NArg(); i++ { - f, err := file.Open(flag.Arg(i), 0, 0) + f, err := file.Open(flag.Arg(i)) if f == nil { fmt.Fprintf(os.Stderr, "cat: can't open %s: error %s\n", flag.Arg(i), err) os.Exit(1) diff --git a/doc/progs/file.go b/doc/progs/file.go index df3a3cf71..2875ce73a 100644 --- a/doc/progs/file.go +++ b/doc/progs/file.go @@ -27,7 +27,7 @@ var ( Stderr = newFile(syscall.Stderr, "/dev/stderr") ) -func Open(name string, mode int, perm uint32) (file *File, err os.Error) { +func OpenFile(name string, mode int, perm uint32) (file *File, err os.Error) { r, e := syscall.Open(name, mode, perm) if e != 0 { err = os.Errno(e) @@ -35,6 +35,21 @@ func Open(name string, mode int, perm uint32) (file *File, err os.Error) { return newFile(r, name), err } +const ( + O_RDONLY = syscall.O_RDONLY + O_RDWR = syscall.O_RDWR + O_CREATE = syscall.O_CREAT + O_TRUNC = syscall.O_TRUNC +) + +func Open(name string) (file *File, err os.Error) { + return OpenFile(name, O_RDONLY, 0) +} + +func Create(name string) (file *File, err os.Error) { + return OpenFile(name, O_RDWR|O_CREATE|O_TRUNC, 0666) +} + func (file *File) Close() os.Error { if file == nil { return os.EINVAL diff --git a/doc/progs/helloworld3.go b/doc/progs/helloworld3.go index adbcea324..5bb0be218 100644 --- a/doc/progs/helloworld3.go +++ b/doc/progs/helloworld3.go @@ -13,7 +13,7 @@ import ( func main() { hello := []byte("hello, world\n") file.Stdout.Write(hello) - f, err := file.Open("/does/not/exist", 0, 0) + f, err := file.Open("/does/not/exist") if f == nil { fmt.Printf("can't open file; err=%s\n", err.String()) os.Exit(1) diff --git a/doc/progs/sieve.go b/doc/progs/sieve.go index fb649e049..c7c3e7812 100644 --- a/doc/progs/sieve.go +++ b/doc/progs/sieve.go @@ -28,7 +28,7 @@ func filter(in, out chan int, prime int) { func main() { ch := make(chan int) // Create a new channel. go generate(ch) // Start generate() as a goroutine. - for { + for i := 0; i < 100; i++ { // Print the first hundred primes. prime := <-ch fmt.Println(prime) ch1 := make(chan int) diff --git a/doc/progs/sieve1.go b/doc/progs/sieve1.go index 71468d06e..e785e2035 100644 --- a/doc/progs/sieve1.go +++ b/doc/progs/sieve1.go @@ -45,7 +45,7 @@ func sieve() chan int { func main() { primes := sieve() - for { + for i := 0; i < 100; i++ { // Print the first hundred primes. fmt.Println(<-primes) } } |