ReactOS 0.4.16-dev-927-g467dec4
file.c File Reference
#include <errno.h>
#include <direct.h>
#include <stdarg.h>
#include <locale.h>
#include <process.h>
#include <share.h>
#include <sys/stat.h>
#include <windef.h>
#include <winbase.h>
#include <winnls.h>
#include "wine/test.h"
#include <corecrt_io.h>
Include dependency graph for file.c:

Go to the source code of this file.

Macros

#define STDIN_FILENO   0
 
#define STDOUT_FILENO   1
 
#define STDERR_FILENO   2
 

Functions

static void test_std_stream_buffering (void)
 
int CDECL _get_stream_buffer_pointers (FILE *, char ***, char ***, int **)
 
static void test_iobuf_layout (void)
 
static void test_std_stream_open (void)
 
static void test_fopen (void)
 
static void test_utf8 (const char *argv0)
 
static void test_utf8_argument (void)
 
 START_TEST (file)
 

Macro Definition Documentation

◆ STDERR_FILENO

#define STDERR_FILENO   2

Definition at line 37 of file file.c.

◆ STDIN_FILENO

#define STDIN_FILENO   0

Definition at line 35 of file file.c.

◆ STDOUT_FILENO

#define STDOUT_FILENO   1

Definition at line 36 of file file.c.

Function Documentation

◆ _get_stream_buffer_pointers()

int CDECL _get_stream_buffer_pointers ( FILE public_stream,
char ***  base,
char ***  ptr,
int **  count 
)

Definition at line 153 of file _file.cpp.

159{
160 _VALIDATE_RETURN_ERRCODE(public_stream != nullptr, EINVAL);
161
162 __crt_stdio_stream const stream(public_stream);
163 if (base)
164 {
165 *base = &stream->_base;
166 }
167
168 if (ptr)
169 {
170 *ptr = &stream->_ptr;
171 }
172
173 if (count)
174 {
175 *count = &stream->_cnt;
176 }
177
178 return 0;
179}
#define EINVAL
Definition: acclib.h:90
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define _VALIDATE_RETURN_ERRCODE(expr, errorcode)
static PVOID ptr
Definition: dispmode.c:27
Definition: parse.h:23

Referenced by test_iobuf_layout().

◆ START_TEST()

START_TEST ( file  )

Definition at line 460 of file file.c.

461{
462 int arg_c;
463 char** arg_v;
464
465 arg_c = winetest_get_mainargs(&arg_v);
466 if(arg_c == 4 && !strcmp(arg_v[2], "utf8"))
467 {
469 return;
470 }
471
475 test_fopen();
476 test_utf8(arg_v[0]);
477}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
static void test_std_stream_buffering(void)
Definition: file.c:3074
static void test_std_stream_open(void)
Definition: file.c:3132
static void test_fopen(void)
Definition: file.c:181
static void test_utf8_argument(void)
Definition: file.c:441
static void test_utf8(const char *argv0)
Definition: file.c:226
static void test_iobuf_layout(void)
Definition: file.c:101
int winetest_get_mainargs(char ***pargv)

◆ test_fopen()

static void test_fopen ( void  )
static

Definition at line 181 of file file.c.

