Debian Codegraph @

filelock/file_lock_windows.go

raw symbols SCIP
1 // Copyright 2013 The LevelDB-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 filelock
6
7 import (
8 "io"
9 "syscall"
10 )
11
12 // lockCloser hides all of an syscall.Handle's methods, except for Close.
13 type lockCloser struct {
14 fd syscall.Handle
15 }
16
17 func (l lockCloser) Close() error {
18 return syscall.Close(l.fd)
19 }
20
21 func Lock(name string) (io.Closer, error) {
22 p, err := syscall.UTF16PtrFromString(name)
23 if err != nil {
24 return nil, err
25 }
26 fd, err := syscall.CreateFile(p,
27 syscall.GENERIC_READ|syscall.GENERIC_WRITE,
28 0, nil, syscall.CREATE_ALWAYS,
29 syscall.FILE_ATTRIBUTE_NORMAL,
30 0,
31 )
32 if err != nil {
33 return nil, err
34 }
35 return lockCloser{fd: fd}, nil
36 }