示例#1
0
RETCODE  SQL_API
SQLErrorW(HENV EnvironmentHandle,
		  HDBC ConnectionHandle, HSTMT StatementHandle,
		  SQLWCHAR *Sqlstate, SQLINTEGER *NativeError,
		  SQLWCHAR *MessageText, SQLSMALLINT BufferLength,
		  SQLSMALLINT *TextLength)
{
	RETCODE	ret;
	SWORD	tlen, buflen;
	char	*qst = NULL, *mtxt = NULL;

	mylog("[SQLErrorW]");
	if (Sqlstate)
		qst = malloc(8);
	buflen = 0;
	if (MessageText && BufferLength > 0)
	{
		buflen = BufferLength * 3 + 1;
		mtxt = malloc(buflen);
	}
	ret = PGAPI_Error(EnvironmentHandle, ConnectionHandle, StatementHandle,
					  qst, NativeError, mtxt, buflen, &tlen);
	if (qst)
		utf8_to_ucs2(qst, strlen(qst), Sqlstate, 5);
	if (NULL != mtxt)
	{
		SQLULEN	tulen = utf8_to_ucs2(mtxt, tlen, MessageText, BufferLength);
		if (NULL != TextLength)
			*TextLength = tulen;
		free(mtxt);
	}
	if (qst)
		free(qst);
	return ret;
}
示例#2
0
static void
osk_open(glw_root_t *gr, const char *title, const char *input, glw_t *w,
	 int password)
{
  oskParam param = {0};
  oskInputFieldInfo ifi = {0};
  glw_ps3_t *gp = (glw_ps3_t *)gr;
  
  if(gp->osk_widget)
    return;

  if(title == NULL)
    title = "";

  if(input == NULL)
    input = "";

  void *title16;
  void *input16;

  size_t s;
  s = utf8_to_ucs2(NULL, title, 0);
  title16 = malloc(s);
  utf8_to_ucs2(title16, title, 0);

  s = utf8_to_ucs2(NULL, input, 0);
  input16 = malloc(s);
  utf8_to_ucs2(input16, input, 0);

  param.firstViewPanel = password ? OSK_PANEL_TYPE_PASSWORD :
    OSK_PANEL_TYPE_DEFAULT;
  param.allowedPanels = param.firstViewPanel;
  param.prohibitFlags = OSK_PROHIBIT_RETURN;

  ifi.message_addr = (intptr_t)title16;
  ifi.startText_addr = (intptr_t)input16;
  ifi.maxLength = 256;

  if(lv2MemContinerCreate(&gp->osk_container, 2 * 1024 * 1024))
    gp->osk_container = 0xFFFFFFFFU;

  oskSetKeyLayoutOption(3);

  int ret = oskLoadAsync(gp->osk_container, &param, &ifi);

  if(!ret) {
    gp->osk_widget = w;
    glw_ref(w);
  }

  free(title16);
  free(input16);
}
示例#3
0
文件: win_io.c 项目: Youka/luajit-win
FILE* _ufreopen (const char* filename, const char* mode, FILE* stream){
	wchar_t* wfilename, *wmode;
	if(!(wfilename = utf8_to_ucs2(filename)))
		return NULL;
	if(!(wmode = utf8_to_ucs2(mode))){
		free(wfilename);
		return NULL;
	}
	stream = _wfreopen(wfilename, wmode, stream);
	free(wfilename);
	free(wmode);
	return stream;
}
示例#4
0
文件: win_io.c 项目: Youka/luajit-win
FILE* _ufopen(const char* filename, const char* mode){
	wchar_t* wfilename, *wmode;
	FILE* file;
	if(!(wfilename = utf8_to_ucs2(filename)))
		return NULL;
	if(!(wmode = utf8_to_ucs2(mode))){
		free(wfilename);
		return NULL;
	}
	file = _wfopen(wfilename, wmode);
	free(wfilename);
	free(wmode);
	return file;
}
示例#5
0
文件: win_io.c 项目: Youka/luajit-win
int _urename(const char* oldname, const char* newname){
	wchar_t* woldname, *wnewname;
	int status;
	if(!(woldname = utf8_to_ucs2(oldname)))
		return 1;
	if(!(wnewname = utf8_to_ucs2(newname))){
		free(woldname);
		return 1;
	}
	status = _wrename(woldname, wnewname);
	free(woldname);
	free(wnewname);
	return status;
}
示例#6
0
文件: win_io.c 项目: Youka/luajit-win
FILE* _upopen(const char* command, const char* mode){
	wchar_t* wcommand, *wmode;
	FILE* stream;
	if(!(wcommand = utf8_to_ucs2(command)))
		return NULL;
	if(!(wmode = utf8_to_ucs2(mode))){
		free(wcommand);
		return NULL;
	}
	stream = _wfopen(wcommand, wmode);
	free(wcommand);
	free(wmode);
	return stream;
}
示例#7
0
文件: tfile.c 项目: graphis/libk
static int tcommit_one(struct tfile_t* tf, size_t off)
{
	#ifdef __WINNT__
	wchar_t* wtf = 0;
	wchar_t* wf = 0;
	#endif
	int old_errno;

	if (fchmod(tf->fd, tf->mode))
		goto err;
#if 0
	/* TODO: make this optional */
	if (fsync(tf->fd))
		goto err;
#endif
	if (close(tf->fd))
		goto err;
	/* TODO: rename is broken on windows. it doesn't allow to replace
	 * exising files atomically. see google for existing implementations
	 * and replace rename() for windows targets with a suitable one. */
#ifdef __WINNT__
	wtf = utf8_to_ucs2(tf->tmpfilename);
	wf = utf8_to_ucs2(tf->filename);
	if (!wtf || !wf)
		goto err;
	if (_wrename(wtf, wf))
		goto err;
	free(wtf);
	free(wf);
#else
	if (rename(tf->tmpfilename, tf->filename))
		goto err;
#endif
	free(tf->filename);
	free(tf->tmpfilename);
	pool_cut(&mappool, off, sizeof(struct tfile_t));
	return 0;
err:
	#ifdef __WINNT__
	if (wtf)
		free(wtf);
	if (wf)
		free(wf);
	#endif
	old_errno = errno;
	trollback_one(tf, off);
	errno = old_errno;
	return -1;
}
示例#8
0
文件: bitmap.cpp 项目: Ancurio/mkxp
IntRect Bitmap::textSize(const char *str)
{
	guardDisposed();

	GUARD_MEGA;

	TTF_Font *font = p->font->getSdlFont();

	std::string fixed = fixupString(str);
	str = fixed.c_str();

	int w, h;
	TTF_SizeUTF8(font, str, &w, &h);

	/* If str is one character long, *endPtr == 0 */
	const char *endPtr;
	uint16_t ucs2 = utf8_to_ucs2(str, &endPtr);

	/* For cursive characters, returning the advance
	 * as width yields better results */
	if (p->font->getItalic() && *endPtr == '\0')
		TTF_GlyphMetrics(font, ucs2, 0, 0, 0, 0, &w);

	return IntRect(0, 0, w, h);
}
示例#9
0
文件: ms_funcs.c 项目: Adrellias/mana
/**
 * encrypt_pw_block_with_password_hash - EncryptPwBlockWithPasswordHash() - RFC 2759, Sect. 8.10
 * @password: 0-to-256-unicode-char Password (IN; UTF-8)
 * @password_len: Length of password
 * @password_hash: 16-octet PasswordHash (IN)
 * @pw_block: 516-byte PwBlock (OUT)
 * Returns: 0 on success, -1 on failure
 */
