2 * Copyright 2022 Paul Gofman for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "wine/test.h"
33 #define WX_READNL 0x04
35 #define WX_DONTINHERIT 0x10
36 #define WX_APPEND 0x20
40 #define MSVCRT_FD_BLOCK_SIZE 32
48 CRITICAL_SECTION crit
;
53 BOOL utf8translations
;
58 static ioinfo
**__pioinfo
;
60 static int (__cdecl
*p__open
)(const char *, int, ...);
61 static int (__cdecl
*p__close
)(int);
62 static intptr_t (__cdecl
*p__get_osfhandle
)(int);
64 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hcrt,y)
65 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
66 static BOOL
init(void)
70 SetLastError(0xdeadbeef);
71 hcrt
= LoadLibraryA("msvcr80.dll");
73 win_skip("msvcr80.dll not installed (got %ld)\n", GetLastError());
77 SET(__pioinfo
, "__pioinfo");
79 SET(p__close
,"_close");
80 SET(p__get_osfhandle
, "_get_osfhandle");
85 static void test_ioinfo_flags(void)
92 tempf
= _tempnam(".","wne");
94 tempfd
= p__open(tempf
, _O_CREAT
|_O_TRUNC
|_O_WRONLY
|_O_WTEXT
, _S_IWRITE
);
95 ok(tempfd
!= -1, "_open failed with error: %d\n", errno
);
96 handle
= (HANDLE
)p__get_osfhandle(tempfd
);
97 info
= &__pioinfo
[tempfd
/ MSVCRT_FD_BLOCK_SIZE
][tempfd
% MSVCRT_FD_BLOCK_SIZE
];
98 ok(!!info
, "NULL info.\n");
99 ok(info
->handle
== handle
, "Unexpected handle %p, expected %p.\n", info
->handle
, handle
);
100 ok(info
->exflag
== 1, "Unexpected exflag %#x.\n", info
->exflag
);
101 ok(info
->wxflag
== (WX_TEXT
| WX_OPEN
), "Unexpected wxflag %#x.\n", info
->wxflag
);
102 ok(info
->unicode
, "Unicode is not set.\n");
103 ok(info
->textmode
== 2, "Unexpected textmode %d.\n", info
->textmode
);
106 ok(info
->handle
== INVALID_HANDLE_VALUE
, "Unexpected handle %p.\n", info
->handle
);
107 ok(info
->exflag
== 1, "Unexpected exflag %#x.\n", info
->exflag
);
108 ok(info
->unicode
, "Unicode is not set.\n");
109 ok(!info
->wxflag
, "Unexpected wxflag %#x.\n", info
->wxflag
);
110 ok(info
->textmode
== 2, "Unexpected textmode %d.\n", info
->textmode
);
112 info
= &__pioinfo
[(tempfd
+ 4) / MSVCRT_FD_BLOCK_SIZE
][(tempfd
+ 4) % MSVCRT_FD_BLOCK_SIZE
];
113 ok(!!info
, "NULL info.\n");
114 ok(info
->handle
== INVALID_HANDLE_VALUE
, "Unexpected handle %p.\n", info
->handle
);
115 ok(!info
->exflag
, "Unexpected exflag %#x.\n", info
->exflag
);
116 ok(!info
->textmode
, "Unexpected textmode %d.\n", info
->textmode
);
118 tempfd
= p__open(tempf
, _O_CREAT
|_O_TRUNC
|_O_WRONLY
|_O_TEXT
, _S_IWRITE
);
119 ok(tempfd
!= -1, "_open failed with error: %d\n", errno
);
120 info
= &__pioinfo
[tempfd
/ MSVCRT_FD_BLOCK_SIZE
][tempfd
% MSVCRT_FD_BLOCK_SIZE
];
121 ok(!!info
, "NULL info.\n");
122 ok(info
->exflag
== 1, "Unexpected exflag %#x.\n", info
->exflag
);
123 ok(info
->wxflag
== (WX_TEXT
| WX_OPEN
), "Unexpected wxflag %#x.\n", info
->wxflag
);
124 ok(!info
->unicode
, "Unicode is not set.\n");
125 ok(!info
->textmode
, "Unexpected textmode %d.\n", info
->textmode
);
128 tempfd
= p__open(tempf
, _O_CREAT
|_O_TRUNC
|_O_WRONLY
|_O_U8TEXT
, _S_IWRITE
);
129 ok(tempfd
!= -1, "_open failed with error: %d\n", errno
);
130 info
= &__pioinfo
[tempfd
/ MSVCRT_FD_BLOCK_SIZE
][tempfd
% MSVCRT_FD_BLOCK_SIZE
];
131 ok(!!info
, "NULL info.\n");
132 ok(info
->exflag
== 1, "Unexpected exflag %#x.\n", info
->exflag
);
133 ok(info
->wxflag
== (WX_TEXT
| WX_OPEN
), "Unexpected wxflag %#x.\n", info
->wxflag
);
134 ok(!info
->unicode
, "Unicode is not set.\n");
135 ok(info
->textmode
== 1, "Unexpected textmode %d.\n", info
->textmode
);