182{
183 int i;
184 FILE *f;
185 wchar_t wpath[MAX_PATH];
186 static const struct {
187 const char *loc;
188 const char *path;
189 } tests[] = {
190 { "German.utf8", "t\xc3\xa4\xc3\x8f\xc3\xb6\xc3\x9f.txt" },
191 { "Polish.utf8", "t\xc4\x99\xc5\x9b\xc4\x87.txt" },
192 { "Turkish.utf8", "t\xc3\x87\xc4\x9e\xc4\xb1\xc4\xb0\xc5\x9e.txt" },
193 { "Arabic.utf8", "t\xd8\xaa\xda\x86.txt" },
194 { "Japanese.utf8", "t\xe3\x82\xaf\xe3\x83\xa4.txt" },
195 { "Chinese.utf8", "t\xe4\xb8\x82\xe9\xbd\xab.txt" },
196 { "Japanese", "t\xb8\xd5.txt" },
197
198 };
199
200 for(i=0; i<ARRAY_SIZE(tests); i++) {
201 if(!setlocale(LC_ALL, tests[i].loc)) {
202 win_skip("skipping locale %s\n", tests[i].loc);
203 continue;
204 }
205
208 continue;
209
210 f = _fsopen(tests[i].path, "w", SH_DENYNO);
211 ok(!!f, "failed to create %s with locale %s\n",
212 debugstr_a(tests[i].path), tests[i].loc);
213 fclose(f);
214
215 f = _wfsopen(wpath, L"r", SH_DENYNO);
216 ok(!!f, "failed to open %s with locale %s\n",
217 debugstr_a(tests[i].path), tests[i].loc);
218 if(f) fclose(f);
219
220 ok(!unlink(tests[i].path), "failed to unlink %s with locale %s\n",
221 tests[i].path, tests[i].loc);
222 }
223 setlocale(LC_ALL, "C");
224}
#define ok(value,...)
Definition: atltest.h:57
#define ARRAY_SIZE(A)
Definition: main.h:20
#define SH_DENYNO
Definition: share.h:25
#define CP_ACP
Definition: compat.h:109
#define MAX_PATH
Definition: compat.h:34
#define MultiByteToWideChar
Definition: compat.h:110
GLfloat f
Definition: glext.h:7540
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define MB_ERR_INVALID_CHARS
Definition: unicode.h:41
#define LC_ALL
Definition: locale.h:17
_CRTIMP unsigned int __cdecl ___lc_codepage_func(void)
Definition: locale.c:629
_Check_return_ _CRTIMP FILE *__cdecl _wfsopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode, _In_ int _ShFlag)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl _fsopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode, _In_ int _ShFlag)
#define f
Definition: ke_i.h:83
#define debugstr_a
Definition: kernel32.h:31
#define unlink
Definition: syshdrs.h:54
static struct test_info tests[]
#define L(x)
Definition: ntvdm.h:50
#define CP_UTF8
Definition: nls.h:20
#define win_skip
Definition: test.h:164
#define setlocale(n, s)
Definition: locale.h:46
#define MB_PRECOMPOSED
Definition: winnls.h:283

Referenced by START_TEST().

◆ test_iobuf_layout()

static void test_iobuf_layout ( void  )
static

Definition at line 101 of file file.c.