int encrypt_pw_block_with_password_hash(
	const u8 *password, size_t password_len,
	const u8 *password_hash, u8 *pw_block)
{
	size_t ucs2_len, offset;
	u8 *pos;

	os_memset(pw_block, 0, PWBLOCK_LEN);

	if (utf8_to_ucs2(password, password_len, pw_block, 512, &ucs2_len) < 0)
		return -1;

	if (ucs2_len > 256)
		return -1;

	offset = (256 - ucs2_len) * 2;
	if (offset != 0) {
		os_memmove(pw_block + offset, pw_block, ucs2_len * 2);
		if (os_get_random(pw_block, offset) < 0)
			return -1;
	}
	/*
	 * PasswordLength is 4 octets, but since the maximum password length is
	 * 256, only first two (in little endian byte order) can be non-zero.
	 */
	pos = &pw_block[2 * 256];
	WPA_PUT_LE16(pos, password_len * 2);
	rc4_skip(password_hash, 16, 0, pw_block, PWBLOCK_LEN);
	return 0;
}
示例#10
0
RETCODE  SQL_API
SQLDescribeColW(HSTMT StatementHandle,
				SQLUSMALLINT ColumnNumber, SQLWCHAR *ColumnName,
				SQLSMALLINT BufferLength, SQLSMALLINT *NameLength,
				SQLSMALLINT *DataType, SQLULEN *ColumnSize,
				SQLSMALLINT *DecimalDigits, SQLSMALLINT *Nullable)
{
	CSTR func = "SQLDescribeColW";
	RETCODE	ret;
	StatementClass	*stmt = (StatementClass *) StatementHandle;
	SQLSMALLINT	buflen, nmlen;
	char	*clName = NULL, *clNamet = NULL;

	mylog("[%s]", func);
	buflen = 0;
	if (BufferLength > 0)
		buflen = BufferLength * 3;
	else if (NameLength)
		buflen = 32;
	if (buflen > 0)
		clNamet = malloc(buflen);
	ENTER_STMT_CS(stmt);
	SC_clear_error(stmt);
	StartRollbackState(stmt);
	for (;; buflen = nmlen + 1, clNamet = realloc(clName, buflen))
	{
		if (!clNamet)
		{
			SC_set_error(stmt, STMT_NO_MEMORY_ERROR, "Could not allocate memory for column name", func);
			ret = SQL_ERROR;
			break;
		}
		clName = clNamet;
		ret = PGAPI_DescribeCol(StatementHandle, ColumnNumber,
								(SQLCHAR *) clName, buflen,
								&nmlen, DataType, ColumnSize,
			DecimalDigits, Nullable);
		if (SQL_SUCCESS_WITH_INFO != ret || nmlen < buflen)
			break;
	}
	if (SQL_SUCCEEDED(ret))
	{
		SQLLEN	nmcount = nmlen;

		if (nmlen < buflen)
			nmcount = utf8_to_ucs2(clName, nmlen, ColumnName, BufferLength);
		if (SQL_SUCCESS == ret && BufferLength > 0 && nmcount > BufferLength)
		{
			ret = SQL_SUCCESS_WITH_INFO;
			SC_set_error(stmt, STMT_TRUNCATED, "Column name too large", func);
		}
		if (NameLength)
			*NameLength = (SQLSMALLINT) nmcount;
	}
	ret = DiscardStatementSvp(stmt, ret, FALSE);
	LEAVE_STMT_CS(stmt);
	if (clName)
		free(clName);
	return ret;
}
示例#11
0
RETCODE SQL_API
SQLNativeSqlW(HDBC			hdbc,
			  SQLWCHAR	   *szSqlStrIn,
			  SQLINTEGER	cbSqlStrIn,
			  SQLWCHAR	   *szSqlStr,
			  SQLINTEGER	cbSqlStrMax,
			  SQLINTEGER   *pcbSqlStr)
{
	CSTR func = "SQLNativeSqlW";
	RETCODE		ret;
	char		*szIn, *szOut = NULL, *szOutt = NULL;
	SQLLEN		slen;
	SQLINTEGER	buflen, olen;
	ConnectionClass *conn = (ConnectionClass *) hdbc;

	mylog("[%s}", func);
	CC_examine_global_transaction(conn);
	ENTER_CONN_CS(conn);
	CC_clear_error(conn);
	CC_set_in_unicode_driver(conn);
	szIn = ucs2_to_utf8(szSqlStrIn, cbSqlStrIn, &slen, FALSE);
	buflen = 3 * cbSqlStrMax;
	if (buflen > 0)
		szOutt = malloc(buflen);
	for (;; buflen = olen + 1, szOutt = realloc(szOut, buflen))
	{
		if (!szOutt)
		{
			CC_set_error(conn, CONN_NO_MEMORY_ERROR, "Could not allocate memory for output buffer", func);
			ret = SQL_ERROR;
			break;
		}
		szOut = szOutt;
		ret = PGAPI_NativeSql(hdbc, (SQLCHAR *) szIn, (SQLINTEGER) slen,
							  (SQLCHAR *) szOut, buflen, &olen);
		if (SQL_SUCCESS_WITH_INFO != ret || olen < buflen)
			break;
	}
	if (szIn)
		free(szIn);
	if (SQL_SUCCEEDED(ret))
	{
		SQLLEN	szcount = olen;

		if (olen < buflen)
			szcount = utf8_to_ucs2(szOut, olen, szSqlStr, cbSqlStrMax);
		if (SQL_SUCCESS == ret && szcount > cbSqlStrMax)
		{
			ConnectionClass	*conn = (ConnectionClass *) hdbc;

			ret = SQL_SUCCESS_WITH_INFO;
			CC_set_error(conn, CONN_TRUNCATED, "Sql string too large", func);
		}
		if (pcbSqlStr)
			*pcbSqlStr = (SQLINTEGER) szcount;
	}
	LEAVE_CONN_CS(conn);
	free(szOut);
	return ret;
}
示例#12
0
文件: win_io.c 项目: Youka/luajit-win
int _usystem(const char* command){
	wchar_t* wcommand;
	int status;
	if(!(wcommand = utf8_to_ucs2(command)))
		return -1;
	status = _wsystem(wcommand);
	free(wcommand);
	return status;
}
示例#13
0
RETCODE SQL_API
SQLGetDescFieldW(SQLHDESC hdesc, SQLSMALLINT iRecord, SQLSMALLINT iField,
				PTR rgbValue, SQLINTEGER cbValueMax,
    				SQLINTEGER *pcbValue)
{
	CSTR func = "SQLGetDescFieldW";
	RETCODE	ret;
	SQLINTEGER		blen = 0, bMax,	*pcbV;
        char    *rgbV = NULL;

	mylog("[%s]", func);
	switch (iField)
	{
		case SQL_DESC_BASE_COLUMN_NAME:
		case SQL_DESC_BASE_TABLE_NAME:
		case SQL_DESC_CATALOG_NAME:
		case SQL_DESC_LABEL:
		case SQL_DESC_LITERAL_PREFIX:
		case SQL_DESC_LITERAL_SUFFIX:
		case SQL_DESC_LOCAL_TYPE_NAME:
		case SQL_DESC_NAME:
		case SQL_DESC_SCHEMA_NAME:
		case SQL_DESC_TABLE_NAME:
		case SQL_DESC_TYPE_NAME:
			bMax = cbValueMax * 3 / WCLEN;
			rgbV = malloc(bMax + 1);
			pcbV = &blen;
			for (;; bMax = blen + 1, rgbV = realloc(rgbV, bMax))
			{
				ret = PGAPI_GetDescField(hdesc, iRecord, iField, rgbV, bMax, pcbV);
				if (SQL_SUCCESS_WITH_INFO != ret || blen < bMax)
					break;
			}
			if (SQL_SUCCEEDED(ret))
			{
				blen = (SQLINTEGER) utf8_to_ucs2(rgbV, blen, (SQLWCHAR *) rgbValue, cbValueMax / WCLEN);
				if (SQL_SUCCESS == ret && blen * WCLEN >= cbValueMax)
				{
					ret = SQL_SUCCESS_WITH_INFO;
					DC_set_error(hdesc, STMT_TRUNCATED, "The buffer was too small for the rgbDesc.");
				}
				if (pcbValue)
					*pcbValue = blen * WCLEN;
			}
			if (rgbV)
				free(rgbV);
			break;
		default:
			rgbV = rgbValue;
			bMax = cbValueMax;
			pcbV = pcbValue;
			ret = PGAPI_GetDescField(hdesc, iRecord, iField, rgbV, bMax, pcbV);
			break;
	}

	return ret;
}
示例#14
0
文件: win_io.c 项目: Youka/luajit-win
int _uremove(const char* filename){
	wchar_t* wfilename;
	int status;
	if(!(wfilename = utf8_to_ucs2(filename)))
		return 1;
	status = _wremove(wfilename);
	free(wfilename);
	return status;
}
示例#15
0
RETCODE SQL_API	SQLGetDiagRecW(SQLSMALLINT fHandleType,
		SQLHANDLE	handle,
		SQLSMALLINT	iRecord,
		SQLWCHAR	*szSqlState,
		SQLINTEGER	*pfNativeError,
		SQLWCHAR	*szErrorMsg,
		SQLSMALLINT	cbErrorMsgMax,
		SQLSMALLINT	*pcbErrorMsg)
{
	CSTR func = "SQLGetDiagRecW";
	RETCODE	ret;
        SQLSMALLINT	buflen, tlen;
        char    *qstr = NULL, *mtxt = NULL;

	mylog("[%s]", func);
        if (szSqlState)
                qstr = malloc(8);
	buflen = 0;
        if (szErrorMsg && cbErrorMsgMax > 0)
	{
		buflen = cbErrorMsgMax;
                mtxt = malloc(buflen);
	}
        ret = PGAPI_GetDiagRec(fHandleType, handle, iRecord, qstr,
                pfNativeError, mtxt, buflen, &tlen);
	if (SQL_SUCCEEDED(ret))
	{
        	if (qstr)
                	utf8_to_ucs2(qstr, strlen(qstr), szSqlState, 6);
		if (mtxt && tlen <= cbErrorMsgMax)
		{
        		tlen = (SQLSMALLINT) utf8_to_ucs2(mtxt, tlen, szErrorMsg, cbErrorMsgMax);
			if (tlen >= cbErrorMsgMax)
				ret = SQL_SUCCESS_WITH_INFO;
		}
		if (pcbErrorMsg)
        		*pcbErrorMsg = tlen;
	}
        if (qstr)
        	free(qstr);
	if (mtxt)
        	free(mtxt);
        return ret;
}
示例#16
0
/*
 *	ntpwdhash converts Unicode password to 16-byte NT hash
 *	with MD4
 */
