28 bool isinstance =
false;
44 if (file ==
nullptr) {
61 if (file !=
nullptr) {
66 intptr_t file_pointer =
reinterpret_cast<intptr_t
>(file);
74static void ReleaseFile(
void* isolate_callback_data,
void* peer) {
75 File* file =
reinterpret_cast<File*
>(peer);
82 File* file =
reinterpret_cast<File*
>(file_pointer);
84 dart_this,
reinterpret_cast<void*
>(file),
sizeof(*file),
ReleaseFile);
85 file->SetFinalizableHandle(handle);
86 SetFile(dart_this, file_pointer);
101 if (file !=
nullptr) {
123 "File_Close expects the receiver to be a _RandomAccessFileOpsImpl."));
128 reinterpret_cast<intptr_t*
>(&file)));
129 if (file ==
nullptr) {
146 int64_t bytes_read = file->Read(
reinterpret_cast<void*
>(&
buffer), 1);
147 if (bytes_read == 1) {
149 }
else if (bytes_read == 0) {
161 uint8_t
buffer =
static_cast<uint8_t
>(
byte & 0xff);
162 bool success = file->WriteFully(
reinterpret_cast<void*
>(&
buffer), 1);
184 uint8_t*
buffer =
nullptr;
191 int64_t bytes_read = file->Read(
reinterpret_cast<void*
>(
buffer),
length);
192 if (bytes_read < 0) {
196 if (bytes_read <
length) {
197 const int kNumArgs = 3;
199 dart_args[0] = external_array;
207 kNumArgs, dart_args);
226 intptr_t array_len = 0;
232 bool is_byte_data =
false;
237 intptr_t bytes_count;
239 reinterpret_cast<void**
>(&
buffer),
244 ASSERT(bytes_count == array_len);
254 int64_t bytes_read = file->Read(
reinterpret_cast<void*
>(
buffer),
length);
258 if (bytes_read >= 0) {
285 intptr_t buffer_len = 0;
296 char* byte_buffer =
reinterpret_cast<char*
>(
buffer);
297 bool success = file->WriteFully(byte_buffer +
start,
length);
313 intptr_t return_value = file->Position();
314 if (return_value >= 0) {
324 int64_t position = 0;
326 if (file->SetPosition(position)) {
342 if (file->Truncate(
length)) {
356 int64_t return_value = file->Length();
357 if (return_value >= 0) {
368 if (return_value >= 0) {
379 if (return_value >= 0) {
391 "The second argument must be a 64-bit int."));
404 if (return_value >= 0) {
416 "The second argument must be a 64-bit int."));
572 const char* path =
nullptr;
575 if (path !=
nullptr) {
591 ASSERT((fd == STDIN_FILENO) || (fd == STDOUT_FILENO) ||
592 (fd == STDERR_FILENO));
624 intptr_t data_length_unused;
626 returned_data, &data_type_unused, &data_location, &data_length_unused);
646#define IS_SEPARATOR(c) ((c) == '/' || (c) == 0)
650#define CHECK_CAN_INCREMENT(i) \
651 if ((i) + 1 >= outlen) { \
657 snprintf(out, outlen,
".");
661 const bool rooted = (in[0] ==
'/');
662 intptr_t in_index = 0;
663 intptr_t out_index = 0;
666 out[out_index++] =
'/';
670 intptr_t dotdot = out_index;
672 while (in[in_index] != 0) {
673 if (in[in_index] ==
'/') {
677 }
else if ((in[in_index] ==
'.') &&
IS_SEPARATOR(in[in_index + 1])) {
681 }
else if ((in[in_index] ==
'.') && (in[in_index + 1] ==
'.') &&
685 if (out_index > dotdot) {
689 while ((out_index > dotdot) && (out[out_index] !=
'/')) {
696 }
else if (!rooted) {
698 out[out_index++] =
'/';
701 out[out_index++] =
'.';
702 out[out_index++] =
'.';
706 if ((rooted && out_index != 1) || (!rooted && out_index != 0)) {
708 out[out_index++] =
'/';
713 out[out_index++] = in[in_index++];
718 if (out_index == 0) {
719 snprintf(out, outlen,
".");
743 return reinterpret_cast<File*
>(
value.Value());
792 if (!
CreatePipe(namespc, &readPipe, &writePipe)) {
803 pipes->
SetAt(0, readHandle);
804 pipes->
SetAt(1, writeHandle);
824 namespc,
reinterpret_cast<const char*
>(filename.
Buffer()), file_mode);
825 if (file ==
nullptr) {
829 reinterpret_cast<intptr_t
>(file),
sizeof(*file),
ReleaseFile));
877 return File::Copy(namespc,
reinterpret_cast<const char*
>(old_path.
Buffer()),
894 namespc,
reinterpret_cast<const char*
>(filename.
Buffer()));
913 ASSERT(!file->IsClosed());
924 if (file->IsClosed()) {
927 const intptr_t return_value = file->Position();
928 if (return_value < 0) {
943 if (file->IsClosed()) {
959 if (file->IsClosed()) {
963 if (file->Truncate(
length)) {
975 if (file->IsClosed()) {
978 const int64_t return_value = file->Length();
979 if (return_value < 0) {
996 namespc,
reinterpret_cast<const char*
>(filepath.
Buffer()));
997 if (return_value < 0) {
1014 namespc,
reinterpret_cast<const char*
>(filepath.
Buffer()));
1015 if (return_value < 0) {
1035 namespc,
reinterpret_cast<const char*
>(filepath.
Buffer()), millis)
1051 namespc,
reinterpret_cast<const char*
>(filepath.
Buffer()));
1052 if (return_value < 0) {
1072 namespc,
reinterpret_cast<const char*
>(filepath.
Buffer()), millis)
1083 if (file->IsClosed()) {
1095 if (file->IsClosed()) {
1099 const int64_t bytes_read = file->Read(
reinterpret_cast<void*
>(&
buffer), 1);
1100 if (bytes_read < 0) {
1103 if (bytes_read == 0) {
1118 if (file->IsClosed()) {
1122 uint8_t
buffer =
static_cast<uint8_t
>(
byte & 0xff);
1123 return file->WriteFully(
reinterpret_cast<void*
>(&
buffer), 1)
1137 if (file->IsClosed()) {
1142 if (io_buffer ==
nullptr) {
1146 const int64_t bytes_read = file->Read(
data,
length);
1147 if (bytes_read < 0) {
1159 result->SetAt(1, external_array);
1172 if (file->IsClosed()) {
1177 if (io_buffer ==
nullptr) {
1181 const int64_t bytes_read = file->Read(
data,
length);
1182 if (bytes_read < 0) {
1195 result->SetAt(2, external_array);
1233 if ((request.
Length() != 4) ||
1238 if (file->IsClosed()) {
1244 const uint8_t* buffer_start;
1245 if (request[1]->IsTypedData()) {
1253 buffer_start = allocated_buffer;
1254 for (
int i = 0; i <
length; i++) {
1255 if (array[i +
start]->IsInt32OrInt64()) {
1257 allocated_buffer[i] =
static_cast<uint8_t
>(
value & 0xFF);
1265 return file->WriteFully(
reinterpret_cast<const void*
>(buffer_start),
length)
1276 if (!request[1]->IsUint8Array() || !request[2]->IsString()) {
1282 reinterpret_cast<const char*
>(link_name.
Buffer()),
1294 if (!request[1]->IsUint8Array()) {
1299 reinterpret_cast<const char*
>(link_path.
Buffer()))
1310 if (!request[1]->IsUint8Array() || !request[2]->IsString()) {
1316 reinterpret_cast<const char*
>(old_path.
Buffer()),
1328 if (!request[1]->IsUint8Array()) {
1333 namespc,
reinterpret_cast<const char*
>(link_path.
Buffer()));
1346 if (!request[1]->IsUint8Array() || !request[2]->IsBool()) {
1352 File::GetType(namespc,
reinterpret_cast<const char*
>(path.Buffer()),
1353 follow_links.
Value());
1363 if (!request[1]->IsString() || !request[2]->IsString()) {
1411 if (file->IsClosed()) {
1424 const char* ch = uri;
1425 while ((*ch !=
'\0') && (*ch !=
'%')) {
1430 decoded_ =
const_cast<char*
>(uri);
1433 const intptr_t len = strlen(uri);
1436 char* dest =
reinterpret_cast<char*
>(
malloc(len + 1));
1439 strncpy(dest, uri, i);
1442 while (*ch !=
'\0') {
1444 *(dest++) = *(ch++);
1447 if ((i + 3 > len) || !HexCharPairToByte(ch + 1, dest)) {
1459 if (uri_ != decoded_ && decoded_ !=
nullptr) {
1464bool UriDecoder::HexCharPairToByte(
const char* pch,
char*
const dest) {
1466 for (
int i = 0; i < 2; i++) {
1467 char char_code = *(pch + i);
1468 if (0x30 <= char_code && char_code <= 0x39) {
1469 byte =
byte * 16 + char_code - 0x30;
1473 if (0x61 <= char_code && char_code <= 0x66) {
1474 byte =
byte * 16 + char_code - 0x57;
#define DEBUG_ASSERT(cond)
#define FUNCTION_NAME(name)
void SetAt(intptr_t index, CObject *value)
const char * CString() const
const uint8_t * Buffer() const
Dart_TypedData_Type Type() const
const uint8_t * Buffer() const
static Dart_CObject * NewString(const char *str)
static CObject * IllegalArgumentError()
static CObject * FileClosedError()
static void FreeIOBufferData(Dart_CObject *object)
static Dart_CObject * NewIntptr(intptr_t value)
static Dart_CObject * NewIOBuffer(int64_t length)
static CObject * Bool(bool value)
static Dart_CObject * NewArray(intptr_t length)
static constexpr int kSuccess
static Dart_CObject * NewNativePointer(intptr_t ptr, intptr_t size, Dart_HandleFinalizer callback)
static Dart_CObject * NewInt32(int32_t value)
static Dart_CObject * NewInt64(int64_t value)
static CObject * NewOSError()
static void ShrinkIOBuffer(Dart_CObject *cobject, int64_t new_length)
static int64_t GetNativeIntegerArgument(Dart_NativeArguments args, intptr_t index)
static const char * GetNativeTypedDataArgument(Dart_NativeArguments args, intptr_t index)
static Dart_Handle NewDartOSError()
static bool GetBooleanValue(Dart_Handle bool_obj)
static bool GetInt64Value(Dart_Handle value_obj, int64_t *value)
static intptr_t GetNativeIntptrArgument(Dart_NativeArguments args, intptr_t index)
static Dart_Handle NewString(const char *str)
static Dart_Handle NewDartArgumentError(const char *message)
static Dart_Handle NewInternalError(const char *message)
static Dart_Handle GetDartType(const char *library_url, const char *class_name)
static const char * GetNativeStringArgument(Dart_NativeArguments args, intptr_t index)
static bool GetNativeBooleanArgument(Dart_NativeArguments args, intptr_t index)
static bool CreatePipe(Namespace *namespc, File **readPipe, File **writePipe)
static CObject * PositionRequest(const CObjectArray &request)
static CObject * OpenRequest(const CObjectArray &request)
static CObject * TypeRequest(const CObjectArray &request)
static CObject * LengthFromPathRequest(const CObjectArray &request)
static bool DeleteLink(Namespace *namespc, const char *path)
static CObject * FlushRequest(const CObjectArray &request)
static CObject * TruncateRequest(const CObjectArray &request)
static CObject * DeleteRequest(const CObjectArray &request)
static CObject * ReadIntoRequest(const CObjectArray &request)
static const char * GetCanonicalPath(Namespace *namespc, const char *path, char *dest=nullptr, int dest_size=0)
static CObject * ReadByteRequest(const CObjectArray &request)
static CObject * RenameRequest(const CObjectArray &request)
static CObject * ExistsRequest(const CObjectArray &request)
static CObject * SetLastModifiedRequest(const CObjectArray &request)
static bool SetLastAccessed(Namespace *namespc, const char *path, int64_t millis)
static CObject * StatRequest(const CObjectArray &request)
static CObject * CopyRequest(const CObjectArray &request)
static bool SetLastModified(Namespace *namespc, const char *path, int64_t millis)
static CObject * SetPositionRequest(const CObjectArray &request)
static time_t LastModified(Namespace *namespc, const char *path)
static void Stat(Namespace *namespc, const char *path, int64_t *data)
static bool Create(Namespace *namespc, const char *path, bool exclusive)
static CObject * LinkTargetRequest(const CObjectArray &request)
static bool Rename(Namespace *namespc, const char *old_path, const char *new_path)
static CObject * WriteFromRequest(const CObjectArray &request)
static bool Delete(Namespace *namespc, const char *path)
static CObject * DeleteLinkRequest(const CObjectArray &request)
static CObject * ReadRequest(const CObjectArray &request)
static CObject * RenameLinkRequest(const CObjectArray &request)
static int64_t LengthFromPath(Namespace *namespc, const char *path)
static CObject * CreateLinkRequest(const CObjectArray &request)
static bool Copy(Namespace *namespc, const char *old_path, const char *new_path)
static time_t LastAccessed(Namespace *namespc, const char *path)
static intptr_t CleanUnixPath(const char *in, char *out, intptr_t outlen)
static CObject * IdenticalRequest(const CObjectArray &request)
static CObject * LengthRequest(const CObjectArray &request)
static CObject * WriteByteRequest(const CObjectArray &request)
static bool Exists(Namespace *namespc, const char *path)
static File * Open(Namespace *namespc, const char *path, FileOpenMode mode)
static FileOpenMode DartModeToFileMode(DartFileOpenMode mode)
static CObject * CreateRequest(const CObjectArray &request)
static CObject * LastAccessedRequest(const CObjectArray &request)
static CObject * ResolveSymbolicLinksRequest(const CObjectArray &request)
static Identical AreIdentical(Namespace *namespc_1, const char *file_1, Namespace *namespc_2, const char *file_2)
static const char * LinkTarget(Namespace *namespc, const char *pathname, char *dest=nullptr, int dest_size=0)
static bool CreateLink(Namespace *namespc, const char *path, const char *target)
static CObject * CreatePipeRequest(const CObjectArray &request)
static File * OpenStdio(int fd)
static StdioHandleType GetStdioHandleType(int fd)
static CObject * SetLastAccessedRequest(const CObjectArray &request)
static Type GetType(Namespace *namespc, const char *path, bool follow_links)
static CObject * CloseRequest(const CObjectArray &request)
static CObject * LockRequest(const CObjectArray &request)
static CObject * LastModifiedRequest(const CObjectArray &request)
static bool RenameLink(Namespace *namespc, const char *old_path, const char *new_path)
static Dart_Handle Allocate(intptr_t size, uint8_t **buffer)
static Namespace * GetNamespace(Dart_NativeArguments args, intptr_t index)
UriDecoder(const char *uri)
struct _Dart_Handle * Dart_Handle
struct _Dart_NativeArguments * Dart_NativeArguments
@ Dart_TypedData_kFloat32x4
@ Dart_TypedData_kInt32x4
@ Dart_TypedData_kFloat64x2
@ Dart_TypedData_kFloat32
@ Dart_TypedData_kFloat64
@ Dart_TypedData_kUint8Clamped
struct _Dart_FinalizableHandle * Dart_FinalizableHandle
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static const uint8_t buffer[]
void FUNCTION_NAME() File_WriteByte(Dart_NativeArguments args)
void FUNCTION_NAME() File_Rename(Dart_NativeArguments args)
void FUNCTION_NAME() File_AreIdentical(Dart_NativeArguments args)
void FUNCTION_NAME() File_RenameLink(Dart_NativeArguments args)
void FUNCTION_NAME() File_SetPosition(Dart_NativeArguments args)
void FUNCTION_NAME() File_Read(Dart_NativeArguments args)
void FUNCTION_NAME() File_ReadByte(Dart_NativeArguments args)
void FUNCTION_NAME() File_GetStdioHandleType(Dart_NativeArguments args)
void FUNCTION_NAME() File_GetFD(Dart_NativeArguments args)
static Dart_Handle ThrowIfError(Dart_Handle handle)
void FUNCTION_NAME() File_OpenStdio(Dart_NativeArguments args)
void FUNCTION_NAME() File_GetType(Dart_NativeArguments args)
static void ReleaseFile(void *isolate_callback_data, void *peer)
void FUNCTION_NAME() File_Lock(Dart_NativeArguments args)
static bool IsFile(Dart_Handle file_obj)
static constexpr int kFileNativeFieldIndex
static File * CObjectToFilePointer(CObject *cobject)
void FUNCTION_NAME() File_Delete(Dart_NativeArguments args)
static File * GetFile(Dart_NativeArguments args)
void FUNCTION_NAME() File_CreateLink(Dart_NativeArguments args)
void FUNCTION_NAME() File_Exists(Dart_NativeArguments args)
void FUNCTION_NAME() File_LengthFromPath(Dart_NativeArguments args)
void FUNCTION_NAME() File_Close(Dart_NativeArguments args)
void FUNCTION_NAME() File_Copy(Dart_NativeArguments args)
void FUNCTION_NAME() File_LastModified(Dart_NativeArguments args)
void FUNCTION_NAME() File_SetLastAccessed(Dart_NativeArguments args)
void FUNCTION_NAME() File_SetPointer(Dart_NativeArguments args)
static void SetFile(Dart_Handle dart_this, intptr_t file_pointer)
void FUNCTION_NAME() File_Position(Dart_NativeArguments args)
void FUNCTION_NAME() File_LinkTarget(Dart_NativeArguments args)
void FUNCTION_NAME() File_CreatePipe(Dart_NativeArguments args)
void FUNCTION_NAME() File_SetLastModified(Dart_NativeArguments args)
void FUNCTION_NAME() File_GetPointer(Dart_NativeArguments args)
void FUNCTION_NAME() File_Create(Dart_NativeArguments args)
void FUNCTION_NAME() File_Open(Dart_NativeArguments args)
static int64_t CObjectInt32OrInt64ToInt64(CObject *cobject)
static int SizeInBytes(Dart_TypedData_Type type)
void FUNCTION_NAME() File_Length(Dart_NativeArguments args)
void FUNCTION_NAME() File_Stat(Dart_NativeArguments args)
void FUNCTION_NAME() File_Flush(Dart_NativeArguments args)
void FUNCTION_NAME() File_Truncate(Dart_NativeArguments args)
void FUNCTION_NAME() File_WriteFrom(Dart_NativeArguments args)
void FUNCTION_NAME() File_ResolveSymbolicLinks(Dart_NativeArguments args)
void FUNCTION_NAME() File_LastAccessed(Dart_NativeArguments args)
void FUNCTION_NAME() File_ReadInto(Dart_NativeArguments args)
void FUNCTION_NAME() File_DeleteLink(Dart_NativeArguments args)
static Namespace * CObjectToNamespacePointer(CObject *cobject)
DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, int index, intptr_t *value)
DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, Dart_Handle name, int number_of_arguments, Dart_Handle *arguments)
DART_EXPORT void Dart_SetBooleanReturnValue(Dart_NativeArguments args, bool retval)
void * malloc(size_t size)
DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception)
DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value)
DART_EXPORT void Dart_PropagateError(Dart_Handle handle)
DART_EXPORT Dart_FinalizableHandle Dart_NewFinalizableHandle(Dart_Handle object, void *peer, intptr_t external_allocation_size, Dart_HandleFinalizer callback)
DART_EXPORT Dart_Handle Dart_NewTypedData(Dart_TypedData_Type type, intptr_t length)
DART_EXPORT uint8_t * Dart_ScopeAllocate(intptr_t size)
DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, Dart_Handle retval)
DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object, Dart_TypedData_Type *type, void **data, intptr_t *len)
DART_EXPORT Dart_Isolate Dart_CurrentIsolate()
DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, intptr_t index, Dart_Handle value)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, int index, intptr_t value)
DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args, int64_t retval)
DART_EXPORT Dart_Handle Dart_ObjectIsType(Dart_Handle object, Dart_Handle type, bool *value)
constexpr intptr_t kMillisecondsPerSecond
DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, intptr_t offset, const uint8_t *native_array, intptr_t length)
DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, int index)
DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object)
DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t *len)
DART_EXPORT Dart_Handle Dart_NewList(intptr_t length)
DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url)
DART_EXPORT bool Dart_IsList(Dart_Handle object)
DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception)
DART_EXPORT bool Dart_IsNull(Dart_Handle object)
DART_EXPORT bool Dart_IsTypedData(Dart_Handle handle)
DART_EXPORT Dart_Handle Dart_Null()
static int8_t data[kExtLength]
union _Dart_CObject::@86 value
struct _Dart_CObject::@86::@91 as_external_typed_data
#define CHECK_CAN_INCREMENT(i)