コード例 #1
0
ファイル: bytes.c プロジェクト: shinpei/konoha-wand
void knh_Bytes_unputc(knh_Bytes_t *ba, int c)
{
	if(BA_size(ba) >= c) {
		BA_size(ba) -= c;
		knh_bzero(ba->bu.ubuf + BA_size(ba), c);
	}
}
コード例 #2
0
ファイル: bytes.c プロジェクト: shinpei/konoha-wand
void knh_Bytes_clear(knh_Bytes_t *ba, size_t pos)
{
	if(pos < BA_size(ba)) {
		knh_bzero(ba->bu.ubuf + pos, BA_size(ba) - pos);
		BA_size(ba) = pos;
	}
}
コード例 #3
0
void knh_Bytes_unputc(knh_Bytes_t *ba)
{
	if(BA_size(ba) > 0) {
		BA_size(ba) -= 1;
		ba->bu.ubuf[BA_size(ba)] = '\0';
	}
}
コード例 #4
0
void knh_Bytes_putc(Ctx *ctx, knh_Bytes_t *ba, int ch)
{
	if(BA_size(ba) == ba->capacity) {
		knh_Bytes_expands(ctx, ba, ba->capacity * 2);
	}
	ba->bu.ubuf[BA_size(ba)] = ch;
	BA_size(ba) += 1;
}
コード例 #5
0
void knh_Bytes_clear(knh_Bytes_t *ba, size_t pos)
{
	DBG_ASSERT(!knh_Bytes_isStatic(ba));
	if(pos < BA_size(ba)) {
		knh_bzero(ba->bu.ubuf + pos, BA_size(ba) - pos);
		BA_size(ba) = pos;
	}
}
コード例 #6
0
ファイル: bytes.c プロジェクト: shinpei/konoha-wand
void knh_Bytes_putc(CTX ctx, knh_Bytes_t *ba, int ch)
{
	size_t capacity = ba->dim->capacity;
	if(BA_size(ba) == capacity) {
		knh_Bytes_expands(ctx, ba, k_grow(capacity));
	}
	ba->bu.ubuf[BA_size(ba)] = ch;
	BA_size(ba) += 1;
}
コード例 #7
0
ファイル: bytes.c プロジェクト: shinpei/konoha-wand
const char *knh_Bytes_ensureZero(CTX ctx, knh_Bytes_t *ba)
{
	size_t size = BA_size(ba);
	size_t capacity = ba->dim->capacity;
	if(size == capacity) {
		knh_Bytes_expands(ctx, ba, k_grow(capacity));
	}
	ba->bu.ubuf[BA_size(ba)] = 0;
	return ba->bu.text;
}
コード例 #8
0
void knh_Bytes_write(Ctx *ctx, knh_Bytes_t *ba, knh_bytes_t t)
{
	if(t.len == 0) return ;
	if(BA_size(ba) + t.len >= ba->capacity) {
		size_t newsize = ba->capacity * 2;
		if(newsize < BA_size(ba) + t.len) newsize = knh_good_size(BA_size(ba) + t.len);
		knh_Bytes_expands(ctx, ba, newsize);
	}
	knh_memcpy(ba->bu.ubuf + BA_size(ba), t.ustr, t.len);
	BA_size(ba) += t.len;
}
コード例 #9
0
ファイル: bytes.c プロジェクト: shinpei/konoha-wand
void knh_Bytes_write(CTX ctx, knh_Bytes_t *ba, knh_bytes_t t)
{
	size_t capacity = ba->dim->capacity;
	if(t.len == 0) return ;
	if(BA_size(ba) + t.len >= capacity) {
		size_t newsize = k_grow(capacity);
		if(newsize < BA_size(ba) + t.len) newsize = k_goodsize(BA_size(ba) + t.len);
		knh_Bytes_expands(ctx, ba, newsize);
	}
	knh_memcpy(ba->bu.ubuf + BA_size(ba), t.utext, t.len);
	BA_size(ba) += t.len;
}
コード例 #10
0
knh_InputStream_t* new_BytesInputStream(Ctx *ctx, knh_Bytes_t *ba)
{
	knh_InputStream_t* in = new_(InputStream);
	DBG_ASSERT(ba != ctx->bufa);
	DP(in)->fd = IO_NULL;
	KNH_SETv(ctx, DP(in)->ba, ba);
	DP(in)->buf = (char*)(ba)->bu.ubuf;
	DP(in)->bufsiz = BA_size(ba);
	DP(in)->bufpos   = 0;
	DP(in)->bufend   = BA_size(ba);
	return in;
}
コード例 #11
0
const char *knh_Bytes_ensureZero(Ctx *ctx, knh_Bytes_t *ba)
{
	DBG_ASSERT(!knh_Bytes_isStatic(ba));
	size_t size = BA_size(ba);
	if(size == ba->capacity) {
		knh_Bytes_expands(ctx, ba, ba->capacity * 2);
	}
	ba->bu.ubuf[BA_size(ba)] = 0;
//	if(ba->bu.text[size] != 0) {
//		DBG_P("@@@@ pos=%d, ch=%d, %c", size, ba->bu.ubuf[size], ba->bu.ubuf[size]);
//		knh_bzero(ba->bu.ubuf + size, ba->capacity - size);
//	}
	return ba->bu.text;
}
コード例 #12
0
KNHAPI(void) knh_ResultSet_setNULL(Ctx *ctx, knh_ResultSet_t *o, size_t n)
{
	KNH_ASSERT(n < DP(o)->column_size);
	DP(o)->column[n].ctype = knh_ResultSet_CTYPE__null;
	DP(o)->column[n].start = BA_size(DP(o)->databuf);
	DP(o)->column[n].len = 0;
}
コード例 #13
0
void knh_Bytes_ensureSize(Ctx *ctx, knh_Bytes_t *ba, size_t len)
{
	DBG_ASSERT(!knh_Bytes_isStatic(ba));
	if(ba->capacity < len) {
		knh_Bytes_expands(ctx, ba, len);
	}
	BA_size(ba) = len;
}
コード例 #14
0
KNHAPI(void) knh_ResultSet_setInt(Ctx *ctx, knh_ResultSet_t *rs, size_t n, knh_int_t value)
{
	KNH_ASSERT(n < DP(rs)->column_size);
	knh_bytes_t t = {{(const char*)(&value)}, sizeof(knh_int_t)};
	DP(rs)->column[n].ctype = knh_ResultSet_CTYPE__integer;
	DP(rs)->column[n].start = BA_size(DP(rs)->databuf);
	DP(rs)->column[n].len = sizeof(knh_int_t);
	knh_Bytes_write(ctx, DP(rs)->databuf, t);
}
コード例 #15
0
KNHAPI(void) knh_ResultSet_setBlob(Ctx *ctx, knh_ResultSet_t *o, size_t n, knh_bytes_t t)
{
	KNH_ASSERT(n < DP(o)->column_size);
	DP(o)->column[n].ctype = knh_ResultSet_CTYPE__bytes;
	DP(o)->column[n].start = BA_size(DP(o)->databuf);
	DP(o)->column[n].len = t.len;
	knh_Bytes_write(ctx, DP(o)->databuf, t);
	int i, c = t.len % sizeof(void*);
	for(i = 0; i < c; i++) knh_Bytes_putc(ctx, DP(o)->databuf, 0);    /* zero */
}
コード例 #16
0
void knh_BytesInputStream_setpos(Ctx *ctx, knh_InputStream_t *in, size_t s, size_t e)
{
	knh_Bytes_t *ba = DP(in)->ba;
	DBG_ASSERT(DP(in)->fd == IO_NULL);
	DP(in)->buf = (char*)(ba)->bu.ubuf;
	DP(in)->bufsiz = (ba)->bu.len;
	DBG_ASSERT(e <= BA_size(ba));
	DBG_ASSERT(s <= e);
	DP(in)->bufpos   = s;
	DP(in)->bufend   = e;
}
コード例 #17
0
KNHAPI(void) knh_OutputStream_write(Ctx *ctx, knh_OutputStream_t *w, knh_bytes_t buf)
{
	knh_Bytes_t *ba = DP(w)->ba;
	DBG_ASSERT(IS_Bytes(ba));
	knh_Bytes_write(ctx, ba, buf);
	if(!knh_OutputStream_isStoringBuffer(w) && BA_size(ba) > SP(w)->dspi->bufsiz) {
		SP(w)->dspi->fwrite(ctx, DP(w)->fd, (ba)->bu.text, (ba)->bu.len);
		knh_Bytes_clear(ba, 0);
	}
	DP(w)->size += buf.len;
}
コード例 #18
0
KNHAPI(void) knh_ResultSet_setFloat(Ctx *ctx, knh_ResultSet_t *rs, size_t n, knh_float_t value)
{
	KNH_ASSERT(n < DP(rs)->column_size);
	knh_bytes_t t = {{(const char*)(&value)}, sizeof(knh_float_t)};
	DP(rs)->column[n].ctype = knh_ResultSet_CTYPE__float;
	DP(rs)->column[n].start = BA_size(DP(rs)->databuf);
	DP(rs)->column[n].len = sizeof(knh_float_t);
	knh_Bytes_write(ctx, DP(rs)->databuf, t);
	int i, c = t.len % sizeof(void*);
	for(i = 0; i < c; i++) knh_Bytes_putc(ctx, DP(rs)->databuf, 0);    /* zero */
}
コード例 #19
0
ファイル: os.c プロジェクト: shidasan/konoha2
kbool_t knh_buff_mkdir(CTX, kBytes *ba, size_t pos)
{
	kchar_t *ubuf = ba->bu.ubuf;
	size_t i, len = BA_size(ba);
	for(i = pos + 1; i < len; i++) {
		int ch = ubuf[i];
		if(ch == K_SEP) {
			int res = 0;
			ubuf[i] = 0;
			if(knh_isdir(_ctx, (const char*)ubuf + pos)) {
				res = knh_mkdir(_ctx, (const char*)ubuf + pos);
			}
			ubuf[i] = ch;
			if(res == -1) return 0;
		}
	}
	return knh_mkdir(_ctx, (const char*)ubuf + pos);
}
コード例 #20
0
ファイル: blob.c プロジェクト: wakamori/konoha.libgit2
/* Close an open blob */
//## @Native void GitBlob.close();
KMETHOD GitBlob_close(CTX ctx, ksfp_t *sfp _RIX)
{
    kGitBlob_free(ctx, sfp[0].p);
    RETURNvoid_();
}

