aboutsummaryrefslogtreecommitdiff
path: root/librsync/librsync_callback.go
blob: c8b9e4f02e14c16696a700fd2c4691bc37984547 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package librsync

/*
#include <stdio.h>
#include <librsync.h>
*/
import "C"

import (
	"io"
	"unsafe"
)

//export patchCallbackGo
func patchCallbackGo(_patcher unsafe.Pointer, pos C.rs_long_t, len *C.size_t, _buf *unsafe.Pointer) C.rs_result {
	patcher := (*Patcher)(_patcher)

	patcher.buf = make([]byte, int(*len))
	n, err := patcher.basis.ReadAt(patcher.buf, int64(pos))
	if n < int(*len) {
		if err != io.EOF {
			panic(jobInternalPanic{err})
		} else {
			return C.RS_INPUT_ENDED
		}
	}
	*len = C.size_t(n)
	*_buf = unsafe.Pointer(&(patcher.buf[0]))

	return C.RS_DONE
}