102{
103 union
104 {
105 FILE *f;
106 struct
107 {
108 char* _ptr;
109 char* _base;
110 int _cnt;
111 int _flag;
112 int _file;
113 int _charbuf;
114 int _bufsiz;
115 char* _tmpfname;
116 CRITICAL_SECTION _crit;
117 } *iobuf;
118 } fp;
119 char *tempf, *ptr, **file_ptr, **file_base;
120 int cnt, r, *file_cnt;
121
122 tempf = _tempnam(".","wne");
123 fp.f = fopen(tempf, "wb");
124 ok(fp.f != NULL, "fopen failed with error: %d\n", errno);
125
126 ok(!(fp.iobuf->_flag & 0x440), "fp.iobuf->_flag = %x\n", fp.iobuf->_flag);
127 r = fprintf(fp.f, "%s", "init");
128 ok(r == 4, "fprintf returned %d\n", r);
129 ok(fp.iobuf->_flag & 0x40, "fp.iobuf->_flag = %x\n", fp.iobuf->_flag);
130 ok(fp.iobuf->_cnt + 4 == fp.iobuf->_bufsiz, "_cnt = %d, _bufsiz = %d\n",
131 fp.iobuf->_cnt, fp.iobuf->_bufsiz);
132
133 ptr = fp.iobuf->_ptr;
134 cnt = fp.iobuf->_cnt;
135 r = fprintf(fp.f, "%s", "hello");
136 ok(r == 5, "fprintf returned %d\n", r);
137 ok(ptr + 5 == fp.iobuf->_ptr, "fp.iobuf->_ptr = %p, expected %p\n", fp.iobuf->_ptr, ptr + 5);
138 ok(cnt - 5 == fp.iobuf->_cnt, "fp.iobuf->_cnt = %d, expected %d\n", fp.iobuf->_cnt, cnt - 5);
139 ok(fp.iobuf->_ptr + fp.iobuf->_cnt == fp.iobuf->_base + fp.iobuf->_bufsiz,
140 "_ptr = %p, _cnt = %d, _base = %p, _bufsiz = %d\n",
141 fp.iobuf->_ptr, fp.iobuf->_cnt, fp.iobuf->_base, fp.iobuf->_bufsiz);
142
143 _get_stream_buffer_pointers(fp.f, &file_base, &file_ptr, &file_cnt);
144 ok(file_base == &fp.iobuf->_base, "_base = %p, expected %p\n", file_base, &fp.iobuf->_base);
145 ok(file_ptr == &fp.iobuf->_ptr, "_ptr = %p, expected %p\n", file_ptr, &fp.iobuf->_ptr);
146 ok(file_cnt == &fp.iobuf->_cnt, "_cnt = %p, expected %p\n", file_cnt, &fp.iobuf->_cnt);
147
148 r = setvbuf(fp.f, NULL, _IONBF, 0);
149 ok(!r, "setvbuf returned %d\n", r);
150 ok(fp.iobuf->_flag & 0x400, "fp.iobuf->_flag = %x\n", fp.iobuf->_flag);
151
152 ok(TryEnterCriticalSection(&fp.iobuf->_crit), "TryEnterCriticalSection section returned FALSE\n");
153 LeaveCriticalSection(&fp.iobuf->_crit);
154
155 fclose(fp.f);
156 unlink(tempf);
157}
#define NULL
Definition: types.h:112
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
_Check_return_ _CRTIMP char *__cdecl _tempnam(_In_opt_z_ const char *_DirName, _In_opt_z_ const char *_FilePrefix)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define _IONBF
Definition: stdio.h:129
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl setvbuf(_Inout_ FILE *_File, _Inout_updates_opt_z_(_Size) char *_Buf, _In_ int _Mode, _In_ size_t _Size)
int CDECL _get_stream_buffer_pointers(FILE *, char ***, char ***, int **)
Definition: _file.cpp:153
#define errno
Definition: errno.h:18
_In_ size_t cnt
Definition: wcstombs.cpp:43
BOOL WINAPI TryEnterCriticalSection(LPCRITICAL_SECTION)
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by START_TEST().

◆ test_std_stream_buffering()

static void test_std_stream_buffering ( void  )
static

Definition at line 39 of file file.c.