void mschap_ntpwdhash (uint8_t *szHash, char const *szPassword)
{
    unsigned char unicodePass[512];
    size_t nPasswordLen;
    utf8_to_ucs2(szPassword, strlen(szPassword), unicodePass, sizeof(unicodePass), &nPasswordLen);

    /* Encrypt Unicode password to a 16-byte MD4 hash */
    nPasswordLen *= 2;
    fr_md4_calc(szHash, (uint8_t *) unicodePass, nPasswordLen);
}
示例#17
0
	static ConfigSetting WString(const char *option, Setter<wstring> setter, Getter<wstring> getter, const char *description = nullptr) {
		auto getterAdapter = [=] {
			return ucs2_to_utf8(getter());
		};
		auto setterAdapter = [=](string value) {
			setter(utf8_to_ucs2(value));
		};

		return ConfigSetting(option, setterAdapter, getterAdapter, description);
	}
示例#18
0
RETCODE  SQL_API
SQLGetCursorNameW(HSTMT StatementHandle,
				  SQLWCHAR *CursorName, SQLSMALLINT BufferLength,
				  SQLSMALLINT *NameLength)
{
	CSTR func = "SQLGetCursorNameW";
	RETCODE	ret;
	StatementClass * stmt = (StatementClass *) StatementHandle;
	char	*crName = NULL, *crNamet;
	SQLSMALLINT	clen, buflen;

	mylog("[%s]", func);
	if (BufferLength > 0)
		buflen = BufferLength * 3;
	else
		buflen = 32;
	crNamet = malloc(buflen);
	ENTER_STMT_CS(stmt);
	SC_clear_error(stmt);
	StartRollbackState(stmt);
	for (;; buflen = clen + 1, crNamet = realloc(crName, buflen))
	{
		if (!crNamet)
		{
			SC_set_error(stmt, STMT_NO_MEMORY_ERROR, "Could not allocate memory for cursor name", func);
			ret = SQL_ERROR;
			break;
		}
		crName = crNamet;
		ret = PGAPI_GetCursorName(StatementHandle, (SQLCHAR *) crName, buflen, &clen);
		if (SQL_SUCCESS_WITH_INFO != ret || clen < buflen)
			break;
	}
	if (SQL_SUCCEEDED(ret))
	{
		SQLLEN	nmcount = clen;

		if (clen < buflen)
			nmcount = utf8_to_ucs2(crName, clen, CursorName, BufferLength);
		if (SQL_SUCCESS == ret && nmcount > BufferLength)
		{
			ret = SQL_SUCCESS_WITH_INFO;
			SC_set_error(stmt, STMT_TRUNCATED, "Cursor name too large", func);
		}
		if (NameLength)
			*NameLength = (SQLSMALLINT) nmcount;
	}
	ret = DiscardStatementSvp(stmt, ret, FALSE);
	LEAVE_STMT_CS(stmt);
	free(crName);
	return ret;
}
示例#19
0
Iso9660DirectoryRecord *VIsoFile::findDirRecord(char *dirName, Iso9660DirectoryRecord *parentRecord, size_t size, bool joliet)
{
	uint8_t *strCheck = new uint8_t[256];
	uint8_t *buf, *p;
	uint32_t pos = 0;
	int strCheckSize;

	memset(strCheck, 0, 256);

	if (!joliet)
	{
		strncpy_upper((char *)strCheck, dirName, MAX_ISONAME-2);
		strCheckSize = strlen((const char *)strCheck);
	}
	else
	{
		strCheckSize = utf8_to_ucs2((const unsigned char *)dirName, (uint16_t *)strCheck, MAX_ISODIR/2) * 2;
	}

	buf = p = (uint8_t *)parentRecord;

	while ((p < (buf+size)))
	{
		Iso9660DirectoryRecord *current = (Iso9660DirectoryRecord *)p;

		if (current->len_dr == 0)
		{
			p += (0x800 - (pos&0x7ff));
			pos += (0x800 - (pos&0x7ff));
			if (p >= (buf+size))
				break;

			current = (Iso9660DirectoryRecord *)p;
			if (current->len_dr == 0)
				break;
		}

		if (current->len_fi == strCheckSize && memcmp(&current->fi, strCheck, strCheckSize) == 0)
		{
			delete[] strCheck;
			return current;
		}

		p += current->len_dr;
		pos += current->len_dr;
	}

	//printf("%s not found (joliet=%d)!!!!!!!\n", dirName, joliet);
	delete[] strCheck;
	return NULL;
}
示例#20
0
文件: ms_funcs.c 项目: Adrellias/mana
/**
 * nt_password_hash - NtPasswordHash() - RFC 2759, Sect. 8.3
 * @password: 0-to-256-unicode-char Password (IN; UTF-8)
 * @password_len: Length of password
 * @password_hash: 16-octet PasswordHash (OUT)
 * Returns: 0 on success, -1 on failure
 */
