作者:shellree
项目:gone
// Set a pixel through direct memory access
// TODO: higher-level functions
func WritePixel(x int, y int, r byte, g byte, b byte, a byte) {
if x > C.RESOLUTION_W || y > C.RESOLUTION_H {
// This is important, because write_byte has no bounds checking!
panic(fmt.Sprintf("WritePixel out of range: (%d,%d)\n", x, y))
}
offset := 4 * (x + y*C.RESOLUTION_W)
C.write_byte(C.off_t(offset+0), C.uint8_t(r))
C.write_byte(C.off_t(offset+1), C.uint8_t(g))
C.write_byte(C.off_t(offset+2), C.uint8_t(b))
C.write_byte(C.off_t(offset+3), C.uint8_t(a))
}
作者:BurntSush
项目:go-wayland-simple-sh
func (w *window) newBuffer(width, height int,
format uint32) *C.struct_wl_buffer {
stride := width * 4
size := stride * height
fd := C.os_create_anonymous_file(C.off_t(size))
if fd < 0 {
panic("Could not create buffer file.")
}
data := C.mmap(nil, C.size_t(size), C.PROT_READ|C.PROT_WRITE,
C.MAP_SHARED, C.int(fd), 0)
if *(*int)(data) == -1 {
panic("mmap failed")
C.close(fd)
return nil
}
pool := C.wl_shm_create_pool(w.display.shm,
C.int32_t(fd), C.int32_t(size))
buffer := C.wl_shm_pool_create_buffer(pool, 0,
C.int32_t(width), C.int32_t(height),
C.int32_t(stride), C.uint32_t(format))
C.wl_shm_pool_destroy(pool)
C.close(fd)
w.shmData = data
return buffer
}
作者:rayyang200
项目:clama
//export pread_cb
func pread_cb(handle unsafe.Pointer, buf unsafe.Pointer, count C.size_t, offset C.off_t) C.off_t {
v, ok := preadHandleCallbacks[(*interface{})(handle)]
if !ok {
return -1 // couldn't find callback
}
return C.off_t(v((*interface{})(handle), C.GoBytes(buf, C.int(count)), int64(offset)))
}
作者:TriangleG
项目:golang.or
func (a *asset) Seek(offset int64, whence int) (int64, error) {
// TODO(crawshaw): use AAsset_seek64 if it is available.
off := C.AAsset_seek(a.ptr, C.off_t(offset), C.int(whence))
if off == -1 {
return 0, a.errorf("seek", "bad result for offset=%d, whence=%d", offset, whence)
}
return int64(off), nil
}
作者:proglotti
项目:gpgm
//export gogpgme_seekfunc
func gogpgme_seekfunc(handle unsafe.Pointer, offset C.off_t, whence C.int) C.off_t {
d := callbackLookup(uintptr(handle)).(*Data)
n, err := d.s.Seek(int64(offset), int(whence))
if err != nil {
C.gpgme_err_set_errno(C.EIO)
return -1
}
return C.off_t(n)
}
作者:neurodron
项目:picar
// ReadAt reads the information from the vdi starting from the
// given offset. We implemented the io.ReaderAt interface here.
// The returned values match the returned values of Read.
func (v *VDI) ReadAt(buf []byte, offset int) (int, error) {
_, err := C.sd_vdi_read(
v.cluster.cluster,
v.vdi,
unsafe.Pointer(&buf[0]),
C.size_t(len(buf)),
C.off_t(offset))
return len(buf), err
}
作者:kshl
项目:gogfap
func (fd *Fd) Fallocate(mode int, offset int64, len int64) error {
ret, err := C.glfs_fallocate(fd.fd, C.int(mode),
C.off_t(offset), C.size_t(len))
if ret == 0 {
err = nil
}
return err
}
作者:neurodron
项目:picar
// WriteAt helps implement the io.WriterAt interface by allowing
// an additional offset to start writing to within the VDI.
func (v *VDI) WriteAt(buf []byte, offset int) (int, error) {
if _, err := C.sd_vdi_write(
v.cluster.cluster,
v.vdi,
unsafe.Pointer(&buf[0]),
C.size_t(len(buf)),
C.off_t(offset),
); err != nil {
return 0, err
}
return len(buf), nil
}
作者:ymqyt
项目:cse223_distFileSy
func (a *InoAttr) toCStat(o *C.struct_stat, timeout *C.double) {
o.st_ino = C.__darwin_ino64_t(a.Ino)
o.st_mode = C.mode_t(a.Mode)
o.st_nlink = C.nlink_t(a.Nlink)
o.st_size = C.off_t(a.Size)
if a.Uid != nil {
o.st_uid = C.uid_t(*a.Uid)
}
if a.Gid != nil {
o.st_gid = C.gid_t(*a.Gid)
}
toCTime(&o.st_ctimespec, a.Ctim)
toCTime(&o.st_mtimespec, a.Mtim)
toCTime(&o.st_atimespec, a.Atim)
if timeout != nil {
(*timeout) = C.double(a.Timeout)
}
}
作者:meidowork
项目:nekoq-commo
func falloc(fileSize int64, filePath string) error {
err := checkParam(fileSize, filePath)
if err != nil {
return err
}
f, err := os.OpenFile(filePath, os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
return err
}
errno := C.posix_fallocate(C.int(f.Fd()), 0, C.off_t(int32(fileSize)))
if errno != 0 {
return syscall.Errno(errno)
}
return nil
}
作者:XenServerBestPractic
项目:nov
func (buf *VirtioBuffer) doIO(
fd int,
fd_offset int64,
buf_offset int,
length int,
write C.int) (int, error) {
// Gather the appropriate elements.
ptrs, lens := buf.Gather(buf_offset, length)
// Actually execute our readv/writev.
rval := C.do_iovec(
C.int(fd),
C.int(len(ptrs)),
&ptrs[0],
&lens[0],
C.off_t(fd_offset),
write)
if rval < 0 {
return 0, syscall.Errno(int(-rval))
}
return int(rval), nil
}
作者:proglotti
项目:gpgm
func (d *Data) Seek(offset int64, whence int) (int64, error) {
n, err := C.gpgme_data_seek(d.dh, C.off_t(offset), C.int(whence))
return int64(n), err
}
作者:vbellu
项目:gogfap
// Pwrite writes len(b) bytes from b into the Fd from offset off
//
// Returns number of bytes written on success and error on failure
func (fd *Fd) Pwrite(b []byte, off int64) (int, error) {
n, err := C.glfs_pwrite(fd.fd, unsafe.Pointer(&b[0]), C.size_t(len(b)), C.off_t(off), 0)
return int(n), err
}
作者:vbellu
项目:gogfap
// Ftruncate truncates the size of the Fd to the given size
//
// Returns error on failure
func (fd *Fd) Ftruncate(size int64) error {
_, err := C.glfs_ftruncate(fd.fd, C.off_t(size))
return err
}
作者:vbellu
项目:gogfap
func (fd *Fd) lseek(offset int64, whence int) (int64, error) {
ret, err := C.glfs_lseek(fd.fd, C.off_t(offset), C.int(whence))
return int64(ret), err
}
作者:ymqyt
项目:cse223_distFileSy
func (d *dirBuf) Add(name string, ino int64, mode int, next int64) bool {
cstr := C.CString(name)
res := C.DirBufAdd(d.db, cstr, C.fuse_ino_t(ino), C.int(mode), C.off_t(next))
C.free(unsafe.Pointer(cstr))
return res == 0
}
作者:y
项目:go-cur
// curl_easy_setopt - set options for a curl easy handle
// WARNING: a function pointer is &fun, but function addr is reflect.ValueOf(fun).Pointer()
func (curl *CURL) Setopt(opt int, param interface{}) error {
p := curl.handle
if param == nil {
// NOTE: some option will crash program when got a nil param
return newCurlError(C.curl_easy_setopt_pointer(p, C.CURLoption(opt), nil))
}
switch {
// not really set
case opt == OPT_READDATA: // OPT_INFILE
curl.readData = ¶m
return nil
case opt == OPT_DEBUGDATA:
curl.debugData = ¶m
return nil
case opt == OPT_PROGRESSDATA:
curl.progressData = ¶m
return nil
case opt == OPT_HEADERDATA: // also known as OPT_WRITEHEADER
curl.headerData = ¶m
return nil
case opt == OPT_WRITEDATA: // OPT_FILE
curl.writeData = ¶m
return nil
case opt == OPT_READFUNCTION:
fun := param.(func([]byte, interface{}) int)
curl.readFunction = &fun
ptr := C.return_read_function()
if err := newCurlError(C.curl_easy_setopt_pointer(p, C.CURLoption(opt), ptr)); err == nil {
return newCurlError(C.curl_easy_setopt_pointer(p, OPT_READDATA,
unsafe.Pointer(reflect.ValueOf(curl).Pointer())))
} else {
return err
}
case opt == OPT_PROGRESSFUNCTION:
fun := param.(func(float64, float64, float64, float64, interface{}) bool)
curl.progressFunction = &fun
ptr := C.return_progress_function()
if err := newCurlError(C.curl_easy_setopt_pointer(p, C.CURLoption(opt), ptr)); err == nil {
return newCurlError(C.curl_easy_setopt_pointer(p, OPT_PROGRESSDATA,
unsafe.Pointer(reflect.ValueOf(curl).Pointer())))
} else {
return err
}
case opt == OPT_DEBUGFUNCTION:
fun := param.(func(int, []byte) bool)
curl.debugFunction = &fun
ptr := C.return_debug_function()
if err := newCurlError(C.curl_easy_setopt_pointer(p, C.CURLoption(opt), ptr)); err == nil {
return newCurlError(C.curl_easy_setopt_pointer(p, OPT_DEBUGDATA,
unsafe.Pointer(reflect.ValueOf(curl).Pointer())))
} else {
return err
}
case opt == OPT_HEADERFUNCTION:
fun := param.(func([]byte, interface{}) bool)
curl.headerFunction = &fun
ptr := C.return_header_function()
if err := newCurlError(C.curl_easy_setopt_pointer(p, C.CURLoption(opt), ptr)); err == nil {
return newCurlError(C.curl_easy_setopt_pointer(p, OPT_HEADERDATA,
unsafe.Pointer(reflect.ValueOf(curl).Pointer())))
} else {
return err
}
case opt == OPT_WRITEFUNCTION:
fun := param.(func([]byte, interface{}) bool)
curl.writeFunction = &fun
ptr := C.return_write_function()
if err := newCurlError(C.curl_easy_setopt_pointer(p, C.CURLoption(opt), ptr)); err == nil {
return newCurlError(C.curl_easy_setopt_pointer(p, OPT_WRITEDATA,
unsafe.Pointer(reflect.ValueOf(curl).Pointer())))
} else {
return err
}
// for OPT_HTTPPOST, use struct Form
case opt == OPT_HTTPPOST:
post := param.(*Form)
ptr := post.head
return newCurlError(C.curl_easy_setopt_pointer(p, C.CURLoption(opt), unsafe.Pointer(ptr)))
case opt >= C.CURLOPTTYPE_OFF_T:
val := C.off_t(0)
switch t := param.(type) {
case int:
val = C.off_t(t)
case uint64:
val = C.off_t(t)
default:
//.........这里部分代码省略.........