40{
41 int dup_fd, ret, pos;
42 FILE *file;
43 char ch;
44
45 dup_fd = _dup(STDOUT_FILENO);
46 ok(dup_fd != -1, "_dup failed\n");
47
48 file = freopen("std_stream_test.tmp", "w", stdout);
49 ok(file != NULL, "freopen failed\n");
50
51 ret = fprintf(stdout, "test");
53
55 _dup2(dup_fd, STDOUT_FILENO);
56 close(dup_fd);
58
59 ok(ret == 4, "fprintf(stdout) returned %d\n", ret);
60 ok(!pos, "expected stdout to be buffered\n");
61
62 dup_fd = _dup(STDERR_FILENO);
63 ok(dup_fd != -1, "_dup failed\n");
64
65 file = freopen("std_stream_test.tmp", "w", stderr);
66 ok(file != NULL, "freopen failed\n");
67
68 ret = fprintf(stderr, "test");
69 ok(ret == 4, "fprintf(stderr) returned %d\n", ret);
71 if (broken(!GetProcAddress(GetModuleHandleA("ucrtbase"), "__CxxFrameHandler4") && !pos))
72 trace("stderr is buffered\n");
73 else
74 ok(pos == 4, "expected stderr to be unbuffered (%d)\n", pos);
75
77 _dup2(dup_fd, STDERR_FILENO);
78 close(dup_fd);
79
80 dup_fd = _dup(STDIN_FILENO);
81 ok(dup_fd != -1, "_dup failed\n");
82
83 file = freopen("std_stream_test.tmp", "r", stdin);
84 ok(file != NULL, "freopen failed\n");
85
86 ch = 0;
87 ret = fscanf(stdin, "%c", &ch);
88 ok(ret == 1, "fscanf returned %d\n", ret);
89 ok(ch == 't', "ch = 0x%x\n", (unsigned char)ch);
91 ok(pos == 4, "pos = %d\n", pos);
92
94 _dup2(dup_fd, STDIN_FILENO);
95 close(dup_fd);
96
97 ok(DeleteFileA("std_stream_test.tmp"), "DeleteFile failed\n");
98}
#define close
Definition: acwin.h:98
#define trace
Definition: atltest.h:70
#define broken(x)
Definition: atltest.h:178
#define GetProcAddress(x, y)
Definition: compat.h:753
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
_Check_return_ _CRTIMP FILE *__cdecl freopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode, _Inout_ FILE *_File)
#define stdout
Definition: stdio.h:99
#define stderr
Definition: stdio.h:100
_Check_return_ _CRTIMP int __cdecl fscanf(_Inout_ FILE *_File, _In_z_ _Scanf_format_string_ const char *_Format,...)
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
#define stdin
Definition: stdio.h:98
#define STDOUT_FILENO
Definition: syshdrs.h:89
#define STDERR_FILENO
Definition: syshdrs.h:90
#define STDIN_FILENO
Definition: syshdrs.h:88
_Check_return_ _CRTIMP int __cdecl _dup2(_In_ int _FileHandleSrc, _In_ int _FileHandleDst)
_Check_return_ _CRTIMP int __cdecl _dup(_In_ int _FileHandle)
__int64 CDECL _telli64(int fd)
Definition: file.c:2527
Definition: fci.c:127
int ret

◆ test_std_stream_open()

static void test_std_stream_open ( void  )
static

Definition at line 159 of file file.c.

160{
161 FILE *f;
162 int fd;
163
165 ok(fd != -1, "_dup failed\n");
166
167 ok(!fclose(stdin), "fclose failed\n");
168 f = fopen("nul", "r");
169 ok(f != stdin, "f = %p, stdin = %p\n", f, stdin);
170 ok(_fileno(f) == STDIN_FILENO, "_fileno(f) = %d\n", _fileno(f));
171 ok(!fclose(f), "fclose failed\n");
172
173 f = freopen("nul", "r", stdin);
174 ok(f == stdin, "f = %p, expected %p\n", f, stdin);
175 ok(_fileno(f) == STDIN_FILENO, "_fileno(f) = %d\n", _fileno(f));
176
178 close(fd);
179}
_Check_return_ _CRTIMP int __cdecl _fileno(_In_ FILE *_File)
static int fd
Definition: io.c:51

◆ test_utf8()

static void test_utf8 ( const char argv0)
static

Definition at line 226 of file file.c.

