Add file access modes to sk_exists.
Both Windows and Posix 'access' calls take a mode parameter which, in addition to checking existence, checks access modes. This change exposes this functionality. R=mtklein@google.com, reed@google.com Author: bungeman@google.com Review URL: https://codereview.chromium.org/384903002
This commit is contained in:
parent
bbf9f6d1cb
commit
bf0b9ced0b
@ -77,8 +77,10 @@ bool sk_fidentical(SkFILE* a, SkFILE* b);
|
||||
*/
|
||||
int sk_fileno(SkFILE* f);
|
||||
|
||||
// Returns true if something (file, directory, ???) exists at this path.
|
||||
bool sk_exists(const char *path);
|
||||
/** 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);
|
||||
|
@ -7,6 +7,10 @@
|
||||
|
||||
#include "SkOSFile.h"
|
||||
|
||||
bool sk_exists(const char *path, SkFILE_Flags flags) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool sk_fidentical(SkFILE* a, SkFILE* b) {
|
||||
return false;
|
||||
}
|
||||
|
@ -13,6 +13,18 @@
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
bool sk_exists(const char *path, SkFILE_Flags flags) {
|
||||
int mode = F_OK;
|
||||
if (flags & kRead_SkFILE_Flag) {
|
||||
mode |= R_OK;
|
||||
}
|
||||
if (flags & kWrite_SkFILE_Flag) {
|
||||
mode |= W_OK;
|
||||
}
|
||||
return (0 == access(path, mode));
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
dev_t dev;
|
||||
|
@ -15,8 +15,6 @@
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
SkFILE* sk_fopen(const char path[], SkFILE_Flags flags) {
|
||||
@ -123,14 +121,6 @@ void sk_fclose(SkFILE* f) {
|
||||
::fclose((FILE*)f);
|
||||
}
|
||||
|
||||
bool sk_exists(const char *path) {
|
||||
#ifdef _WIN32
|
||||
return (0 == _access(path, 0));
|
||||
#else
|
||||
return (0 == access(path, 0));
|
||||
#endif
|
||||
}
|
||||
|
||||
bool sk_isdir(const char *path) {
|
||||
struct stat status;
|
||||
if (0 != stat(path, &status)) {
|
||||
|
@ -13,6 +13,17 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
bool sk_exists(const char *path, SkFILE_Flags flags) {
|
||||
int mode = 0; // existence
|
||||
if (flags & kRead_SkFILE_Flag) {
|
||||
mode |= 4; // read
|
||||
}
|
||||
if (flags & kWrite_SkFILE_Flag) {
|
||||
mode |= 2; // write
|
||||
}
|
||||
return (0 == _access(path, mode));
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
ULONGLONG fVolume;
|
||||
ULONGLONG fLsbSize;
|
||||
|
Loading…
Reference in New Issue
Block a user