2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2009 Blender Foundation.
19 * All rights reserved.
21 * Contributor(s): Alexandr Kuznetsov, Andrea Weikert
23 * ***** END GPL LICENSE BLOCK *****
29 #define _WIN32_IE 0x0501
32 #include "utf_winfunc.h"
38 FILE * ufopen(const char * filename, const char * mode)
41 UTF16_ENCODE(filename);
44 if(filename_16 && mode_16) {
45 f = _wfopen(filename_16, mode_16);
48 UTF16_UN_ENCODE(mode);
49 UTF16_UN_ENCODE(filename);
52 if ((f = fopen(filename, mode))) {
53 printf("WARNING: %s is not utf path. Please update it.\n",filename);
60 int uopen(const char *filename, int oflag, int pmode)
63 UTF16_ENCODE(filename);
66 f = _wopen(filename_16, oflag, pmode);
69 UTF16_UN_ENCODE(filename);
72 if ((f=open(filename,oflag, pmode)) != -1) {
73 printf("WARNING: %s is not utf path. Please update it.\n",filename);
80 int urename(const char *oldname, const char *newname )
83 UTF16_ENCODE(oldname);
84 UTF16_ENCODE (newname);
86 if(oldname_16 && newname_16) r = _wrename(oldname_16, newname_16);
88 UTF16_UN_ENCODE(newname);
89 UTF16_UN_ENCODE(oldname);
93 int umkdir(const char *pathname)
97 UTF16_ENCODE(pathname);
99 if(pathname_16) r = CreateDirectoryW(pathname_16, NULL);
101 UTF16_UN_ENCODE(pathname);
106 char * u_alloc_getenv(const char *varname)
110 UTF16_ENCODE(varname);
112 str = _wgetenv(varname_16);
113 r = alloc_utf_8_from_16(str, 0);
115 UTF16_UN_ENCODE(varname);
119 void u_free_getenv(char *val)
124 int uput_getenv(const char *varname, char * value, size_t buffsize)
128 if(!buffsize) return r;
130 UTF16_ENCODE(varname);
132 str = _wgetenv(varname_16);
133 conv_utf_16_to_8(str, value, buffsize);
136 UTF16_UN_ENCODE(varname);
138 if (!r) value[0] = 0;
143 int uputenv(const char *name, const char *value)
148 if(name_16 && value_16) {
149 r = (SetEnvironmentVariableW(name_16,value_16)!= 0) ? 0 : -1;
151 UTF16_UN_ENCODE(value);
152 UTF16_UN_ENCODE(name);