1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 var root syscall
.Handle
14 rootpathp
, _
:= syscall
.UTF16PtrFromString(`\`)
15 if syscall
.RegOpenKeyEx(syscall
.HKEY_CLASSES_ROOT
, rootpathp
,
16 0, syscall
.KEY_READ
, &root
) != nil {
19 defer syscall
.RegCloseKey(root
)
21 if syscall
.RegQueryInfoKey(root
, nil, nil, nil, &count
, nil, nil, nil, nil, nil, nil, nil) != nil {
24 var buf
[1 << 10]uint16
25 for i
:= uint32(0); i
< count
; i
++ {
27 if syscall
.RegEnumKeyEx(root
, i
, &buf
[0], &n
, nil, nil, nil, nil) != nil {
30 ext
:= syscall
.UTF16ToString(buf
[:])
31 if len(ext
) < 2 || ext
[0] != '.' { // looking for extensions only
35 extpathp
, _
:= syscall
.UTF16PtrFromString(`\` + ext
)
36 if syscall
.RegOpenKeyEx(
37 syscall
.HKEY_CLASSES_ROOT
, extpathp
,
38 0, syscall
.KEY_READ
, &h
) != nil {
42 n
= uint32(len(buf
) * 2) // api expects array of bytes, not uint16
43 contenttypep
, _
:= syscall
.UTF16PtrFromString("Content Type")
44 if syscall
.RegQueryValueEx(
46 nil, &typ
, (*byte)(unsafe
.Pointer(&buf
[0])), &n
) != nil {
47 syscall
.RegCloseKey(h
)
50 syscall
.RegCloseKey(h
)
51 if typ
!= syscall
.REG_SZ
{ // null terminated strings only
54 mimeType
:= syscall
.UTF16ToString(buf
[:])
55 setExtensionType(ext
, mimeType
)
59 func initMimeForTests() map[string]string {
60 return map[string]string{