Exemplo n.º 1
0
static char* ConvertFromUtf8Filename(const char* fName){
#if _WIN32
	char* convertedFilename;
	int nChar, nb_byte;
	LPWSTR wideFilename;
	
	nChar = MultiByteToWideChar(CP_UTF8, 0, fName, -1, NULL, 0);
	if (nChar == 0) return NULL;
	wideFilename = bctbx_malloc(nChar*sizeof(wideFilename[0]));
	if (wideFilename == NULL) return NULL;
	nChar = MultiByteToWideChar(CP_UTF8, 0, fName, -1, wideFilename, nChar);
	if (nChar == 0) {
		bctbx_free(wideFilename);
		wideFilename = 0;
	}
	
	nb_byte = WideCharToMultiByte(CP_ACP, 0, wideFilename, -1, 0, 0, 0, 0);
	if (nb_byte == 0) return NULL;
	convertedFilename = bctbx_malloc(nb_byte);
	if (convertedFilename == NULL) return NULL;
	nb_byte = WideCharToMultiByte(CP_ACP, 0, wideFilename, -1, convertedFilename, nb_byte, 0, 0);
	if (nb_byte == 0) {
		bctbx_free(convertedFilename);
		convertedFilename = 0;
	}
	bctbx_free(wideFilename);
	return convertedFilename;
#elif defined(__QNXNTO__)
	return bctbx_strdup(fName);
#else
	#define MAX_PATH_SIZE 1024
	char db_file_utf8[MAX_PATH_SIZE] = {'\0'};
	char db_file_locale[MAX_PATH_SIZE] = "";
	char *outbuf=db_file_locale, *inbuf=db_file_utf8;
	size_t inbyteleft = MAX_PATH_SIZE, outbyteleft = MAX_PATH_SIZE;
	iconv_t cb;
	
	if (strcasecmp("UTF-8", nl_langinfo(CODESET)) == 0) {
		strncpy(db_file_locale, fName, MAX_PATH_SIZE - 1);
	} else {
		strncpy(db_file_utf8, fName, MAX_PATH_SIZE-1);
		cb = iconv_open(nl_langinfo(CODESET), "UTF-8");
		if (cb != (iconv_t)-1) {
			int ret;
			ret = iconv(cb, &inbuf, &inbyteleft, &outbuf, &outbyteleft);
			if(ret == -1) db_file_locale[0] = '\0';
			iconv_close(cb);
		}
	}
	return bctbx_strdup(db_file_locale);
#endif
}
Exemplo n.º 2
0
char *bctbx_strndup(const char *str,int n){
	int min=MIN((int)strlen(str),n)+1;
	char *ret=(char*)bctbx_malloc(min);
	strncpy(ret,str,min);
	ret[min-1]='\0';
	return ret;
}
Exemplo n.º 3
0
char * bctbx_strdup(const char *tmp){
	size_t sz;
	char *ret;
	if (tmp==NULL)
	  return NULL;
	sz=strlen(tmp)+1;
	ret=(char*)bctbx_malloc(sz);
	strcpy(ret,tmp);
	ret[sz-1]='\0';
	return ret;
}
Exemplo n.º 4
0
bctbx_vfs_file_t* bctbx_file_open2(bctbx_vfs_t *pVfs, const char *fName, const int openFlags) {
	int ret;
	bctbx_vfs_file_t *p_ret = (bctbx_vfs_file_t *)bctbx_malloc(sizeof(bctbx_vfs_file_t));

	if (p_ret) {
		memset(p_ret, 0, sizeof(bctbx_vfs_file_t));
		ret = file_open(pVfs, p_ret, fName, openFlags);
		if (ret == BCTBX_VFS_OK) return p_ret;
	}

	return NULL;
}
Exemplo n.º 5
0
void * bctbx_malloc0(size_t size){
	void *ptr=bctbx_malloc(size);
	memset(ptr,0,size);
	return ptr;
}