From: Adam Tkac Date: Mon, 7 Feb 2011 10:46:45 +0000 (+0000) Subject: [Development] os: introduce new function called "fileexists" X-Git-Tag: v1.0.90~64 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c480ee32669fffd940de34f2f55d8c144c32f706;p=tigervnc.git [Development] os: introduce new function called "fileexists" git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4255 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- diff --git a/common/os/os.cxx b/common/os/os.cxx index c08b5728..46470eaa 100644 --- a/common/os/os.cxx +++ b/common/os/os.cxx @@ -85,3 +85,13 @@ int getvnchomedir(char **dirp) return 0; } +int fileexists(char *file) +{ +#ifdef WIN32 + return (GetFileAttributes(file) == INVALID_FILE_ATTRIBUTES) ? -1 : 0; +#else + return access(file, R_OK); +#endif +} + + diff --git a/common/os/os.h b/common/os/os.h index d011764e..1847a494 100644 --- a/common/os/os.h +++ b/common/os/os.h @@ -37,4 +37,13 @@ */ int getvnchomedir(char **dirp); +/* + * Check if the file exists + * + * Returns: + * 0 - Success + * -1 - Failure + */ +int fileexists(char *file); + #endif /* OS_OS_H */