bf111d7bc9
It is moved to src/utils. It is almost a tool, but has two uses in src/ports. The existing SkOSFile.cpp is left empty for the time being since it is mentioned in Chromium's BUILD.gn for Skia. Change-Id: I3bb7f7c4214359eb6ab906bfe76737d20bf1d6c7 Reviewed-on: https://skia-review.googlesource.com/4536 Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Ben Wagner <bungeman@google.com>
107 lines
2.9 KiB
C++
107 lines
2.9 KiB
C++
/*
|
|
* Copyright 2006 The Android Open Source Project
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
|
|
// TODO: add unittests for all these operations
|
|
|
|
#ifndef SkOSFile_DEFINED
|
|
#define SkOSFile_DEFINED
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "SkString.h"
|
|
|
|
enum SkFILE_Flags {
|
|
kRead_SkFILE_Flag = 0x01,
|
|
kWrite_SkFILE_Flag = 0x02
|
|
};
|
|
|
|
FILE* sk_fopen(const char path[], SkFILE_Flags);
|
|
void sk_fclose(FILE*);
|
|
|
|
size_t sk_fgetsize(FILE*);
|
|
/** Return true if the file could seek back to the beginning
|
|
*/
|
|
bool sk_frewind(FILE*);
|
|
|
|
size_t sk_fread(void* buffer, size_t byteCount, FILE*);
|
|
size_t sk_fwrite(const void* buffer, size_t byteCount, FILE*);
|
|
|
|
char* sk_fgets(char* str, int size, FILE* f);
|
|
|
|
void sk_fflush(FILE*);
|
|
void sk_fsync(FILE*);
|
|
|
|
bool sk_fseek(FILE*, size_t);
|
|
bool sk_fmove(FILE*, long);
|
|
size_t sk_ftell(FILE*);
|
|
|
|
/** Maps a file into memory. Returns the address and length on success, NULL otherwise.
|
|
* The mapping is read only.
|
|
* When finished with the mapping, free the returned pointer with sk_fmunmap.
|
|
*/
|
|
void* sk_fmmap(FILE* f, size_t* length);
|
|
|
|
/** Maps a file descriptor into memory. Returns the address and length on success, NULL otherwise.
|
|
* The mapping is read only.
|
|
* When finished with the mapping, free the returned pointer with sk_fmunmap.
|
|
*/
|
|
void* sk_fdmmap(int fd, size_t* length);
|
|
|
|
/** Unmaps a file previously mapped by sk_fmmap or sk_fdmmap.
|
|
* The length parameter must be the same as returned from sk_fmmap.
|
|
*/
|
|
void sk_fmunmap(const void* addr, size_t length);
|
|
|
|
/** Returns true if the two point at the exact same filesystem object. */
|
|
bool sk_fidentical(FILE* a, FILE* b);
|
|
|
|
/** Returns the underlying file descriptor for the given file.
|
|
* The return value will be < 0 on failure.
|
|
*/
|
|
int sk_fileno(FILE* f);
|
|
|
|
/** Returns true if something (file, directory, ???) exists at this path,
|
|
* and has the specified access flags.
|
|
*/
|
|
bool sk_exists(const char *path, SkFILE_Flags = (SkFILE_Flags)0);
|
|
|
|
// Returns true if a directory exists at this path.
|
|
bool sk_isdir(const char *path);
|
|
|
|
// Have we reached the end of the file?
|
|
int sk_feof(FILE *);
|
|
|
|
|
|
// Create a new directory at this path; returns true if successful.
|
|
// If the directory already existed, this will return true.
|
|
// Description of the error, if any, will be written to stderr.
|
|
bool sk_mkdir(const char* path);
|
|
|
|
class SkOSFile {
|
|
public:
|
|
class Iter {
|
|
public:
|
|
Iter();
|
|
Iter(const char path[], const char suffix[] = NULL);
|
|
~Iter();
|
|
|
|
void reset(const char path[], const char suffix[] = NULL);
|
|
/** If getDir is true, only returns directories.
|
|
Results are undefined if true and false calls are
|
|
interleaved on a single iterator.
|
|
*/
|
|
bool next(SkString* name, bool getDir = false);
|
|
|
|
static const size_t kStorageSize = 40;
|
|
private:
|
|
SkAlignedSStorage<kStorageSize> fSelf;
|
|
};
|
|
};
|
|
|
|
#endif
|