Skip to content

Commit 428d79b

Browse files
committed
os: add example for OpenFile
New beginners are not familiar with open(2)-style masking of the flags. Add an example demonstrates the flag or'ing. Change-Id: Ifa8009c55173ba0dc6642c1d3b3124c766b1ebbb Reviewed-on: https://go-review.googlesource.com/27996 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 650c2c1 commit 428d79b

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/os/example_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2016 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package os_test
6+
7+
import (
8+
"log"
9+
"os"
10+
)
11+
12+
func ExampleOpenFile() {
13+
f, err := os.OpenFile("notes.txt", os.O_RDWR|os.O_CREATE, 0755)
14+
if err != nil {
15+
log.Fatal(err)
16+
}
17+
if err := f.Close(); err != nil {
18+
log.Fatal(err)
19+
}
20+
}

0 commit comments

Comments
 (0)