OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [mime/] [type_windows.go] - Blame information for rev 747

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// 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.
4
 
5
package mime
6
 
7
import (
8
        "syscall"
9
        "unsafe"
10
)
11
 
12
func initMime() {
13
        var root syscall.Handle
14
        if syscall.RegOpenKeyEx(syscall.HKEY_CLASSES_ROOT, syscall.StringToUTF16Ptr(`\`),
15
                0, syscall.KEY_READ, &root) != nil {
16
                return
17
        }
18
        defer syscall.RegCloseKey(root)
19
        var count uint32
20
        if syscall.RegQueryInfoKey(root, nil, nil, nil, &count, nil, nil, nil, nil, nil, nil, nil) != nil {
21
                return
22
        }
23
        var buf [1 << 10]uint16
24
        for i := uint32(0); i < count; i++ {
25
                n := uint32(len(buf))
26
                if syscall.RegEnumKeyEx(root, i, &buf[0], &n, nil, nil, nil, nil) != nil {
27
                        continue
28
                }
29
                ext := syscall.UTF16ToString(buf[:])
30
                if len(ext) < 2 || ext[0] != '.' { // looking for extensions only
31
                        continue
32
                }
33
                var h syscall.Handle
34
                if syscall.RegOpenKeyEx(
35
                        syscall.HKEY_CLASSES_ROOT, syscall.StringToUTF16Ptr(`\`+ext),
36
                        0, syscall.KEY_READ, &h) != nil {
37
                        continue
38
                }
39
                var typ uint32
40
                n = uint32(len(buf) * 2) // api expects array of bytes, not uint16
41
                if syscall.RegQueryValueEx(
42
                        h, syscall.StringToUTF16Ptr("Content Type"),
43
                        nil, &typ, (*byte)(unsafe.Pointer(&buf[0])), &n) != nil {
44
                        syscall.RegCloseKey(h)
45
                        continue
46
                }
47
                syscall.RegCloseKey(h)
48
                if typ != syscall.REG_SZ { // null terminated strings only
49
                        continue
50
                }
51
                mimeType := syscall.UTF16ToString(buf[:])
52
                setExtensionType(ext, mimeType)
53
        }
54
}
55
 
56
func initMimeForTests() map[string]string {
57
        return map[string]string{
58
                ".bmp": "image/bmp",
59
                ".png": "image/png",
60
        }
61
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.