39 #define MSVCRT_FD_BLOCK_SIZE 32 52 static int (
__cdecl *p__wfopen_s)(
FILE**,
const wchar_t*,
const wchar_t*);
61 if(*
ret==
'\\' || *
ret==
'/')
87 fp =
fopen(
"filbuf.tst",
"wb");
88 fwrite(
"\n\n\n\n", 1, 4, fp);
91 fp =
fopen(
"filbuf.tst",
"rt");
93 ok(
c ==
'\n',
"read wrong byte\n");
105 ok(
ftell(fp) == -2,
"ascii crlf removal does not match native\n");
107 ok(
pos == -2,
"ftell does not match fgetpos\n");
114 static const char buffer[] = {0,1,2,3,4,5,6,7,8,9};
134 static const char outbuffer[] =
"0,1,2,3,4,5,6,7,8,9";
147 for (bufmode=0; bufmode <
ARRAY_SIZE(bufmodes); bufmode++)
152 if(bufmodes[bufmode] ==
_IOFBF)
153 ok(
file->_bufsiz == 2048,
"file->_bufsiz = %d\n",
file->_bufsiz);
154 ok(
file->_base !=
NULL,
"file->_base = NULL\n");
158 ok(
feof(
file) !=0,
"feof doesn't signal EOF for bufmode=%x\n", bufmodes[bufmode]);
163 ok(
strlen(
buffer) == 1,
"fgets dropped chars for bufmode=%x\n", bufmodes[bufmode]);
171 ok((
c =
fgetc(
file)) ==
EOF,
"getc did not return EOF for bufmode=%x\n", bufmodes[bufmode]);
172 ok(
feof(
file),
"feof did not return EOF for bufmode=%x\n", bufmodes[bufmode]);
173 ok(
ungetc(
c,
file) ==
EOF,
"ungetc(EOF) did not return EOF for bufmode=%x\n", bufmodes[bufmode]);
174 ok(
feof(
file),
"feof after ungetc(EOF) did not return EOF for bufmode=%x\n", bufmodes[bufmode]);
175 ok(
fgetc(
file) ==
EOF,
"getc did not return EOF for bufmode=%x\n", bufmodes[bufmode]);
177 ok(
ungetc(
c,
file) ==
c,
"ungetc did not return its input for bufmode=%x\n", bufmodes[bufmode]);
178 ok(!
feof(
file),
"feof after ungetc returned EOF for bufmode=%x\n", bufmodes[bufmode]);
179 ok((
c =
fgetc(
file)) !=
EOF,
"getc after ungetc returned EOF for bufmode=%x\n", bufmodes[bufmode]);
181 "getc did not return ungetc'd data for bufmode=%x\n", bufmodes[bufmode]);
182 ok(!
feof(
file),
"feof after getc returned EOF prematurely for bufmode=%x\n", bufmodes[bufmode]);
183 ok(
fgetc(
file) ==
EOF,
"getc did not return EOF for bufmode=%x\n", bufmodes[bufmode]);
184 ok(
feof(
file),
"feof after getc did not return EOF for bufmode=%x\n", bufmodes[bufmode]);
187 ok(
fgetpos(
file,&
pos) == 0,
"fgetpos failed unexpected for bufmode=%x\n", bufmodes[bufmode]);
190 ok(
fsetpos(
file, &
pos) == 0,
"fsetpos failed unexpected for bufmode=%x\n", bufmodes[bufmode]);
191 ok(
fgetpos(
file,&
pos) == 0,
"fgetpos failed unexpected for bufmode=%x\n", bufmodes[bufmode]);
200 ok(
feof(
file) !=0,
"feof doesn't signal EOF\n");
205 ok(
lstrlenW(wbuffer) == 1,
"fgets dropped chars\n");
219 #define IOMODE (ao?"ascii mode":"binary mode") 222 static const char outbuffer[] =
"0,1,2,3,4,5,6,7,8,9\r\n\r\nA,B,C,D,E\r\nX,Y,Z";
223 static const char padbuffer[] =
"ghjghjghjghj";
224 static const char nlbuffer[] =
"\r\n";
265 ok(
l == pl,
"padding line ftell got %d should be %d in %s\n",
l, pl,
IOMODE);
266 ok(
lstrlenA(
buffer) == pl+ao,
"padding line fgets got size %d should be %d in %s\n",
273 ok(
l == pl+fp,
"line 1 ftell got %d should be %d in %s\n",
l, pl+fp,
IOMODE);
274 ok(
lstrlenA(
buffer) == fp+ao,
"line 1 fgets got size %d should be %d in %s\n",
280 ok(
l == pl,
"ftell after seek got %d should be %d in %s\n",
l, pl,
IOMODE);
283 ok(
l == pl+fp,
"second read of line 1 ftell got %d should be %d in %s\n",
l, pl+fp,
IOMODE);
284 ok(
lstrlenA(
buffer) == fp+ao,
"second read of line 1 fgets got size %d should be %d in %s\n",
289 ok(
l == pl+fp,
"line 2 ftell got %d should be %d in %s\n",
l, pl+fp,
IOMODE);
290 ok(
lstrlenA(
buffer) == 2+ao,
"line 2 fgets got size %d should be %d in %s\n",
301 ok(
l == pl+
j-(ao*4)-5,
"ftell after fread got %d should be %d in %s\n",
l, pl+
j-(ao*4)-5,
IOMODE);
309 if (ao && (*optr ==
'\r'))
318 ok(
i==
j,
"fread failed, expected %d got %d in %s\n",
j,
i,
IOMODE);
337 ok(
i == *
ip,
"_getw failed, expected %08x got %08x in %s\n", *
ip,
i,
IOMODE);
343 for (
i=0,
j=0;
i<6;
i++) {
349 ok(
i == *
ip,
"_getw failed, expected %08x got %08x in %s\n", *
ip,
i,
IOMODE);
356 ok(
fd != -1,
"open failed\n");
363 ok(
fd != -1,
"open failed\n");
369 ok(!
i,
"fread succeeded\n");
370 ok(
file->_bufsiz == 4096,
"file->_bufsiz = %d\n",
file->_bufsiz);
371 for(
i=0;
i<4096;
i++)
372 if(
buffer[
i] != (
i==1 ? 0x1a :
'a'))
break;
386 fp =
fopen(
"ascii.tst",
"wb");
389 fp =
fopen(
"ascii.tst",
"rt");
391 ok(0 ==
strcmp(
buf,
"\r\n"),
"CR CR LF not read as CR LF\n");
398 fp =
fopen(
"ascii.tst",
"wb");
399 fputs(
"foo\032", fp);
403 fp =
fopen(
"ascii.tst",
"rt");
405 ok(0 ==
strcmp(
buf,
"foo"),
"foo ^Z not read as foo by fgets\n");
408 ok((
fread(
buf, 1,
sizeof(
buf), fp) == 3) && (0 ==
strcmp(
buf,
"foo")),
"foo ^Z not read as foo by fread\n");
409 ok((
fread(
buf, 1,
sizeof(
buf), fp) == 0),
"fread after logical EOF\n");
413 fp=
fopen(
"ascii.tst",
"wb");
414 fputs(
"0\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n", fp);
417 fp =
fopen(
"ascii.tst",
"r");
419 ok(
c ==
'0',
"fgetc failed, expected '0', got '%c'\n",
c);
421 ok(
c ==
'\n',
"fgetc failed, expected '\\n', got '%c'\n",
c);
423 for(
i=1;
i<10;
i++) {
424 ok((
j =
ftell(fp)) ==
i*3,
"ftell fails in TEXT mode\n");
426 ok((
c =
fgetc(fp)) ==
'0'+
i,
"fgetc after fseek failed in line %d\n",
i);
428 ok(
c ==
'\n',
"fgetc failed, expected '\\n', got '%c'\n",
c);
433 ok(
c ==
'0',
"fgetc failed, expected '0', got '%c'\n",
c);
435 for(
i=1;
i<10;
i++) {
436 ok((
c =
fgetc(fp)) ==
'0'+
i,
"fgetc after fseek with pos Offset failed in line %d\n",
i);
441 ok(
c ==
'9',
"fgetc failed, expected '9', got '%c'\n",
c);
443 for(
i= 8;
i>=0;
i--) {
444 ok((
c =
fgetc(fp)) ==
'0'+
i,
"fgetc after fseek with neg Offset failed in line %d\n",
i);
449 fp =
fopen(
"ascii.tst",
"r");
451 ok((
c =
fgetc(fp)) ==
'1',
"fgetc fails to read next char when positioned on \\r\n");
470 static const char obuf[] =
472 "000000000000000000000000000000000000000000000000000000000000000000000000000000\n" 473 "000000000000000000000000000000000000000000000000000000000000000000000000000000\n" 474 "000000000000000000000000000000000000000000000000000000000000000000000000000000\n" 475 "000000000000000000000000000000000000000000000000000000000000000000000000000000\n" 476 "000000000000000000000000000000000000000000000000000000000000000000000000000000\n" 477 "000000000000000000000000000000000000000000000000000000000000000000000000000000\n" 478 "000000000000000000\n" 479 "1111111111111111111";
481 fp =
fopen(
"ascii2.tst",
"wt");
485 fp =
fopen(
"ascii2.tst",
"rt");
486 ok(
getc(fp) ==
'0',
"first char not 0\n");
487 memset(ibuf, 0,
sizeof(ibuf));
488 i =
fread(ibuf, 1,
sizeof(ibuf), fp);
489 ok(
i ==
sizeof(ibuf),
"fread i %d != sizeof(ibuf)\n",
i);
490 ok(0 ==
strncmp(ibuf,
obuf+1,
sizeof(ibuf)),
"ibuf != obuf\n");
497 char DATA [] = {26,
't',
'e',
's' ,
't'};
510 f =
fopen(tempfile,
"w+bDT");
513 bytesRead =
fread(DATA2, 1,
sizeof(DATA2),
f);
517 "fopen file mode 'T' wrongly interpreted as 't'\n" );
539 char buf[513], rbuf[513];
541 for (
i = 0;
i < 511;
i++)
543 j = (
i%(
'~' -
' ')+
' ');
548 fp =
fopen(
"boundary.tst",
"wt");
551 fp =
fopen(
"boundary.tst",
"rt");
561 ok(
strcmp(
buf, rbuf) == 0,
"CRLF on buffer boundary failure\n");
571 tempfh =
fopen(tempf,
"w+");
576 ok(ich ==
ret,
"First fgetc expected %x got %x\n", ich,
ret);
578 ok(ich ==
ret,
"Second fgetc expected %x got %x\n", ich,
ret);
580 tempfh =
fopen(tempf,
"wt");
583 tempfh =
fopen(tempf,
"wt");
586 ok(
ret == -1,
"Unbuffered fgetc in text mode must failed on \\r\\n\n");
599 tempfh =
fopen(tempf,
"wb");
601 ok(0 ==
ret,
"fputc(0,tempfh) expected %x got %x\n", 0,
ret);
603 ok(0xff ==
ret,
"fputc(0xff,tempfh) expected %x got %x\n", 0xff,
ret);
605 ok(0xff ==
ret,
"fputc(0xffffffff,tempfh) expected %x got %x\n", 0xff,
ret);
608 tempfh =
fopen(tempf,
"rb");
610 ok(
EOF ==
ret,
"fputc(0,tempfh) on r/o file expected %x got %x\n",
EOF,
ret);
627 for (bufmode=0; bufmode <
ARRAY_SIZE(bufmodes); bufmode++)
629 tempfh =
fopen(tempf,
"wb");
632 ok(0 ==
ret,
"_flsbuf(0,tempfh) with bufmode %x expected %x got %x\n",
633 bufmodes[bufmode], 0,
ret);
635 ok(0xff ==
ret,
"_flsbuf(0xff,tempfh) with bufmode %x expected %x got %x\n",
636 bufmodes[bufmode], 0xff,
ret);
638 ok(0xff ==
ret,
"_flsbuf(0xffffffff,tempfh) with bufmode %x expected %x got %x\n",
639 bufmodes[bufmode], 0xff,
ret);
643 tempfh->
_base[1] =
'a';
645 ok(
ret == 0xab,
"_flsbuf(0xab,tempfh) with bufmode %x expected 0xab got %x\n",
646 bufmodes[bufmode],
ret);
647 ok(tempfh->
_base[1] ==
'a',
"tempfh->_base[1] should not be changed (%d)\n",
654 tempfh =
fopen(tempf,
"rb");
656 ok(
EOF ==
ret,
"_flsbuf(0,tempfh) on r/o file expected %x got %x\n",
EOF,
ret);
660 tempfh =
fopen(tempf,
"w");
661 ok(tempfh->
_cnt == 0,
"_cnt on freshly opened file was %d\n", tempfh->
_cnt);
663 ok(tempfh->
_cnt == 0,
"_cnt on unbuffered file was %d\n", tempfh->
_cnt);
668 ok(
'Q' ==
ret,
"_flsbuf('Q',tempfh) expected %x got %x\n",
'Q',
ret);
670 ok(tempfh->
_cnt == 0,
"after unbuf _flsbuf, _cnt was %d\n", tempfh->
_cnt);
673 tempfh =
fopen(tempf,
"r");
675 ok(
c ==
'Q',
"first byte should be 'Q'\n");
677 ok(
c ==
EOF,
"there should only be one byte\n");
686 static const char obuf[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
687 char buf1[16], buf2[24];
695 tempfh =
fopen(tempf,
"wb");
696 ok(tempfh !=
NULL,
"Can't open test file.\n");
701 tempfh =
fopen(tempf,
"rb");
702 ok(tempfh !=
NULL,
"Can't open test file.\n");
703 fread(buf1, 1,
sizeof(buf1), tempfh);
709 ok(
ret == 0,
"expected 0, got %d\n",
ret);
710 memset(buf2,
'?',
sizeof(buf2));
711 fread(buf2, 1,
sizeof(buf2), tempfh);
712 ok(
memcmp(buf1, buf2,
sizeof(buf1)) == 0,
"Got unexpected data (%c)\n", buf2[0]);
717 ok(
ret == 0,
"expected 0, got %d\n",
ret);
718 memset(buf2,
'?',
sizeof(buf2));
719 fread(buf2, 1,
sizeof(buf2), tempfh);
720 ok(
memcmp(buf1, buf2,
sizeof(buf1)) != 0,
"Got unexpected data (%c)\n", buf2[0]);
725 ok(
ret >= 0,
"unexpected ret %d\n",
ret);
726 memset(buf2,
'?',
sizeof(buf2));
727 fread(buf2, 1,
sizeof(buf2), tempfh);
728 ok(
memcmp(buf1, buf2,
sizeof(buf1)) == 0,
"Got unexpected data (%c)\n", buf2[0]);
742 static const char mytext[]=
"This is test_fgetwc\r\n";
751 tempfh =
fopen(tempf,
"wb");
760 fputs(mytext,tempfh);
764 tempfh =
fopen(tempf,
"rt");
771 mytextW =
AtoW (mytext);
774 for (
i=0;
i<
strlen(mytext)-2;
i++, aptr++, wptr++)
776 diff_found |= (*aptr != *wptr);
778 ok(!(diff_found),
"fgetwc difference found in TEXT mode\n");
779 ok(*wptr ==
'\n',
"Carriage return was not skipped\n");
783 tempfh =
fopen(tempf,
"wb");
798 tempfh =
fopen(tempf,
"rb");
803 ok(
l==
j,
"ftell expected %d got %d\n",
j,
l);
805 ok(
i==
'a',
"fgetc expected %d got %d\n", 0x61,
i);
808 ok(
l==
j,
"ftell expected %d got %d\n",
j,
l);
810 ok(wtextW[0]==
'\r',
"expected carriage return got %04hx\n", wtextW[0]);
811 ok(wtextW[1]==
'\n',
"expected newline got %04hx\n", wtextW[1]);
814 ok(
l==
j,
"ftell expected %d got %d\n",
j,
l);
821 ok(
l==
j,
"ftell expected %d got %d\n",
j,
l);
825 for (
i=0;
i<
strlen(mytext)-2;
i++, aptr++, wptr++)
827 ok(*aptr == *wptr,
"Char %d expected %04hx got %04hx\n",
i, *aptr, *wptr);
828 diff_found |= (*aptr != *wptr);
830 ok(!(diff_found),
"fgetwc difference found in BINARY mode\n");
831 ok(*wptr ==
'\n',
"Should get newline\n");
840 for (
i=0;
i<
strlen(mytext)-2;
i++, aptr++, wptr++)
842 ok(*aptr == *wptr,
"Char %d expected %04hx got %04hx\n",
i, *aptr, *wptr);
843 diff_found |= (*aptr != *wptr);
845 ok(!(diff_found),
"fgetwc difference found in BINARY mode\n");
846 ok(*wptr ==
'\n',
"Should get newline\n");
858 static const WCHAR wchar_text[] = { 0xfeff, 0xff1f,
'!' };
872 tempfh =
fopen(tempfile,
"wb");
873 ok(tempfh !=
NULL,
"can't open tempfile\n");
882 ok(
ret > 0,
"MultiByteToWideChar failed\n");
888 for (
p =
text; *
p !=
'\0';
p++)
889 wtextW[
ret++] = (
unsigned char)*
p;
893 tempfh =
fopen(tempfile,
"rt");
894 ok(tempfh !=
NULL,
"can't open tempfile\n");
896 for (
i = 0;
i <
ret-1;
i++)
899 ok(ch == wtextW[
i],
"got %04hx, expected %04hx (cp%d[%d])\n", ch, wtextW[
i],
codepage,
i);
902 ok(ch ==
WEOF,
"got %04hx, expected WEOF (cp%d)\n", ch,
codepage);
905 tempfh =
fopen(tempfile,
"wb");
906 ok(tempfh !=
NULL,
"can't open tempfile\n");
907 fwrite(wchar_text, 1,
sizeof(wchar_text), tempfh);
910 tempfh =
fopen(tempfile,
"rb");
911 ok(tempfh !=
NULL,
"can't open tempfile\n");
915 ok(ch == wchar_text[
i],
"got %04hx, expected %04x (cp%d[%d])\n", ch, wchar_text[
i],
codepage,
i);
918 ok(ch ==
WEOF,
"got %04hx, expected WEOF (cp%d)\n", ch,
codepage);
927 static const WCHAR wchar_text[] = { 0xfeff, 0xff1f,
'!' };
937 win_skip(
"fopen_s not available\n");
941 tempfh =
fopen(tempfile,
"wb");
942 ok(tempfh !=
NULL,
"can't open tempfile\n");
943 fwrite(wchar_text, 1,
sizeof(wchar_text), tempfh);
946 tempfh =
fopen(tempfile,
"rt,ccs=unicode");
947 ok(tempfh !=
NULL,
"can't open tempfile\n");
951 ok(ch == wchar_text[
i],
952 "got %04hx, expected %04x (unicode[%d])\n", ch, wchar_text[
i],
i-1);
955 ok(ch ==
WEOF,
"got %04hx, expected WEOF (unicode)\n", ch);
958 tempfh =
fopen(tempfile,
"wb");
959 ok(tempfh !=
NULL,
"can't open tempfile\n");
961 utf8_text,
sizeof(utf8_text),
NULL,
NULL);
962 ok(
ret > 0,
"utf-8 conversion failed\n");
963 fwrite(utf8_text,
sizeof(
char),
ret, tempfh);
966 tempfh =
fopen(tempfile,
"rt, ccs=UTF-8");
967 ok(tempfh !=
NULL,
"can't open tempfile\n");
971 ok(ch == wchar_text[
i],
972 "got %04hx, expected %04x (utf8[%d])\n", ch, wchar_text[
i],
i-1);
975 ok(ch ==
WEOF,
"got %04hx, expected WEOF (utf8)\n", ch);
993 ok(
ret ==
'a',
"fputwc returned %x, expected 'a'\n",
ret);
995 ok(
ret ==
'\n',
"fputwc returned %x, expected '\\n'\n",
ret);
998 f =
fopen(tempfile,
"rb");
1000 ok(
ret == 3,
"fread returned %d, expected 3\n",
ret);
1001 ok(!
memcmp(
buf,
"a\r\n", 3),
"incorrect file data\n");
1005 f =
fopen(tempfile,
"w,ccs=unicode");
1007 ok(
ret ==
'a',
"fputwc returned %x, expected 'a'\n",
ret);
1009 ok(
ret ==
'\n',
"fputwc returned %x, expected '\\n'\n",
ret);
1012 f =
fopen(tempfile,
"rb");
1014 ok(
ret == 8,
"fread returned %d, expected 8\n",
ret);
1015 ok(!
memcmp(
buf,
"\xff\xfe\x61\x00\r\x00\n\x00", 8),
"incorrect file data\n");
1018 f =
fopen(tempfile,
"w,ccs=utf-8");
1020 ok(
ret ==
'a',
"fputwc returned %x, expected 'a'\n",
ret);
1022 ok(
ret ==
'\n',
"fputwc returned %x, expected '\\n'\n",
ret);
1025 f =
fopen(tempfile,
"rb");
1027 ok(
ret == 6,
"fread returned %d, expected 6\n",
ret);
1028 ok(!
memcmp(
buf,
"\xef\xbb\xbf\x61\r\n", 6),
"incorrect file data\n");
1031 win_skip(
"fputwc tests on unicode files\n");
1041 static const char mytext[]=
"This is test_ctrlz";
1047 tempfh =
fopen(tempf,
"wb");
1048 fputs(mytext,tempfh);
1058 tempfh =
fopen(tempf,
"rt");
1059 ok(
fgets(
buffer,256,tempfh) != 0,
"fgets failed unexpected\n");
1062 ok(
i==
j,
"returned string length expected %d got %d\n",
j,
i);
1065 ok(
l==
j,
"ftell expected %d got %d\n",
j,
l);
1066 ok(
feof(tempfh),
"did not get EOF\n");
1069 tempfh =
fopen(tempf,
"rb");
1070 ok(
fgets(
buffer,256,tempfh) != 0,
"fgets failed unexpected\n");
1073 ok(
i==
j,
"returned string length expected %d got %d\n",
j,
i);
1075 ok(
l==
j,
"ftell expected %d got %d\n",
j,
l);
1076 ok(
fgets(
buffer,256,tempfh) != 0,
"fgets failed unexpected\n");
1078 ok(
i==1,
"returned string length expected %d got %d\n", 1,
i);
1079 ok(
feof(tempfh),
"did not get EOF\n");
1089 static const char mytext[]=
"This is a test_file_put_get\n";
1090 static const char dostext[]=
"This is a test_file_put_get\r\n";
1098 tempfh =
fopen(tempf,
"wt");
1099 fputs(mytext,tempfh);
1101 tempfh =
fopen(tempf,
"rb");
1103 ok(
strlen(mytext) + 1 ==
strlen(btext),
"TEXT/BINARY mode not handled for write\n");
1104 ok( btext[
strlen(mytext)-1] ==
'\r',
"CR not written\n");
1106 tempfh =
fopen(tempf,
"wb");
1107 fputs(dostext,tempfh);
1109 tempfh =
fopen(tempf,
"rt");
1111 ok(
strcmp(btext, mytext) == 0,
"_O_TEXT read doesn't strip CR\n");
1113 tempfh =
fopen(tempf,
"rb");
1115 ok(
strcmp(btext, dostext) == 0,
"_O_BINARY read doesn't preserve CR\n");
1118 tempfh =
fopen(tempf,
"rt");
1120 mytextW =
AtoW (mytext);
1124 for (
i=0;
i<
strlen(mytext);
i++, aptr++, wptr++)
1126 diff_found |= (*aptr != *wptr);
1128 ok(!(diff_found),
"fgetwc doesn't strip CR in TEXT mode\n");
1139 static const char mytext[]=
"This is test_file_write_read\nsecond line\n";
1140 static const char dostext[]=
"This is test_file_write_read\r\nsecond line\r\n";
1148 "Can't open '%s': %d\n", tempf,
errno);
1150 "_write _O_BINARY bad return value\n");
1155 "_read _O_BINARY got bad length\n");
1157 "problems with _O_BINARY _write / _read\n");
1161 "_read _O_TEXT got bad length\n");
1163 "problems with _O_BINARY _write / _O_TEXT _read\n");
1168 "Can't open '%s': %d\n", tempf,
errno);
1170 "_write _O_TEXT bad return value\n");
1174 "_read _O_BINARY got bad length\n");
1176 "problems with _O_TEXT _write / _O_BINARY _read\n");
1177 ok( btext[
strlen(dostext)-2] ==
'\r',
"CR not written or read\n");
1181 "_read _O_TEXT got bad length\n");
1183 "problems with _O_TEXT _write / _read\n");
1188 ok(
tell(tempfd) == 0,
"bad position %u expecting 0\n",
tell(tempfd));
1190 ok(
memcmp(mytext,btext,
strlen(mytext)) == 0,
"problems with _O_APPEND _read\n");
1197 ok(
ret == 1 && *btext ==
'\n',
"_read expected 1 got bad length: %d\n",
ret);
1200 ok(
ret == 1 && *btext ==
'\n',
"_read expected '\\n' got bad length: %d\n",
ret);
1203 ok(
ret == 1 && *btext ==
'\n',
"_read returned %d, buf: %d\n",
ret, *btext);
1205 ok(
ret == 0,
"_read returned %d, expected 0\n",
ret);
1208 ok(
ret == 1 && *btext ==
'e',
"_read expected 'e' got \"%.*s\" bad length: %d\n",
ret, btext,
ret);
1209 ok(
tell(tempfd) == 41,
"bad position %u expecting 41\n",
tell(tempfd));
1212 ok(
ret == 1 && *btext ==
'e',
"_read expected 'e' got \"%.*s\" bad length: %d\n",
ret, btext,
ret);
1213 ok(
tell(tempfd) == 42,
"bad position %u expecting 42\n",
tell(tempfd));
1216 ok(
ret == 2 && *btext ==
'e',
"_read expected 'e' got \"%.*s\" bad length: %d\n",
ret, btext,
ret);
1217 ok(
tell(tempfd) == 43,
"bad position %u expecting 43\n",
tell(tempfd));
1221 ok(
ret == 0 ,
"Can't unlink '%s': %d\n", tempf,
errno);
1227 "Can't open '%s': %d\n", tempf,
errno);
1229 "_write _O_BINARY bad return value\n");
1233 "_read _O_BINARY got bad length\n");
1235 "problems with _O_BINARY _write / _read\n");
1236 ok( btext[
strlen(dostext)-2] ==
'\r',
"CR not written or read\n");
1240 "_read _O_TEXT got bad length\n");
1242 "problems with _O_BINARY _write / _O_TEXT _read\n");
1249 _read(tempfd,btext, 1);
1250 ok(btext[0] == mytext[
i],
"_read failed at pos %d 0x%02x vs 0x%02x\n",
i, btext[0], mytext[
i]);
1252 while (
_read(tempfd,btext, 1));
1258 ok(
i ==
strlen(mytext)-1,
"_read_i %d\n",
i);
1265 ok(tempfd != -1,
"_open failed with error: %d\n",
errno);
1267 ok(
ret == -1,
"_write returned %d, expected -1\n",
ret);
1268 ret =
_write(tempfd,
"a\x00\n\x00\xff\xff", 6);
1269 ok(
ret == 6,
"_write returned %d, expected 6\n",
ret);
1273 ok(tempfd != -1,
"_open failed with error: %d\n",
errno);
1274 ret =
_read(tempfd, btext,
sizeof(btext));
1275 ok(
ret == 10,
"_read returned %d, expected 10\n",
ret);
1276 ok(!
memcmp(btext,
"\xff\xfe\x61\x00\r\x00\n\x00\xff\xff", 10),
"btext is incorrect\n");
1280 ok(tempfd != -1,
"_open failed with error: %d\n",
errno);
1283 ok(
ret == -1,
"_read returned %d, expected -1\n",
ret);
1285 ret =
_read(tempfd, btext,
sizeof(btext));
1286 ok(
ret == 6,
"_read returned %d, expected 6\n",
ret);
1287 ok(!
memcmp(btext,
"\x61\x00\n\x00\xff\xff", 6),
"btext is incorrect\n");
1291 ok(tempfd != -1,
"_open failed with error: %d\n",
errno);
1294 ok(
ret == -1,
"_write returned %d, expected -1\n",
ret);
1296 ret =
_write(tempfd,
"a\x00\n\x00\x62\x00", 6);
1297 ok(
ret == 6,
"_write returned %d, expected 6\n",
ret);
1301 ok(tempfd != -1,
"_open failed with error: %d\n",
errno);
1302 ret =
_read(tempfd, btext,
sizeof(btext));
1303 ok(
ret == 7,
"_read returned %d, expected 7\n",
ret);
1304 ok(!
memcmp(btext,
"\xef\xbb\xbf\x61\r\n\x62", 7),
"btext is incorrect\n");
1308 ok(tempfd != -1,
"_open failed with error: %d\n",
errno);
1309 ret =
_read(tempfd, btext,
sizeof(btext));
1310 ok(
ret == 6,
"_read returned %d, expected 6\n",
ret);
1311 ok(!
memcmp(btext,
"\x61\x00\n\x00\x62\x00", 6),
"btext is incorrect\n");
1320 ok(
ret == 2,
"_read returned %d, expected 2\n",
ret);
1321 ok(!
memcmp(btext,
"\x62\x00", 2),
"btext is incorrect\n");
1325 ok(tempfd != -1,
"_open failed with error: %d\n",
errno);
1326 ret =
_write(tempfd,
"\xef\xbb\xbf\x61\xc4\x85\x62\xc5\xbc\r\r\n", 12);
1327 ok(
ret == 12,
"_write returned %d, expected 9\n",
ret);
1331 ok(tempfd != -1,
"_open failed with error: %d\n",
errno);
1332 ret =
_read(tempfd, btext,
sizeof(btext));
1333 ok(
ret == 12,
"_read returned %d, expected 12\n",
ret);
1334 ok(!
memcmp(btext,
"\x61\x00\x05\x01\x62\x00\x7c\x01\x0d\x00\x0a\x00", 12),
"btext is incorrect\n");
1338 ret =
_read(tempfd, btext,
sizeof(btext));
1341 todo_wine ok(!
memcmp(btext,
"\xfd\xff", 2),
"invalid UTF8 character was not replaced by U+FFFD\n");
1342 ok(!
memcmp(btext+
ret-8,
"\x62\x00\x7c\x01\x0d\x00\x0a\x00", 8),
"btext is incorrect\n");
1347 win_skip(
"unicode mode tests on file\n");
1352 "Can't chmod '%s' to read-write: %d\n", tempf,
errno);
1354 ok(
ret == 0 ,
"Can't unlink '%s': %d\n", tempf,
errno);
1368 ok(
memcmp(
buffer,
"Success", 8) == 0,
"Couldn't read back the data\n");
1378 "Wrong write result in child process on %d (%s)\n",
fd,
strerror(
errno));
1396 wxflag_ptr[
i] = 0x81;
1420 sa.nLength =
sizeof(
sa);
1421 sa.lpSecurityDescriptor =
NULL;
1422 sa.bInheritHandle =
TRUE;
1428 startup->hStdOutput = hErrorFile;
1437 ok(
strcmp(
data,
"Success" ),
"%s: Error file shouldn't contain data\n",
descr );
1447 ok(
strcmp(
data,
"Success" ),
"%s: Stdout file shouldn't contain data\n",
descr );
1457 const char* arg_v[5];
1465 ok(
fd != -1,
"Couldn't create test file\n");
1467 arg_v[1] =
"tests/file.c";
1468 arg_v[2] =
"inherit";
1476 ok(
unlink(
"fdopen.tst") == 0,
"Couldn't unlink\n");
1479 ok(
fd != -1,
"Couldn't create test file\n");
1480 arg_v[1] =
"tests/file.c";
1481 arg_v[2] =
"inherit_no";
1488 ok(
unlink(
"fdopen.tst") == 0,
"Couldn't unlink\n");
1491 sa.nLength =
sizeof(
sa);
1492 sa.lpSecurityDescriptor =
NULL;
1493 sa.bInheritHandle =
TRUE;
1516 *(
unsigned int *)
startup.lpReserved2 = 0;
1563 ok(
info->wxflag == 0xc1,
"info->wxflag = %x\n",
info->wxflag);
1569 ok(!
ret,
"fread(stdin) returned %d\n",
ret);
1574 ok(
ret == -1,
"read(-2) returned %d\n",
ret);
1579 ok(
ret == -1,
"read(STDIN_FILENO) returned %d\n",
ret);
1584 ok(
ret ==
EOF,
"_flsbuf(stdin) returned %d\n",
ret);
1589 ok(!
ret,
"fwrite(stdin) returned %d\n",
ret);
1594 ok(
ret == -1,
"write(-2) returned %d\n",
ret);
1599 ok(
ret == -1,
"write(STDIN_FILENO) returned %d\n",
ret);
1604 ok(
ret == -1,
"fclose(stdin) returned %d\n",
ret);
1609 ok(
ret == -1,
"close(-2) returned %d\n",
ret);
1614 ok(
ret==-1 || !
ret,
"close(STDIN_FILENO) returned %d\n",
ret);
1629 win_skip(
"skipping invalid stdin tests\n");
1634 ok(!
ret,
"RegOpenCurrentUser failed: %x\n",
ret);
1636 sa.nLength =
sizeof(
sa);
1637 sa.lpSecurityDescriptor =
NULL;
1638 sa.bInheritHandle =
TRUE;
1653 ok(!
ret,
"RegCloseKey failed: %x\n",
ret);
1662 ok(
res !=
NULL,
"tmpnam returned NULL\n");
1663 ok(
res[0] ==
'\\',
"first character is not a backslash\n");
1664 ok(
strchr(
res+1,
'\\') == 0,
"file not in the root directory\n");
1665 ok(
res[
strlen(
res)-1] ==
'.',
"first call - last character is not a dot\n");
1668 ok(
res !=
NULL,
"tmpnam returned NULL\n");
1669 ok(
res ==
name,
"supplied buffer was not used\n");
1670 ok(
res[0] ==
'\\',
"first character is not a backslash\n");
1671 ok(
strchr(
res+1,
'\\') == 0,
"file not in the root directory\n");
1672 ok(
res[
strlen(
res)-1] !=
'.',
"second call - last character is a dot\n");
1679 char temptext[] =
"012345678";
1680 char *tempfile =
_tempnam(
".",
"tst" );
1682 ok( tempfile !=
NULL,
"Couldn't create test file: %s\n", tempfile );
1685 ok(
fd > 0,
"Couldn't open test file\n" );
1688 ok(
count > 0,
"Couldn't write to test file\n" );
1694 ok(
_chsize(
fd,
sizeof(temptext) / 2 ) == 0,
"_chsize() failed\n" );
1697 ok(
cur ==
pos,
"File pointer changed from: %d to: %d\n",
cur,
pos );
1701 ok(
_chsize(
fd,
sizeof(temptext) * 2 ) == 0,
"_chsize() failed\n" );
1704 ok(
cur ==
pos,
"File pointer changed from: %d to: %d\n",
cur,
pos );
1714 char fname1[] =
"empty1";
1715 char fname2[] =
"empty2";
1716 char fname3[] =
"empty3";
1717 FILE *stream1, *stream2, *stream3, *stream4;
1721 stream1 =
fopen(fname1,
"w+");
1722 ok(stream1 !=
NULL,
"The file '%s' was not opened\n", fname1);
1723 stream2 =
fopen(fname2,
"w ");
1724 ok(stream2 !=
NULL,
"The file '%s' was not opened\n", fname2 );
1726 stream3 =
fopen(fname3,
"r");
1727 ok(stream3 ==
NULL,
"The file '%s' shouldn't exist before\n", fname3 );
1728 stream3 =
fopen(fname3,
"w+");
1729 ok(stream3 !=
NULL,
"The file '%s' should be opened now\n", fname3 );
1731 stream4 =
fopen(
"",
"w+");
1733 "filename is empty, errno = %d (expected 2 or 22)\n",
errno);
1737 "filename is NULL, errno = %d (expected 2 or 22)\n",
errno);
1741 ok(
ret == 0,
"The file '%s' was not closed\n", fname2);
1743 ok(
ret == 0,
"The file '%s' was not closed\n", fname3);
1746 ok(
ret ==
EOF,
"Closing file '%s' returned %d\n", fname2,
ret);
1749 ok(
ret ==
EOF,
"Closing file '%s' returned %d\n", fname3,
ret);
1755 ok(numclosed == 1,
"Number of files closed by fcloseall(): %u\n", numclosed);
1757 ok(numclosed == 0,
"Number of files closed by fcloseall(): %u\n", numclosed);
1759 ok(
_unlink(fname1) == 0,
"Couldn't unlink file named '%s'\n", fname1);
1760 ok(
_unlink(fname2) == 0,
"Couldn't unlink file named '%s'\n", fname2);
1761 ok(
_unlink(fname3) == 0,
"Couldn't unlink file named '%s'\n", fname3);
1766 const char name[] =
"empty1";
1768 unsigned char *ubuff = (
unsigned char*)
buff;
1775 win_skip(
"Skipping fopen_s test\n");
1780 ok(
ret == 0,
"fopen_s failed with %d\n",
ret);
1781 ok(
file != 0,
"fopen_s failed to return value\n");
1785 ok(
ret !=
EOF,
"File failed to close\n");
1788 ok(
file != 0,
"fopen failed\n");
1795 ok(
ret !=
EOF,
"File failed to close\n");
1798 ok(
ret == 0,
"fopen_s failed with %d\n",
ret);
1800 ok(
ret == 2,
"fwrite returned %d\n",
ret);
1804 ok(
ret == 0,
"fopen_s failed with %d\n",
ret);
1807 ok(ubuff[0]==0xff && ubuff[1]==0xfe,
"buff[0]=%02x, buff[1]=%02x\n",
1808 ubuff[0], ubuff[1]);
1812 ok(
ret == 0,
"fopen_s failed with %d\n",
ret);
1815 ok(ubuff[0]==
'a' && ubuff[1]==0,
"buff[0]=%02x, buff[1]=%02x\n",
1816 ubuff[0], ubuff[1]);
1820 ok(
ret == 0,
"fopen_s failed with %d\n",
ret);
1823 ok(ubuff[0]==
'a' && ubuff[1]==0,
"buff[0]=%02x, buff[1]=%02x\n",
1824 ubuff[0], ubuff[1]);
1828 ok(
ret == 0,
"fopen_s failed with %d\n",
ret);
1831 ok(ubuff[0]==
'a' && ubuff[1]==0,
"buff[0]=%02x, buff[1]=%02x\n",
1832 ubuff[0], ubuff[1]);
1836 ok(
ret == 0,
"fopen_s failed with %d\n",
ret);
1840 ok(
ret == 0,
"fopen_s failed with %d\n",
ret);
1843 ok(ubuff[0]==0xff && ubuff[1]==0xfe,
"buff[0]=%02x, buff[1]=%02x\n",
1844 ubuff[0], ubuff[1]);
1848 ok(
ret == 0,
"fopen_s failed with %d\n",
ret);
1852 ok(
ret == 0,
"fopen_s failed with %d\n",
ret);
1855 ok(ubuff[0]==0xef && ubuff[1]==0xbb && ubuff[2]==0xbf,
1856 "buff[0]=%02x, buff[1]=%02x, buff[2]=%02x\n",
1857 ubuff[0], ubuff[1], ubuff[2]);
1863 ret = p_fopen_s(&file2,
name,
"r");
1864 ok(!
ret,
"fopen_s failed with %d\n",
ret);
1865 ok(
file == file2,
"file != file2 %p %p\n",
file, file2);
1866 ok(!
file->_ptr,
"file->_ptr != NULL\n");
1867 ok(!
file->_cnt,
"file->_cnt != 0\n");
1868 ok(!
file->_base,
"file->_base != NULL\n");
1869 ok(
file->_flag == 1,
"file->_flag = %x\n",
file->_flag);
1870 ok(
file->_file,
"file->_file == 0\n");
1871 ok(
file->_charbuf == 0xfefefefe,
"file->_charbuf = %x\n",
file->_charbuf);
1872 ok(
file->_bufsiz == 0xfefefefe,
"file->_bufsiz = %x\n",
file->_bufsiz);
1873 ok(!
file->_tmpfname,
"file->_tmpfname != NULL\n");
1881 const char name[] =
"empty1";
1882 const WCHAR wname[] = {
1883 'e',
'm',
'p',
't',
'y',
'1',0
1885 const WCHAR wmode[] = {
1895 win_skip(
"Skipping _wfopen_s test\n");
1899 ret = p__wfopen_s(&
file, wname, wmode);
1900 ok(
ret == 0,
"_wfopen_s failed with %d\n",
ret);
1901 ok(
file != 0,
"_wfopen_s failed to return value\n");
1905 ok(
ret !=
EOF,
"File failed to close\n");
1908 ok(
file != 0,
"fopen failed\n");
1915 ok(
ret !=
EOF,
"File failed to close\n");
1922 const char name[] =
"empty1";
1926 win_skip(
"unicode file modes are not available, skipping setmode tests\n");
1932 ok(
ret == -1,
"_setmode returned %x, expected -1\n",
ret);
1937 ok(
ret == -1,
"_setmode returned %x, expected -1\n",
ret);
1941 ok(
fd != -1,
"failed to open file\n");
1945 ok(
ret == -1,
"_setmode returned %x, expected -1\n",
ret);
1950 ok(
ret == -1,
"_setmode returned %x, expected -1\n",
ret);
1955 ok(
ret == -1,
"_setmode returned %x, expected -1\n",
ret);
1960 ok(
ret == -1,
"_setmode returned %x, expected -1\n",
ret);
1988 char fname[] =
"t_get_osfhanle";
1989 DWORD bytes_written;
1997 ok(
fd != -1,
"Couldn't open '%s' after _get_osfhandle()\n", fname);
2028 ok((
buf.st_mode & 0777) == 0666,
"bad st_mode = %06o\n",
buf.st_mode);
2029 ok(
buf.st_dev == 0,
"st_dev is %d, expected 0\n",
buf.st_dev);
2030 ok(
buf.st_dev ==
buf.st_rdev,
"st_dev (%d) and st_rdev (%d) differ\n",
buf.st_dev,
buf.st_rdev);
2031 ok(
buf.st_nlink == 1,
"st_nlink is %d, expected 1\n",
buf.st_nlink);
2032 ok(
buf.st_size == 0,
"st_size is %d, expected 0\n",
buf.st_size);
2037 ok((
buf.st_mode & 0777) == 0666,
"bad st_mode = %06o\n",
buf.st_mode);
2038 ok(
buf.st_dev ==
buf.st_rdev,
"st_dev (%d) and st_rdev (%d) differ\n",
buf.st_dev,
buf.st_rdev);
2039 ok(
buf.st_nlink == 1,
"st_nlink is %d, expected 1\n",
buf.st_nlink);
2040 ok(
buf.st_size == 0,
"st_size is %d, expected 0\n",
buf.st_size);
2044 ok(
ret == -1,
"stat returned %d\n",
ret);
2051 skip(
"open failed with errno %d\n",
errno);
2054 if (
_dup2(0, 10) == 0)
2057 ok(!
ret,
"fstat(stdin) failed: errno=%d\n",
errno);
2061 ok(
buf.st_dev == 10,
"st_dev is %d, expected 10\n",
buf.st_dev);
2062 ok(
buf.st_rdev == 10,
"st_rdev is %d, expected 10\n",
buf.st_rdev);
2063 ok(
buf.st_nlink == 1,
"st_nlink is %d, expected 1\n",
buf.st_nlink);
2066 skip(
"stdin is not a char device? st_mode=%06o\n",
buf.st_mode);
2070 skip(
"_dup2 failed with errno %d\n",
errno);
2076 ok(!
ret,
"fstat(pipe) failed: errno=%d\n",
errno);
2078 ok(
buf.st_dev == pipes[0],
"st_dev is %d, expected %d\n",
buf.st_dev, pipes[0]);
2079 ok(
buf.st_rdev == pipes[0],
"st_rdev is %d, expected %d\n",
buf.st_rdev, pipes[0]);
2080 ok(
buf.st_nlink == 1,
"st_nlink is %d, expected 1\n",
buf.st_nlink);
2085 skip(
"pipe failed with errno %d\n",
errno);
2088 if(
mkdir(
"stat.tst") == 0)
2091 ok(!
ret,
"stat(directory) failed: errno=%d\n",
errno);
2093 ok((
buf.st_mode & 0777) == 0777,
"bad st_mode = %06o\n",
buf.st_mode);
2094 ok(
buf.st_dev ==
buf.st_rdev,
"st_dev (%d) and st_rdev (%d) differ\n",
buf.st_dev,
buf.st_rdev);
2095 ok(
buf.st_nlink == 1,
"st_nlink is %d, expected 1\n",
buf.st_nlink);
2099 ok(
ret == -1,
"stat returned %d\n",
ret);
2101 rmdir(
"stat.tst" );
2104 skip(
"mkdir failed with errno %d\n",
errno);
2108 ok(
ret == -1,
"stat returned %d\n",
ret);
2112 ok(!
ret,
"stat returned %d\n",
ret);
2113 ok(
buf.st_dev == 2,
"st_dev = %d\n",
buf.st_dev);
2114 ok(
buf.st_rdev == 2,
"st_rdev = %d\n",
buf.st_rdev);
2120 #define N_TEST_MESSAGES 3 2130 ok(0,
"not enough parameters: %d\n",
argc);
2136 ok(!
i,
"unable to close %d: %d\n",
fd,
errno);
2149 ok(!
i,
"unable to close %d: %d\n",
fd,
errno);
2155 char str_fdr[12], str_fdw[12];
2157 const char* arg_v[6];
2166 ok(0,
"pipe failed with errno %d\n",
errno);
2171 arg_v[1] =
"tests/file.c";
2173 arg_v[3] = str_fdr;
sprintf(str_fdr,
"%d", pipes[0]);
2174 arg_v[4] = str_fdw;
sprintf(str_fdw,
"%d", pipes[1]);
2178 ok(!
i,
"unable to close %d: %d\n", pipes[1],
errno);
2189 ok(
r == 0,
"expected to read 0 bytes, got %d\n",
r);
2191 ok(!
i,
"unable to close %d: %d\n", pipes[0],
errno);
2196 ok(0,
"pipe failed with errno %d\n",
errno);
2200 arg_v[1] =
"tests/file.c";
2202 arg_v[3] = str_fdr;
sprintf(str_fdr,
"%d", pipes[0]);
2203 arg_v[4] = str_fdw;
sprintf(str_fdw,
"%d", pipes[1]);
2207 ok(!
i,
"unable to close %d: %d\n", pipes[1],
errno);
2226 ok(
r == 0,
"fread() returned %d instead of 0\n",
r);
2231 ok(!
i,
"unable to close the pipe: %d\n",
errno);
2236 ok(0,
"pipe failed with errno %d\n",
errno);
2239 r =
write(pipes[1],
"\r\n\rab\r\n", 7);
2240 ok(
r == 7,
"write returned %d, errno = %d\n",
r,
errno);
2243 ok(
r == 1,
"read returned %d, expected 1\n",
r);
2244 ok(
buf[0] ==
'\n',
"buf[0] = %x, expected '\\n'\n",
buf[0]);
2246 ok(
r == 1,
"read returned %d, expected 1\n",
r);
2247 ok(
buf[0] ==
'\r',
"buf[0] = %x, expected '\\r'\n",
buf[0]);
2249 ok(
r == 1,
"read returned %d, expected 1\n",
r);
2250 ok(
buf[0] ==
'a',
"buf[0] = %x, expected 'a'\n",
buf[0]);
2252 ok(
r == 2,
"read returned %d, expected 1\n",
r);
2253 ok(
buf[0] ==
'b',
"buf[0] = %x, expected 'b'\n",
buf[0]);
2254 ok(
buf[1] ==
'\n',
"buf[1] = %x, expected '\\n'\n",
buf[1]);
2259 r =
write(pipes[1],
"a\0b", 3);
2260 ok(
r == 3,
"write returned %d, errno = %d\n",
r,
errno);
2265 ok(
r == 2,
"read returned %d, expected 2\n",
r);
2266 ok(!
memcmp(
buf,
"a\0bz", 4),
"read returned incorrect data\n");
2267 r =
write(pipes[1],
"\0", 1);
2268 ok(
r == 1,
"write returned %d, errno = %d\n",
r,
errno);
2272 ok(
r == 0,
"read returned %d, expected 0\n",
r);
2273 ok(!
memcmp(
buf,
"\0z", 2),
"read returned incorrect data\n");
2277 win_skip(
"unicode mode tests on pipe\n");
2287 ok(
mkdir(
"test_unlink") == 0,
"unable to create test dir\n");
2288 file =
fopen(
"test_unlink\\empty",
"w");
2289 ok(
file !=
NULL,
"unable to create test file\n");
2292 ok(
_unlink(
"test_unlink") != 0,
"unlinking a non-empty directory must fail\n");
2293 unlink(
"test_unlink\\empty");
2294 rmdir(
"test_unlink");
2299 ok(-1 ==
_dup2(0, -1),
"expected _dup2 to fail when second arg is negative\n" );
2310 ok(stdin_dup != -1,
"_dup(STDIN_FILENO) failed\n");
2313 "GetStdHandle(STD_INPUT_HANDLE) != _get_osfhandle(STDIN_FILENO)\n");
2316 ok(
r ==
TRUE,
"SetStdHandle returned %x, expected TRUE\n",
r);
2325 ok(
fd != -1,
"open failed\n");
2333 ok(
r != -1,
"_dup2 failed\n");
2352 ok(!
_mktemp(
buf),
"_mktemp(\"testXXXXXXa\") != NULL\n");
2366 ok(
fd == -1,
"_open_osfhandle returned %d\n",
fd);
2371 ok(
fd > 0,
"_open_osfhandle returned %d (%d)\n",
fd,
errno);
2373 ok(
info->handle ==
h,
"info->handle = %p, expected %p\n",
info->handle,
h);
2374 ok(
info->wxflag == 1,
"info->wxflag = %x, expected 1\n",
info->wxflag);
2377 ok(
info->wxflag == 0,
"info->wxflag = %x, expected 0\n",
info->wxflag);
2382 ok(
fd == -1,
"_open_osfhandle returned %d\n",
fd);
2387 ok(
fd > 0,
"_open_osfhandle returned %d (%d)\n",
fd,
errno);
2389 ok(
info->handle ==
h,
"info->handle = %p, expected %p\n",
info->handle,
h);
2390 ok(
info->wxflag == 9,
"info->wxflag = %x, expected 9\n",
info->wxflag);
2405 _snprintf(
outbuffer,
bufsize + 1,
"0,1,2,3,4,5,6,7,8,9");
2409 ok(
file->_cnt == 0,
"_cnt should be 0 after rewind, but is %d\n",
file->_cnt);
2416 ok(
file->_cnt == 0,
"_cnt should be 0 after fflush, but is %d\n",
file->_cnt);
2437 ok(!
file->_cnt,
"file->_cnt = %d\n",
file->_cnt);
2438 ok(
file->_ptr !=
file->_base,
"file->_ptr == file->_base\n");
2441 ok(!
file->_cnt,
"file->_cnt = %d\n",
file->_cnt);
2442 ok(
file->_ptr ==
file->_base,
"file->_ptr == file->_base\n");
2457 ok(
file !=
NULL,
"unable to create test file\n");
2459 ok(
file->_bufsiz == 4096,
"incorrect default buffer size: %d\n",
file->_bufsiz);
2470 ioinfo *stdout_info, stdout_copy, *stderr_info, stderr_copy;
2471 int fd1, fd2, ret1, ret2, ret3, ret4;
2481 ok(fd1 != -1,
"_open_osfhandle failed (%d)\n",
errno);
2483 ok(fd2 != -1,
"_open_osfhandle failed (%d)\n",
errno);
2484 ok(fd1 != fd2,
"fd1 == fd2\n");
2491 ok(!ret1,
"close(fd1) failed (%d)\n",
errno);
2493 ok(
close(fd2),
"close(fd2) succeeded\n");
2498 ok(ret1 == -1,
"close(fd1) succeeded\n");
2509 stdout_copy = *stdout_info;
2510 stderr_copy = *stderr_info;
2519 *stdout_info = stdout_copy;
2520 *stderr_info = stderr_copy;
2525 ok(!ret1,
"close(STDOUT_FILENO) failed\n");
2526 ok(ret2,
"GetHandleInformation failed\n");
2527 ok(!ret3,
"close(STDERR_FILENO) failed\n");
2528 ok(!ret4,
"GetHandleInformation succeeded\n");
2535 int fd,
pos,
count, readonly, old_fmode = 0, have_fmode;
2536 char buf[6],
testdata[4] = {
'a',
'\n',
'b',
'\n'};
2538 have_fmode = p__get_fmode && p__set_fmode && !p__get_fmode(&old_fmode);
2540 win_skip(
"_fmode can't be set, skipping mode tests\n");
2545 ok(
fd > 0,
"_creat failed\n");
2549 ok(
pos == 6,
"expected pos 6 (text mode), got %d\n",
pos);
2553 ok(
count == 4,
"_read returned %d, expected 4\n",
count);
2558 ok(readonly,
"expected read-only file\n");
2565 ok(
fd > 0,
"_creat failed\n");
2569 ok(
pos == 4,
"expected pos 4 (binary mode), got %d\n",
pos);
2573 ok(
count == 4,
"_read returned %d, expected 4\n",
count);
2578 ok(!readonly,
"expected rw file\n");
2583 p__set_fmode(old_fmode);
2598 if (
strcmp(arg_v[2],
"inherit") == 0)
2600 else if (
strcmp(arg_v[2],
"inherit_no") == 0)
2602 else if (
strcmp(arg_v[2],
"pipes") == 0)
2604 else if (
strcmp(arg_v[2],
"stdin") == 0)
2607 ok(0,
"invalid argument '%s'\n", arg_v[2]);
static unsigned int block
static void test_write_flush_size(FILE *file, int bufsize)
static void test_file_put_get(void)
static HANDLE PIO_APC_ROUTINE void PIO_STATUS_BLOCK void ULONG PLARGE_INTEGER PULONG key
static void test_stdout_handle(STARTUPINFOA *startup, char *cmdline, HANDLE hstdout, BOOL expect_stdout, const char *descr)
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
const unsigned char * inbuffer
LONG CDECL _filelength(int fd)
int CDECL fsetpos(FILE *file, const fpos_t *pos)
unsigned char ** outbuffer
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
_Check_return_ _CRTIMP long __cdecl tell(_In_ int _FileHandle)
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
static void test_fflush(void)
int CDECL _flsbuf(int c, FILE *file)
static struct object_header ** handles
static void test_asciimode2(void)
#define WideCharToMultiByte
int CDECL fseek(FILE *file, long offset, int whence)
char * strcat(char *DstString, const char *SrcString)
static const char * get_base_name(const char *path)
static void test_chsize(void)
ACPI_SIZE strlen(const char *String)
static void test_stdin(void)
LONG CDECL ftell(FILE *file)
GLdouble GLdouble GLdouble r
static void test__wfopen_s(void)
char *CDECL _mktemp(char *pattern)
GLuint GLuint GLsizei count
static void test_fdopen(void)
void CDECL setbuf(FILE *file, char *buf)
static int(__cdecl *p_fopen_s)(FILE **
wint_t CDECL fputwc(wchar_t c, FILE *stream)
__MINGW_EXTENSION typedef __int64 fpos_t
#define INVALID_HANDLE_VALUE
char *CDECL _tempnam(const char *dir, const char *prefix)
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
int startup(int argc, const char *argv[])
int CDECL _pipe(int *pfds, unsigned int psize, int textmode)
_Check_return_opt_ _CRTIMP long __cdecl lseek(_In_ int _FileHandle, _In_ long _Offset, _In_ int _Origin)
#define CREATE_DEFAULT_ERROR_MODE
static void test_readboundary(void)
int CDECL feof(FILE *file)
#define NORMAL_PRIORITY_CLASS
GLenum GLuint GLsizei bufsize
int CDECL _creat(const char *path, int flags)
DWORD WINAPI WaitForMultipleObjects(IN DWORD nCount, IN CONST HANDLE *lpHandles, IN BOOL bWaitAll, IN DWORD dwMilliseconds)
int CDECL _setmode(int fd, int mode)
static void test_unlink(void)
static void test_fopen_s(void)
const char * strerror(int err)
int CDECL _getw(FILE *file)
GLfloat GLfloat GLfloat GLfloat h
static void test_filbuf(void)
static HANDLE PIO_APC_ROUTINE void PIO_STATUS_BLOCK void * buffer
#define sprintf(buf, format,...)
GLenum GLuint GLenum GLsizei const GLchar * buf
static void test_asciimode(void)
int CDECL getc(FILE *file)
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
static void test_fileops(void)
int CDECL fputws(const wchar_t *s, FILE *file)
DWORD WINAPI GetFileAttributesA(LPCSTR lpFileName)
static void test_fputwc(void)
static struct _test_info info[]
int CDECL _read(int fd, void *buf, unsigned int count)
int CDECL fgetpos(FILE *file, fpos_t *pos)
static void test_file_inherit_child(const char *fd_s)
int CDECL _filbuf(FILE *file)
static void test_file_inherit(const char *selfname)
static void test__creat(void)
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
BOOL WINAPI SetFileAttributesA(LPCSTR lpFileName, DWORD dwFileAttributes)
int CDECL _sopen(const char *path, int oflags, int shflags,...)
int CDECL _setmaxstdio(int newmax)
static void test_tmpnam(void)
static void test__open_osfhandle(void)
static void test_close(void)
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 GLint GLint j
#define STARTF_USESTDHANDLES
static void test_invalid_stdin_child(void)
static void test_pipes(const char *selfname)
static void test_fgetwc_locale(const char *text, const char *locale, int codepage)
int CDECL _fcloseall(void)
static void test_fgetwc_unicode(void)
_Check_return_ _CRTIMP int __cdecl fileno(_In_ FILE *_File)
static const char const char *static const wchar_t const wchar_t *static errno_t(__cdecl *p__get_fmode)(int *)
void CDECL rewind(FILE *file)
#define MSVCRT_FD_BLOCK_SIZE
int CDECL fputc(int c, FILE *file)
static const char * read_file(HANDLE file)
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
size_t CDECL fwrite(const void *ptr, size_t size, size_t nmemb, FILE *file)
int CDECL _unlink(const char *path)
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
#define FILE_ATTRIBUTE_READONLY
int CDECL _write(int fd, const void *buf, unsigned int count)
static void create_io_inherit_block(STARTUPINFOA *startup, unsigned int count, const HANDLE *handles)
FILE *CDECL fopen(const char *path, const char *mode)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
static void test_get_osfhandle(void)
int winetest_get_mainargs(char ***pargv)
static void test_fgetwc(void)
static void test_setmode(void)
int CDECL ungetc(int c, FILE *file)
BOOL WINAPI DECLSPEC_HOTPATCH SetStdHandle(DWORD nStdHandle, HANDLE hHandle)
#define FILE_ATTRIBUTE_NORMAL
int CDECL _chsize(int fd, long size)
static void test_file_inherit_child_no(const char *fd_s)
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
LONG CDECL _lseek(int fd, LONG offset, int whence)
#define STD_OUTPUT_HANDLE
int CDECL remove(const char *path)
int CDECL _chmod(const char *path, int flags)
BOOL WINAPI CreatePipe(PHANDLE hReadPipe, PHANDLE hWritePipe, LPSECURITY_ATTRIBUTES lpPipeAttributes, DWORD nSize)
_Check_return_ _CRTIMP int __cdecl setmode(_In_ int _FileHandle, _In_ int _Mode)
static void test_write_flush(void)
static PEXPLICIT_ACCESSW *static HMODULE hmod
GLenum GLsizei GLuint GLint * bytesWritten
void winetest_wait_child_process(HANDLE process)
int CDECL fflush(FILE *file)
_CRTIMP int __cdecl stat(const char *_Filename, struct stat *_Stat)
int CDECL _fileno(FILE *file)
static void test_stat(void)
int WINAPI lstrlenA(LPCSTR lpString)
int CDECL ferror(FILE *file)
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
static void test_pipes_child(int argc, char **args)
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
wint_t CDECL fgetwc(FILE *file)
char *CDECL fgets(char *s, int size, FILE *file)
wchar_t *CDECL fgetws(wchar_t *s, int size, FILE *file)
#define ReadFile(a, b, c, d, e)
_Check_return_ _CRTIMP FILE *__cdecl fdopen(_In_ int _FileHandle, _In_z_ const char *_Format)
size_t CDECL fread(void *ptr, size_t size, size_t nmemb, FILE *file)
#define MultiByteToWideChar
static void test_fopen_fclose_fcloseall(void)
char * strchr(const char *String, int ch)
int CDECL _open(const char *path, int flags,...)
static void test_readmode(BOOL ascii_mode)
int CDECL _flushall(void)
intptr_t CDECL _get_osfhandle(int fd)
static void test_ctrlz(void)
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
LONG WINAPI RegOpenCurrentUser(IN REGSAM samDesired, OUT PHKEY phkResult)
static void test_fgetc(void)
static void test_flsbuf(void)
static WCHAR * AtoW(const char *p)
_CRTIMP int __cdecl fstat(int _Desc, struct stat *_Stat)
char * strcpy(char *DstString, const char *SrcString)
static ioinfo ** __pioinfo
BOOL WINAPI GetHandleInformation(IN HANDLE hObject, OUT LPDWORD lpdwFlags)
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
int strcmp(const char *String1, const char *String2)
int CDECL _open_osfhandle(intptr_t handle, int oflags)
int CDECL _dup2(int od, int nd)
static void test_mktemp(void)
#define GetProcAddress(x, y)
int CDECL fclose(FILE *file)
static void test_setmaxstdio(void)
_CRTIMP intptr_t __cdecl _spawnvp(_In_ int _Mode, _In_z_ const char *_Filename, _In_z_ const char *const *_ArgList)
#define CreateFileA(a, b, c, d, e, f, g)
static void test_fputc(void)
static void test_invalid_stdin(const char *selfname)
static CHAR selfname[MAX_PATH]
static const char * pipe_string
int CDECL fgetc(FILE *file)
HANDLE WINAPI FindFirstFileA(IN LPCSTR lpFileName, OUT LPWIN32_FIND_DATAA lpFindFileData)
static unsigned char buff[32768]
UINT WINAPI GetTempFileNameA(IN LPCSTR lpPathName, IN LPCSTR lpPrefixString, IN UINT uUnique, OUT LPSTR lpTempFileName)
#define RegCloseKey(hKey)
static struct sockaddr_in sa
static void test_file_write_read(void)
static HANDLE proc_handles[2]
char *CDECL tmpnam(char *s)
static void test_filemodeT(void)
_CRTIMP int __cdecl read(_In_ int _FileHandle, _Out_writes_bytes_(_MaxCharCount) void *_DstBuf, _In_ unsigned int _MaxCharCount)
static unsigned(__cdecl *hash_bstr)(bstr_t s)
int CDECL fputs(const char *s, FILE *file)
int CDECL setvbuf(FILE *file, char *buf, int mode, size_t size)
static void test_dup2(void)
BOOL WINAPI FindClose(HANDLE hFindFile)
GLuint const GLchar * name