Пример #1
0
// LoadHTML loads the given content string with the specified baseURI. The MIME
// type of the document will be "text/html".
//
// See also: webkit_web_view_load_html at
// http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-load-html
func (v *WebView) LoadHTML(content, baseURI string) {
	cContent := C.CString(content)
	defer C.free(unsafe.Pointer(cContent))
	cBaseURI := C.CString(baseURI)
	defer C.free(unsafe.Pointer(cBaseURI))
	C.webkit_web_view_load_html(v.webView, (*C.gchar)(cContent), (*C.gchar)(cBaseURI))
}
Пример #2
0
func (v *WebKitWebView) LoadHtmlString(content, base_uri string) {
	pcontent := C.CString(content)
	defer C.free_string(pcontent)
	pbase_uri := C.CString(base_uri)
	defer C.free_string(pbase_uri)
	C.webkit_web_view_load_html_string(v.getWebView(), C.to_gcharptr(pcontent), C.to_gcharptr(pbase_uri))
}
Пример #3
0
func (c *driverConn) Prepare(query string) (driver.Stmt, error) {
	// Generate unique statement name.
	stmtname := strconv.Itoa(c.stmtNum)
	cstmtname := C.CString(stmtname)
	c.stmtNum++
	defer C.free(unsafe.Pointer(cstmtname))
	stmtstr := C.CString(query)
	defer C.free(unsafe.Pointer(stmtstr))
	res := C.PQprepare(c.db, cstmtname, stmtstr, 0, nil)
	err := resultError(res)
	if err != nil {
		C.PQclear(res)
		return nil, err
	}
	stmtinfo := C.PQdescribePrepared(c.db, cstmtname)
	err = resultError(stmtinfo)
	if err != nil {
		C.PQclear(stmtinfo)
		return nil, err
	}
	defer C.PQclear(stmtinfo)
	nparams := int(C.PQnparams(stmtinfo))
	statement := &driverStmt{stmtname, c.db, res, nparams}
	runtime.SetFinalizer(statement, (*driverStmt).Close)
	return statement, nil
}
Пример #4
0
func (v *Reference) Rename(name string, force bool, sig *Signature, msg string) (*Reference, error) {
	var ptr *C.git_reference
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))

	csig := sig.toC()
	defer C.free(unsafe.Pointer(csig))

	var cmsg *C.char
	if msg == "" {
		cmsg = nil
	} else {
		cmsg = C.CString(msg)
		defer C.free(unsafe.Pointer(cmsg))
	}

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	ret := C.git_reference_rename(&ptr, v.ptr, cname, cbool(force), csig, cmsg)

	if ret < 0 {
		return nil, MakeGitError(ret)
	}

	return newReferenceFromC(ptr), nil
}
Пример #5
0
func (provider *Provider) AddProbe(function string, name string, signature ...reflect.Kind) Probe {
	cFunction := C.CString(function)
	cName := C.CString(name)
	defer C.free(unsafe.Pointer(cFunction))
	defer C.free(unsafe.Pointer(cName))

	cTypes := make([]*C.char, len(signature))

	for i, kind := range signature {
		switch kind {
		case reflect.Int:
			cTypes[i] = C.CString("int")
			defer C.free(unsafe.Pointer(cTypes[i]))
		case reflect.String:
			cTypes[i] = C.CString("char *")
			defer C.free(unsafe.Pointer(cTypes[i]))
		default:
			cTypes[i] = nil
		}
	}

	probedef := C.usdt_create_probe(cFunction, cName, C.size_t(len(signature)), &cTypes[0])
	C.usdt_provider_add_probe(provider.provider_t, probedef)

	newProbe := Probe{
		function,
		name,
		probedef,
	}

	provider.Probes = append(provider.Probes, newProbe)

	return newProbe
}
Пример #6
0
func (e Enumerate) AddNoMatchSysAttr(sysattr string, value string) error {
	err := C.udev_enumerate_add_match_sysattr(e.ptr, C.CString(sysattr), C.CString(value))
	if err != 0 {
		return Error(err)
	}
	return nil
}
Пример #7
0
// GetApproximateSizes returns the approximate number of bytes of file system
// space used by one or more key ranges.
//
// The keys counted will begin at Range.Start and end on the key before
// Range.Limit.
func (db *DB) GetApproximateSizes(ranges []Range) []uint64 {
	starts := make([]*C.char, len(ranges))
	limits := make([]*C.char, len(ranges))
	startLens := make([]C.size_t, len(ranges))
	limitLens := make([]C.size_t, len(ranges))
	for i, r := range ranges {
		starts[i] = C.CString(string(r.Start))
		startLens[i] = C.size_t(len(r.Start))
		limits[i] = C.CString(string(r.Limit))
		limitLens[i] = C.size_t(len(r.Limit))
	}
	sizes := make([]uint64, len(ranges))
	numranges := C.int(len(ranges))
	startsPtr := &starts[0]
	limitsPtr := &limits[0]
	startLensPtr := &startLens[0]
	limitLensPtr := &limitLens[0]
	sizesPtr := (*C.uint64_t)(&sizes[0])
	C.hyperleveldb_rocksdb_approximate_sizes(
		db.Ldb, numranges, startsPtr, startLensPtr,
		limitsPtr, limitLensPtr, sizesPtr)
	for i := range ranges {
		C.free(unsafe.Pointer(starts[i]))
		C.free(unsafe.Pointer(limits[i]))
	}
	return sizes
}
Пример #8
0
// ConfigureTUN sets up the tun device, this is equivalent to the
// badvpn-tun2socks configuration, except for the --socks-server-addr.
func ConfigureTUN(tundev, ipaddr, netmask, udpgw string, d dialer) error {
	if d == nil {
		d = dummyDialer
	}

	Dialer = d
	udpGwServerAddress = udpgw

	ctundev := C.CString(tundev)
	cipaddr := C.CString(ipaddr)
	cnetmask := C.CString(netmask)
	cudpgw_addr := C.CString(udpgw)

	defer func() {
		C.free(unsafe.Pointer(ctundev))
		C.free(unsafe.Pointer(cipaddr))
		C.free(unsafe.Pointer(cnetmask))
		C.free(unsafe.Pointer(cudpgw_addr))
	}()

	log.Printf("Configuring with TUN device...")

	if err_t := C.configure_tun(ctundev, cipaddr, cnetmask, cudpgw_addr); err_t != C.ERR_OK {
		return errors.New("Failed to configure device.")
	}

	return nil
}
Пример #9
0
// Publish publishes an announcement at an interval
func (b *Beacon) Publish(announcement string, interval int) error {
	cmd := C.CString("PUBLISH")
	defer C.free(unsafe.Pointer(cmd))

	cAnnouncement := C.CString(announcement)
	defer C.free(unsafe.Pointer(cAnnouncement))

	cInterval := C.CString(strconv.Itoa(interval))
	defer C.free(unsafe.Pointer(cInterval))

	rc := C.zstr_sendm(unsafe.Pointer(b.zactorT), cmd)
	if rc == -1 {
		return ErrActorCmd
	}

	rc = C.zstr_sendm(unsafe.Pointer(b.zactorT), cAnnouncement)
	if rc == -1 {
		return ErrActorCmd
	}

	rc = C.zstr_send(unsafe.Pointer(b.zactorT), cInterval)
	if rc == -1 {
		return ErrActorCmd
	}

	return nil
}
Пример #10
0
// CurrentUnitName attempts to retrieve the name of the systemd system unit
// from which the calling process has been invoked. It wraps the systemd
// `sd_pid_get_unit` call, with the same caveat: for processes not part of a
// systemd system unit, this function will return an error.
func CurrentUnitName() (unit string, err error) {
	var h *libHandle
	h, err = getHandle()
	if err != nil {
		return
	}
	defer func() {
		if err1 := h.Close(); err1 != nil {
			err = err1
		}
	}()

	sym := C.CString("sd_pid_get_unit")
	defer C.free(unsafe.Pointer(sym))
	sd_pid_get_unit := C.dlsym(h.handle, sym)
	if sd_pid_get_unit == nil {
		err = fmt.Errorf("error resolving sd_pid_get_unit function")
		return
	}

	var s string
	u := C.CString(s)
	defer C.free(unsafe.Pointer(u))

	ret := C.my_sd_pid_get_unit(sd_pid_get_unit, 0, &u)
	if ret < 0 {
		err = fmt.Errorf("error calling sd_pid_get_unit: %v", syscall.Errno(-ret))
		return
	}

	unit = C.GoString(u)
	return
}
Пример #11
0
// ConfigureFD sets up the tun device using a file descriptor.
func ConfigureFD(tunFd int, tunMTU int, ipaddr, netmask, udpgw string, d dialer) error {
	if d == nil {
		d = dummyDialer
	}

	Dialer = d
	udpGwServerAddress = udpgw

	ctunFd := C.int(tunFd)
	ctunMTU := C.int(tunMTU)
	cipaddr := C.CString(ipaddr)
	cnetmask := C.CString(netmask)
	cudpgw_addr := C.CString(udpgw)

	defer func() {
		C.free(unsafe.Pointer(cipaddr))
		C.free(unsafe.Pointer(cnetmask))
		C.free(unsafe.Pointer(cudpgw_addr))
	}()

	log.Printf("Configuring with file descriptor...")

	if err_t := C.configure_fd(ctunFd, ctunMTU, cipaddr, cnetmask, cudpgw_addr); err_t != C.ERR_OK {
		return errors.New("Failed to configure device.")
	}

	return nil
}
Пример #12
0
// GetRunningSlice attempts to retrieve the name of the systemd slice in which
// the current process is running.
// This function is a wrapper around the libsystemd C library; if it cannot be
// opened, an error is returned.
func GetRunningSlice() (slice string, err error) {
	var h *libHandle
	h, err = getHandle()
	if err != nil {
		return
	}
	defer func() {
		if err1 := h.Close(); err1 != nil {
			err = err1
		}
	}()

	sym := C.CString("sd_pid_get_slice")
	defer C.free(unsafe.Pointer(sym))
	sd_pid_get_slice := C.dlsym(h.handle, sym)
	if sd_pid_get_slice == nil {
		err = fmt.Errorf("error resolving sd_pid_get_slice function")
		return
	}

	var s string
	sl := C.CString(s)
	defer C.free(unsafe.Pointer(sl))

	ret := C.my_sd_pid_get_slice(sd_pid_get_slice, 0, &sl)
	if ret < 0 {
		err = fmt.Errorf("error calling sd_pid_get_slice: %v", syscall.Errno(-ret))
		return
	}

	return C.GoString(sl), nil
}
Пример #13
0
func (repo *Repository) CreateBranch(branchName string, target *Commit, force bool, signature *Signature, msg string) (*Branch, error) {

	ref := new(Reference)
	cBranchName := C.CString(branchName)
	cForce := cbool(force)

	cSignature, err := signature.toC()
	if err != nil {
		return nil, err
	}
	defer C.git_signature_free(cSignature)

	var cmsg *C.char
	if msg == "" {
		cmsg = nil
	} else {
		cmsg = C.CString(msg)
		defer C.free(unsafe.Pointer(cmsg))
	}

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	ret := C.git_branch_create(&ref.ptr, repo.ptr, cBranchName, target.cast_ptr, cForce, cSignature, cmsg)
	if ret < 0 {
		return nil, MakeGitError(ret)
	}
	return ref.Branch(), nil
}
Пример #14
0
func (b *Branch) Move(newBranchName string, force bool, signature *Signature, msg string) (*Branch, error) {
	var ptr *C.git_reference
	cNewBranchName := C.CString(newBranchName)
	cForce := cbool(force)

	cSignature, err := signature.toC()
	if err != nil {
		return nil, err
	}
	defer C.git_signature_free(cSignature)

	var cmsg *C.char
	if msg == "" {
		cmsg = nil
	} else {
		cmsg = C.CString(msg)
		defer C.free(unsafe.Pointer(cmsg))
	}

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	ret := C.git_branch_move(&ptr, b.Reference.ptr, cNewBranchName, cForce, cSignature, cmsg)
	if ret < 0 {
		return nil, MakeGitError(ret)
	}
	return newReferenceFromC(ptr, b.repo).Branch(), nil
}
Пример #15
0
func sqlOpen(name string, flags int, vfs string) (conn *sqlConnection, rc int) {
	conn = new(sqlConnection)

	p := C.CString(name)
	if len(vfs) > 0 {
		q := C.CString(vfs)
		rc = int(C.sqlite3_open_v2(p, &conn.handle, C.int(flags), q))
		C.free(unsafe.Pointer(q))
	} else {
		rc = int(C.sqlite3_open_v2(p, &conn.handle, C.int(flags), nil))
	}
	C.free(unsafe.Pointer(p))

	// We could get a handle even if there's an error, see
	// http://www.sqlite.org/c3ref/open.html for details.
	// Initially we didn't want to return a connection on
	// error, but we actually have to since we want to fill
	// in a SystemError struct. Sigh.
	//	if rc != StatusOk && conn.handle != nil {
	//		_ = conn.sqlClose();
	//		conn = nil;
	//	}

	return
}
Пример #16
0
// void dsyevd_(char *jobz, char *uplo, int *n, double *A, int *ldA, double *W,
//		double *work, int *lwork, int *iwork, int *liwork, int *info);
func dsyevd(jobz, uplo string, N int, A []float64, lda int, W []float64) int {
	var info int = 0
	var lwork int = -1
	var liwork int = -1
	var iwork int32
	var work float64

	cjobz := C.CString(jobz)
	defer C.free(unsafe.Pointer(cjobz))
	cuplo := C.CString(uplo)
	defer C.free(unsafe.Pointer(cuplo))

	// pre-calculate work buffer size
	C.dsyevd_(cjobz, cuplo, (*C.int)(unsafe.Pointer(&N)), nil,
		(*C.int)(unsafe.Pointer(&lda)), nil,
		(*C.double)(unsafe.Pointer(&work)), (*C.int)(unsafe.Pointer(&lwork)),
		(*C.int)(unsafe.Pointer(&iwork)), (*C.int)(unsafe.Pointer(&liwork)),
		(*C.int)(unsafe.Pointer(&info)))

	// allocate work area
	lwork = int(work)
	wbuf := make([]float64, lwork)
	liwork = int(iwork)
	wibuf := make([]int32, liwork)

	C.dsyevd_(cjobz, cuplo, (*C.int)(unsafe.Pointer(&N)),
		(*C.double)(unsafe.Pointer(&A[0])),
		(*C.int)(unsafe.Pointer(&lda)), (*C.double)(unsafe.Pointer(&W[0])),
		(*C.double)(unsafe.Pointer(&wbuf[0])), (*C.int)(unsafe.Pointer(&lwork)),
		(*C.int)(unsafe.Pointer(&wibuf[0])), (*C.int)(unsafe.Pointer(&liwork)),
		(*C.int)(unsafe.Pointer(&info)))
	return info
}
Пример #17
0
func (conn *connection) performLogon(dsn string) error {

	user, pwd, host := parseDsn(dsn)
	puser := C.CString(user)
	defer C.free(unsafe.Pointer(puser))
	ppwd := C.CString(pwd)
	defer C.free(unsafe.Pointer(ppwd))
	phost := C.CString(host)
	defer C.free(unsafe.Pointer(phost))

	result := C.OCILogon2((*C.OCIEnv)(unsafe.Pointer(conn.env)),
		(*C.OCIError)(conn.err),
		(**C.OCIServer)(unsafe.Pointer(&conn.svr)),
		(*C.OraText)(unsafe.Pointer(puser)),
		C.ub4(C.strlen(puser)),
		(*C.OraText)(unsafe.Pointer(ppwd)),
		C.ub4(C.strlen(ppwd)),
		(*C.OraText)(unsafe.Pointer(phost)),
		C.ub4(C.strlen(phost)),
		C.OCI_LOGON2_STMTCACHE)
	if result != C.OCI_SUCCESS {
		return ociGetError(conn.err)
	}
	return nil
}
Пример #18
0
func NewTrailDBConstructor(path string, ofields ...string) (*TrailDBConstructor, error) {
	cons := C.tdb_cons_init()
	cpath := C.CString(path)
	defer C.free(unsafe.Pointer(cpath))

	var ofield_p *C.char
	ptrSize := unsafe.Sizeof(ofield_p)

	// Allocate the char** list.
	ptr := C.malloc(C.size_t(len(ofields)) * C.size_t(ptrSize))
	defer C.free(ptr)

	// Assign each byte slice to its appropriate offset.
	for i := 0; i < len(ofields); i++ {
		element := (**C.char)(unsafe.Pointer(uintptr(ptr) + uintptr(i)*ptrSize))
		cofield := C.CString(ofields[i])
		defer C.free(unsafe.Pointer(cofield))
		*element = cofield
	}

	if err := C.tdb_cons_open(cons, cpath, (**C.char)(ptr), C.uint64_t(len(ofields))); err != 0 {
		return nil, errors.New(errToString(err))
	}
	return &TrailDBConstructor{
		cons:         cons,
		path:         path,
		ofields:      ofields,
		valueLengths: make([]C.uint64_t, len(ofields)),
		valuePtr:     C.malloc(C.size_t(len(ofields)) * C.size_t(ptrSize)),
	}, nil
}
Пример #19
0
func (e Enumerate) AddMatchProperty(property string, value string) error {
	err := C.udev_enumerate_add_match_property(e.ptr, C.CString(property), C.CString(value))
	if err != 0 {
		return Error(err)
	}
	return nil
}
Пример #20
0
func (p *Comment) AddTag(tag string, contents string) {
	cTag := C.CString(tag)
	cContents := C.CString(contents)
	C.vorbis_comment_add_tag((*C.vorbis_comment)(p), cTag, cContents)
	C.free(unsafe.Pointer(cTag))
	C.free(unsafe.Pointer(cContents))
}
Пример #21
0
func (v *Reference) SetSymbolicTarget(target string, sig *Signature, msg string) (*Reference, error) {
	var ptr *C.git_reference

	ctarget := C.CString(target)
	defer C.free(unsafe.Pointer(ctarget))

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	csig := sig.toC()
	defer C.free(unsafe.Pointer(csig))

	var cmsg *C.char
	if msg == "" {
		cmsg = nil
	} else {
		cmsg = C.CString(msg)
		defer C.free(unsafe.Pointer(cmsg))
	}

	ret := C.git_reference_symbolic_set_target(&ptr, v.ptr, ctarget, csig, cmsg)
	if ret < 0 {
		return nil, MakeGitError(ret)
	}

	return newReferenceFromC(ptr), nil
}
Пример #22
0
// Create a new layer on the data source
func (ds DataSource) CreateLayer(
	name string,
	sr SpatialReference,
	geomType GeometryType,
	options []string,
) Layer {
	cName := C.CString(name)
	defer C.free(unsafe.Pointer(cName))

	length := len(options)
	opts := make([]*C.char, length+1)
	for i := 0; i < length; i++ {
		opts[i] = C.CString(options[i])
		defer C.free(unsafe.Pointer(opts[i]))
	}
	opts[length] = (*C.char)(unsafe.Pointer(nil))

	layer := C.OGR_DS_CreateLayer(
		ds.cval,
		cName,
		sr.cval,
		C.OGRwkbGeometryType(geomType),
		(**C.char)(unsafe.Pointer(&opts[0])),
	)
	return Layer{layer}
}
Пример #23
0
// VlmAddVOD adds a VOD with given input.
//
//     name: The name of the new broadcast.
//     input: The input MRL.
//     options: Additional options.
//     mux: The muxer of the vod media.
//     enabled: Enable the new broadcast?
//
func (this *Instance) VlmAddVOD(name, input, output, mux string, options []string, enabled bool) error {
	if this.ptr == nil {
		return os.EINVAL
	}

	a := C.CString(name)
	b := C.CString(input)
	c := C.int(len(options))
	d := make([]*C.char, len(options))

	for i := range d {
		d[i] = C.CString(options[i])
	}

	var e C.int
	if enabled {
		e = 1
	}

	f := C.CString(mux)

	C.libvlc_vlm_add_vod(this.ptr, a, b, c, *(***C.char)(unsafe.Pointer(&d)), e, f)

	C.free(unsafe.Pointer(a))
	C.free(unsafe.Pointer(b))

	for i := range d {
		C.free(unsafe.Pointer(d[i]))
	}

	C.free(unsafe.Pointer(f))
	return checkError()
}
Пример #24
0
func Clone(url string, path string, options *CloneOptions) (*Repository, error) {
	repo := new(Repository)

	curl := C.CString(url)
	defer C.free(unsafe.Pointer(curl))

	cpath := C.CString(path)
	defer C.free(unsafe.Pointer(cpath))

	var copts C.git_clone_options
	populateCloneOptions(&copts, options)
	defer freeCheckoutOpts(&copts.checkout_opts)

	if len(options.CheckoutBranch) != 0 {
		copts.checkout_branch = C.CString(options.CheckoutBranch)
		defer C.free(unsafe.Pointer(copts.checkout_branch))
	}

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()
	ret := C.git_clone(&repo.ptr, curl, cpath, &copts)
	if ret < 0 {
		return nil, MakeGitError(ret)
	}

	runtime.SetFinalizer(repo, (*Repository).Free)
	return repo, nil
}
Пример #25
0
// Create a codec which convert a string encoded in fromcode into a string
// encoded in tocode
//
// If you add //TRANSLIT at the end of tocode, any character which doesn't
// exists in the destination charset will be replaced by its closest
// equivalent (for example, € will be represented by EUR in ASCII). Else,
// such a character will trigger an error.
func Open(tocode string, fromcode string) (*Iconv, error) {
	ret, err := C.iconv_open(C.CString(tocode), C.CString(fromcode))
	if err != nil {
		return nil, err
	}
	return &Iconv{ret}, nil
}
Пример #26
0
// MONGO_EXPORT int mongo_update( mongo *conn, const char *ns, const bson *cond,
//                                const bson *op, int flags, mongo_write_concern *custom_write_concern );
func (m *Mongo) Update(ns string, cond, op *Bson, flags int, writeConcern *MongoWriteConcern) int {
	if writeConcern == nil {
		return int(C.mongo_update(m.conn, C.CString(ns), cond._bson, op._bson, C.int(flags), nil))
	}
	return int(C.mongo_update(m.conn, C.CString(ns), cond._bson,
		op._bson, C.int(flags), writeConcern.writeConcern))
}
Пример #27
0
func connect(conninfo string) (*PgConn, error) {
	cs := C.CString(conninfo)
	defer C.free(unsafe.Pointer(cs))
	conn := C.PQconnectdb(cs)
	if C.PQstatus(conn) != C.CONNECTION_OK {
		cerr := C.PQerrorMessage(conn)
		err := fmt.Errorf("connection failed: %s", C.GoString(cerr))
		C.PQfinish(conn)
		return nil, err
	}

	// TODO: support other encodings?
	pname := C.CString("client_encoding")
	defer C.free(unsafe.Pointer(pname))
	cenc := C.PQparameterStatus(conn, pname)
	if cenc == nil {
		err := errors.New("connection failed: no client encoding")
		C.PQfinish(conn)
		return nil, err
	}
	if enc := C.GoString(cenc); enc != "UTF8" {
		err := fmt.Errorf(
			"connection failed: client encoding not supported: %s", enc)
		C.PQfinish(conn)
		return nil, err
	}

	// one-line error message
	C.PQsetErrorVerbosity(conn, C.PQERRORS_TERSE)

	return &PgConn{conn: conn, conninfo: conninfo}, nil
}
Пример #28
0
// Remove the specified `keys` from the omap `oid`
func (ioctx *IOContext) RmOmapKeys(oid string, keys []string) error {
	c_oid := C.CString(oid)
	defer C.free(unsafe.Pointer(c_oid))

	var c *C.char
	ptrSize := unsafe.Sizeof(c)

	c_keys := C.malloc(C.size_t(len(keys)) * C.size_t(ptrSize))
	defer C.free(unsafe.Pointer(c_keys))

	i := 0
	for _, key := range keys {
		c_key_ptr := (**C.char)(unsafe.Pointer(uintptr(c_keys) + uintptr(i)*ptrSize))
		*c_key_ptr = C.CString(key)
		defer C.free(unsafe.Pointer(*c_key_ptr))
		i++
	}

	op := C.rados_create_write_op()
	C.rados_write_op_omap_rm_keys(
		op,
		(**C.char)(c_keys),
		C.size_t(len(keys)))

	ret := C.rados_write_op_operate(op, ioctx.ioctx, c_oid, nil, 0)
	C.rados_release_write_op(op)

	return GetRadosError(ret)
}
Пример #29
0
func OpenWithFallback(fromCode string, toCode string, fallbackPolicy int) (ic *Iconv, err error) {
	var pIconv C.iconv_t

	toCodeCharPtr := C.CString(toCode)
	defer C.free(unsafe.Pointer(toCodeCharPtr))
	fromCodeCharPtr := C.CString(fromCode)
	defer C.free(unsafe.Pointer(fromCodeCharPtr))

	pIconv, err = C.iconv_open(toCodeCharPtr, fromCodeCharPtr)
	if err == nil {
		if pIconv == nil {
			err = NilIconvPointer
			return
		}
		if fallbackPolicy == DISCARD_UNRECOGNIZED {
			ic = &Iconv{pIconv: pIconv, fallbackPolicy: fallbackPolicy, fallback: fallbackDiscardUnrecognized}
		} else if fallbackPolicy == KEEP_UNRECOGNIZED {
			ic = &Iconv{pIconv: pIconv, fallbackPolicy: fallbackPolicy, fallback: fallbackKeepIntactUnrecognized}
		} else if fallbackPolicy == NEXT_ENC_UNRECOGNIZED {
			ic = &Iconv{pIconv: pIconv, fallbackPolicy: fallbackPolicy}
		} else {
			err = InvalidFallbackPolicy
		}
	}
	return
}
Пример #30
0
// Sets the authority for a node
func (sr SpatialReference) SetAuthority(target, authority string, code int) error {
	cTarget := C.CString(target)
	defer C.free(unsafe.Pointer(cTarget))
	cAuthority := C.CString(authority)
	defer C.free(unsafe.Pointer(cAuthority))
	return C.OSRSetAuthority(sr.cval, cTarget, cAuthority, C.int(code)).Err()
}