X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fcommon%2Fcommon-utils.c;h=80de826ba783045253c0730b3acd7757947dc6ec;hb=25e3c82c0e927398e759e2d5e35623012b8683f7;hp=ae2dd9db2b54b5f8f4e089a6ac50efb9433b9953;hpb=b4987c956dfa44ca9fd8552f63e15f5fa094b2a4;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/common/common-utils.c b/gdb/common/common-utils.c index ae2dd9db2b..80de826ba7 100644 --- a/gdb/common/common-utils.c +++ b/gdb/common/common-utils.c @@ -20,6 +20,7 @@ #include "common-defs.h" #include "common-utils.h" #include "host-defs.h" +#include #include /* The xmalloc() (libiberty.h) family of memory management routines. @@ -408,3 +409,34 @@ stringify_argv (const std::vector &args) return ret; } + +/* See common/common-utils.h. */ + +bool +is_regular_file (const char *name, int *errno_ptr) +{ + struct stat st; + const int status = stat (name, &st); + + /* Stat should never fail except when the file does not exist. + If stat fails, analyze the source of error and return true + unless the file does not exist, to avoid returning false results + on obscure systems where stat does not work as expected. */ + + if (status != 0) + { + if (errno != ENOENT) + return true; + *errno_ptr = ENOENT; + return false; + } + + if (S_ISREG (st.st_mode)) + return true; + + if (S_ISDIR (st.st_mode)) + *errno_ptr = EISDIR; + else + *errno_ptr = EINVAL; + return false; +}