Lines Matching defs:fp
49 FILE* fp = fopen("/dev/null", "w");
50 ASSERT_TRUE(fp != NULL);
51 flockfile(fp);
52 feof(fp);
53 funlockfile(fp);
54 fclose(fp);
58 FILE* fp = tmpfile();
59 ASSERT_TRUE(fp != NULL);
61 int fd = fileno(fp);
69 rc = fprintf(fp, "hello\n");
72 rewind(fp);
75 char* s = fgets(buf, sizeof(buf), fp);
79 fclose(fp);
83 FILE* fp = tmpfile64();
84 ASSERT_TRUE(fp != nullptr);
85 fclose(fp);
107 FILE* fp = tmpfile();
108 ASSERT_TRUE(fp != NULL);
111 int rc = fprintf(fp, "%s", line_written);
114 rewind(fp);
121 ASSERT_FALSE(feof(fp));
122 ASSERT_EQ(getdelim(&word_read, &allocated_length, ' ', fp), static_cast<int>(strlen(expected[i])));
127 ASSERT_TRUE(feof(fp));
128 clearerr(fp);
133 ASSERT_EQ(getdelim(&word_read, &allocated_length, ' ', fp), -1);
135 ASSERT_TRUE(feof(fp));
138 fclose(fp);
142 FILE* fp = tmpfile();
143 ASSERT_TRUE(fp != NULL);
150 ASSERT_EQ(getdelim(NULL, &buffer_length, ' ', fp), -1);
155 ASSERT_EQ(getdelim(&buffer, NULL, ' ', fp), -1);
159 ASSERT_EQ(0, close(fileno(fp)));
161 ASSERT_EQ(getdelim(&buffer, &buffer_length, ' ', fp), -1);
163 fclose(fp);
167 FILE* fp = fopen("/proc", "r");
168 ASSERT_TRUE(fp != NULL);
171 ASSERT_EQ(-1, getdelim(&word_read, &allocated_length, ' ', fp));
172 fclose(fp);
176 FILE* fp = tmpfile();
177 ASSERT_TRUE(fp != NULL);
183 int rc = fprintf(fp, "%s", line_written);
187 rewind(fp);
194 while ((read_char_count = getline(&line_read, &allocated_length, fp)) != -1) {
203 ASSERT_TRUE(feof(fp));
204 clearerr(fp);
209 ASSERT_EQ(getline(&line_read, &allocated_length, fp), -1);
211 ASSERT_TRUE(feof(fp));
214 fclose(fp);
218 FILE* fp = tmpfile();
219 ASSERT_TRUE(fp != NULL);
226 ASSERT_EQ(getline(NULL, &buffer_length, fp), -1);
231 ASSERT_EQ(getline(&buffer, NULL, fp), -1);
235 ASSERT_EQ(0, close(fileno(fp)));
237 ASSERT_EQ(getline(&buffer, &buffer_length, fp), -1);
239 fclose(fp);
573 FILE* fp;
576 ASSERT_NE(nullptr, fp = tmpfile());
577 setbuf(fp, NULL);
578 ASSERT_EQ(4, fprintf(fp, "epic"));
579 ASSERT_EQ(0, close(fileno(fp)));
580 ASSERT_EQ(-1, fprintf(fp, "fail"));
581 ASSERT_EQ(-1, fclose(fp));
587 ASSERT_NE(nullptr, fp = tmpfile());
588 ASSERT_EQ(4, fprintf(fp, "epic"));
589 ASSERT_EQ(0, close(fileno(fp)));
590 ASSERT_EQ(4, fprintf(fp, "fail"));
591 ASSERT_EQ(-1, fclose(fp));
595 FILE* fp = popen("cat /proc/version", "r");
596 ASSERT_TRUE(fp != NULL);
599 char* s = fgets(buf, sizeof(buf), fp);
603 ASSERT_EQ(0, pclose(fp));
607 FILE* fp = fopen("/proc/version", "r");
608 ASSERT_TRUE(fp != NULL);
609 ASSERT_EQ('L', getc(fp));
610 ASSERT_EQ('i', getc(fp));
611 ASSERT_EQ('n', getc(fp));
612 ASSERT_EQ('u', getc(fp));
613 ASSERT_EQ('x', getc(fp));
614 fclose(fp);
618 FILE* fp = fopen("/proc/version", "r");
619 ASSERT_TRUE(fp != NULL);
620 ASSERT_EQ(EOF, putc('x', fp));
621 fclose(fp);
637 FILE* fp = fopen("/proc/version", "r");
645 EXPECT_EQ(EOF, putc('x', fp));
649 EXPECT_EQ(EOF, fprintf(fp, "hello"));
653 EXPECT_EQ(EOF, fwprintf(fp, L"hello"));
659 EXPECT_EQ(0U, fwrite("hello", 1, 2, fp));
663 EXPECT_EQ(EOF, fputs("hello", fp));
667 EXPECT_EQ(WEOF, fputwc(L'x', fp));
679 FILE* fp = tmpfile();
680 ASSERT_TRUE(fp != NULL);
688 ASSERT_EQ(mb_one_bytes, static_cast<wchar_t>(fputwc(mb_one_bytes, fp)));
689 ASSERT_EQ(mb_two_bytes, static_cast<wchar_t>(fputwc(mb_two_bytes, fp)));
690 ASSERT_EQ(mb_three_bytes, static_cast<wchar_t>(fputwc(mb_three_bytes, fp)));
691 ASSERT_EQ(mb_four_bytes, static_cast<wchar_t>(fputwc(mb_four_bytes, fp)));
693 rewind(fp);
701 EXPECT_EQ(0, fgetpos(fp, &pos1));
702 ASSERT_EQ(mb_one_bytes, static_cast<wchar_t>(fgetwc(fp)));
703 EXPECT_EQ(0, fgetpos(fp, &pos2));
704 ASSERT_EQ(mb_two_bytes, static_cast<wchar_t>(fgetwc(fp)));
705 EXPECT_EQ(0, fgetpos(fp, &pos3));
706 ASSERT_EQ(mb_three_bytes, static_cast<wchar_t>(fgetwc(fp)));
707 EXPECT_EQ(0, fgetpos(fp, &pos4));
708 ASSERT_EQ(mb_four_bytes, static_cast<wchar_t>(fgetwc(fp)));
709 EXPECT_EQ(0, fgetpos(fp, &pos5));
724 ASSERT_EQ(0, fsetpos(fp, &pos2));
725 ASSERT_EQ(mb_two_bytes, static_cast<wchar_t>(fgetwc(fp)));
726 ASSERT_EQ(0, fsetpos(fp, &pos1));
727 ASSERT_EQ(mb_one_bytes, static_cast<wchar_t>(fgetwc(fp)));
728 ASSERT_EQ(0, fsetpos(fp, &pos4));
729 ASSERT_EQ(mb_four_bytes, static_cast<wchar_t>(fgetwc(fp)));
730 ASSERT_EQ(0, fsetpos(fp, &pos3));
731 ASSERT_EQ(mb_three_bytes, static_cast<wchar_t>(fgetwc(fp)));
732 ASSERT_EQ(0, fsetpos(fp, &pos5));
733 ASSERT_EQ(WEOF, fgetwc(fp));
735 fclose(fp);
749 FILE* fp = fdopen(tf.fd, "w+");
750 ASSERT_TRUE(fp != NULL);
757 ASSERT_EQ(mb_two_bytes, static_cast<wchar_t>(fputwc(mb_two_bytes, fp)));
758 ASSERT_EQ(mb_three_bytes, static_cast<wchar_t>(fputwc(mb_three_bytes, fp)));
759 ASSERT_EQ(mb_four_bytes, static_cast<wchar_t>(fputwc(mb_four_bytes, fp)));
761 fflush(fp);
762 fclose(fp);
764 fp = fopen(tf.filename, "r");
765 ASSERT_TRUE(fp != NULL);
769 ASSERT_EQ(0, fgetpos(fp, &mb_two_bytes_pos));
773 ASSERT_EQ(0, fseek(fp, offset_inside_mb, SEEK_SET));
777 ASSERT_EQ(0, fgetpos(fp, &pos_inside_mb));
783 ASSERT_EQ(WEOF, fgetwc(fp));
787 ASSERT_EQ(0, fsetpos(fp, &mb_two_bytes_pos));
788 ASSERT_EQ(mb_two_bytes, static_cast<wchar_t>(fgetwc(fp)));
792 ASSERT_EQ(0, fsetpos(fp, &pos_inside_mb));
793 ASSERT_EQ(WEOF, fgetwc(fp));
796 fclose(fp);
802 FILE* fp = fmemopen(buf, sizeof(buf), "r+");
803 ASSERT_EQ('<', fputc('<', fp));
804 ASSERT_NE(EOF, fputs("abc>\n", fp));
805 fflush(fp);
809 rewind(fp);
812 char* s = fgets(line, sizeof(line), fp);
816 fclose(fp);
820 FILE* fp = fmemopen(nullptr, 128, "r+");
821 ASSERT_NE(EOF, fputs("xyz\n", fp));
823 rewind(fp);
826 char* s = fgets(line, sizeof(line), fp);
830 fclose(fp);
850 FILE* fp = open_memstream(&p, &size);
851 ASSERT_NE(EOF, fputs("hello, world!", fp));
852 fclose(fp);
887 FILE* fp = fdopen(fd, "re");
888 ASSERT_TRUE(fp != NULL);
891 flags = fcntl(fileno(fp), F_GETFD);
895 fclose(fp);
900 FILE* fp = fopen("/proc/version", "r");
901 ASSERT_TRUE(fp != NULL);
904 int flags = fcntl(fileno(fp), F_GETFD);
908 fp = freopen("/proc/version", "re", fp);
911 flags = fcntl(fileno(fp), F_GETFD);
915 fclose(fp);
919 FILE* fp = fopen64("/proc/version", "r");
920 ASSERT_TRUE(fp != nullptr);
921 fp = freopen64("/proc/version", "re", fp);
922 ASSERT_TRUE(fp != nullptr);
923 fclose(fp);
929 FILE* fp = fopen("/dev/zero", "r");
930 ASSERT_TRUE(fp != NULL);
933 setvbuf(fp, 0, _IONBF, 0);
940 ASSERT_EQ(1U, fread(buf, 64*1024, 1, fp));
944 fclose(fp);
959 FILE* fp = fmemopen(&digits[0], digits.size(), "r");
964 ASSERT_EQ(2U, fread(buf1, 4, 4, fp));
966 ASSERT_TRUE(feof(fp));
968 rewind(fp);
973 ASSERT_EQ(2U, fread(buf2, 4, 4096, fp));
975 ASSERT_TRUE(feof(fp));
977 fclose(fp);
981 FILE* fp = fopen("/dev/null", "w");
984 ASSERT_EQ(0U, fread(&buf[0], n, 1, fp));
986 ASSERT_TRUE(ferror(fp));
987 ASSERT_FALSE(feof(fp));
988 fclose(fp);
1002 FILE* fp = fdopen(tf.fd, "w+");
1003 ASSERT_EQ(1U, fwrite("1", 1, 1, fp));
1004 fflush(fp);
1008 ASSERT_EQ(0U, fread(&buf[0], 1, buf.size(), fp));
1009 ASSERT_TRUE(feof(fp));
1013 ASSERT_EQ(1U, fwrite("2", 1, 1, fp)) << strerror(errno);
1016 rewind(fp);
1017 ASSERT_EQ(2U, fread(&buf[0], 1, buf.size(), fp));
1021 fclose(fp);
1036 FILE* fp = fopen(tf.filename, "w+");
1037 ASSERT_TRUE(fp != nullptr);
1043 ASSERT_EQ(12288U, fwrite(file_data, 1, 12288, fp));
1044 fclose(fp);
1046 fp = fopen(tf.filename, "r");
1047 ASSERT_TRUE(fp != nullptr);
1052 ASSERT_EQ(100U, fread(buffer, 1, 100, fp));
1055 cur_location = static_cast<size_t>(ftell(fp));
1058 ASSERT_EQ(8192U, fread(buffer, 1, 8192, fp));
1062 ASSERT_EQ(0, fseek(fp, -22, SEEK_CUR)) << strerror(errno);
1063 cur_location = static_cast<size_t>(ftell(fp));
1064 ASSERT_EQ(22U, fread(buffer, 1, 22, fp));
1067 fclose(fp);
1123 FILE* fp = funopen(nullptr, read_fn, nullptr, nullptr, nullptr);
1124 ASSERT_TRUE(fp != nullptr);
1128 ASSERT_EQ(-1, ftell(fp));
1133 ASSERT_EQ(-1, fseek(fp, 0, SEEK_CUR));
1138 ASSERT_EQ(-1, fseek(fp, 0, SEEK_SET));
1141 fclose(fp);
1164 FILE* fp = funopen(nullptr, read_fn, nullptr, seek_fn, nullptr);
1165 ASSERT_TRUE(fp != nullptr);
1168 EXPECT_EQ(0, fgetpos(fp, &pos)) << strerror(errno);
1171 EXPECT_EQ(-1, fgetpos(fp, &pos)) << strerror(errno);
1192 FILE* fp = fopen(tf->filename, "w+");
1193 fps.push_back(fp);
1194 fprintf(fp, "hello %zu!\n", i);
1195 fflush(fp);
1213 static void AssertFileOffsetAt(FILE* fp, off64_t offset) {
1214 EXPECT_EQ(offset, ftell(fp));
1215 EXPECT_EQ(offset, ftello(fp));
1216 EXPECT_EQ(offset, ftello64(fp));
1219 EXPECT_EQ(0, fgetpos(fp, &pos));
1220 EXPECT_EQ(0, fgetpos64(fp, &pos64));
1231 FILE* fp = fdopen(tf.fd, "w+");
1234 AssertFileOffsetAt(fp, 0);
1237 ASSERT_EQ(0, fseek(fp, 8192, SEEK_SET));
1238 AssertFileOffsetAt(fp, 8192);
1240 ASSERT_EQ(0, fgetpos(fp, &eight_k_pos));
1243 ASSERT_EQ(0, fseek(fp, 8192, SEEK_CUR));
1244 AssertFileOffsetAt(fp, 8192 + 8192);
1246 ASSERT_EQ(0, fgetpos64(fp, &sixteen_k_pos64));
1249 ASSERT_EQ(0, fseek(fp, -8192, SEEK_CUR));
1250 AssertFileOffsetAt(fp, 8192);
1253 ASSERT_EQ(0, fseek(fp, 0, SEEK_END));
1254 AssertFileOffsetAt(fp, 0);
1257 ASSERT_EQ(0, fsetpos64(fp, &sixteen_k_pos64));
1258 AssertFileOffsetAt(fp, 8192 + 8192);
1260 ASSERT_EQ(0, fsetpos(fp, &eight_k_pos));
1261 AssertFileOffsetAt(fp, 8192);
1264 ASSERT_EQ(0, fseeko(fp, 1234, SEEK_SET));
1265 AssertFileOffsetAt(fp, 1234);
1266 ASSERT_EQ(0, fseeko64(fp, 5678, SEEK_SET));
1267 AssertFileOffsetAt(fp, 5678);
1269 fclose(fp);
1274 FILE* fp = fdopen(tf.fd, "w+");
1278 ASSERT_EQ(-1, fseek(fp, 0, 123));
1281 ASSERT_EQ(-1, fseeko(fp, 0, 123));
1284 ASSERT_EQ(-1, fseeko64(fp, 0, 123));
1289 ASSERT_EQ(-1, fseek(fp, -1, SEEK_SET));
1292 ASSERT_EQ(-1, fseeko(fp, -1, SEEK_SET));
1295 ASSERT_EQ(-1, fseeko64(fp, -1, SEEK_SET));
1298 fclose(fp);