Blender  V3.3
utf_winfunc.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2012 Blender Foundation. All rights reserved. */
3 
8 #ifndef _WIN32_IE
9 # define _WIN32_IE 0x0501
10 #endif
11 
12 #include "utf_winfunc.h"
13 #include "utfconv.h"
14 #include <io.h>
15 #include <wchar.h>
16 #include <windows.h>
17 
18 FILE *ufopen(const char *filename, const char *mode)
19 {
20  FILE *f = NULL;
21  UTF16_ENCODE(filename);
22  UTF16_ENCODE(mode);
23 
24  if (filename_16 && mode_16) {
25  f = _wfopen(filename_16, mode_16);
26  }
27 
28  UTF16_UN_ENCODE(mode);
29  UTF16_UN_ENCODE(filename);
30 
31  if (!f) {
32  if ((f = fopen(filename, mode))) {
33  printf("WARNING: %s is not utf path. Please update it.\n", filename);
34  }
35  }
36 
37  return f;
38 }
39 
40 int uopen(const char *filename, int oflag, int pmode)
41 {
42  int f = -1;
43  UTF16_ENCODE(filename);
44 
45  if (filename_16) {
46  f = _wopen(filename_16, oflag, pmode);
47  }
48 
49  UTF16_UN_ENCODE(filename);
50 
51  if (f == -1) {
52  if ((f = open(filename, oflag, pmode)) != -1) {
53  printf("WARNING: %s is not utf path. Please update it.\n", filename);
54  }
55  }
56 
57  return f;
58 }
59 
60 int uaccess(const char *filename, int mode)
61 {
62  int r = -1;
63  UTF16_ENCODE(filename);
64 
65  if (filename_16) {
66  r = _waccess(filename_16, mode);
67  }
68 
69  UTF16_UN_ENCODE(filename);
70 
71  return r;
72 }
73 
74 int urename(const char *oldname, const char *newname)
75 {
76  int r = -1;
77  UTF16_ENCODE(oldname);
78  UTF16_ENCODE(newname);
79 
80  if (oldname_16 && newname_16) {
81  r = _wrename(oldname_16, newname_16);
82  }
83 
84  UTF16_UN_ENCODE(newname);
85  UTF16_UN_ENCODE(oldname);
86  return r;
87 }
88 
89 int umkdir(const char *pathname)
90 {
91 
92  BOOL r = 0;
93  UTF16_ENCODE(pathname);
94 
95  if (pathname_16) {
96  r = CreateDirectoryW(pathname_16, NULL);
97  }
98 
99  UTF16_UN_ENCODE(pathname);
100 
101  return r ? 0 : -1;
102 }
103 
104 char *u_alloc_getenv(const char *varname)
105 {
106  char *r = 0;
107  wchar_t *str;
109  if (varname_16) {
110  str = _wgetenv(varname_16);
111  r = alloc_utf_8_from_16(str, 0);
112  }
114 
115  return r;
116 }
117 void u_free_getenv(char *val)
118 {
119  free(val);
120 }
121 
122 int uput_getenv(const char *varname, char *value, size_t buffsize)
123 {
124  int r = 0;
125  wchar_t *str;
126 
127  if (!buffsize) {
128  return r;
129  }
130 
132  if (varname_16) {
133  str = _wgetenv(varname_16);
134  conv_utf_16_to_8(str, value, buffsize);
135  r = 1;
136  }
138 
139  if (!r) {
140  value[0] = 0;
141  }
142 
143  return r;
144 }
145 
146 int uputenv(const char *name, const char *value)
147 {
148  int r = -1;
149  UTF16_ENCODE(name);
150 
151  if (value) {
152  /* set */
153  UTF16_ENCODE(value);
154 
155  if (name_16 && value_16) {
156  r = (SetEnvironmentVariableW(name_16, value_16) != 0) ? 0 : -1;
157  }
158  UTF16_UN_ENCODE(value);
159  }
160  else {
161  /* clear */
162  if (name_16) {
163  r = (SetEnvironmentVariableW(name_16, NULL) != 0) ? 0 : -1;
164  }
165  }
166 
167  UTF16_UN_ENCODE(name);
168 
169  return r;
170 }
void BLI_kdtree_nd_() free(KDTree *tree)
Definition: kdtree_impl.h:102
_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)
static const pxr::TfToken varname("varname", pxr::TfToken::Immortal)
int uput_getenv(const char *varname, char *value, size_t buffsize)
Definition: utf_winfunc.c:122
int uputenv(const char *name, const char *value)
Definition: utf_winfunc.c:146
int umkdir(const char *pathname)
Definition: utf_winfunc.c:89
void u_free_getenv(char *val)
Definition: utf_winfunc.c:117
FILE * ufopen(const char *filename, const char *mode)
Definition: utf_winfunc.c:18
int uopen(const char *filename, int oflag, int pmode)
Definition: utf_winfunc.c:40
int uaccess(const char *filename, int mode)
Definition: utf_winfunc.c:60
int urename(const char *oldname, const char *newname)
Definition: utf_winfunc.c:74
char * u_alloc_getenv(const char *varname)
Definition: utf_winfunc.c:104
char * alloc_utf_8_from_16(const wchar_t *in16, size_t add)
Definition: utfconv.c:279
int conv_utf_16_to_8(const wchar_t *in16, char *out8, size_t size8)
Definition: utfconv.c:115
#define UTF16_ENCODE(in8str)
Definition: utfconv.h:83
#define UTF16_UN_ENCODE(in8str)
Definition: utfconv.h:87