Make gdbserver work with filename-only binaries
[deliverable/binutils-gdb.git] / gdb / common / common-utils.c
index ae2dd9db2b54b5f8f4e089a6ac50efb9433b9953..80de826ba783045253c0730b3acd7757947dc6ec 100644 (file)
@@ -20,6 +20,7 @@
 #include "common-defs.h"
 #include "common-utils.h"
 #include "host-defs.h"
+#include <sys/stat.h>
 #include <ctype.h>
 
 /* The xmalloc() (libiberty.h) family of memory management routines.
@@ -408,3 +409,34 @@ stringify_argv (const std::vector<char *> &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;
+}
This page took 0.053364 seconds and 4 git commands to generate.