227{
228 const char file[] = "file\xc4\x99\xc5\x9b\xc4\x87.a";
229 const char dir[] = "dir\xc4\x99\xc5\x9b\xc4\x87";
230 const WCHAR fileW[] = L"file\x0119\x015b\x0107.a";
231 const WCHAR dirW[] = L"dir\x0119\x015b\x0107";
232
233 char file2[32], buf[256], *p, *q, *env[2];
234 struct _finddata64i32_t fdata64i32;
235 struct _finddata32_t fdata32;
236 struct _finddata64_t fdata64;
237 intptr_t hfind, hproc;
238 WCHAR bufW[256], *pW;
239 struct _stat64 stat;
240 FILE *f;
241 int ret;
242
243 if (!setlocale(LC_ALL, ".utf8"))
244 {
245 win_skip("utf-8 tests\n");
246 return;
247 }
248
249 ret = _mkdir(dir);
250 if (ret == -1 && errno == ENOENT)
251 {
252 skip("can't create test environment\n");
253 return;
254 }
255 ok(!ret, "_mkdir returned %d, error %d\n", ret, errno);
256
257 ret = _chdir(dir);
258 ok(!ret, "_chdir returned %d, error %d\n", ret, errno);
259
260 p = _getcwd(buf, sizeof(buf));
261 ok(p == buf, "_getcwd returned %p, errno %d\n", p, errno);
262 p = strrchr(p, '\\');
263 ok(!!p, "strrchr returned NULL, buf = %s\n", debugstr_a(buf));
264 ok(!strcmp(p + 1, dir), "unexpected working directory: %s\n", debugstr_a(buf));
265
266 p = _getdcwd(_getdrive(), buf, sizeof(buf));
267 ok(p == buf, "_getdcwd returned %p, errno %d\n", p, errno);
268 p = strrchr(p, '\\');
269 ok(!!p, "strrchr returned NULL, buf = %s\n", debugstr_a(buf));
270 ok(!strcmp(p + 1, dir), "unexpected working directory: %s\n", debugstr_a(buf));
271
272 p = _fullpath(buf, NULL, sizeof(buf));
273 ok(p == buf, "_fulpath returned %p, errno %d\n", p, errno);
274 p = strrchr(p, '\\');
275 ok(!!p, "strrchr returned NULL, buf = %s\n", debugstr_a(buf));
276 ok(!strcmp(p + 1, dir), "unexpected working directory: %s\n", debugstr_a(buf));
277
278 f = fopen(file, "w");
279 ok(!!f, "fopen returned %d, error %d\n", ret, errno);
280 fclose(f);
281
282 ret = access(file, 0);
283 ok(!ret, "access returned %d, error %d\n", ret, errno);
284
285 ret = _stat64(file, &stat);
286 ok(!ret, "_stat64 returned %d, error %d\n", ret, errno);
287
289 ok(!ret, "_chmod returned %d, error %d\n", ret, errno);
290
291 strcpy(file2, file);
292 strcat(file2, "XXXXXX");
293 p = _mktemp(file2);
294 ok(p == file2, "_mktemp returned %p, file2 %p, errno %d\n", p, file2, errno);
295 ok(!memcmp(file2, file, sizeof(file) - 1), "file2 = %s\n", debugstr_a(file2));
296 ok(p[ARRAY_SIZE(file) - 1] == 'a', "p = %s\n", debugstr_a(p));
297 f = fopen(p, "w");
298 ok(!!f, "fopen returned %d, error %d\n", ret, errno);
299 fclose(f);
300
301 strcpy(buf, file);
302 strcat(buf, "XXXXXX");
303 p = _mktemp(buf);
304 ok(p == buf, "_mktemp returned %p, buf %p, errno %d\n", p, buf, errno);
305 ok(!memcmp(buf, file, sizeof(file) - 1), "buf = %s\n", debugstr_a(buf));
306 ok(p[ARRAY_SIZE(file) - 1] == 'b', "p = %s\n", debugstr_a(p));
307
308 strcpy(buf, file);
309 strcat(buf, "XXXXXX");
310 ret = _mktemp_s(buf, sizeof(buf));
311 ok(!memcmp(buf, file, sizeof(file) - 1), "buf = %s\n", debugstr_a(buf));
312 ok(buf[ARRAY_SIZE(file) - 1] == 'b', "buf = %s\n", debugstr_a(buf));
313
314 strcpy(buf, file);
315 strcat(buf, "*");
316 fdata32.name[0] = 'x';
317 hfind = _findfirst32(buf, &fdata32);
318 ok(hfind != -1, "_findfirst32 returned %Id, errno %d\n", hfind, errno);
319 ok(!memcmp(file, fdata32.name, sizeof(file) - 1), "fdata32.name = %s\n", debugstr_a(fdata32.name));
320
321 fdata32.name[0] = 'x';
322 ret = _findnext32(hfind, &fdata32);
323 ok(!ret, "_findnext32 returned %d, errno %d\n", ret, errno);
324 ok(!memcmp(file, fdata32.name, sizeof(file) - 1), "fdata32.name = %s\n", debugstr_a(fdata32.name));
325 ret = _findclose(hfind);
326 ok(!ret, "_findclose returned %d, errno %d\n", ret, errno);
327
328
329 strcpy(buf, file);
330 strcat(buf, "*");
331 fdata64.name[0] = 'x';
332 hfind = _findfirst64(buf, &fdata64);
333 ok(hfind != -1, "_findfirst64 returned %Id, errno %d\n", hfind, errno);
334 ok(!memcmp(file, fdata64.name, sizeof(file) - 1), "fdata64.name = %s\n", debugstr_a(fdata64.name));
335
336 fdata64.name[0] = 'x';
337 ret = _findnext64(hfind, &fdata64);
338 ok(!ret, "_findnext64 returned %d, errno %d\n", ret, errno);
339 ok(!memcmp(file, fdata64.name, sizeof(file) - 1), "fdata64.name = %s\n", debugstr_a(fdata64.name));
340 ret = _findclose(hfind);
341 ok(!ret, "_findclose returned %d, errno %d\n", ret, errno);
342
343 strcpy(buf, file);
344 strcat(buf, "*");
345 fdata64i32.name[0] = 'x';
346 hfind = _findfirst64i32(buf, &fdata64i32);
347 ok(hfind != -1, "_findfirst64i32 returned %Id, errno %d\n", hfind, errno);
348 ok(!memcmp(file, fdata64i32.name, sizeof(file) - 1), "fdata64i32.name = %s\n", debugstr_a(fdata64i32.name));
349
350 fdata64i32.name[0] = 'x';
351 ret = _findnext64i32(hfind, &fdata64i32);
352 ok(!ret, "_findnext64i32 returned %d, errno %d\n", ret, errno);
353 ok(!memcmp(file, fdata64i32.name, sizeof(file) - 1), "fdata64i32.name = %s\n", debugstr_a(fdata64i32.name));
354 ret = _findclose(hfind);
355 ok(!ret, "_findclose returned %d, errno %d\n", ret, errno);
356
357 ret = remove(file2);
358 ok(!ret, "remove returned %d, errno %d\n", ret, errno);
359
360 buf[0] = 'x';
361 _searchenv(file, "env", buf);
362 p = strrchr(buf, '\\');
363 ok(!!p, "buf = %s\n", debugstr_a(buf));
364 ok(!strcmp(p + 1, file), "buf = %s\n", debugstr_a(buf));
365
366 ret = _wunlink(fileW);
367 ok(!ret, "_wunlink returned %d, errno %d\n", ret, errno);
368
369 ret = _chdir("..");
370 ok(!ret, "_chdir returned %d, error %d\n", ret, errno);
371
372 ret = _wrmdir(dirW);
373 ok(!ret, "_wrmdir returned %d, errno %d\n", ret, errno);
374
375 p = _tempnam(NULL, file);
376 ok(!!p, "_tempnam returned NULL, error %d\n", errno);
377 q = strrchr(p, '\\');
378 ok(!!q, "_tempnam returned %s\n", debugstr_a(p));
379 todo_wine ok(!memcmp(q + 1, file, ARRAY_SIZE(file) - 1),
380 "incorrect file prefix: %s\n", debugstr_a(p));
381 free(p);
382
383 /* native implementation mixes CP_UTF8 and CP_ACP */
384 if (GetACP() != CP_UTF8)
385 {
386 /* make sure wide environment is initialized (works around bug in native) */
387 ret = _putenv("__wine_env_test=test");
388 ok(!ret, "_putenv returned %d, errno %d\n", ret, errno);
389 _wgetenv(L"__wine_env_test");
390
391 strcpy(buf, file);
392 strcat(buf, "=test");
393 ret = _putenv(buf);
394 ok(!ret, "_putenv returned %d, errno %d\n", ret, errno);
395 /* bug in native _wgetenv/_putenv implementation */
396 pW = _wgetenv(fileW);
397 ok(!pW, "environment variable name was converted\n");
398 bufW[0] = 0;
400 todo_wine ok(ret, "GetEnvironmentVariableW returned error %lu\n", GetLastError());
401 todo_wine ok(!wcscmp(bufW, L"test"), "bufW = %s\n", debugstr_w(bufW));
402 strcpy(buf, file);
403 strcat(buf, "=");
404 ret = _putenv(buf);
405 ok(!ret, "_putenv returned %d, errno %d\n", ret, errno);
406
407 strcpy(buf, "__wine_env_test=");
408 strcat(buf, file);
409 ret = _putenv(buf);
410 ok(!ret, "_putenv returned %d, errno %d\n", ret, errno);
411 /* bug in native _wgetenv/_putenv implementation */
412 pW = _wgetenv(L"__wine_env_test");
413 ok(wcscmp(pW, fileW), "pW = %s\n", debugstr_w(pW));
414 ret = GetEnvironmentVariableW(L"__wine_env_test", bufW, ARRAY_SIZE(bufW));
415 ok(ret, "GetEnvironmentVariableW returned error %lu\n", GetLastError());
416 todo_wine ok(!wcscmp(bufW, fileW), "bufW = %s\n", debugstr_w(bufW));
417
418 wcscpy(bufW, L"__wine_env_test=");
419 wcscat(bufW, fileW);
420 ret = _wputenv(bufW);
421 ok(!ret, "_wputenv returned %d, errno %d\n", ret, errno);
422 p = getenv("__wine_env_test");
423 ok(strcmp(p, file), "environment variable was converted\n");
424 strcpy(buf, "__wine_env_test=");
425 ret = _putenv(buf);
426 ok(!ret, "_putenv returned %d, errno %d\n", ret, errno);
427 }
428
429 strcpy(buf, "__wine_env_test=");
430 strcat(buf, file);
431 env[0] = buf;
432 env[1] = NULL;
433 hproc = _spawnle(_P_NOWAIT, argv0, argv0, "file", "utf8", file, NULL, env);
434 ok(hproc != -1, "_spawnl returned %Id, errno %d\n", hproc, errno);
436 CloseHandle((HANDLE)hproc);
437
438 setlocale(LC_ALL, "C");
439}
#define ENOENT
Definition: acclib.h:79
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
unsigned int dir
Definition: maze.c:112
#define skip(...)
Definition: atltest.h:64
wcscat
wcscpy
_Check_return_ _CRTIMP int __cdecl _getdrive(void)
Definition: getdrive.c:20
_Check_return_ _Ret_opt_z_ _CRTIMP char *__cdecl _getcwd(_Out_writes_opt_(_SizeInBytes) char *_DstBuf, _In_ int _SizeInBytes)
_Check_return_ _CRTIMP int __cdecl _wrmdir(_In_z_ const wchar_t *_Path)
_Check_return_ _Ret_opt_z_ _CRTIMP char *__cdecl _getdcwd(_In_ int _Drive, _Out_writes_opt_(_SizeInBytes) char *_DstBuf, _In_ int _SizeInBytes)
_Check_return_ _CRTIMP int __cdecl _chdir(_In_z_ const char *_Path)
_Check_return_ _CRTIMP int __cdecl _mkdir(_In_z_ const char *_Path)
static LPCWSTR LPCWSTR LPCWSTR env
Definition: db.cpp:170
#define free
Definition: debug_ros.c:5
#define _S_IWRITE
Definition: cabinet.h:33
#define _S_IREAD
Definition: cabinet.h:34
#define CloseHandle
Definition: compat.h:739
#define GetEnvironmentVariableW(x, y, z)
Definition: compat.h:755
UINT WINAPI GetACP(void)
Definition: locale.c:2021
static const WCHAR fileW[]
Definition: url.c:111
int __cdecl _findnext64i32(intptr_t const handle, _finddata64i32_t *const result)
Definition: findfile.cpp:342
intptr_t __cdecl _findfirst64i32(char const *const pattern, _finddata64i32_t *const result)
Definition: findfile.cpp:210
intptr_t __cdecl _findfirst64(char const *const pattern, __finddata64_t *const result)
Definition: findfile.cpp:216
int __cdecl _findnext64(intptr_t const handle, __finddata64_t *const result)
Definition: findfile.cpp:348
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
GLfloat GLfloat p
Definition: glext.h:8902
_Check_return_ _CRTIMP char *__cdecl _fullpath(_Out_writes_opt_z_(_SizeInBytes) char *_FullPath, _In_z_ const char *_Path, _In_ size_t _SizeInBytes)
_Check_return_ _CRTIMP int __cdecl _wputenv(_In_z_ const wchar_t *_EnvString)
_Check_return_ _CRTIMP wchar_t *__cdecl _wgetenv(_In_z_ const wchar_t *_VarName)
_Check_return_ _CRTIMP int __cdecl _putenv(_In_z_ const char *_EnvString)
_CRTIMP void __cdecl _searchenv(_In_z_ const char *_Filename, _In_z_ const char *_EnvVar, _Pre_notnull_ _Post_z_ char *_ResultPath)
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
#define debugstr_w
Definition: kernel32.h:32
errno_t __cdecl _mktemp_s(char *const template_string, size_t const buffer_size_in_chars)
Definition: mktemp.cpp:119
#define todo_wine
Definition: custom.c:89
#define _P_NOWAIT
Definition: port.h:371
int remove
Definition: msacm.c:1366
_Check_return_ _CRTIMP int __cdecl _wunlink(_In_z_ const wchar_t *_Filename)
_Check_return_ _CRTIMP int __cdecl _chmod(_In_z_ const char *_Filename, _In_ int _Mode)
_Check_return_ _CRTIMP char *__cdecl _mktemp(_Inout_z_ char *_TemplateName)
_Check_return_ _CRTIMP int __cdecl _findnext32(_In_ intptr_t _FindHandle, _Out_ struct _finddata32_t *_FindData)
_Check_return_ _CRTIMP intptr_t __cdecl _findfirst32(_In_z_ const char *_Filename, _Out_ struct _finddata32_t *_FindData)
_Check_return_opt_ _CRTIMP int __cdecl _findclose(_In_ intptr_t _FindHandle)
_CRTIMP intptr_t __cdecl _spawnle(_In_ int _Mode, _In_z_ const char *_Filename, _In_z_ const char *_ArgList,...)
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_CRT_RESTORE_GCC_WARNINGS _CRT_DISABLE_GCC_WARNINGS _Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
#define wait_child_process
Definition: test.h:166
strcat
Definition: string.h:92
strcpy
Definition: string.h:131
static char argv0[MAX_PATH]
Definition: shlexec.c:49
Definition: stat.h:70
char name[1]
Definition: fci.c:135
Definition: stat.h:55
int intptr_t
Definition: vcruntime.h:134
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ test_utf8_argument()

