Exemple #1
0
static pchar *pstrdup( const pchar *s, int len ) {
	pchar *ret;
	if( len < 0 ) len = (int)pstrlen(s);
	ret = (pchar*)hl_copy_bytes((vbyte*)s,sizeof(pchar)*(len+1));;
	ret[len] = 0;
	return ret;
}
Exemple #2
0
HL_PRIM varray *hl_exception_stack() {
	hl_thread_info *t = hl_get_thread();
	varray *a = hl_alloc_array(&hlt_bytes, t->exc_stack_count);
	int i;
	for(i=0;i<t->exc_stack_count;i++) {
		void *addr = t->exc_stack_trace[i];
		uchar sym[512];
		int size = 512;
		uchar *str = resolve_symbol_func(addr, sym, &size);
		if( str == NULL ) {
			int iaddr = (int)(int_val)addr;
			str = sym;
			size = usprintf(str,512,USTR("@0x%X"),iaddr);
		}
		hl_aptr(a,vbyte*)[i] = hl_copy_bytes((vbyte*)str,sizeof(uchar)*(size+1));
	}
	return a;
}
Exemple #3
0
HL_PRIM vdynamic *hl_alloc_strbytes( const uchar *fmt, ... ) {
	uchar _buf[256];
	vdynamic *d;
	int len;
	uchar *buf = _buf;
	int bsize = sizeof(_buf) / sizeof(uchar);
	va_list args;
	while( true ) {
		va_start(args, fmt);
		len = uvszprintf(buf,bsize,fmt,args);
		va_end(args);
		if( (len + 2) << 1 < bsize ) break;
		if( buf != _buf ) free(buf);
		bsize <<= 1;
		buf = (uchar*)malloc(bsize * sizeof(uchar));
	}
	d = hl_alloc_dynamic(&hlt_bytes);
	d->v.ptr = hl_copy_bytes((vbyte*)buf,(len + 1) << 1);
	if( buf != _buf ) free(buf);
	return d;
}
Exemple #4
0
HL_PRIM vbyte *hl_host_local() {
	char buf[256];
	if( gethostname(buf,256) == SOCKET_ERROR )
		return NULL;
	return hl_copy_bytes((vbyte*)buf,(int)strlen(buf)+1);
}