Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(43)

Side by Side Diff: src/pkg/syscall/syscall_darwin.go

Issue 12349044: code review 12349044: os, syscall: implement Getwd on darwin using getattrlist (Closed)
Patch Set: diff -r 6dee0694f35b https://go.googlecode.com/hg/ Created 11 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009,2010 The Go Authors. All rights reserved. 1 // Copyright 2009,2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // Darwin system calls. 5 // Darwin system calls.
6 // This file is compiled as ordinary Go code, 6 // This file is compiled as ordinary Go code,
7 // but it is also input to mksyscall, 7 // but it is also input to mksyscall,
8 // which parses the //sys lines and generates system call stubs. 8 // which parses the //sys lines and generates system call stubs.
9 // Note that sometimes we use a lowercase //sys name and wrap 9 // Note that sometimes we use a lowercase //sys name and wrap
10 // it in our own nicer implementation, either here or in 10 // it in our own nicer implementation, either here or in
11 // syscall_bsd.go or syscall_unix.go. 11 // syscall_bsd.go or syscall_unix.go.
12 12
13 package syscall 13 package syscall
14 14
15 import "unsafe" 15 import (
16 » errorspkg "errors"
17 » "unsafe"
18 )
16 19
17 type SockaddrDatalink struct { 20 type SockaddrDatalink struct {
18 Len uint8 21 Len uint8
19 Family uint8 22 Family uint8
20 Index uint16 23 Index uint16
21 Type uint8 24 Type uint8
22 Nlen uint8 25 Nlen uint8
23 Alen uint8 26 Alen uint8
24 Slen uint8 27 Slen uint8
25 Data [12]int8 28 Data [12]int8
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 count++ 82 count++
80 names = append(names, name) 83 names = append(names, name)
81 } 84 }
82 return origlen - len(buf), count, names 85 return origlen - len(buf), count, names
83 } 86 }
84 87
85 //sys ptrace(request int, pid int, addr uintptr, data uintptr) (err error) 88 //sys ptrace(request int, pid int, addr uintptr, data uintptr) (err error)
86 func PtraceAttach(pid int) (err error) { return ptrace(PT_ATTACH, pid, 0, 0) } 89 func PtraceAttach(pid int) (err error) { return ptrace(PT_ATTACH, pid, 0, 0) }
87 func PtraceDetach(pid int) (err error) { return ptrace(PT_DETACH, pid, 0, 0) } 90 func PtraceDetach(pid int) (err error) { return ptrace(PT_DETACH, pid, 0, 0) }
88 91
92 const (
93 attrBitMapCount = 5
94 AttrCmnFullpath = 0x08000000
95 )
96
97 type AttrList struct {
98 bitmapCount uint16
99 _ uint16
100 CommonAttr uint32
101 VolAttr uint32
102 DirAttr uint32
103 FileAttr uint32
104 Forkattr uint32
105 }
106
107 func GetAttrList(path string, attrList AttrList, attrBuf []byte, options uint) ( attrs [][]byte, err error) {
108 if len(attrBuf) < 4 {
109 return nil, errorspkg.New("attrBuf too small")
110 }
111 attrList.bitmapCount = attrBitMapCount
112
113 var _p0 *byte
114 _p0, err = BytePtrFromString(path)
115 if err != nil {
116 return nil, err
117 }
118
119 _, _, e1 := Syscall6(
120 SYS_GETATTRLIST,
121 uintptr(unsafe.Pointer(_p0)),
122 uintptr(unsafe.Pointer(&attrList)),
123 uintptr(unsafe.Pointer(&attrBuf[0])),
124 uintptr(len(attrBuf)),
125 uintptr(options),
126 0,
127 )
128 if e1 != 0 {
129 return nil, e1
130 }
131 size := *(*uint32)(unsafe.Pointer(&attrBuf[0]))
132
133 // dat is the section of attrBuf that contains valid data,
134 // without the 4 byte length header. All attribute offsets
135 // are relative to dat.
136 dat := attrBuf
137 if int(size) < len(attrBuf) {
138 dat = dat[:size]
139 }
140 dat = dat[4:] // remove length prefix
141
142 for i := uint32(0); int(i) < len(dat); {
143 header := dat[i:]
144 if len(header) < 8 {
145 return attrs, errorspkg.New("truncated attribute header" )
146 }
147 datOff := *(*int32)(unsafe.Pointer(&header[0]))
148 attrLen := *(*uint32)(unsafe.Pointer(&header[4]))
149 if datOff < 0 || uint32(datOff)+attrLen > uint32(len(dat)) {
150 return attrs, errorspkg.New("truncated results; attrBuf too small")
151 }
152 end := uint32(datOff) + attrLen
153 attrs = append(attrs, dat[datOff:end])
154 i = end
155 if r := i % 4; r != 0 {
156 i += (4 - r)
157 }
158 }
159 return
160 }
161
89 //sysnb pipe() (r int, w int, err error) 162 //sysnb pipe() (r int, w int, err error)
90 163
91 func Pipe(p []int) (err error) { 164 func Pipe(p []int) (err error) {
92 if len(p) != 2 { 165 if len(p) != 2 {
93 return EINVAL 166 return EINVAL
94 } 167 }
95 p[0], p[1], err = pipe() 168 p[0], p[1], err = pipe()
96 return 169 return
97 } 170 }
98 171
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 // Poll_nocancel 462 // Poll_nocancel
390 // Msgsnd_nocancel 463 // Msgsnd_nocancel
391 // Msgrcv_nocancel 464 // Msgrcv_nocancel
392 // Sem_wait_nocancel 465 // Sem_wait_nocancel
393 // Aio_suspend_nocancel 466 // Aio_suspend_nocancel
394 // __sigwait_nocancel 467 // __sigwait_nocancel
395 // __semwait_signal_nocancel 468 // __semwait_signal_nocancel
396 // __mac_mount 469 // __mac_mount
397 // __mac_get_mount 470 // __mac_get_mount
398 // __mac_getfsstat 471 // __mac_getfsstat
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b