Move mkdir_recursive to common/filestuff.c
[deliverable/binutils-gdb.git] / gdb / common / filestuff.h
index 0e46eb5da0b1ffe2edbc349651372fb3a787ca2e..ecfc18d60044c600e80ebbcfe2ebd72929de0e76 100644 (file)
@@ -48,6 +48,16 @@ extern void close_most_fds (void);
 extern int gdb_open_cloexec (const char *filename, int flags,
                             /* mode_t */ unsigned long mode);
 
+/* Convenience wrapper for the above, which takes the filename as an
+   std::string.  */
+
+static inline int
+gdb_open_cloexec (const std::string &filename, int flags,
+                 /* mode_t */ unsigned long mode)
+{
+  return gdb_open_cloexec (filename.c_str (), flags, mode);
+}
+
 struct gdb_file_deleter
 {
   void operator() (FILE *file) const
@@ -66,6 +76,15 @@ typedef std::unique_ptr<FILE, gdb_file_deleter> gdb_file_up;
 extern gdb_file_up gdb_fopen_cloexec (const char *filename,
                                      const char *opentype);
 
+/* Convenience wrapper for the above, which takes the filename as an
+   std::string.  */
+
+static inline gdb_file_up
+gdb_fopen_cloexec (const std::string &filename, const char *opentype)
+{
+  return gdb_fopen_cloexec (filename.c_str (), opentype);
+}
+
 /* Like 'socketpair', but ensures that the returned file descriptors
    have the close-on-exec flag set.  */
 
@@ -98,4 +117,19 @@ struct gdb_dir_deleter
 
 typedef std::unique_ptr<DIR, gdb_dir_deleter> gdb_dir_up;
 
+/* Return true if the file NAME exists and is a regular file.
+   If the result is false then *ERRNO_PTR is set to a useful value assuming
+   we're expecting a regular file.  */
+extern bool is_regular_file (const char *name, int *errno_ptr);
+
+
+/* A cheap (as in low-quality) recursive mkdir.  Try to create all the
+   parents directories up to DIR and DIR itself.  Stop if we hit an
+   error along the way.  There is no attempt to remove created
+   directories in case of failure.
+
+   Returns false on failure and sets errno.  */
+
+extern bool mkdir_recursive (const char *dir);
+
 #endif /* FILESTUFF_H */
This page took 0.026615 seconds and 4 git commands to generate.