Last change
on this file since 822 was 822, checked in by yakumo.izuru, 22 months ago |
Prefer immortal.run over runit and rc.d, use vendored modules
for convenience.
Signed-off-by: Izuru Yakumo <yakumo.izuru@…>
|
File size:
871 bytes
|
Line | |
---|
1 | // Package pq is a pure Go Postgres driver for the database/sql package.
|
---|
2 | package pq
|
---|
3 |
|
---|
4 | import (
|
---|
5 | "path/filepath"
|
---|
6 | "syscall"
|
---|
7 | )
|
---|
8 |
|
---|
9 | // Perform Windows user name lookup identically to libpq.
|
---|
10 | //
|
---|
11 | // The PostgreSQL code makes use of the legacy Win32 function
|
---|
12 | // GetUserName, and that function has not been imported into stock Go.
|
---|
13 | // GetUserNameEx is available though, the difference being that a
|
---|
14 | // wider range of names are available. To get the output to be the
|
---|
15 | // same as GetUserName, only the base (or last) component of the
|
---|
16 | // result is returned.
|
---|
17 | func userCurrent() (string, error) {
|
---|
18 | pw_name := make([]uint16, 128)
|
---|
19 | pwname_size := uint32(len(pw_name)) - 1
|
---|
20 | err := syscall.GetUserNameEx(syscall.NameSamCompatible, &pw_name[0], &pwname_size)
|
---|
21 | if err != nil {
|
---|
22 | return "", ErrCouldNotDetectUsername
|
---|
23 | }
|
---|
24 | s := syscall.UTF16ToString(pw_name)
|
---|
25 | u := filepath.Base(s)
|
---|
26 | return u, nil
|
---|
27 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.