LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 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 // Windows system calls. | 5 // Windows system calls. |
6 | 6 |
7 package syscall | 7 package syscall |
8 | 8 |
9 import ( | 9 import ( |
10 "unicode/utf16" | 10 "unicode/utf16" |
11 "unsafe" | 11 "unsafe" |
12 ) | 12 ) |
13 | 13 |
14 type Handle uintptr | 14 type Handle uintptr |
15 | 15 |
16 const InvalidHandle = ^Handle(0) | 16 const InvalidHandle = ^Handle(0) |
17 | |
18 /* | |
19 | |
20 small demo to detect version of windows you are running: | |
21 | |
22 package main | |
23 | |
24 import ( | |
25 "syscall" | |
26 ) | |
27 | |
28 func abort(funcname string, err error) { | |
29 panic(funcname + " failed: " + err.Error()) | |
30 } | |
31 | |
32 func print_version(v uint32) { | |
33 major := byte(v) | |
34 minor := uint8(v >> 8) | |
35 build := uint16(v >> 16) | |
36 print("windows version ", major, ".", minor, " (Build ", build, ")\n") | |
37 } | |
38 | |
39 func main() { | |
40 h, err := syscall.LoadLibrary("kernel32.dll") | |
41 if err != nil { | |
42 abort("LoadLibrary", err) | |
43 } | |
44 defer syscall.FreeLibrary(h) | |
45 proc, err := syscall.GetProcAddress(h, "GetVersion") | |
46 if err != nil { | |
47 abort("GetProcAddress", err) | |
48 } | |
49 r, _, _ := syscall.Syscall(uintptr(proc), 0, 0, 0, 0) | |
50 print_version(uint32(r)) | |
51 } | |
52 | |
53 */ | |
54 | 17 |
55 // StringToUTF16 is deprecated. Use UTF16FromString instead. | 18 // StringToUTF16 is deprecated. Use UTF16FromString instead. |
56 // If s contains a NUL byte this function panics instead of | 19 // If s contains a NUL byte this function panics instead of |
57 // returning an error. | 20 // returning an error. |
58 func StringToUTF16(s string) []uint16 { | 21 func StringToUTF16(s string) []uint16 { |
59 a, err := UTF16FromString(s) | 22 a, err := UTF16FromString(s) |
60 if err != nil { | 23 if err != nil { |
61 panic("syscall: string with NUL passed to StringToUTF16") | 24 panic("syscall: string with NUL passed to StringToUTF16") |
62 } | 25 } |
63 return a | 26 return a |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 return e == EINTR || e == EMFILE || e.Timeout() | 98 return e == EINTR || e == EMFILE || e.Timeout() |
136 } | 99 } |
137 | 100 |
138 func (e Errno) Timeout() bool { | 101 func (e Errno) Timeout() bool { |
139 return e == EAGAIN || e == EWOULDBLOCK || e == ETIMEDOUT | 102 return e == EAGAIN || e == EWOULDBLOCK || e == ETIMEDOUT |
140 } | 103 } |
141 | 104 |
142 // Converts a Go function to a function pointer conforming | 105 // Converts a Go function to a function pointer conforming |
143 // to the stdcall calling convention. This is useful when | 106 // to the stdcall calling convention. This is useful when |
144 // interoperating with Windows code requiring callbacks. | 107 // interoperating with Windows code requiring callbacks. |
145 // Implemented in ../runtime/windows/syscall.goc | 108 // Implemented in ../runtime/syscall_windows.goc |
146 func NewCallback(fn interface{}) uintptr | 109 func NewCallback(fn interface{}) uintptr |
147 | 110 |
148 // windows api calls | 111 // windows api calls |
149 | 112 |
150 //sys GetLastError() (lasterr error) | 113 //sys GetLastError() (lasterr error) |
151 //sys LoadLibrary(libname string) (handle Handle, err error) = LoadLibraryW | 114 //sys LoadLibrary(libname string) (handle Handle, err error) = LoadLibraryW |
152 //sys FreeLibrary(handle Handle) (err error) | 115 //sys FreeLibrary(handle Handle) (err error) |
153 //sys GetProcAddress(module Handle, procname string) (proc uintptr, err error) | 116 //sys GetProcAddress(module Handle, procname string) (proc uintptr, err error) |
154 //sys GetVersion() (ver uint32, err error) | 117 //sys GetVersion() (ver uint32, err error) |
155 //sys FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32,
buf []uint16, args *byte) (n uint32, err error) = FormatMessageW | 118 //sys FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32,
buf []uint16, args *byte) (n uint32, err error) = FormatMessageW |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 | 784 |
822 func (s Signal) String() string { | 785 func (s Signal) String() string { |
823 if 0 <= s && int(s) < len(signals) { | 786 if 0 <= s && int(s) < len(signals) { |
824 str := signals[s] | 787 str := signals[s] |
825 if str != "" { | 788 if str != "" { |
826 return str | 789 return str |
827 } | 790 } |
828 } | 791 } |
829 return "signal " + itoa(int(s)) | 792 return "signal " + itoa(int(s)) |
830 } | 793 } |
LEFT | RIGHT |