2012-03-20 02:17:37 +00:00
|
|
|
/*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2012-04-12 02:15:33 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2012-03-20 02:17:37 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
2012-04-12 02:37:28 +00:00
|
|
|
* The Original Code is Copyright (C) 2012 Blender Foundation.
|
2012-03-20 02:17:37 +00:00
|
|
|
* All rights reserved.
|
2012-04-12 02:15:33 +00:00
|
|
|
*
|
2012-03-20 02:17:37 +00:00
|
|
|
* Contributor(s): Alexandr Kuznetsov, Andrea Weikert
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _WIN32_IE
|
|
|
|
#define _WIN32_IE 0x0501
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "utf_winfunc.h"
|
|
|
|
#include <io.h>
|
|
|
|
#include <Windows.h>
|
|
|
|
#include <wchar.h>
|
|
|
|
|
|
|
|
|
|
|
|
FILE * ufopen(const char * filename, const char * mode)
|
|
|
|
{
|
2012-04-12 02:15:33 +00:00
|
|
|
FILE *f = NULL;
|
2012-03-20 02:17:37 +00:00
|
|
|
UTF16_ENCODE(filename);
|
|
|
|
UTF16_ENCODE (mode);
|
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
if (filename_16 && mode_16) {
|
2012-04-12 02:15:33 +00:00
|
|
|
f = _wfopen(filename_16, mode_16);
|
|
|
|
}
|
2012-03-20 02:17:37 +00:00
|
|
|
|
|
|
|
UTF16_UN_ENCODE(mode);
|
|
|
|
UTF16_UN_ENCODE(filename);
|
|
|
|
|
2012-04-12 02:15:33 +00:00
|
|
|
if (!f) {
|
|
|
|
if ((f = fopen(filename, mode))) {
|
2012-03-20 02:17:37 +00:00
|
|
|
printf("WARNING: %s is not utf path. Please update it.\n",filename);
|
2012-04-12 02:15:33 +00:00
|
|
|
}
|
2012-03-20 02:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
int uopen(const char *filename, int oflag, int pmode)
|
|
|
|
{
|
|
|
|
int f = -1;
|
|
|
|
UTF16_ENCODE(filename);
|
|
|
|
|
2012-04-12 02:15:33 +00:00
|
|
|
if (filename_16) {
|
|
|
|
f = _wopen(filename_16, oflag, pmode);
|
|
|
|
}
|
2012-03-20 02:17:37 +00:00
|
|
|
|
|
|
|
UTF16_UN_ENCODE(filename);
|
|
|
|
|
2012-04-12 02:15:33 +00:00
|
|
|
if (f == -1) {
|
|
|
|
if ((f=open(filename,oflag, pmode)) != -1) {
|
2012-03-20 02:17:37 +00:00
|
|
|
printf("WARNING: %s is not utf path. Please update it.\n",filename);
|
2012-04-12 02:15:33 +00:00
|
|
|
}
|
2012-03-20 02:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
int urename(const char *oldname, const char *newname )
|
|
|
|
{
|
|
|
|
int r = -1;
|
|
|
|
UTF16_ENCODE(oldname);
|
|
|
|
UTF16_ENCODE (newname);
|
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
if (oldname_16 && newname_16) r = _wrename(oldname_16, newname_16);
|
2012-03-20 02:17:37 +00:00
|
|
|
|
|
|
|
UTF16_UN_ENCODE(newname);
|
|
|
|
UTF16_UN_ENCODE(oldname);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
int umkdir(const char *pathname)
|
|
|
|
{
|
|
|
|
|
|
|
|
BOOL r = 0;
|
|
|
|
UTF16_ENCODE(pathname);
|
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
if (pathname_16) r = CreateDirectoryW(pathname_16, NULL);
|
2012-03-20 02:17:37 +00:00
|
|
|
|
|
|
|
UTF16_UN_ENCODE(pathname);
|
|
|
|
|
2012-04-12 02:15:33 +00:00
|
|
|
return r ? 0 : -1;
|
2012-03-20 02:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char * u_alloc_getenv(const char *varname)
|
|
|
|
{
|
|
|
|
char * r = 0;
|
|
|
|
wchar_t * str;
|
|
|
|
UTF16_ENCODE(varname);
|
2012-04-12 02:15:33 +00:00
|
|
|
if (varname_16) {
|
|
|
|
str = _wgetenv(varname_16);
|
|
|
|
r = alloc_utf_8_from_16(str, 0);
|
|
|
|
}
|
2012-03-20 02:17:37 +00:00
|
|
|
UTF16_UN_ENCODE(varname);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
void u_free_getenv(char *val)
|
|
|
|
{
|
|
|
|
free(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
int uput_getenv(const char *varname, char * value, size_t buffsize)
|
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
wchar_t * str;
|
2012-04-28 06:31:57 +00:00
|
|
|
if (!buffsize) return r;
|
2012-03-20 02:17:37 +00:00
|
|
|
|
|
|
|
UTF16_ENCODE(varname);
|
2012-04-28 06:31:57 +00:00
|
|
|
if (varname_16) {
|
2012-04-12 02:15:33 +00:00
|
|
|
str = _wgetenv(varname_16);
|
|
|
|
conv_utf_16_to_8(str, value, buffsize);
|
|
|
|
r = 1;
|
|
|
|
}
|
2012-03-20 02:17:37 +00:00
|
|
|
UTF16_UN_ENCODE(varname);
|
|
|
|
|
2012-04-12 02:15:33 +00:00
|
|
|
if (!r) value[0] = 0;
|
2012-03-20 02:17:37 +00:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
int uputenv(const char *name, const char *value)
|
|
|
|
{
|
|
|
|
int r = -1;
|
2012-04-12 02:15:33 +00:00
|
|
|
UTF16_ENCODE(name);
|
|
|
|
UTF16_ENCODE(value);
|
2012-04-28 06:31:57 +00:00
|
|
|
if (name_16 && value_16) {
|
2012-04-12 02:15:33 +00:00
|
|
|
r = (SetEnvironmentVariableW(name_16,value_16)!= 0) ? 0 : -1;
|
2012-03-20 02:17:37 +00:00
|
|
|
}
|
2012-04-12 02:15:33 +00:00
|
|
|
UTF16_UN_ENCODE(value);
|
|
|
|
UTF16_UN_ENCODE(name);
|
2012-03-20 02:17:37 +00:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|