From: Ray Strode Date: Wed, 23 May 2007 19:32:06 +0000 (-0400) Subject: add new functions that check if a file or dir exists X-Git-Tag: 0.1.0~254 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=178fd654ab7e31cef4dd7d72bed5f6dba12f46f8;p=thirdparty%2Fplymouth.git add new functions that check if a file or dir exists --- diff --git a/src/ply-utils.c b/src/ply-utils.c index 5b531b73..a3f29a09 100644 --- a/src/ply-utils.c +++ b/src/ply-utils.c @@ -349,4 +349,26 @@ ply_restore_errno (void) errno = errno_stack[errno_stack_position]; } +bool +ply_directory_exists (const char *dir) +{ + struct stat file_info; + + if (stat (dir, &file_info) < 0) + return false; + + return S_ISDIR (file_info.st_mode); +} + +bool +ply_file_exists (const char *file) +{ + struct stat file_info; + + if (stat (file, &file_info) < 0) + return false; + + return S_ISREG (file_info.st_mode); +} + /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/ply-utils.h b/src/ply-utils.h index 9cdebfd0..caa54df8 100644 --- a/src/ply-utils.h +++ b/src/ply-utils.h @@ -61,6 +61,9 @@ double ply_get_timestamp (void); void ply_save_errno (void); void ply_restore_errno (void); + +bool ply_directory_exists (const char *dir); +bool ply_file_exists (const char *file); #endif #endif /* PLY_UTILS_H */