Blender  V2.93
utf_winfunc.c
Go to the documentation of this file.
1 /*
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.
6  *
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.
11  *
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.
15  *
16  * The Original Code is Copyright (C) 2012 Blender Foundation.
17  * All rights reserved.
18  */
19 
20 #ifndef _WIN32_IE
21 # define _WIN32_IE 0x0501
22 #endif
23 
24 #include "utf_winfunc.h"
25 #include "utfconv.h"
26 #include <io.h>
27 #include <wchar.h>
28 #include <windows.h>
29 
30 FILE *ufopen(const char *filename, const char *mode)
31 {
32  FILE *f = NULL;
33  UTF16_ENCODE(filename);
34  UTF16_ENCODE(mode);
35 
36  if (filename_16 && mode_16) {
37  f = _wfopen(filename_16, mode_16);
38  }
39 
40  UTF16_UN_ENCODE(mode);
41  UTF16_UN_ENCODE(filename);
42 
43  if (!f) {
44  if ((f = fopen(filename, mode))) {
45  printf("WARNING: %s is not utf path. Please update it.\n", filename);
46  }
47  }
48 
49  return f;
50 }
51 
52 int uopen(const char *filename, int oflag, int pmode)
53 {
54  int f = -1;
55  UTF16_ENCODE(filename);
56 
57  if (filename_16) {
58  f = _wopen(filename_16, oflag, pmode);
59  }
60 
61  UTF16_UN_ENCODE(filename);
62 
63  if (f == -1) {
64  if ((f = open(filename, oflag, pmode)) != -1) {
65  printf("WARNING: %s is not utf path. Please update it.\n", filename);
66  }
67  }
68 
69  return f;
70 }
71 
72 int uaccess(const char *filename, int mode)
73 {
74  int r = -1;
75  UTF16_ENCODE(filename);
76 
77  if (filename_16) {
78  r = _waccess(filename_16, mode);
79  }
80 
81  UTF16_UN_ENCODE(filename);
82 
83  return r;
84 }
85 
86 int urename(const char *oldname, const char *newname)
87 {
88  int r = -1;
89  UTF16_ENCODE(oldname);
90  UTF16_ENCODE(newname);
91 
92  if (oldname_16 && newname_16) {
93  r = _wrename(oldname_16, newname_16);
94  }
95 
96  UTF16_UN_ENCODE(newname);
97  UTF16_UN_ENCODE(oldname);
98  return r;
99 }
100 
101 int umkdir(const char *pathname)
102 {
103 
104  BOOL r = 0;
105  UTF16_ENCODE(pathname);
106 
107  if (pathname_16) {
108  r = CreateDirectoryW(pathname_16, NULL);
109  }
110 
111  UTF16_UN_ENCODE(pathname);
112 
113  return r ? 0 : -1;
114 }
115 
116 char *u_alloc_getenv(const char *varname)
117 {
118  char *r = 0;
119  wchar_t *str;
120  UTF16_ENCODE(varname);
121  if (varname_16) {
122  str = _wgetenv(varname_16);
123  r = alloc_utf_8_from_16(str, 0);
124  }
125  UTF16_UN_ENCODE(varname);
126 
127  return r;
128 }
129 void u_free_getenv(char *val)
130 {
131  free(val);
132 }
133 
134 int uput_getenv(const char *varname, char *value, size_t buffsize)
135 {
136  int r = 0;
137  wchar_t *str;
138 
139  if (!buffsize) {
140  return r;
141  }
142 
143  UTF16_ENCODE(varname);
144  if (varname_16) {
145  str = _wgetenv(varname_16);
146  conv_utf_16_to_8(str, value, buffsize);
147  r = 1;
148  }
149  UTF16_UN_ENCODE(varname);
150 
151  if (!r) {
152  value[0] = 0;
153  }
154 
155  return r;
156 }
157 
158 int uputenv(const char *name, const char *value)
159 {
160  int r = -1;
161  UTF16_ENCODE(name);
162 
163  if (value) {
164  /* set */
165  UTF16_ENCODE(value);
166 
167  if (name_16 && value_16) {
168  r = (SetEnvironmentVariableW(name_16, value_16) != 0) ? 0 : -1;
169  }
170  UTF16_UN_ENCODE(value);
171  }
172  else {
173  /* clear */
174  if (name_16) {
175  r = (SetEnvironmentVariableW(name_16, NULL) != 0) ? 0 : -1;
176  }
177  }
178 
179  UTF16_UN_ENCODE(name);
180 
181  return r;
182 }
void BLI_kdtree_nd_() free(KDTree *tree)
Definition: kdtree_impl.h:116
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
ATTR_WARN_UNUSED_RESULT const BMFlagLayer const short oflag
#define str(s)
int uput_getenv(const char *varname, char *value, size_t buffsize)
Definition: utf_winfunc.c:134
int uputenv(const char *name, const char *value)
Definition: utf_winfunc.c:158
int umkdir(const char *pathname)
Definition: utf_winfunc.c:101
void u_free_getenv(char *val)
Definition: utf_winfunc.c:129
FILE * ufopen(const char *filename, const char *mode)
Definition: utf_winfunc.c:30
int uopen(const char *filename, int oflag, int pmode)
Definition: utf_winfunc.c:52
int uaccess(const char *filename, int mode)
Definition: utf_winfunc.c:72
int urename(const char *oldname, const char *newname)
Definition: utf_winfunc.c:86
char * u_alloc_getenv(const char *varname)
Definition: utf_winfunc.c:116
char * alloc_utf_8_from_16(const wchar_t *in16, size_t add)
Definition: utfconv.c:285
int conv_utf_16_to_8(const wchar_t *in16, char *out8, size_t size8)
Definition: utfconv.c:127
#define UTF16_ENCODE(in8str)
Definition: utfconv.h:96
#define UTF16_UN_ENCODE(in8str)
Definition: utfconv.h:100