2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version 2
5 * of the License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software Foundation,
14 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * The Original Code is Copyright (C) 2012 Blender Foundation.
17 * All rights reserved.
21 #define _WIN32_IE 0x0501
24 #include "utf_winfunc.h"
31 FILE *ufopen(const char *filename, const char *mode)
34 UTF16_ENCODE(filename);
37 if (filename_16 && mode_16) {
38 f = _wfopen(filename_16, mode_16);
41 UTF16_UN_ENCODE(mode);
42 UTF16_UN_ENCODE(filename);
45 if ((f = fopen(filename, mode))) {
46 printf("WARNING: %s is not utf path. Please update it.\n",filename);
53 int uopen(const char *filename, int oflag, int pmode)
56 UTF16_ENCODE(filename);
59 f = _wopen(filename_16, oflag, pmode);
62 UTF16_UN_ENCODE(filename);
65 if ((f = open(filename,oflag, pmode)) != -1) {
66 printf("WARNING: %s is not utf path. Please update it.\n",filename);
73 int uaccess(const char *filename, int mode)
76 UTF16_ENCODE(filename);
79 r = _waccess(filename_16, mode);
82 UTF16_UN_ENCODE(filename);
87 int urename(const char *oldname, const char *newname )
90 UTF16_ENCODE(oldname);
91 UTF16_ENCODE(newname);
93 if (oldname_16 && newname_16) {
94 r = _wrename(oldname_16, newname_16);
97 UTF16_UN_ENCODE(newname);
98 UTF16_UN_ENCODE(oldname);
102 int umkdir(const char *pathname)
106 UTF16_ENCODE(pathname);
109 r = CreateDirectoryW(pathname_16, NULL);
112 UTF16_UN_ENCODE(pathname);
117 char *u_alloc_getenv(const char *varname)
121 UTF16_ENCODE(varname);
123 str = _wgetenv(varname_16);
124 r = alloc_utf_8_from_16(str, 0);
126 UTF16_UN_ENCODE(varname);
130 void u_free_getenv(char *val)
135 int uput_getenv(const char *varname, char *value, size_t buffsize)
144 UTF16_ENCODE(varname);
146 str = _wgetenv(varname_16);
147 conv_utf_16_to_8(str, value, buffsize);
150 UTF16_UN_ENCODE(varname);
159 int uputenv(const char *name, const char *value)
168 if (name_16 && value_16) {
169 r = (SetEnvironmentVariableW(name_16,value_16)!= 0) ? 0 : -1;
171 UTF16_UN_ENCODE(value);
176 r = (SetEnvironmentVariableW(name_16,NULL)!= 0) ? 0 : -1;
180 UTF16_UN_ENCODE(name);