OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 // TODO: add unittests for all these operations | 10 // TODO: add unittests for all these operations |
11 | 11 |
12 #ifndef SkOSFile_DEFINED | 12 #ifndef SkOSFile_DEFINED |
13 #define SkOSFile_DEFINED | 13 #define SkOSFile_DEFINED |
14 | 14 |
| 15 #include <stdio.h> |
| 16 |
15 #include "SkString.h" | 17 #include "SkString.h" |
16 | 18 |
17 struct SkFILE; | |
18 | |
19 enum SkFILE_Flags { | 19 enum SkFILE_Flags { |
20 kRead_SkFILE_Flag = 0x01, | 20 kRead_SkFILE_Flag = 0x01, |
21 kWrite_SkFILE_Flag = 0x02 | 21 kWrite_SkFILE_Flag = 0x02 |
22 }; | 22 }; |
23 | 23 |
24 #ifdef _WIN32 | 24 #ifdef _WIN32 |
25 const static char SkPATH_SEPARATOR = '\\'; | 25 const static char SkPATH_SEPARATOR = '\\'; |
26 #else | 26 #else |
27 const static char SkPATH_SEPARATOR = '/'; | 27 const static char SkPATH_SEPARATOR = '/'; |
28 #endif | 28 #endif |
29 | 29 |
30 SkFILE* sk_fopen(const char path[], SkFILE_Flags); | 30 FILE* sk_fopen(const char path[], SkFILE_Flags); |
31 void sk_fclose(SkFILE*); | 31 void sk_fclose(FILE*); |
32 | 32 |
33 size_t sk_fgetsize(SkFILE*); | 33 size_t sk_fgetsize(FILE*); |
34 /** Return true if the file could seek back to the beginning | 34 /** Return true if the file could seek back to the beginning |
35 */ | 35 */ |
36 bool sk_frewind(SkFILE*); | 36 bool sk_frewind(FILE*); |
37 | 37 |
38 size_t sk_fread(void* buffer, size_t byteCount, SkFILE*); | 38 size_t sk_fread(void* buffer, size_t byteCount, FILE*); |
39 size_t sk_fwrite(const void* buffer, size_t byteCount, SkFILE*); | 39 size_t sk_fwrite(const void* buffer, size_t byteCount, FILE*); |
40 | 40 |
41 char* sk_fgets(char* str, int size, SkFILE* f); | 41 char* sk_fgets(char* str, int size, FILE* f); |
42 | 42 |
43 void sk_fflush(SkFILE*); | 43 void sk_fflush(FILE*); |
44 | 44 |
45 bool sk_fseek(SkFILE*, size_t); | 45 bool sk_fseek(FILE*, size_t); |
46 bool sk_fmove(SkFILE*, long); | 46 bool sk_fmove(FILE*, long); |
47 size_t sk_ftell(SkFILE*); | 47 size_t sk_ftell(FILE*); |
48 | 48 |
49 /** Maps a file into memory. Returns the address and length on success, NULL oth
erwise. | 49 /** Maps a file into memory. Returns the address and length on success, NULL oth
erwise. |
50 * The mapping is read only. | 50 * The mapping is read only. |
51 * When finished with the mapping, free the returned pointer with sk_fmunmap. | 51 * When finished with the mapping, free the returned pointer with sk_fmunmap. |
52 */ | 52 */ |
53 void* sk_fmmap(SkFILE* f, size_t* length); | 53 void* sk_fmmap(FILE* f, size_t* length); |
54 | 54 |
55 /** Maps a file descriptor into memory. Returns the address and length on succes
s, NULL otherwise. | 55 /** Maps a file descriptor into memory. Returns the address and length on succes
s, NULL otherwise. |
56 * The mapping is read only. | 56 * The mapping is read only. |
57 * When finished with the mapping, free the returned pointer with sk_fmunmap. | 57 * When finished with the mapping, free the returned pointer with sk_fmunmap. |
58 */ | 58 */ |
59 void* sk_fdmmap(int fd, size_t* length); | 59 void* sk_fdmmap(int fd, size_t* length); |
60 | 60 |
61 /** Unmaps a file previously mapped by sk_fmmap or sk_fdmmap. | 61 /** Unmaps a file previously mapped by sk_fmmap or sk_fdmmap. |
62 * The length parameter must be the same as returned from sk_fmmap. | 62 * The length parameter must be the same as returned from sk_fmmap. |
63 */ | 63 */ |
64 void sk_fmunmap(const void* addr, size_t length); | 64 void sk_fmunmap(const void* addr, size_t length); |
65 | 65 |
66 /** Returns true if the two point at the exact same filesystem object. */ | 66 /** Returns true if the two point at the exact same filesystem object. */ |
67 bool sk_fidentical(SkFILE* a, SkFILE* b); | 67 bool sk_fidentical(FILE* a, FILE* b); |
68 | 68 |
69 /** Returns the underlying file descriptor for the given file. | 69 /** Returns the underlying file descriptor for the given file. |
70 * The return value will be < 0 on failure. | 70 * The return value will be < 0 on failure. |
71 */ | 71 */ |
72 int sk_fileno(SkFILE* f); | 72 int sk_fileno(FILE* f); |
73 | 73 |
74 /** Returns true if something (file, directory, ???) exists at this path, | 74 /** Returns true if something (file, directory, ???) exists at this path, |
75 * and has the specified access flags. | 75 * and has the specified access flags. |
76 */ | 76 */ |
77 bool sk_exists(const char *path, SkFILE_Flags = (SkFILE_Flags)0); | 77 bool sk_exists(const char *path, SkFILE_Flags = (SkFILE_Flags)0); |
78 | 78 |
79 // Returns true if a directory exists at this path. | 79 // Returns true if a directory exists at this path. |
80 bool sk_isdir(const char *path); | 80 bool sk_isdir(const char *path); |
81 | 81 |
82 // Have we reached the end of the file? | 82 // Have we reached the end of the file? |
83 int sk_feof(SkFILE *); | 83 int sk_feof(FILE *); |
84 | 84 |
85 | 85 |
86 // Create a new directory at this path; returns true if successful. | 86 // Create a new directory at this path; returns true if successful. |
87 // If the directory already existed, this will return true. | 87 // If the directory already existed, this will return true. |
88 // Description of the error, if any, will be written to stderr. | 88 // Description of the error, if any, will be written to stderr. |
89 bool sk_mkdir(const char* path); | 89 bool sk_mkdir(const char* path); |
90 | 90 |
91 class SkOSFile { | 91 class SkOSFile { |
92 public: | 92 public: |
93 class Iter { | 93 class Iter { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 * Behaves like python's os.path.dirname. If the fullPath is | 139 * Behaves like python's os.path.dirname. If the fullPath is |
140 * /dir/subdir/ the return will be /dir/subdir/ | 140 * /dir/subdir/ the return will be /dir/subdir/ |
141 * @param fullPath Full path to the file. | 141 * @param fullPath Full path to the file. |
142 * @return SkString The dir containing the file - anything preceding the | 142 * @return SkString The dir containing the file - anything preceding the |
143 * final slash, or the full name if ending in a slash. | 143 * final slash, or the full name if ending in a slash. |
144 */ | 144 */ |
145 static SkString Dirname(const char* fullPath); | 145 static SkString Dirname(const char* fullPath); |
146 }; | 146 }; |
147 | 147 |
148 #endif | 148 #endif |
OLD | NEW |