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) 2012 Blender Foundation.
19 * All rights reserved.
21 * Contributor(s): Alexandr Kuznetsov, Andrea Weikert
23 * ***** END GPL LICENSE BLOCK *****
27 #define _WIN32_IE 0x0501
30 #include "utf_winfunc.h"
36 FILE * ufopen(const char * filename, const char * mode)
39 UTF16_ENCODE(filename);
42 if(filename_16 && mode_16) {
43 f = _wfopen(filename_16, mode_16);
46 UTF16_UN_ENCODE(mode);
47 UTF16_UN_ENCODE(filename);
50 if ((f = fopen(filename, mode))) {
51 printf("WARNING: %s is not utf path. Please update it.\n",filename);
58 int uopen(const char *filename, int oflag, int pmode)
61 UTF16_ENCODE(filename);
64 f = _wopen(filename_16, oflag, pmode);
67 UTF16_UN_ENCODE(filename);
70 if ((f=open(filename,oflag, pmode)) != -1) {
71 printf("WARNING: %s is not utf path. Please update it.\n",filename);
78 int urename(const char *oldname, const char *newname )
81 UTF16_ENCODE(oldname);
82 UTF16_ENCODE (newname);
84 if(oldname_16 && newname_16) r = _wrename(oldname_16, newname_16);
86 UTF16_UN_ENCODE(newname);
87 UTF16_UN_ENCODE(oldname);
91 int umkdir(const char *pathname)
95 UTF16_ENCODE(pathname);
97 if(pathname_16) r = CreateDirectoryW(pathname_16, NULL);
99 UTF16_UN_ENCODE(pathname);
104 char * u_alloc_getenv(const char *varname)
108 UTF16_ENCODE(varname);
110 str = _wgetenv(varname_16);
111 r = alloc_utf_8_from_16(str, 0);
113 UTF16_UN_ENCODE(varname);
117 void u_free_getenv(char *val)
122 int uput_getenv(const char *varname, char * value, size_t buffsize)
126 if(!buffsize) return r;
128 UTF16_ENCODE(varname);
130 str = _wgetenv(varname_16);
131 conv_utf_16_to_8(str, value, buffsize);
134 UTF16_UN_ENCODE(varname);
136 if (!r) value[0] = 0;
141 int uputenv(const char *name, const char *value)
146 if(name_16 && value_16) {
147 r = (SetEnvironmentVariableW(name_16,value_16)!= 0) ? 0 : -1;
149 UTF16_UN_ENCODE(value);
150 UTF16_UN_ENCODE(name);