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.
13 #include <sys/types.h>
20 SkFILE* sk_fopen(const char path[], SkFILE_Flags flags) {
24 if (flags & kRead_SkFILE_Flag) {
27 if (flags & kWrite_SkFILE_Flag) {
33 //TODO: on Windows fopen is just ASCII or the current code page,
34 //convert to utf16 and use _wfopen
35 return (SkFILE*)::fopen(path, perm);
38 char* sk_fgets(char* str, int size, SkFILE* f) {
39 return ::fgets(str, size, (FILE *)f);
42 int sk_feof(SkFILE *f) {
43 // no :: namespace qualifier because it breaks android
44 return feof((FILE *)f);
47 size_t sk_fgetsize(SkFILE* f) {
50 long curr = ::ftell((FILE*)f); // remember where we are
55 ::fseek((FILE*)f, 0, SEEK_END); // go to the end
56 long size = ::ftell((FILE*)f); // record the size
61 ::fseek((FILE*)f, curr, SEEK_SET); // go back to our prev location
65 bool sk_frewind(SkFILE* f) {
71 size_t sk_fread(void* buffer, size_t byteCount, SkFILE* f) {
74 size_t curr = ::ftell((FILE*)f);
75 if ((long)curr == -1) {
76 SkDEBUGF(("sk_fread: ftell(%p) returned -1 feof:%d ferror:%d\n", f, feof((FILE*)f), ferror((FILE*)f)));
79 int err = ::fseek((FILE*)f, (long)byteCount, SEEK_CUR);
81 SkDEBUGF(("sk_fread: fseek(%d) tell:%d failed with feof:%d ferror:%d returned:%d\n",
82 byteCount, curr, feof((FILE*)f), ferror((FILE*)f), err));
88 return ::fread(buffer, 1, byteCount, (FILE*)f);
91 size_t sk_fwrite(const void* buffer, size_t byteCount, SkFILE* f) {
93 return ::fwrite(buffer, 1, byteCount, (FILE*)f);
96 void sk_fflush(SkFILE* f) {
101 bool sk_fseek(SkFILE* f, size_t byteCount) {
102 int err = ::fseek((FILE*)f, (long)byteCount, SEEK_SET);
106 bool sk_fmove(SkFILE* f, long byteCount) {
107 int err = ::fseek((FILE*)f, byteCount, SEEK_CUR);
111 size_t sk_ftell(SkFILE* f) {
112 long curr = ::ftell((FILE*)f);
119 void sk_fclose(SkFILE* f) {
124 bool sk_isdir(const char *path) {
126 if (0 != stat(path, &status)) {
129 return SkToBool(status.st_mode & S_IFDIR);
132 bool sk_mkdir(const char* path) {
133 if (sk_isdir(path)) {
136 if (sk_exists(path)) {
138 "sk_mkdir: path '%s' already exists but is not a directory\n",
145 retval = _mkdir(path);
147 retval = mkdir(path, 0777);
152 fprintf(stderr, "sk_mkdir: error %d creating dir '%s'\n", errno, path);