Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkOSFile.h
1 
2 /*
3  * Copyright 2006 The Android Open Source Project
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 
10 // TODO: add unittests for all these operations
11 
12 #ifndef SkOSFile_DEFINED
13 #define SkOSFile_DEFINED
14 
15 #include <stdio.h>
16 
17 #include "SkString.h"
18 
19 enum SkFILE_Flags {
20  kRead_SkFILE_Flag = 0x01,
21  kWrite_SkFILE_Flag = 0x02
22 };
23 
24 #ifdef _WIN32
25 const static char SkPATH_SEPARATOR = '\\';
26 #else
27 const static char SkPATH_SEPARATOR = '/';
28 #endif
29 
30 FILE* sk_fopen(const char path[], SkFILE_Flags);
31 void sk_fclose(FILE*);
32 
33 size_t sk_fgetsize(FILE*);
36 bool sk_frewind(FILE*);
37 
38 size_t sk_fread(void* buffer, size_t byteCount, FILE*);
39 size_t sk_fwrite(const void* buffer, size_t byteCount, FILE*);
40 
41 char* sk_fgets(char* str, int size, FILE* f);
42 
43 void sk_fflush(FILE*);
44 void sk_fsync(FILE*);
45 
46 bool sk_fseek(FILE*, size_t);
47 bool sk_fmove(FILE*, long);
48 size_t sk_ftell(FILE*);
49 
54 void* sk_fmmap(FILE* f, size_t* length);
55 
60 void* sk_fdmmap(int fd, size_t* length);
61 
65 void sk_fmunmap(const void* addr, size_t length);
66 
68 bool sk_fidentical(FILE* a, FILE* b);
69 
73 int sk_fileno(FILE* f);
74 
78 bool sk_exists(const char *path, SkFILE_Flags = (SkFILE_Flags)0);
79 
80 // Returns true if a directory exists at this path.
81 bool sk_isdir(const char *path);
82 
83 // Have we reached the end of the file?
84 int sk_feof(FILE *);
85 
86 
87 // Create a new directory at this path; returns true if successful.
88 // If the directory already existed, this will return true.
89 // Description of the error, if any, will be written to stderr.
90 bool sk_mkdir(const char* path);
91 
92 class SkOSFile {
93 public:
94  class Iter {
95  public:
96  Iter();
97  Iter(const char path[], const char suffix[] = NULL);
98  ~Iter();
99 
100  void reset(const char path[], const char suffix[] = NULL);
105  bool next(SkString* name, bool getDir = false);
106 
107  static const size_t kStorageSize = 40;
108  private:
109  SkAlignedSStorage<kStorageSize> fSelf;
110  };
111 };
112 
116 class SkOSPath {
117 public:
126  static SkString Join(const char* rootPath, const char* relativePath);
127 
136  static SkString Basename(const char* fullPath);
137 
146  static SkString Dirname(const char* fullPath);
147 };
148 
149 #endif
static SkString Dirname(const char *fullPath)
Given a qualified file name returns the directory.
Functions for modifying SkStrings which represent paths on the filesystem.
Definition: SkOSFile.h:116
static SkString Basename(const char *fullPath)
Return the name of the file, ignoring the directory structure.
Definition: SkOSFile.h:92
Definition: SkOSFile.h:94
static SkString Join(const char *rootPath, const char *relativePath)
Assembles rootPath and relativePath into a single path, like this: rootPath/relativePath.
bool next(SkString *name, bool getDir=false)
If getDir is true, only returns directories.
Light weight class for managing strings.
Definition: SkString.h:121