Bad File Descriptor?

3,157 views
Skip to first unread message

Xiphos

unread,
Aug 19, 2010, 8:44:40 PM8/19/10
to golang-nuts
Hi Everyone,

I am just trying something really simple here: write something into a
file. It worked this morning on a windows machine using the windows
port of go. Now I am home and trying it on my Ubuntu 10.04. I am
getting a Bad File Descriptor err. Tried many things and nothing
worked... Here is the code, plz anyone have a look...

Thank you so very much~

// It failed on the Only Write call in the code. The folder exists.
Permission of the folder is: drwxr-xr-x

package main

import (
"strings"
"os"
)

func main() {
file, err := os.Open("golang.org/golang.org_start_page.html",
os.O_CREATE, 0644)

if err != nil {
panic(err)
}

const NBUF = 512
var buf [NBUF]byte

reader := strings.NewReader("abcdefghijklmnopqrstuvwxyz")
nr, er := reader.Read(&buf)

if er == nil {
if nw, ew := file.Write(buf[0:nr]); nw != nr {
panic(ew)
}
} else {
panic(er)
}
}

Xiphos

unread,
Aug 19, 2010, 8:49:19 PM8/19/10
to golang-nuts
NVM I figured it out. You have to or the O_CREATE with one of the flag
that allows to write.

drew m

unread,
Aug 20, 2010, 3:20:06 PM8/20/10
to golang-nuts
and what would that flag be?
Reply all
Reply to author
Forward
0 new messages