static void test_files(skiatest::Reporter* reporter) { SkString tmpDir = skiatest::Test::GetTmpDir(); if (tmpDir.isEmpty()) { return; } SkString path = SkOSPath::SkPathJoin(tmpDir.c_str(), "data_test"); const char s[] = "abcdefghijklmnopqrstuvwxyz"; { SkFILEWStream writer(path.c_str()); if (!writer.isValid()) { ERRORF(reporter, "Failed to create tmp file %s\n", path.c_str()); return; } writer.write(s, 26); } SkFILE* file = sk_fopen(path.c_str(), kRead_SkFILE_Flag); SkAutoTUnref<SkData> r1(SkData::NewFromFILE(file)); REPORTER_ASSERT(reporter, r1.get() != NULL); REPORTER_ASSERT(reporter, r1->size() == 26); REPORTER_ASSERT(reporter, strncmp(static_cast<const char*>(r1->data()), s, 26) == 0); int fd = sk_fileno(file); SkAutoTUnref<SkData> r2(SkData::NewFromFD(fd)); REPORTER_ASSERT(reporter, r2.get() != NULL); REPORTER_ASSERT(reporter, r2->size() == 26); REPORTER_ASSERT(reporter, strncmp(static_cast<const char*>(r2->data()), s, 26) == 0); }
size_t sk_qread(FILE* file, void* buffer, size_t count, size_t offset) { int fileno = sk_fileno(file); HANDLE fileHandle = (HANDLE)_get_osfhandle(fileno); if (INVALID_HANDLE_VALUE == file) { return SIZE_MAX; } OVERLAPPED overlapped = {0}; ULARGE_INTEGER winOffset; winOffset.QuadPart = offset; overlapped.Offset = winOffset.LowPart; overlapped.OffsetHigh = winOffset.HighPart; if (!SkTFitsIn<DWORD>(count)) { count = std::numeric_limits<DWORD>::max(); } DWORD bytesRead; if (ReadFile(fileHandle, buffer, static_cast<DWORD>(count), &bytesRead, &overlapped)) { return bytesRead; } if (GetLastError() == ERROR_HANDLE_EOF) { return 0; } return SIZE_MAX; }
void* sk_fmmap(FILE* f, size_t* size) { int fd = sk_fileno(f); if (fd < 0) { return nullptr; } return sk_fdmmap(fd, size); }
void* sk_fmmap(FILE* f, size_t* length) { int fileno = sk_fileno(f); if (fileno < 0) { return nullptr; } return sk_fdmmap(fileno, length); }
void* sk_fmmap(SkFILE* f, size_t* length) { int fileno = sk_fileno(f); if (fileno < 0) { return NULL; } return sk_fdmmap(fileno, length); }
void* sk_fmmap(SkFILE* f, size_t* size) { int fd = sk_fileno(f); if (fd < 0) { return NULL; } return sk_fdmmap(fd, size); }
size_t sk_qread(FILE* file, void* buffer, size_t count, size_t offset) { int fd = sk_fileno(file); if (fd < 0) { return SIZE_MAX; } ssize_t bytesRead = pread(fd, buffer, count, offset); if (bytesRead < 0) { return SIZE_MAX; } return bytesRead; }
size_t sk_fgetsize(FILE* f) { int fileno = sk_fileno(f); if (fileno < 0) { return 0; } HANDLE file = (HANDLE)_get_osfhandle(fileno); if (INVALID_HANDLE_VALUE == file) { return 0; } LARGE_INTEGER fileSize; if (0 == GetFileSizeEx(file, &fileSize)) { return 0; } if (!SkTFitsIn<size_t>(fileSize.QuadPart)) { return 0; } return static_cast<size_t>(fileSize.QuadPart); }