Flutter Engine
The Flutter Engine
Classes | Enumerations | Functions
SkOSFile.h File Reference
#include <stdio.h>
#include "include/core/SkString.h"
#include "include/private/base/SkTemplates.h"

Go to the source code of this file.

Classes

class  SkOSFile
 
class  SkOSFile::Iter
 

Enumerations

enum  SkFILE_Flags { kRead_SkFILE_Flag = 0x01 , kWrite_SkFILE_Flag = 0x02 }
 

Functions

FILE * sk_fopen (const char path[], SkFILE_Flags)
 
void sk_fclose (FILE *)
 
size_t sk_fgetsize (FILE *)
 
size_t sk_fwrite (const void *buffer, size_t byteCount, FILE *)
 
void sk_fflush (FILE *)
 
void sk_fsync (FILE *)
 
size_t sk_ftell (FILE *)
 
void * sk_fmmap (FILE *f, size_t *length)
 
void * sk_fdmmap (int fd, size_t *length)
 
void sk_fmunmap (const void *addr, size_t length)
 
bool sk_fidentical (FILE *a, FILE *b)
 
int sk_fileno (FILE *f)
 
bool sk_exists (const char *path, SkFILE_Flags=(SkFILE_Flags) 0)
 
bool sk_isdir (const char *path)
 
size_t sk_qread (FILE *, void *buffer, size_t count, size_t offset)
 
bool sk_mkdir (const char *path)
 

Enumeration Type Documentation

◆ SkFILE_Flags

Enumerator
kRead_SkFILE_Flag 
kWrite_SkFILE_Flag 

Definition at line 19 of file SkOSFile.h.

19 {
20 kRead_SkFILE_Flag = 0x01,
22};
@ kRead_SkFILE_Flag
Definition: SkOSFile.h:20
@ kWrite_SkFILE_Flag
Definition: SkOSFile.h:21

Function Documentation

◆ 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}
FlutterSemanticsFlag flags
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
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_fclose()

void sk_fclose ( FILE *  f)

Definition at line 135 of file SkOSFile_stdio.cpp.

135 {
136 if (f) {
137 fclose(f);
138 }
139}

◆ 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_fflush()

void sk_fflush ( FILE *  f)

Definition at line 122 of file SkOSFile_stdio.cpp.

122 {
123 SkASSERT(f);
124 fflush(f);
125}
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ sk_fgetsize()

size_t sk_fgetsize ( FILE *  f)

Definition at line 99 of file SkOSFile_stdio.cpp.

99 {
100 SkASSERT(f);
101
102 long curr = ftell(f); // remember where we are
103 if (curr < 0) {
104 return 0;
105 }
106
107 fseek(f, 0, SEEK_END); // go to the end
108 long size = ftell(f); // record the size
109 if (size < 0) {
110 size = 0;
111 }
112
113 fseek(f, curr, SEEK_SET); // go back to our prev location
114 return size;
115}

◆ 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_fopen()

FILE * sk_fopen ( const char  path[],
SkFILE_Flags  flags 
)

Definition at line 64 of file SkOSFile_stdio.cpp.

64 {
65 char perm[4] = {0, 0, 0, 0};
66 char* p = perm;
67
69 *p++ = 'r';
70 }
72 *p++ = 'w';
73 }
74 *p = 'b';
75
76 FILE* file = nullptr;
77#ifdef _WIN32
78 file = fopen_win(path, perm);
79#else
80 file = fopen(path, perm);
81#endif
82#ifdef SK_BUILD_FOR_IOS
83 // if not found in default path and read-only, try to open from bundle
84 if (!file && kRead_SkFILE_Flag == flags) {
85 SkString bundlePath;
86 if (ios_get_path_in_bundle(path, &bundlePath)) {
87 file = fopen(bundlePath.c_str(), perm);
88 }
89 }
90#endif
91
92 if (nullptr == file && (flags & kWrite_SkFILE_Flag)) {
93 SkDEBUGF("sk_fopen: fopen(\"%s\", \"%s\") returned nullptr (errno:%d): %s\n",
94 path, perm, errno, strerror(errno));
95 }
96 return file;
97}
#define SkDEBUGF(...)
Definition: SkDebug.h:24
const char * c_str() const
Definition: SkString.h:133

◆ 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_ftell()

size_t sk_ftell ( FILE *  f)

Definition at line 127 of file SkOSFile_stdio.cpp.

127 {
128 long curr = ftell(f);
129 if (curr < 0) {
130 return 0;
131 }
132 return curr;
133}

◆ sk_fwrite()

size_t sk_fwrite ( const void *  buffer,
size_t  byteCount,
FILE *  f 
)

Definition at line 117 of file SkOSFile_stdio.cpp.

117 {
118 SkASSERT(f);
119 return fwrite(buffer, 1, byteCount, f);
120}
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126

◆ sk_isdir()

bool sk_isdir ( const char *  path)

Definition at line 141 of file SkOSFile_stdio.cpp.

141 {
142 struct stat status = {};
143 if (0 != stat(path, &status)) {
144#ifdef SK_BUILD_FOR_IOS
145 // check the bundle directory if not in default path
146 SkString bundlePath;
147 if (ios_get_path_in_bundle(path, &bundlePath)) {
148 if (0 != stat(bundlePath.c_str(), &status)) {
149 return false;
150 }
151 }
152#else
153 return false;
154#endif
155 }
156 return SkToBool(status.st_mode & S_IFDIR);
157}
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35

◆ sk_mkdir()

bool sk_mkdir ( const char *  path)

Definition at line 159 of file SkOSFile_stdio.cpp.

159 {
160 if (sk_isdir(path)) {
161 return true;
162 }
163 if (sk_exists(path)) {
164 fprintf(stderr,
165 "sk_mkdir: path '%s' already exists but is not a directory\n",
166 path);
167 return false;
168 }
169
170 int retval;
171#ifdef _WIN32
172 retval = _mkdir(path);
173#else
174 retval = mkdir(path, 0777);
175 if (retval) {
176 perror("mkdir() failed with error: ");
177 }
178#endif
179 return 0 == retval;
180}
bool sk_exists(const char *path, SkFILE_Flags=(SkFILE_Flags) 0)
bool sk_isdir(const char *path)

◆ 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
Definition: FontMgrTest.cpp:50
SeparatedVector2 offset