/* Write an in-memory buffer to the ODB as a blob */
//## @Native @Static GitOid GitBlob.createFromBuffer(GitRepository repo, Bytes buffer);
KMETHOD GitBlob_createFromBuffer(CTX ctx, ksfp_t *sfp _RIX)
{
    git_oid *oid = (git_oid *)KNH_MALLOC(ctx, sizeof(git_oid));
    git_repository *repo = RawPtr_to(git_repository *, sfp[1]);
    const void *buffer = (const void *)BA_totext(sfp[2].ba);
    size_t len = BA_size(sfp[2].ba);
    int error = git_blob_create_frombuffer(oid, repo, buffer, len);
    if (error < GIT_SUCCESS) {
        TRACE_ERROR(ctx, "git_blob_create_frombuffer", error);
        KNH_FREE(ctx, oid, sizeof(git_oid));
        RETURN_(KNH_NULL);
    }
    RETURN_(new_ReturnRawPtr(ctx, sfp, oid));
}

/* Read a file from the working folder of a repository and write it to the
 * Object Database as a loose blob */
//## @Native @Static GitOid GitBlob.createFromFile(GitRepository repo, String path);
KMETHOD GitBlob_createFromFile(CTX ctx, ksfp_t *sfp _RIX)
{
    git_oid *oid = (git_oid *)KNH_MALLOC(ctx, sizeof(git_oid));