github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/dokan/unsafe.go (about) 1 // Copyright 2016 Keybase Inc. All rights reserved. 2 // Use of this source code is governed by a BSD 3 // license that can be found in the LICENSE file. 4 5 package dokan 6 7 import ( 8 "reflect" 9 "unsafe" 10 ) 11 12 // bufToSlice returns a byte slice aliasing the pointer and length given as arguments. 13 func bufToSlice(ptr unsafe.Pointer, nbytes uint32) []byte { // nolint 14 if ptr == nil || nbytes == 0 { 15 return nil 16 } 17 return *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{ 18 Data: uintptr(ptr), 19 Len: int(nbytes), 20 Cap: int(nbytes)})) 21 }