Skip to content

Instantly share code, notes, and snippets.

@garthk
Created January 17, 2016 23:47
Show Gist options
  • Save garthk/eed8fdef165d735b5bad to your computer and use it in GitHub Desktop.
Save garthk/eed8fdef165d735b5bad to your computer and use it in GitHub Desktop.
could not determine kind of name for C.free
package main
// #include <stdlib.h>
// #include <unistd.h>
// #include <sys/types.h>
// #include <pwd.h>
// #include <grp.h>
import "C"
import "fmt"
func main() {
fmt.Println("Hello, playground")
}
func lookupGroup(groupname string, f func(*C.struct_group) *Group) (*Group, os.Error) {
var grp C.struct_group
var result *C.struct_group
buf, bufSize, err := allocBuffer(groupBuffer)
if err != nil {
return nil, err
}
defer C.free(buf)
nameC := C.CString(groupname)
defer C.free(unsafe.Pointer(nameC))
rv := C.getgrnam_r(nameC,
&grp,
(*C.char)(buf),
C.size_t(bufSize),
&result)
if rv != 0 {
return nil, fmt.Errorf("group: lookup groupname %s: %s", groupname, os.Errno(rv))
}
if result == nil {
return nil, UnknownGroupError(groupname)
}
g := f(&grp)
return g, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment