Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syscall: implement Getwd on OS X #4807

Closed
rsc opened this issue Feb 14, 2013 · 7 comments
Closed

syscall: implement Getwd on OS X #4807

rsc opened this issue Feb 14, 2013 · 7 comments
Assignees
Milestone

Comments

@rsc
Copy link
Contributor

@rsc rsc commented Feb 14, 2013

It appears that Getwd can be implemented on OS X by opening "." and then using
getattrlist to ask for the ATTR_CMN_FULLPATH attribute. Do this once everything else is
ready.
@rsc
Copy link
Contributor Author

@rsc rsc commented Mar 12, 2013

Comment 1:

[The time for maybe has passed.]

Labels changed: removed go1.1maybe.

@rsc
Copy link
Contributor Author

@rsc rsc commented Jul 30, 2013

Comment 2:

Labels changed: added go1.2.

@rsc
Copy link
Contributor Author

@rsc rsc commented Jul 30, 2013

Comment 3:

Labels changed: added feature.

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Aug 2, 2013

Comment 4:

$ go run getwd.go
size=28 buf="\x1c\x00\x00\x00\b\x00\x00\x00\x10\x00\x00\x00/Users/bradfitz\x00"
GetAttrList = <nil>
package main
import (
        "fmt"
        "syscall"
        "unsafe"
)
const (
        AttrBitMapCount = 5
        AttrCmnFullpath = 0x08000000
)
type AttrList struct {
        BitmapCount uint16
        _           uint16
        CommonAttr  uint32
        VolAttr     uint32
        DirAttr     uint32
        FileAttr    uint32
        Forkattr    uint32
}
func GetAttrList(path string, attrs AttrList, options uint) error {
        attrs.BitmapCount = 5
        var _p0 *byte
        _p0, err := syscall.BytePtrFromString(path)
        if err != nil {
                return err
        }
        var buf [4096]byte
        _, _, e1 := syscall.Syscall6(
                syscall.SYS_GETATTRLIST,
                uintptr(unsafe.Pointer(_p0)),
                uintptr(unsafe.Pointer(&attrs)),
                uintptr(unsafe.Pointer(&buf[0])),
                uintptr(4096),
                uintptr(options),
                0,
        )
        if e1 != 0 {
                return e1
        }
        size := *(*uint32)(unsafe.Pointer(&buf[0]))
        fmt.Printf("size=%v buf=%q\n", size, buf[:size])
        return nil
}
func main() {
        err := GetAttrList(".", AttrList{CommonAttr: AttrCmnFullpath}, 0)
        fmt.Printf("GetAttrList = %v\n", err)
}
@rsc
Copy link
Contributor Author

@rsc rsc commented Aug 2, 2013

Comment 5:

Wow. Still, probably cheaper than what we do today.
@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Aug 5, 2013

Comment 6:

https://golang.org/cl/12349044/

Owner changed to @bradfitz.

Status changed to Started.

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Aug 5, 2013

Comment 7:

This issue was closed by revision 7963ba6.

Status changed to Fixed.

@rsc rsc added fixed labels Aug 5, 2013
@rsc rsc added this to the Go1.2 milestone Apr 14, 2015
@rsc rsc removed the go1.2 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.