static void test_utf8_argument ( void  )
static

Definition at line 441 of file file.c.

442{
443 static const WCHAR nameW[] = L"file\x0119\x015b\x0107.a";
444 const WCHAR *cmdline = GetCommandLineW(), *p;
445 WCHAR buf[256];
446 DWORD ret;
447
448 p = wcsrchr(cmdline, ' ');
449 ok(!!p, "cmdline = %s\n", debugstr_w(cmdline));
450 ok(!wcscmp(p + 1, nameW), "cmdline = %s\n", debugstr_w(cmdline));
451
452 ret = GetEnvironmentVariableW(L"__wine_env_test", buf, ARRAY_SIZE(buf));
453 ok(ret, "GetEnvironmentVariableW returned error %lu\n", GetLastError());
454 if (GetACP() == CP_UTF8)
455 ok(!wcscmp(buf, nameW), "__wine_env_test = %s\n", debugstr_w(buf));
456 else
457 ok(wcscmp(buf, nameW), "environment was converted\n");
458}
static const WCHAR nameW[]
Definition: main.c:49
#define wcsrchr
Definition: compat.h:16
LPWSTR WINAPI GetCommandLineW(VOID)
Definition: proc.c:2019
unsigned long DWORD
Definition: ntddk_ex.h:95
TCHAR * cmdline
Definition: stretchblt.cpp:32

Referenced by START_TEST().