Scopira  20080306
file.h
1 
2 /*
3  * Copyright (c) 2003 National Research Council
4  *
5  * All rights reserved.
6  *
7  * This material is confidential and proprietary information of
8  * National Research Council Canada ("Confidential Information").
9  * This Confidential Information may only be used and reproduced
10  * in accordance with the terms of the license agreement.
11  *
12  */
13 
14 #ifndef __INCLUDED_SCOPIRA_TOOL_FILE_H__
15 #define __INCLUDED_SCOPIRA_TOOL_FILE_H__
16 
17 #include <sys/stat.h>
18 
19 #include <string>
20 
21 #include <scopira/tool/export.h>
22 
23 namespace scopira
24 {
25  namespace tool
26  {
27  class file;
28 
29  const char dir_seperator_c = '/';
30 
32  const char * get_username(void);
34  const char * get_homedir(void);
35  }
36 }
37 
48 {
49  public:
50  typedef ::off_t offset_t;
51  private:
52  //const std::string m_filename; // dont need this?
53  bool dm_error; // was there an error on stat? if so, reading from m_stat is useless
54  struct stat dm_stat;
55 
56  public:
58  SCOPIRA_EXPORT file(void);
59 
65  SCOPIRA_EXPORT file(const std::string &fname);
66 
72  SCOPIRA_EXPORT void set(const std::string &fname);
73 
79  SCOPIRA_EXPORT bool exists(void) const;
80 
86  SCOPIRA_EXPORT bool is_file(void) const;
87 
93  SCOPIRA_EXPORT bool is_dir(void) const;
94 
100  SCOPIRA_EXPORT offset_t size(void) const;
101 
107  SCOPIRA_EXPORT static bool check_path(const std::string& path);
108 
117  SCOPIRA_EXPORT static bool has_ext(const std::string &fname, const std::string &ext);
118 
125  SCOPIRA_EXPORT static void expand_homedir(std::string &path);
126 
133  SCOPIRA_EXPORT static void expand_envvar(std::string &path);
134 
143  SCOPIRA_EXPORT static void split_ext(const std::string &fullname, std::string &sansext, std::string &ext);
144 
152  SCOPIRA_EXPORT static void split_path(const std::string &fullname, std::string &path, std::string &name);
153 
160  SCOPIRA_EXPORT static std::string realpath(const std::string &name);
161 
167  SCOPIRA_EXPORT static void create_directory(const std::string &dirname);
168 };
169 
170 #endif
171 
const char * get_username(void)
gets the username of the logged in system, may return "" (but never null)
bool exists(void) const
Definition: archiveflow.h:20
Definition: file.h:47
static void split_ext(const std::string &fullname, std::string &sansext, std::string &ext)
static void split_path(const std::string &fullname, std::string &path, std::string &name)
static bool check_path(const std::string &path)
static bool has_ext(const std::string &fname, const std::string &ext)
static std::string realpath(const std::string &name)
bool is_file(void) const
static void expand_homedir(std::string &path)
static void expand_envvar(std::string &path)
offset_t size(void) const
bool is_dir(void) const
static void create_directory(const std::string &dirname)
const char * get_homedir(void)
gets the user&#39;s home directory, may return "." (but never null)
file(void)
default ctor and copy are fine