本文整理匯總了Golang中C.off_t函數的典型用法代碼示例。如果您正苦於以下問題:Golang off_t函數的具體用法?Golang off_t怎麽用?Golang off_t使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了off_t函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: WritePixel
// 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))
}
示例2: newBuffer
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
}
示例3: pread_cb
//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)))
}
示例4: Seek
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
}
示例5: gogpgme_seekfunc
//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)
}
示例6: ReadAt
// 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
}
示例7: Fallocate
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
}
示例8: WriteAt
// 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
}
示例9: toCStat
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)
}
}
示例10: falloc
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
}
示例11: doIO
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
}
示例12: Seek
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
}
示例13: Pwrite
// 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
}
示例14: Ftruncate
// 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
}
示例15: lseek
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
}