diff options
author | Michael Steinert <[email protected]> | 2015-03-30 18:20:09 -0500 |
---|---|---|
committer | Michael Steinert <[email protected]> | 2015-03-30 18:20:09 -0500 |
commit | 3215d873b90d1aa132c368eae2b5273d20686359 (patch) | |
tree | 2f47a209d3f3ceac6e48d07e6dee944fb39089ea | |
parent | 77471e65f1618fc98af09b0188d9ad138b089366 (diff) |
This looks a bit better
-rw-r--r-- | transaction.go | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/transaction.go b/transaction.go index e99be6a..e6e8d4c 100644 --- a/transaction.go +++ b/transaction.go @@ -242,6 +242,10 @@ func (t *Transaction) GetEnv(name string) string { return C.GoString(value) } +func next(p **C.char) **C.char { + return (**C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(p)) + unsafe.Sizeof(p))) +} + // pam_getenvlist func (t *Transaction) GetEnvList() (map[string]string, error) { env := make(map[string]string) @@ -250,14 +254,12 @@ func (t *Transaction) GetEnvList() (map[string]string, error) { t.status = C.PAM_BUF_ERR return nil, t } - q := p - for *q != nil { + for q := p; *q != nil; q = next(q) { chunks := strings.SplitN(C.GoString(*q), "=", 2) if len(chunks) == 2 { env[chunks[0]] = chunks[1] } C.free(unsafe.Pointer(*q)) - q = (**C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(q)) + unsafe.Sizeof(*p))) } C.free(unsafe.Pointer(p)) return env, nil |