Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions
SkOSFile_posix.cpp File Reference
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkTFitsIn.h"
#include "include/private/base/SkTemplates.h"
#include "src/core/SkOSFile.h"
#include <dirent.h>
#include <new>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

Go to the source code of this file.

Classes

struct  SkFILEID
 
struct  SkOSFileIterData
 

Functions

void sk_fsync (FILE *f)
 
bool sk_exists (const char *path, SkFILE_Flags flags)
 
static bool sk_ino (FILE *a, SkFILEID *id)
 
bool sk_fidentical (FILE *a, FILE *b)
 
void sk_fmunmap (const void *addr, size_t length)
 
void * sk_fdmmap (int fd, size_t *size)
 
int sk_fileno (FILE *f)
 
void * sk_fmmap (FILE *f, size_t *size)
 
size_t sk_qread (FILE *file, void *buffer, size_t count, size_t offset)
 
static bool issuffixfor (const SkString &suffix, const char str[])
 

Function Documentation

◆ issuffixfor()

static bool issuffixfor ( const SkString suffix,
const char  str[] 
)
static

Definition at line 178 of file SkOSFile_posix.cpp.

178 {
179 size_t suffixLen = suffix.size();
180 size_t strLen = strlen(str);
181
182 return strLen >= suffixLen &&
183 memcmp(suffix.c_str(), str + strLen - suffixLen, suffixLen) == 0;
184}

◆ sk_exists()

bool sk_exists ( const char *  path,
SkFILE_Flags  flags = (SkFILE_Flags) 0 
)

Returns true if something (file, directory, ???) exists at this path, and has the specified access flags.

Definition at line 34 of file SkOSFile_posix.cpp.

34 {
35 int mode = F_OK;
37 mode |= R_OK;
38 }
40 mode |= W_OK;
41 }
42#ifdef SK_BUILD_FOR_IOS
43 // if the default path fails, check the bundle (but only if read-only)
44 if (0 == access(path, mode)) {
45 return true;
46 } else {
47 return (kRead_SkFILE_Flag == flags && ios_get_path_in_bundle(path, nullptr));
48 }
49#else
50 return (0 == access(path, mode));
51#endif
52}
@ kRead_SkFILE_Flag
Definition SkOSFile.h:20
@ kWrite_SkFILE_Flag
Definition SkOSFile.h:21
FlutterSemanticsFlag flags
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition switches.h:228

◆ sk_fdmmap()

void * sk_fdmmap ( int  fd,
size_t *  length 
)

Maps a file descriptor into memory. Returns the address and length on success, NULL otherwise. The mapping is read only. When finished with the mapping, free the returned pointer with sk_fmunmap.

Definition at line 84 of file SkOSFile_posix.cpp.

84 {
85 struct stat status = {};
86 if (0 != fstat(fd, &status)) {
87 return nullptr;
88 }
89 if (!S_ISREG(status.st_mode)) {
90 return nullptr;
91 }
92 if (!SkTFitsIn<size_t>(status.st_size)) {
93 return nullptr;
94 }
95 size_t fileSize = static_cast<size_t>(status.st_size);
96
97 void* addr = mmap(nullptr, fileSize, PROT_READ, MAP_PRIVATE, fd, 0);
98 if (MAP_FAILED == addr) {
99 return nullptr;
100 }
101
102 *size = fileSize;
103 return addr;
104}
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259

◆ sk_fidentical()

bool sk_fidentical ( FILE *  a,
FILE *  b 
)

Returns true if the two point at the exact same filesystem object.

Definition at line 73 of file SkOSFile_posix.cpp.

73 {
74 SkFILEID aID, bID;
75 return sk_ino(a, &aID) && sk_ino(b, &bID)
76 && aID.ino == bID.ino
77 && aID.dev == bID.dev;
78}
static bool sk_ino(FILE *a, SkFILEID *id)
static bool b
struct MyStruct a[10]

◆ sk_fileno()

int sk_fileno ( FILE *  f)

Returns the underlying file descriptor for the given file. The return value will be < 0 on failure.

Definition at line 106 of file SkOSFile_posix.cpp.

106 {
107 return fileno(f);
108}

◆ sk_fmmap()

void * sk_fmmap ( FILE *  f,
size_t *  length 
)

Maps a file into memory. Returns the address and length on success, NULL otherwise. The mapping is read only. When finished with the mapping, free the returned pointer with sk_fmunmap.

Definition at line 110 of file SkOSFile_posix.cpp.

110 {
111 int fd = sk_fileno(f);
112 if (fd < 0) {
113 return nullptr;
114 }
115
116 return sk_fdmmap(fd, size);
117}
int sk_fileno(FILE *f)
void * sk_fdmmap(int fd, size_t *size)

◆ sk_fmunmap()

void sk_fmunmap ( const void *  addr,
size_t  length 
)

Unmaps a file previously mapped by sk_fmmap or sk_fdmmap. The length parameter must be the same as returned from sk_fmmap.

Definition at line 80 of file SkOSFile_posix.cpp.

80 {
81 munmap(const_cast<void*>(addr), length);
82}
size_t length

◆ sk_fsync()

void sk_fsync ( FILE *  f)

Definition at line 27 of file SkOSFile_posix.cpp.

27 {
28#if !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__) && !defined(_NEWLIB_VERSION)
29 int fd = fileno(f);
30 fsync(fd);
31#endif
32}

◆ sk_ino()

static bool sk_ino ( FILE *  a,
SkFILEID id 
)
static

Definition at line 59 of file SkOSFile_posix.cpp.

59 {
60 int fd = fileno(a);
61 if (fd < 0) {
62 return 0;
63 }
64 struct stat status = {};
65 if (0 != fstat(fd, &status)) {
66 return 0;
67 }
68 id->dev = status.st_dev;
69 id->ino = status.st_ino;
70 return true;
71}

◆ sk_qread()

size_t sk_qread ( FILE *  file,
void *  buffer,
size_t  count,
size_t  offset 
)

Definition at line 119 of file SkOSFile_posix.cpp.

119 {
120 int fd = sk_fileno(file);
121 if (fd < 0) {
122 return SIZE_MAX;
123 }
124 ssize_t bytesRead = pread(fd, buffer, count, offset);
125 if (bytesRead < 0) {
126 return SIZE_MAX;
127 }
128 return bytesRead;
129}
int count
static const uint8_t buffer[]
Point offset