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) f = _wfopen(filename_16, mode_16);
46 UTF16_UN_ENCODE(mode);
47 UTF16_UN_ENCODE(filename);
51 if(f=fopen(filename,mode))
52 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);
63 if(filename_16) f = _wopen(filename_16, oflag, pmode);
65 UTF16_UN_ENCODE(filename);
69 if((f=open(filename,oflag, pmode))!=-1)
70 printf("WARNING: %s is not utf path. Please update it.\n",filename);
76 int urename(const char *oldname, const char *newname )
79 UTF16_ENCODE(oldname);
80 UTF16_ENCODE (newname);
82 if(oldname_16 && newname_16) r = _wrename(oldname_16, newname_16);
84 UTF16_UN_ENCODE(newname);
85 UTF16_UN_ENCODE(oldname);
89 int umkdir(const char *pathname)
93 UTF16_ENCODE(pathname);
95 if(pathname_16) r = CreateDirectoryW(pathname_16, NULL);
97 UTF16_UN_ENCODE(pathname);
102 char * u_alloc_getenv(const char *varname)
106 UTF16_ENCODE(varname);
107 if(varname_16){ str = _wgetenv(varname_16);
108 r = alloc_utf_8_from_16(str,0);}
109 UTF16_UN_ENCODE(varname);
113 void u_free_getenv(char *val)
118 int uput_getenv(const char *varname, char * value, size_t buffsize)
122 if(!buffsize) return r;
124 UTF16_ENCODE(varname);
127 str = _wgetenv(varname_16);
128 conv_utf_16_to_8(str, value, buffsize);
131 UTF16_UN_ENCODE(varname);
140 int uputenv(const char *name, const char *value)
145 if(name_16 && value_16) {
146 if(SetEnvironmentVariableW(name_16,value_16)!=0)
150 UTF16_UN_ENCODE(value)
151 UTF16_UN_ENCODE(name)