2 * Copyright 2006 The Android Open Source Project
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 // TODO: add unittests for all these operations
11 #ifndef SkOSFile_DEFINED
12 #define SkOSFile_DEFINED
16 #include "include/core/SkString.h"
17 #include "include/private/SkTemplates.h"
20 kRead_SkFILE_Flag = 0x01,
21 kWrite_SkFILE_Flag = 0x02
24 FILE* sk_fopen(const char path[], SkFILE_Flags);
25 void sk_fclose(FILE*);
27 size_t sk_fgetsize(FILE*);
29 size_t sk_fwrite(const void* buffer, size_t byteCount, FILE*);
31 void sk_fflush(FILE*);
34 size_t sk_ftell(FILE*);
36 /** Maps a file into memory. Returns the address and length on success, NULL otherwise.
37 * The mapping is read only.
38 * When finished with the mapping, free the returned pointer with sk_fmunmap.
40 void* sk_fmmap(FILE* f, size_t* length);
42 /** Maps a file descriptor into memory. Returns the address and length on success, NULL otherwise.
43 * The mapping is read only.
44 * When finished with the mapping, free the returned pointer with sk_fmunmap.
46 void* sk_fdmmap(int fd, size_t* length);
48 /** Unmaps a file previously mapped by sk_fmmap or sk_fdmmap.
49 * The length parameter must be the same as returned from sk_fmmap.
51 void sk_fmunmap(const void* addr, size_t length);
53 /** Returns true if the two point at the exact same filesystem object. */
54 bool sk_fidentical(FILE* a, FILE* b);
56 /** Returns the underlying file descriptor for the given file.
57 * The return value will be < 0 on failure.
59 int sk_fileno(FILE* f);
61 /** Returns true if something (file, directory, ???) exists at this path,
62 * and has the specified access flags.
64 bool sk_exists(const char *path, SkFILE_Flags = (SkFILE_Flags)0);
66 // Returns true if a directory exists at this path.
67 bool sk_isdir(const char *path);
69 // Like pread, but may affect the file position marker.
70 // Returns the number of bytes read or SIZE_MAX if failed.
71 size_t sk_qread(FILE*, void* buffer, size_t count, size_t offset);
74 // Create a new directory at this path; returns true if successful.
75 // If the directory already existed, this will return true.
76 // Description of the error, if any, will be written to stderr.
77 bool sk_mkdir(const char* path);
83 // SPI for module use.
85 SK_SPI Iter(const char path[], const char suffix[] = nullptr);
88 SK_SPI void reset(const char path[], const char suffix[] = nullptr);
89 /** If getDir is true, only returns directories.
90 Results are undefined if true and false calls are
91 interleaved on a single iterator.
93 SK_SPI bool next(SkString* name, bool getDir = false);
95 static const size_t kStorageSize = 40;
97 alignas(void*) alignas(double) char fSelf[kStorageSize];