int nt_password_hash(const u8 *password, size_t password_len,
		      u8 *password_hash)
{
	u8 buf[512], *pos;
	size_t len, max_len;

	max_len = sizeof(buf);
	if (utf8_to_ucs2(password, password_len, buf, max_len, &len) < 0)
		return -1;

	len *= 2;
	pos = buf;
	return md4_vector(1, (const u8 **) &pos, &len, password_hash);
}
示例#21
0
svn_error_t *
svn_config__open_file(FILE **pfile,
                      const char *filename,
                      const char *mode,
                      apr_pool_t *pool)
{
  int style;
  apr_status_t apr_err = apr_filepath_encoding(&style, pool);

  if (apr_err)
    return svn_error_wrap_apr(apr_err,
                              "Can't determine the native path encoding");

  if (style == APR_FILEPATH_ENCODING_UTF8)
    {
      WCHAR *filename_ucs2;
      WCHAR *mode_ucs2;

      SVN_ERR(utf8_to_ucs2(&filename_ucs2, filename, pool));
      SVN_ERR(utf8_to_ucs2(&mode_ucs2, mode, pool));
      *pfile = _wfopen(filename_ucs2, mode_ucs2);
    }
  else if (style == APR_FILEPATH_ENCODING_LOCALE)
    {
      const char *filename_native;
      SVN_ERR(svn_utf_cstring_from_utf8(&filename_native, filename, pool));
      *pfile = fopen(filename_native, mode);
    }
  else
    {
      /* There is no third option on Windows; we should never get here. */
      return svn_error_createf(APR_EINVAL, NULL,
                               "Unknown native path encoding (%d)", style);
    }

  return SVN_NO_ERROR;
}
示例#22
0
void cOverworld_Manager :: Load_Dir( const std::string &dir, bool user_dir /* = 0 */ ) 
{
	// set world directory
// fixme : boost should use a codecvt_facet but for now we convert to UCS-2
#ifdef _WIN32
	fs::path full_path( utf8_to_ucs2( dir ) );
#else
	fs::path full_path( dir );
#endif
	fs::directory_iterator end_iter;

	for( fs::directory_iterator dir_itr( full_path ); dir_itr != end_iter; ++dir_itr )
	{
		try
		{
			std::string current_dir = dir_itr->path().filename().string();

			// only directories with an existing description
			if( fs::is_directory( *dir_itr ) && File_Exists( dir + "/" + current_dir + "/description.xml" ) )
			{
				cOverworld *overworld = Get_from_Path( current_dir );

				// already available
				if( overworld )
				{
					overworld->m_description->m_user = 2;
					continue;
				}

				overworld = new cOverworld();

				// set path
				overworld->m_description->m_path = current_dir;
				// default name is the path
				overworld->m_description->m_name = current_dir;
				// set user
				overworld->m_description->m_user = user_dir;

				objects.push_back( overworld );

				overworld->Load();
			}
		}
		catch( const std::exception &ex )
		{
			printf( "%s %s\n", dir_itr->path().filename().string().c_str(), ex.what() );
		}
	}
}
示例#23
0
efi_loadopt_create(uint8_t *buf, ssize_t size, uint32_t attributes,
		   efidp dp, ssize_t dp_size, unsigned char *description,
		   uint8_t *optional_data, size_t optional_data_size)
{
	if (!description) {
		errno = EINVAL;
		return -1;
	}

	ssize_t desc_len = utf8len((uint8_t *)description, 1024) * 2 + 2;
	ssize_t sz = sizeof (attributes)
		     + sizeof (uint16_t) + desc_len
		     + dp_size + optional_data_size;
	if (size == 0)
		return sz;
	if (size < sz) {
		errno = ENOSPC;
		return -1;
	}

	if (!optional_data && optional_data_size != 0) {
		errno = EINVAL;
		return -1;
	}

	if (!dp && dp_size == 0) {
		errno = EINVAL;
		return -1;
	}

	uint8_t *pos = buf;

	*(uint32_t *)pos = attributes;
	pos += sizeof (attributes);

	*(uint16_t *)pos = dp_size;
	pos += sizeof (uint16_t);

	utf8_to_ucs2((uint16_t *)pos, desc_len, 1, (uint8_t *)description);
	pos += desc_len;

	memcpy(pos, dp, dp_size);
	pos += dp_size;

	if (optional_data && optional_data_size > 0)
		memcpy(pos, optional_data, optional_data_size);

	return sz;
}
示例#24
0
TargetContainer
to_ucs2(
	utf8::char_type const * begin,
	utf8::char_type const * end )
{
	TargetContainer container;

	utf8_to_ucs2(
		begin,
		end,
		std::back_inserter(
			container ));

	return std::move( container );
}
示例#25
0
文件: dp-media.c 项目: 10ne1/efivar
efidp_make_file(uint8_t *buf, ssize_t size, char *filepath)
{
	efidp_file *file = (efidp_file *)buf;
	unsigned char *lf = (unsigned char *)filepath;
	ssize_t sz;
	ssize_t len = utf8len(lf, -1) + 1;
	ssize_t req = sizeof (*file) + len * sizeof (uint16_t);
	sz = efidp_make_generic(buf, size, EFIDP_MEDIA_TYPE, EFIDP_MEDIA_FILE,
				req);
	if (size && sz == req) {
		memset(buf+4, 0, req-4);
		utf8_to_ucs2(file->name, req-4, 1, lf);
	}
	return sz;
}
示例#26
0
文件: tfile.c 项目: graphis/libk
static void trollback_one(struct tfile_t* tf, size_t off)
{
	close(tf->fd);
	#ifdef __WINNT__
	wchar_t* wtf = utf8_to_ucs2(tf->tmpfilename);
	if (wtf) {
		_wunlink(wtf);
		free(wtf);
	}
	#else
	unlink(tf->tmpfilename);
	#endif
	free(tf->filename);
	free(tf->tmpfilename);
	pool_cut(&mappool, off, sizeof(struct tfile_t));
}
示例#27
0
文件: tfile.c 项目: graphis/libk
__export_function int k_tcreat(const char* name, mode_t mode)
{
	int res = -1;
	mode_t old_umask;
	size_t namelen;
	struct tfile_t tf;

	if (!tfile_init && __init())
		return -1;

	memset(&tf, 0, sizeof(struct tfile_t));
	tf.fd = -1;
	tf.mode = mode;
	old_umask = umask(077);

	namelen = strlen(name);
	if (!namelen) {
		errno = EINVAL;
		goto err;
	}

	tf.filename = absfilename(name);
	if (!tf.filename)
		goto err;

	/* check if name is valid and if we have read-write permissions in
	 * the case the file exists. ENOENT is not fatal, since we're about
	 * to create the file anyway. */
	#ifdef __WINNT__
	int fd;
	wchar_t* wc = utf8_to_ucs2(tf.filename);
	if (!wc)
		fd = -1;
	else {
		fd = _wopen(wc, O_RDWR);
		free(wc);
	}
	#else
	int fd = open(tf.filename, O_RDWR|O_NOATIME);
	#endif
	if (fd == -1 && errno != ENOENT)
		goto err;
	if (fd != -1)
		if (close(fd))
			goto err;

	tf.tmpfilename = calloc(strlen(tf.filename)+strlen(template)+2, 1);
示例#28
0
bool cLayer :: Save( const std::string &filename )
{
// fixme : Check if there is a more portable way f.e. with imbue()
#ifdef _WIN32
	ofstream file( utf8_to_ucs2( filename ).c_str(), ios::out | ios::trunc );
#else
	ofstream file( filename.c_str(), ios::out | ios::trunc );
#endif


	if( !file )
	{
		pHud_Debug->Set_Text( _("Couldn't save world layer ") + filename );
		return 0;
	}

	CEGUI::XMLSerializer stream( file );

	// begin layer
	stream.openTag( "layer" );

	// lines
	for( LayerLineList::iterator itr = objects.begin(); itr != objects.end(); ++itr )
	{
		cLayer_Line_Point_Start *line = (*itr);

		// begin
		stream.openTag( "line" );
			// start
			Write_Property( stream, "X1", static_cast<int>(line->Get_Line_Pos_X()) );
			Write_Property( stream, "Y1", static_cast<int>(line->Get_Line_Pos_Y()) );
			// end
			Write_Property( stream, "X2", static_cast<int>(line->m_linked_point->Get_Line_Pos_X()) );
			Write_Property( stream, "Y2", static_cast<int>(line->m_linked_point->Get_Line_Pos_Y()) );
			// origin
			Write_Property( stream, "origin", line->m_origin );
		// end line
		stream.closeTag();
	}

	// end layer
	stream.closeTag();

	file.close();

	return 1;
}
示例#29
0
RETCODE SQL_API
SQLBrowseConnectW(HDBC			hdbc,
				  SQLWCHAR	   *szConnStrIn,
				  SQLSMALLINT	cbConnStrIn,
				  SQLWCHAR	   *szConnStrOut,
				  SQLSMALLINT	cbConnStrOutMax,
				  SQLSMALLINT  *pcbConnStrOut)
{
	CSTR func = "SQLBrowseConnectW";
	char	*szIn, *szOut;
	SQLLEN		inlen;
	SQLUSMALLINT	obuflen;
	SQLSMALLINT	olen;
	RETCODE	ret;
	ConnectionClass *conn = (ConnectionClass *) hdbc;

	mylog("[%s]", func);
	CC_examine_global_transaction(conn);
	ENTER_CONN_CS(conn);
	CC_clear_error(conn);
	CC_set_in_unicode_driver(conn);
	szIn = ucs2_to_utf8(szConnStrIn, cbConnStrIn, &inlen, FALSE);
	obuflen = cbConnStrOutMax + 1;
	szOut = malloc(obuflen);
	if (szOut)
		ret = PGAPI_BrowseConnect(hdbc, (SQLCHAR *) szIn, (SQLSMALLINT) inlen,
								  (SQLCHAR *) szOut, cbConnStrOutMax, &olen);
	else
	{
		CC_set_error(conn, CONN_NO_MEMORY_ERROR, "Could not allocate memory for output buffer", func);
		ret = SQL_ERROR;
	}
	LEAVE_CONN_CS(conn);
	if (ret != SQL_ERROR)
	{
		SQLLEN	outlen = utf8_to_ucs2(szOut, olen, szConnStrOut, cbConnStrOutMax);
		if (pcbConnStrOut)
			*pcbConnStrOut = (SQLSMALLINT) outlen;
	}
	free(szOut);
	if (szIn)
		free(szIn);
	return ret;
}
示例#30
0
efi_loadopt_args_as_ucs2(uint16_t *buf, ssize_t size, uint8_t *utf8)
{
	ssize_t req;
	if (!utf8 || (!buf && size > 0)) {
		errno = EINVAL;
		return -1;
	}

	req = utf8len(utf8, -1) * sizeof(uint16_t);
	if (size == 0)
		return req;

	if (size < req) {
		errno = ENOSPC;
		return -1;
	}

	return utf8_to_ucs2(buf, size, 0, utf8);
}