Lines Matching refs:fp
62 FILE* fp; in SetFileTo() local
63 ASSERT_NE(nullptr, fp = fopen(path, "w")); in SetFileTo()
64 ASSERT_NE(EOF, fputs(content, fp)); in SetFileTo()
65 ASSERT_EQ(0, fclose(fp)); in SetFileTo()
69 FILE* fp; in AssertFileIs() local
70 ASSERT_NE(nullptr, fp = fopen(path, "r")); in AssertFileIs()
73 ASSERT_NE(EOF, getline(&line, &length, fp)); in AssertFileIs()
74 ASSERT_EQ(0, fclose(fp)); in AssertFileIs()
79 static void AssertFileIs(FILE* fp, const char* expected, bool is_fmemopen = false) { in AssertFileIs() argument
80 rewind(fp); in AssertFileIs()
84 ASSERT_EQ(line, fgets(line, sizeof(line), fp)); in AssertFileIs()
90 ASSERT_EQ(line, fgets(line, sizeof(line), fp)); in AssertFileIs()
95 ASSERT_EQ(nullptr, fgets(line, sizeof(line), fp)) << "junk at end of file: " << line; in AssertFileIs()
107 FILE* fp = fopen("/dev/null", "w"); in TEST() local
108 ASSERT_TRUE(fp != nullptr); in TEST()
109 flockfile(fp); in TEST()
110 feof(fp); in TEST()
111 funlockfile(fp); in TEST()
112 fclose(fp); in TEST()
116 FILE* fp = tmpfile(); in TEST() local
117 ASSERT_TRUE(fp != nullptr); in TEST()
119 int fd = fileno(fp); in TEST()
127 rc = fprintf(fp, "hello\n"); in TEST()
130 AssertFileIs(fp, "hello\n"); in TEST()
131 fclose(fp); in TEST()
135 FILE* fp = tmpfile64(); in TEST() local
136 ASSERT_TRUE(fp != nullptr); in TEST()
137 fclose(fp); in TEST()
155 FILE* fp = tmpfile(); in TEST() local
156 ASSERT_TRUE(fp != nullptr); in TEST()
159 int rc = fprintf(fp, "%s", line_written); in TEST()
162 rewind(fp); in TEST()
169 ASSERT_FALSE(feof(fp)); in TEST()
170 …ASSERT_EQ(getdelim(&word_read, &allocated_length, ' ', fp), static_cast<int>(strlen(expected[i]))); in TEST()
175 ASSERT_TRUE(feof(fp)); in TEST()
176 clearerr(fp); in TEST()
181 ASSERT_EQ(getdelim(&word_read, &allocated_length, ' ', fp), -1); in TEST()
183 ASSERT_TRUE(feof(fp)); in TEST()
186 fclose(fp); in TEST()
190 FILE* fp = tmpfile(); in TEST() local
191 ASSERT_TRUE(fp != nullptr); in TEST()
198 ASSERT_EQ(getdelim(nullptr, &buffer_length, ' ', fp), -1); in TEST()
203 ASSERT_EQ(getdelim(&buffer, nullptr, ' ', fp), -1); in TEST()
205 fclose(fp); in TEST()
209 FILE* fp = fopen("/proc", "r"); in TEST() local
210 ASSERT_TRUE(fp != nullptr); in TEST()
213 ASSERT_EQ(-1, getdelim(&word_read, &allocated_length, ' ', fp)); in TEST()
214 fclose(fp); in TEST()
218 FILE* fp = tmpfile(); in TEST() local
219 ASSERT_TRUE(fp != nullptr); in TEST()
225 int rc = fprintf(fp, "%s", line_written); in TEST()
229 rewind(fp); in TEST()
236 while ((read_char_count = getline(&line_read, &allocated_length, fp)) != -1) { in TEST()
245 ASSERT_TRUE(feof(fp)); in TEST()
246 clearerr(fp); in TEST()
251 ASSERT_EQ(getline(&line_read, &allocated_length, fp), -1); in TEST()
253 ASSERT_TRUE(feof(fp)); in TEST()
256 fclose(fp); in TEST()
260 FILE* fp = tmpfile(); in TEST() local
261 ASSERT_TRUE(fp != nullptr); in TEST()
268 ASSERT_EQ(getline(nullptr, &buffer_length, fp), -1); in TEST()
273 ASSERT_EQ(getline(&buffer, nullptr, fp), -1); in TEST()
275 fclose(fp); in TEST()
911 FILE* fp; in TEST() local
916 ASSERT_NE(nullptr, fp = tmpfile()); in TEST()
917 setbuf(fp, nullptr); in TEST()
918 ASSERT_EQ(4, fprintf(fp, "epic")); in TEST()
919 ASSERT_NE(-1, dup2(fd_rdonly, fileno(fp))); in TEST()
920 ASSERT_EQ(-1, fprintf(fp, "fail")); in TEST()
921 ASSERT_EQ(0, fclose(fp)); in TEST()
927 ASSERT_NE(nullptr, fp = tmpfile()); in TEST()
928 ASSERT_EQ(4, fprintf(fp, "epic")); in TEST()
929 ASSERT_NE(-1, dup2(fd_rdonly, fileno(fp))); in TEST()
930 ASSERT_EQ(4, fprintf(fp, "fail")); in TEST()
931 ASSERT_EQ(-1, fclose(fp)); in TEST()
935 FILE* fp = popen("cat /proc/version", "r"); in TEST() local
936 ASSERT_TRUE(fp != nullptr); in TEST()
939 char* s = fgets(buf, sizeof(buf), fp); in TEST()
943 ASSERT_EQ(0, pclose(fp)); in TEST()
947 FILE* fp = popen("cat", "r+"); in TEST() local
948 ASSERT_TRUE(fp != nullptr); in TEST()
950 fputs("hello\nworld\n", fp); in TEST()
951 fflush(fp); in TEST()
954 ASSERT_NE(nullptr, fgets(buf, sizeof(buf), fp)); in TEST()
956 ASSERT_NE(nullptr, fgets(buf, sizeof(buf), fp)); in TEST()
959 ASSERT_EQ(0, pclose(fp)); in TEST()
963 FILE* fp = popen("uniq -c", "r+"); in TEST() local
964 ASSERT_TRUE(fp != nullptr); in TEST()
966 fputs("a\na\na\na\nb\n", fp); in TEST()
967 fflush(fp); in TEST()
968 ASSERT_EQ(0, shutdown(fileno(fp), SHUT_WR)); in TEST()
971 ASSERT_NE(nullptr, fgets(buf, sizeof(buf), fp)); in TEST()
973 ASSERT_NE(nullptr, fgets(buf, sizeof(buf), fp)); in TEST()
976 ASSERT_EQ(0, pclose(fp)); in TEST()
980 FILE* fp = popen("true", "r"); in TEST() local
981 ASSERT_TRUE(fp != nullptr); in TEST()
982 int status = pclose(fp); in TEST()
988 FILE* fp = popen("false", "r"); in TEST() local
989 ASSERT_TRUE(fp != nullptr); in TEST()
990 int status = pclose(fp); in TEST()
996 FILE* fp = popen("kill -7 $$", "r"); in TEST() local
997 ASSERT_TRUE(fp != nullptr); in TEST()
998 int status = pclose(fp); in TEST()
1004 FILE* fp = fopen("/proc/version", "r"); in TEST() local
1005 ASSERT_TRUE(fp != nullptr); in TEST()
1006 ASSERT_EQ('L', getc(fp)); in TEST()
1007 ASSERT_EQ('i', getc(fp)); in TEST()
1008 ASSERT_EQ('n', getc(fp)); in TEST()
1009 ASSERT_EQ('u', getc(fp)); in TEST()
1010 ASSERT_EQ('x', getc(fp)); in TEST()
1011 fclose(fp); in TEST()
1015 FILE* fp = fopen("/proc/version", "r"); in TEST() local
1016 ASSERT_TRUE(fp != nullptr); in TEST()
1017 ASSERT_EQ(EOF, putc('x', fp)); in TEST()
1018 fclose(fp); in TEST()
1340 FILE* fp = fopen("/proc/version", "r"); in TEST() local
1348 EXPECT_EQ(EOF, putc('x', fp)); in TEST()
1352 EXPECT_EQ(EOF, fprintf(fp, "hello")); in TEST()
1356 EXPECT_EQ(EOF, fwprintf(fp, L"hello")); in TEST()
1362 EXPECT_EQ(0U, fwrite("hello", 1, 2, fp)); in TEST()
1366 EXPECT_EQ(EOF, fputs("hello", fp)); in TEST()
1370 EXPECT_EQ(WEOF, fputwc(L'x', fp)); in TEST()
1382 FILE* fp = tmpfile(); in TEST() local
1383 ASSERT_TRUE(fp != nullptr); in TEST()
1391 ASSERT_EQ(mb_one_bytes, static_cast<wchar_t>(fputwc(mb_one_bytes, fp))); in TEST()
1392 ASSERT_EQ(mb_two_bytes, static_cast<wchar_t>(fputwc(mb_two_bytes, fp))); in TEST()
1393 ASSERT_EQ(mb_three_bytes, static_cast<wchar_t>(fputwc(mb_three_bytes, fp))); in TEST()
1394 ASSERT_EQ(mb_four_bytes, static_cast<wchar_t>(fputwc(mb_four_bytes, fp))); in TEST()
1396 rewind(fp); in TEST()
1404 EXPECT_EQ(0, fgetpos(fp, &pos1)); in TEST()
1405 ASSERT_EQ(mb_one_bytes, static_cast<wchar_t>(fgetwc(fp))); in TEST()
1406 EXPECT_EQ(0, fgetpos(fp, &pos2)); in TEST()
1407 ASSERT_EQ(mb_two_bytes, static_cast<wchar_t>(fgetwc(fp))); in TEST()
1408 EXPECT_EQ(0, fgetpos(fp, &pos3)); in TEST()
1409 ASSERT_EQ(mb_three_bytes, static_cast<wchar_t>(fgetwc(fp))); in TEST()
1410 EXPECT_EQ(0, fgetpos(fp, &pos4)); in TEST()
1411 ASSERT_EQ(mb_four_bytes, static_cast<wchar_t>(fgetwc(fp))); in TEST()
1412 EXPECT_EQ(0, fgetpos(fp, &pos5)); in TEST()
1427 ASSERT_EQ(0, fsetpos(fp, &pos2)); in TEST()
1428 ASSERT_EQ(mb_two_bytes, static_cast<wchar_t>(fgetwc(fp))); in TEST()
1429 ASSERT_EQ(0, fsetpos(fp, &pos1)); in TEST()
1430 ASSERT_EQ(mb_one_bytes, static_cast<wchar_t>(fgetwc(fp))); in TEST()
1431 ASSERT_EQ(0, fsetpos(fp, &pos4)); in TEST()
1432 ASSERT_EQ(mb_four_bytes, static_cast<wchar_t>(fgetwc(fp))); in TEST()
1433 ASSERT_EQ(0, fsetpos(fp, &pos3)); in TEST()
1434 ASSERT_EQ(mb_three_bytes, static_cast<wchar_t>(fgetwc(fp))); in TEST()
1435 ASSERT_EQ(0, fsetpos(fp, &pos5)); in TEST()
1436 ASSERT_EQ(WEOF, fgetwc(fp)); in TEST()
1438 fclose(fp); in TEST()
1452 FILE* fp = fdopen(tf.fd, "w+"); in TEST() local
1453 ASSERT_TRUE(fp != nullptr); in TEST()
1460 ASSERT_EQ(mb_two_bytes, static_cast<wchar_t>(fputwc(mb_two_bytes, fp))); in TEST()
1461 ASSERT_EQ(mb_three_bytes, static_cast<wchar_t>(fputwc(mb_three_bytes, fp))); in TEST()
1462 ASSERT_EQ(mb_four_bytes, static_cast<wchar_t>(fputwc(mb_four_bytes, fp))); in TEST()
1464 fflush(fp); in TEST()
1465 fclose(fp); in TEST()
1467 fp = fopen(tf.path, "r"); in TEST()
1468 ASSERT_TRUE(fp != nullptr); in TEST()
1472 ASSERT_EQ(0, fgetpos(fp, &mb_two_bytes_pos)); in TEST()
1476 ASSERT_EQ(0, fseek(fp, offset_inside_mb, SEEK_SET)); in TEST()
1480 ASSERT_EQ(0, fgetpos(fp, &pos_inside_mb)); in TEST()
1486 ASSERT_EQ(WEOF, fgetwc(fp)); in TEST()
1490 ASSERT_EQ(0, fsetpos(fp, &mb_two_bytes_pos)); in TEST()
1491 ASSERT_EQ(mb_two_bytes, static_cast<wchar_t>(fgetwc(fp))); in TEST()
1495 ASSERT_EQ(0, fsetpos(fp, &pos_inside_mb)); in TEST()
1496 ASSERT_EQ(WEOF, fgetwc(fp)); in TEST()
1499 ASSERT_EQ(0, fclose(fp)); in TEST()
1505 FILE* fp = fmemopen(buf, sizeof(buf), "r+"); in TEST() local
1506 ASSERT_EQ('<', fputc('<', fp)); in TEST()
1507 ASSERT_NE(EOF, fputs("abc>\n", fp)); in TEST()
1508 fflush(fp); in TEST()
1514 AssertFileIs(fp, "<abc>\n", true); in TEST()
1515 ASSERT_EQ(0, fclose(fp)); in TEST()
1519 FILE* fp = fmemopen(nullptr, 128, "r+"); in TEST() local
1520 ASSERT_NE(EOF, fputs("xyz\n", fp)); in TEST()
1522 AssertFileIs(fp, "xyz\n", true); in TEST()
1523 ASSERT_EQ(0, fclose(fp)); in TEST()
1527 FILE* fp; in TEST() local
1534 ASSERT_NE(nullptr, fp = fmemopen(buf, sizeof(buf), "w")); in TEST()
1536 ASSERT_EQ(0, fflush(fp)); in TEST()
1539 ASSERT_NE(EOF, fputs("hello", fp)); in TEST()
1540 ASSERT_EQ(0, fflush(fp)); in TEST()
1542 ASSERT_NE(EOF, fputs("wo", fp)); in TEST()
1543 ASSERT_EQ(0, fflush(fp)); in TEST()
1545 ASSERT_EQ(0, fclose(fp)); in TEST()
1551 ASSERT_NE(nullptr, fp = fmemopen(buf, sizeof(buf), "r+")); in TEST()
1553 ASSERT_EQ(0, fflush(fp)); in TEST()
1555 ASSERT_NE(EOF, fputs("hello", fp)); in TEST()
1556 ASSERT_EQ(0, fclose(fp)); in TEST()
1560 FILE* fp; in TEST() local
1570 ASSERT_NE(nullptr, fp = fmemopen(buf, 16, "r")); in TEST()
1571 ASSERT_EQ(0, fseek(fp, 0, SEEK_END)); in TEST()
1572 EXPECT_EQ(16, ftell(fp)); in TEST()
1573 EXPECT_EQ(16, ftello(fp)); in TEST()
1574 ASSERT_EQ(0, fseeko(fp, 0, SEEK_END)); in TEST()
1575 EXPECT_EQ(16, ftell(fp)); in TEST()
1576 EXPECT_EQ(16, ftello(fp)); in TEST()
1577 ASSERT_EQ(0, fclose(fp)); in TEST()
1578 ASSERT_NE(nullptr, fp = fmemopen(buf, 16, "r+")); in TEST()
1579 ASSERT_EQ(0, fseek(fp, 0, SEEK_END)); in TEST()
1580 EXPECT_EQ(16, ftell(fp)); in TEST()
1581 EXPECT_EQ(16, ftello(fp)); in TEST()
1582 ASSERT_EQ(0, fseeko(fp, 0, SEEK_END)); in TEST()
1583 EXPECT_EQ(16, ftell(fp)); in TEST()
1584 EXPECT_EQ(16, ftello(fp)); in TEST()
1585 ASSERT_EQ(0, fclose(fp)); in TEST()
1588 ASSERT_NE(nullptr, fp = fmemopen(nullptr, 16, "w")); in TEST()
1589 ASSERT_EQ(0, fseek(fp, 0, SEEK_END)); in TEST()
1590 EXPECT_EQ(0, ftell(fp)); in TEST()
1591 EXPECT_EQ(0, ftello(fp)); in TEST()
1592 ASSERT_EQ(0, fseeko(fp, 0, SEEK_END)); in TEST()
1593 EXPECT_EQ(0, ftell(fp)); in TEST()
1594 EXPECT_EQ(0, ftello(fp)); in TEST()
1595 ASSERT_EQ(0, fclose(fp)); in TEST()
1596 ASSERT_NE(nullptr, fp = fmemopen(nullptr, 16, "w+")); in TEST()
1597 ASSERT_EQ(0, fseek(fp, 0, SEEK_END)); in TEST()
1598 EXPECT_EQ(0, ftell(fp)); in TEST()
1599 EXPECT_EQ(0, ftello(fp)); in TEST()
1600 ASSERT_EQ(0, fseeko(fp, 0, SEEK_END)); in TEST()
1601 EXPECT_EQ(0, ftell(fp)); in TEST()
1602 EXPECT_EQ(0, ftello(fp)); in TEST()
1603 ASSERT_EQ(0, fclose(fp)); in TEST()
1607 ASSERT_NE(nullptr, fp = fmemopen(nullptr, 16, "a")); in TEST()
1608 ASSERT_EQ(0, fseek(fp, 0, SEEK_END)); in TEST()
1609 EXPECT_EQ(0, ftell(fp)); in TEST()
1610 EXPECT_EQ(0, ftello(fp)); in TEST()
1611 ASSERT_EQ(0, fseeko(fp, 0, SEEK_END)); in TEST()
1612 EXPECT_EQ(0, ftell(fp)); in TEST()
1613 EXPECT_EQ(0, ftello(fp)); in TEST()
1614 ASSERT_EQ(0, fclose(fp)); in TEST()
1615 ASSERT_NE(nullptr, fp = fmemopen(nullptr, 16, "a+")); in TEST()
1616 ASSERT_EQ(0, fseek(fp, 0, SEEK_END)); in TEST()
1617 EXPECT_EQ(0, ftell(fp)); in TEST()
1618 EXPECT_EQ(0, ftello(fp)); in TEST()
1619 ASSERT_EQ(0, fseeko(fp, 0, SEEK_END)); in TEST()
1620 EXPECT_EQ(0, ftell(fp)); in TEST()
1621 EXPECT_EQ(0, ftello(fp)); in TEST()
1622 ASSERT_EQ(0, fclose(fp)); in TEST()
1627 ASSERT_NE(nullptr, fp = fmemopen(buf, 16, "a")); in TEST()
1628 ASSERT_EQ(0, fseek(fp, 0, SEEK_END)); in TEST()
1629 EXPECT_EQ(3, ftell(fp)); in TEST()
1630 EXPECT_EQ(3, ftello(fp)); in TEST()
1631 ASSERT_EQ(0, fseeko(fp, 0, SEEK_END)); in TEST()
1632 EXPECT_EQ(3, ftell(fp)); in TEST()
1633 EXPECT_EQ(3, ftello(fp)); in TEST()
1634 ASSERT_EQ(0, fclose(fp)); in TEST()
1637 ASSERT_NE(nullptr, fp = fmemopen(buf, 16, "a+")); in TEST()
1638 ASSERT_EQ(0, fseek(fp, 0, SEEK_END)); in TEST()
1639 EXPECT_EQ(3, ftell(fp)); in TEST()
1640 EXPECT_EQ(3, ftello(fp)); in TEST()
1641 ASSERT_EQ(0, fseeko(fp, 0, SEEK_END)); in TEST()
1642 EXPECT_EQ(3, ftell(fp)); in TEST()
1643 EXPECT_EQ(3, ftello(fp)); in TEST()
1644 ASSERT_EQ(0, fclose(fp)); in TEST()
1649 ASSERT_NE(nullptr, fp = fmemopen(buf, 16, "a")); in TEST()
1650 ASSERT_EQ(0, fseek(fp, 0, SEEK_END)); in TEST()
1651 EXPECT_EQ(16, ftell(fp)); in TEST()
1652 EXPECT_EQ(16, ftello(fp)); in TEST()
1653 ASSERT_EQ(0, fseeko(fp, 0, SEEK_END)); in TEST()
1654 EXPECT_EQ(16, ftell(fp)); in TEST()
1655 EXPECT_EQ(16, ftello(fp)); in TEST()
1656 ASSERT_EQ(0, fclose(fp)); in TEST()
1658 ASSERT_NE(nullptr, fp = fmemopen(buf, 16, "a+")); in TEST()
1659 ASSERT_EQ(0, fseek(fp, 0, SEEK_END)); in TEST()
1660 EXPECT_EQ(16, ftell(fp)); in TEST()
1661 EXPECT_EQ(16, ftello(fp)); in TEST()
1662 ASSERT_EQ(0, fseeko(fp, 0, SEEK_END)); in TEST()
1663 EXPECT_EQ(16, ftell(fp)); in TEST()
1664 EXPECT_EQ(16, ftello(fp)); in TEST()
1665 ASSERT_EQ(0, fclose(fp)); in TEST()
1670 FILE* fp; in TEST() local
1674 ASSERT_NE(nullptr, fp = fmemopen(buf, sizeof(buf), "w+")); in TEST()
1675 ASSERT_NE(EOF, fputs("string", fp)); in TEST()
1676 EXPECT_EQ(0, fseek(fp, 0, SEEK_END)); in TEST()
1677 EXPECT_EQ(static_cast<long>(strlen("string")), ftell(fp)); in TEST()
1678 EXPECT_EQ(static_cast<off_t>(strlen("string")), ftello(fp)); in TEST()
1679 EXPECT_EQ(0, fclose(fp)); in TEST()
1683 ASSERT_NE(nullptr, fp = fmemopen(buf, sizeof(buf), "w+")); in TEST()
1684 ASSERT_NE(EOF, fputs("54321", fp)); in TEST()
1685 EXPECT_EQ(0, fseek(fp, -2, SEEK_END)); in TEST()
1686 EXPECT_EQ('2', fgetc(fp)); in TEST()
1687 EXPECT_EQ(0, fclose(fp)); in TEST()
1693 FILE* fp = fmemopen(buf, sizeof(buf), "w"); in TEST() local
1694 ASSERT_TRUE(fp != nullptr); in TEST()
1700 EXPECT_EQ(-1, fseek(fp, -2, SEEK_SET)); in TEST()
1701 EXPECT_EQ(-1, fseeko(fp, -2, SEEK_SET)); in TEST()
1702 EXPECT_EQ(-1, fseek(fp, sizeof(buf) + 1, SEEK_SET)); in TEST()
1703 EXPECT_EQ(-1, fseeko(fp, sizeof(buf) + 1, SEEK_SET)); in TEST()
1711 FILE* fp = fmemopen(buf, sizeof(buf), "r"); in TEST() local
1712 ASSERT_TRUE(fp != nullptr); in TEST()
1714 ASSERT_EQ(8U, fread(buf2, 1, sizeof(buf2), fp)); in TEST()
1717 ASSERT_TRUE(feof(fp)); in TEST()
1718 ASSERT_EQ(EOF, fgetc(fp)); in TEST()
1719 ASSERT_EQ(0, fclose(fp)); in TEST()
1725 FILE* fp = fmemopen(buf, sizeof(buf), "r"); in TEST() local
1726 ASSERT_TRUE(fp != nullptr); in TEST()
1727 ASSERT_EQ('h', fgetc(fp)); in TEST()
1728 ASSERT_EQ(0, fgetc(fp)); in TEST()
1729 ASSERT_EQ('e', fgetc(fp)); in TEST()
1730 ASSERT_EQ(0, fgetc(fp)); in TEST()
1731 ASSERT_EQ('l', fgetc(fp)); in TEST()
1732 ASSERT_EQ(0, fgetc(fp)); in TEST()
1737 ASSERT_EQ(4U, fread(buf2, 1, sizeof(buf2), fp)); in TEST()
1743 ASSERT_TRUE(feof(fp)); in TEST()
1744 ASSERT_EQ(0, fclose(fp)); in TEST()
1748 FILE* fp; in TEST() local
1754 ASSERT_NE(nullptr, fp = fmemopen(buf, sizeof(buf), "r+")); in TEST()
1755 setbuf(fp, nullptr); // Turn off buffering so we can see what's happening as it happens. in TEST()
1756 ASSERT_EQ(0, fseek(fp, 2, SEEK_SET)); in TEST()
1757 ASSERT_EQ(' ', fputc(' ', fp)); in TEST()
1759 ASSERT_EQ(0, fclose(fp)); in TEST()
1766 ASSERT_NE(nullptr, fp = fmemopen(buf, sizeof(buf), "a+")); in TEST()
1767 setbuf(fp, nullptr); // Turn off buffering so we can see what's happening as it happens. in TEST()
1768 ASSERT_EQ(' ', fputc(' ', fp)); in TEST()
1770 ASSERT_EQ(0, fclose(fp)); in TEST()
1777 ASSERT_NE(nullptr, fp = fmemopen(buf, sizeof(buf), "w+")); in TEST()
1778 setbuf(fp, nullptr); // Turn off buffering so we can see what's happening as it happens. in TEST()
1779 ASSERT_EQ(0, fseek(fp, 0, SEEK_END)); in TEST()
1780 EXPECT_EQ(0, ftell(fp)); in TEST()
1781 ASSERT_EQ(' ', fputc(' ', fp)); in TEST()
1782 ASSERT_EQ(0, fseek(fp, 0, SEEK_END)); in TEST()
1783 EXPECT_EQ(1, ftell(fp)); in TEST()
1784 ASSERT_NE(EOF, fputs("123", fp)); in TEST()
1785 ASSERT_EQ(0, fseek(fp, 0, SEEK_END)); in TEST()
1786 EXPECT_EQ(4, ftell(fp)); in TEST()
1788 ASSERT_EQ(0, fclose(fp)); in TEST()
1794 FILE* fp; in TEST() local
1797 ASSERT_NE(nullptr, fp = fmemopen(nullptr, 4, "w")); in TEST()
1798 setbuf(fp, nullptr); // Turn off buffering so we can see what's happening as it happens. in TEST()
1799 ASSERT_EQ('x', fputc('x', fp)); in TEST()
1800 ASSERT_EQ('x', fputc('x', fp)); in TEST()
1801 ASSERT_EQ('x', fputc('x', fp)); in TEST()
1802 ASSERT_EQ(EOF, fputc('x', fp)); // Only 3 fit because of the implicit NUL. in TEST()
1803 ASSERT_EQ(0, fclose(fp)); in TEST()
1806 ASSERT_NE(nullptr, fp = fmemopen(nullptr, 4, "w")); in TEST()
1807 setbuf(fp, nullptr); // Turn off buffering so we can see what's happening as it happens. in TEST()
1808 ASSERT_EQ(3U, fwrite("xxxx", 1, 4, fp)); in TEST()
1809 ASSERT_EQ(0, fclose(fp)); in TEST()
1816 FILE* fp; in TEST() local
1817 ASSERT_NE(nullptr, fp = fmemopen(buf, sizeof(buf), "r")); in TEST()
1818 EXPECT_EQ(0L, ftell(fp)); in TEST()
1819 EXPECT_EQ(0, fclose(fp)); in TEST()
1820 ASSERT_NE(nullptr, fp = fmemopen(buf, sizeof(buf), "w")); in TEST()
1821 EXPECT_EQ(0L, ftell(fp)); in TEST()
1822 EXPECT_EQ(0, fclose(fp)); in TEST()
1826 ASSERT_NE(nullptr, fp = fmemopen(buf, sizeof(buf), "a")); in TEST()
1827 EXPECT_EQ(5L, ftell(fp)); in TEST()
1828 EXPECT_EQ(0, fclose(fp)); in TEST()
1833 ASSERT_NE(nullptr, fp = fmemopen(buf, sizeof(buf), "a")); in TEST()
1834 EXPECT_EQ(static_cast<long>(sizeof(buf)), ftell(fp)); in TEST()
1835 EXPECT_EQ(0, fclose(fp)); in TEST()
1841 FILE* fp = fmemopen(nullptr, 128, "a+"); in TEST() local
1842 ASSERT_TRUE(fp != nullptr); in TEST()
1843 EXPECT_EQ(0L, ftell(fp)); in TEST()
1844 EXPECT_EQ(0L, fseek(fp, 0, SEEK_SET)); in TEST()
1845 EXPECT_EQ(0, fclose(fp)); in TEST()
1853 FILE* fp; in TEST() local
1855 ASSERT_NE(nullptr, fp = fmemopen(buf, 0, "r+")); in TEST()
1856 ASSERT_EQ(EOF, fgetc(fp)); in TEST()
1857 ASSERT_TRUE(feof(fp)); in TEST()
1858 ASSERT_EQ(0, fclose(fp)); in TEST()
1859 ASSERT_NE(nullptr, fp = fmemopen(nullptr, 0, "r+")); in TEST()
1860 ASSERT_EQ(EOF, fgetc(fp)); in TEST()
1861 ASSERT_TRUE(feof(fp)); in TEST()
1862 ASSERT_EQ(0, fclose(fp)); in TEST()
1864 ASSERT_NE(nullptr, fp = fmemopen(buf, 0, "w+")); in TEST()
1865 setbuf(fp, nullptr); // Turn off buffering so we can see what's happening as it happens. in TEST()
1866 ASSERT_EQ(EOF, fputc('x', fp)); in TEST()
1867 ASSERT_EQ(0, fclose(fp)); in TEST()
1868 ASSERT_NE(nullptr, fp = fmemopen(nullptr, 0, "w+")); in TEST()
1869 setbuf(fp, nullptr); // Turn off buffering so we can see what's happening as it happens. in TEST()
1870 ASSERT_EQ(EOF, fputc('x', fp)); in TEST()
1871 ASSERT_EQ(0, fclose(fp)); in TEST()
1877 FILE* fp = fmemopen(buf, 0, "w"); in TEST() local
1879 ASSERT_EQ(0, fclose(fp)); in TEST()
1885 FILE* fp; in TEST() local
1886 ASSERT_NE(nullptr, fp = fmemopen(nullptr, 16, "r")); in TEST()
1887 ASSERT_EQ(0, fclose(fp)); in TEST()
1888 ASSERT_NE(nullptr, fp = fmemopen(nullptr, 16, "w")); in TEST()
1889 ASSERT_EQ(0, fclose(fp)); in TEST()
1894 FILE* fp = fmemopen(nullptr, 16, "r"); in TEST() local
1895 ASSERT_TRUE(fp != nullptr); in TEST()
1897 ASSERT_EQ(-1, fileno(fp)); in TEST()
1899 ASSERT_EQ(0, fclose(fp)); in TEST()
1906 FILE* fp; in TEST() local
1908 ASSERT_NE(nullptr, fp = fmemopen(buf, sizeof(buf), "a")); in TEST()
1909 setbuf(fp, nullptr); // Turn off buffering so we can see what's happening as it happens. in TEST()
1910 ASSERT_EQ(0, fseek(fp, 0, SEEK_SET)); in TEST()
1911 ASSERT_NE(EOF, fputc('!', fp)); in TEST()
1913 ASSERT_EQ(0, fclose(fp)); in TEST()
1916 ASSERT_NE(nullptr, fp = fmemopen(buf, sizeof(buf), "a+")); in TEST()
1917 setbuf(fp, nullptr); // Turn off buffering so we can see what's happening as it happens. in TEST()
1918 ASSERT_EQ(0, fseek(fp, 0, SEEK_SET)); in TEST()
1919 ASSERT_NE(EOF, fputc('!', fp)); in TEST()
1921 ASSERT_EQ(0, fclose(fp)); in TEST()
1927 FILE* fp = open_memstream(&p, &size); in TEST() local
1928 ASSERT_NE(EOF, fputs("hello, world!", fp)); in TEST()
1929 fclose(fp); in TEST()
1962 FILE* fp = fdopen(fd, "re"); in TEST() local
1963 ASSERT_TRUE(fp != nullptr); in TEST()
1966 AssertCloseOnExec(fileno(fp), true); in TEST()
1968 fclose(fp); in TEST()
1972 FILE* fp = fopen("/proc/version", "r"); in TEST() local
1973 ASSERT_TRUE(fp != nullptr); in TEST()
1976 AssertCloseOnExec(fileno(fp), false); in TEST()
1978 fp = freopen("/proc/version", "re", fp); in TEST()
1981 AssertCloseOnExec(fileno(fp), true); in TEST()
1983 fclose(fp); in TEST()
1987 FILE* fp = fopen64("/proc/version", "r"); in TEST() local
1988 ASSERT_TRUE(fp != nullptr); in TEST()
1989 fp = freopen64("/proc/version", "re", fp); in TEST()
1990 ASSERT_TRUE(fp != nullptr); in TEST()
1991 fclose(fp); in TEST()
1997 FILE* fp = fopen("/dev/zero", "r"); in TEST() local
1998 ASSERT_TRUE(fp != nullptr); in TEST()
2001 setvbuf(fp, nullptr, _IONBF, 0); in TEST()
2008 ASSERT_EQ(1U, fread(buf, 64*1024, 1, fp)); in TEST()
2012 fclose(fp); in TEST()
2027 FILE* fp = fmemopen(&digits[0], digits.size(), "r"); in TEST() local
2032 ASSERT_EQ(2U, fread(buf1, 4, 4, fp)); in TEST()
2034 ASSERT_TRUE(feof(fp)); in TEST()
2036 rewind(fp); in TEST()
2041 ASSERT_EQ(2U, fread(buf2, 4, 4096, fp)); in TEST()
2043 ASSERT_TRUE(feof(fp)); in TEST()
2045 fclose(fp); in TEST()
2049 FILE* fp = fopen("/dev/null", "w"); in test_fread_from_write_only_stream() local
2052 ASSERT_EQ(0U, fread(&buf[0], n, 1, fp)); in test_fread_from_write_only_stream()
2054 ASSERT_TRUE(ferror(fp)); in test_fread_from_write_only_stream()
2055 ASSERT_FALSE(feof(fp)); in test_fread_from_write_only_stream()
2056 fclose(fp); in test_fread_from_write_only_stream()
2070 FILE* fp = fdopen(tf.fd, "w+"); in test_fwrite_after_fread() local
2071 ASSERT_EQ(1U, fwrite("1", 1, 1, fp)); in test_fwrite_after_fread()
2072 fflush(fp); in test_fwrite_after_fread()
2076 ASSERT_EQ(0U, fread(&buf[0], 1, buf.size(), fp)); in test_fwrite_after_fread()
2077 ASSERT_TRUE(feof(fp)); in test_fwrite_after_fread()
2081 ASSERT_EQ(1U, fwrite("2", 1, 1, fp)) << strerror(errno); in test_fwrite_after_fread()
2084 rewind(fp); in test_fwrite_after_fread()
2085 ASSERT_EQ(2U, fread(&buf[0], 1, buf.size(), fp)); in test_fwrite_after_fread()
2089 fclose(fp); in test_fwrite_after_fread()
2104 FILE* fp = fopen(tf.path, "w+"); in TEST() local
2105 ASSERT_TRUE(fp != nullptr); in TEST()
2111 ASSERT_EQ(12288U, fwrite(file_data, 1, 12288, fp)); in TEST()
2112 fclose(fp); in TEST()
2114 fp = fopen(tf.path, "r"); in TEST()
2115 ASSERT_TRUE(fp != nullptr); in TEST()
2120 ASSERT_EQ(100U, fread(buffer, 1, 100, fp)); in TEST()
2123 cur_location = static_cast<size_t>(ftell(fp)); in TEST()
2126 ASSERT_EQ(8192U, fread(buffer, 1, 8192, fp)); in TEST()
2130 ASSERT_EQ(0, fseek(fp, -22, SEEK_CUR)) << strerror(errno); in TEST()
2131 cur_location = static_cast<size_t>(ftell(fp)); in TEST()
2132 ASSERT_EQ(22U, fread(buffer, 1, 22, fp)); in TEST()
2135 fclose(fp); in TEST()
2191 FILE* fp = funopen(nullptr, read_fn, nullptr, nullptr, nullptr); in TEST() local
2192 ASSERT_TRUE(fp != nullptr); in TEST()
2196 ASSERT_EQ(-1, ftell(fp)); in TEST()
2201 ASSERT_EQ(-1, fseek(fp, 0, SEEK_CUR)); in TEST()
2206 ASSERT_EQ(-1, fseek(fp, 0, SEEK_SET)); in TEST()
2209 fclose(fp); in TEST()
2232 FILE* fp = funopen(nullptr, read_fn, nullptr, seek_fn, nullptr); in TEST() local
2233 ASSERT_TRUE(fp != nullptr); in TEST()
2236 EXPECT_EQ(0, fgetpos(fp, &pos)) << strerror(errno); in TEST()
2239 EXPECT_EQ(-1, fgetpos(fp, &pos)) << strerror(errno); in TEST()
2260 FILE* fp = fopen(tf->path, "w+"); in TEST() local
2261 fps.push_back(fp); in TEST()
2262 fprintf(fp, "hello %zu!\n", i); in TEST()
2263 fflush(fp); in TEST()
2276 static void AssertFileOffsetAt(FILE* fp, off64_t offset) { in AssertFileOffsetAt() argument
2277 EXPECT_EQ(offset, ftell(fp)); in AssertFileOffsetAt()
2278 EXPECT_EQ(offset, ftello(fp)); in AssertFileOffsetAt()
2279 EXPECT_EQ(offset, ftello64(fp)); in AssertFileOffsetAt()
2282 EXPECT_EQ(0, fgetpos(fp, &pos)); in AssertFileOffsetAt()
2283 EXPECT_EQ(0, fgetpos64(fp, &pos64)); in AssertFileOffsetAt()
2294 FILE* fp = fdopen(tf.fd, "w+"); in TEST() local
2297 AssertFileOffsetAt(fp, 0); in TEST()
2300 ASSERT_EQ(0, fseek(fp, 8192, SEEK_SET)); in TEST()
2301 AssertFileOffsetAt(fp, 8192); in TEST()
2303 ASSERT_EQ(0, fgetpos(fp, &eight_k_pos)); in TEST()
2306 ASSERT_EQ(0, fseek(fp, 8192, SEEK_CUR)); in TEST()
2307 AssertFileOffsetAt(fp, 8192 + 8192); in TEST()
2309 ASSERT_EQ(0, fgetpos64(fp, &sixteen_k_pos64)); in TEST()
2312 ASSERT_EQ(0, fseek(fp, -8192, SEEK_CUR)); in TEST()
2313 AssertFileOffsetAt(fp, 8192); in TEST()
2316 ASSERT_EQ(0, fseek(fp, 0, SEEK_END)); in TEST()
2317 AssertFileOffsetAt(fp, 0); in TEST()
2320 ASSERT_EQ(0, fsetpos64(fp, &sixteen_k_pos64)); in TEST()
2321 AssertFileOffsetAt(fp, 8192 + 8192); in TEST()
2323 ASSERT_EQ(0, fsetpos(fp, &eight_k_pos)); in TEST()
2324 AssertFileOffsetAt(fp, 8192); in TEST()
2327 ASSERT_EQ(0, fseeko(fp, 1234, SEEK_SET)); in TEST()
2328 AssertFileOffsetAt(fp, 1234); in TEST()
2329 ASSERT_EQ(0, fseeko64(fp, 5678, SEEK_SET)); in TEST()
2330 AssertFileOffsetAt(fp, 5678); in TEST()
2332 fclose(fp); in TEST()
2337 FILE* fp = fdopen(tf.fd, "w+"); in TEST() local
2341 ASSERT_EQ(-1, fseek(fp, 0, 123)); in TEST()
2344 ASSERT_EQ(-1, fseeko(fp, 0, 123)); in TEST()
2347 ASSERT_EQ(-1, fseeko64(fp, 0, 123)); in TEST()
2352 ASSERT_EQ(-1, fseek(fp, -1, SEEK_SET)); in TEST()
2355 ASSERT_EQ(-1, fseeko(fp, -1, SEEK_SET)); in TEST()
2358 ASSERT_EQ(-1, fseeko64(fp, -1, SEEK_SET)); in TEST()
2361 fclose(fp); in TEST()
2468 FILE* fp = fopen(tf.path, "a"); in TEST() local
2469 EXPECT_EQ(10, ftell(fp)); in TEST()
2470 ASSERT_EQ(0, fseek(fp, 2, SEEK_SET)); in TEST()
2471 EXPECT_EQ(2, ftell(fp)); in TEST()
2472 ASSERT_NE(EOF, fputs("xxx", fp)); in TEST()
2473 ASSERT_EQ(0, fflush(fp)); in TEST()
2474 EXPECT_EQ(13, ftell(fp)); in TEST()
2475 ASSERT_EQ(0, fseek(fp, 0, SEEK_END)); in TEST()
2476 EXPECT_EQ(13, ftell(fp)); in TEST()
2477 ASSERT_EQ(0, fclose(fp)); in TEST()
2489 FILE* fp = fdopen(fd, "a"); in TEST() local
2490 EXPECT_EQ(4, ftell(fp)); in TEST()
2491 ASSERT_EQ(0, fseek(fp, 2, SEEK_SET)); in TEST()
2492 EXPECT_EQ(2, ftell(fp)); in TEST()
2493 ASSERT_NE(EOF, fputs("xxx", fp)); in TEST()
2494 ASSERT_EQ(0, fflush(fp)); in TEST()
2495 EXPECT_EQ(13, ftell(fp)); in TEST()
2496 ASSERT_EQ(0, fseek(fp, 0, SEEK_END)); in TEST()
2497 EXPECT_EQ(13, ftell(fp)); in TEST()
2498 ASSERT_EQ(0, fclose(fp)); in TEST()
2506 FILE* fp = freopen(tf.path, "a", other_fp); in TEST() local
2507 EXPECT_EQ(10, ftell(fp)); in TEST()
2508 ASSERT_EQ(0, fseek(fp, 2, SEEK_SET)); in TEST()
2509 EXPECT_EQ(2, ftell(fp)); in TEST()
2510 ASSERT_NE(EOF, fputs("xxx", fp)); in TEST()
2511 ASSERT_EQ(0, fflush(fp)); in TEST()
2512 EXPECT_EQ(13, ftell(fp)); in TEST()
2513 ASSERT_EQ(0, fseek(fp, 0, SEEK_END)); in TEST()
2514 EXPECT_EQ(13, ftell(fp)); in TEST()
2515 ASSERT_EQ(0, fclose(fp)); in TEST()
2539 FILE* fp = fopen(tf.path, "w+"); in TEST() local
2540 ASSERT_TRUE(fp != nullptr); in TEST()
2542 clearerr_unlocked(fp); in TEST()
2543 ASSERT_FALSE(feof_unlocked(fp)); in TEST()
2544 ASSERT_FALSE(ferror_unlocked(fp)); in TEST()
2546 ASSERT_EQ(fileno(fp), fileno_unlocked(fp)); in TEST()
2548 ASSERT_NE(EOF, putc_unlocked('a', fp)); in TEST()
2549 ASSERT_NE(EOF, putc('b', fp)); in TEST()
2550 ASSERT_NE(EOF, fputc_unlocked('c', fp)); in TEST()
2551 ASSERT_NE(EOF, fputc('d', fp)); in TEST()
2553 rewind(fp); in TEST()
2554 ASSERT_EQ('a', getc_unlocked(fp)); in TEST()
2555 ASSERT_EQ('b', getc(fp)); in TEST()
2556 ASSERT_EQ('c', fgetc_unlocked(fp)); in TEST()
2557 ASSERT_EQ('d', fgetc(fp)); in TEST()
2559 rewind(fp); in TEST()
2560 ASSERT_EQ(2U, fwrite_unlocked("AB", 1, 2, fp)); in TEST()
2561 ASSERT_EQ(2U, fwrite("CD", 1, 2, fp)); in TEST()
2562 ASSERT_EQ(0, fflush_unlocked(fp)); in TEST()
2564 rewind(fp); in TEST()
2566 ASSERT_EQ(2U, fread_unlocked(&buf[0], 1, 2, fp)); in TEST()
2567 ASSERT_EQ(2U, fread(&buf[2], 1, 2, fp)); in TEST()
2570 rewind(fp); in TEST()
2571 ASSERT_NE(EOF, fputs("hello ", fp)); in TEST()
2572 ASSERT_NE(EOF, fputs_unlocked("world", fp)); in TEST()
2573 ASSERT_NE(EOF, fputc('\n', fp)); in TEST()
2575 rewind(fp); in TEST()
2576 ASSERT_TRUE(fgets_unlocked(buf, sizeof(buf), fp) != nullptr); in TEST()
2579 ASSERT_EQ(0, fclose(fp)); in TEST()
2584 FILE* fp = fopen64(tf.path, "w+"); in TEST() local
2585 ASSERT_TRUE(fp != nullptr); in TEST()
2586 ASSERT_EQ(0, fseeko64(fp, 0x2'0000'0000, SEEK_SET)); in TEST()
2587 ASSERT_EQ(0x2'0000'0000, ftello64(fp)); in TEST()
2588 ASSERT_EQ(0, fseeko64(fp, 0x1'0000'0000, SEEK_CUR)); in TEST()
2589 ASSERT_EQ(0x3'0000'0000, ftello64(fp)); in TEST()
2590 ASSERT_EQ(0, fclose(fp)); in TEST()
2597 FILE* fp = fopen64(tf.path, "w+"); in TEST() local
2598 ASSERT_EQ(0, ftruncate64(fileno(fp), 0x2'0000'0000)); in TEST()
2602 ASSERT_EQ(0, fseek(fp, 0x7fff'ffff, SEEK_SET)); in TEST()
2603 ASSERT_EQ(-1, fseek(fp, 1, SEEK_CUR)); in TEST()
2610 ASSERT_EQ(0, fseek(fp, 0, SEEK_END)); in TEST()
2611 ASSERT_EQ(0x2'0000'0000, ftello64(fp)); in TEST()
2613 fclose(fp); in TEST()