coan  6.0.1
A C/C++ Configuration Analyzer
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
filesys.h
Go to the documentation of this file.
1 #ifndef FILESYS_H
2 #define FILESYS_H
3 #pragma once
4 /***************************************************************************
5  * Copyright (C) 2007-2013 Mike Kinghan, imk@burroingroingjoing.com *
6  * All rights reserved. *
7  * *
8  * Contributed originally by Mike Kinghan, imk@burroingroingjoing.com *
9  * *
10  * Redistribution and use in source and binary forms, with or without *
11  * modification, are permitted provided that the following conditions *
12  * are met: *
13  * *
14  * Redistributions of source code must retain the above copyright *
15  * notice, this list of conditions and the following disclaimer. *
16  * *
17  * Redistributions in binary form must reproduce the above copyright *
18  * notice, this list of conditions and the following disclaimer in the *
19  * documentation and/or other materials provided with the distribution. *
20  * *
21  * Neither the name of Mike Kinghan nor the names of its contributors *
22  * may be used to endorse or promote products derived from this software *
23  * without specific prior written permission. *
24  * *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
28  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
29  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
30  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
31  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS *
32  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED *
33  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,*
34  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF *
35  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
36  * DAMAGE. *
37  * *
38  **************************************************************************/
39 #include <string>
40 
45 namespace fs {
47 
49 enum {
53  OBJ_SLINK = 1,
55  OBJ_FILE = 2,
57  OBJ_DIR = 4
58 };
59 
61 using obj_type_t = unsigned;
62 
67 inline bool is_file(obj_type_t type)
68 {
69  return (type & OBJ_FILE) != 0;
70 }
71 
76 inline bool is_dir(obj_type_t type)
77 {
78  return (type & OBJ_DIR) != 0;
79 }
80 
85 inline bool is_slink(obj_type_t type)
86 {
87  return (type & OBJ_SLINK) != 0;
88 }
89 
93 extern obj_type_t obj_type(std::string const & name);
94 
104 extern std::string real_path(std::string const & relname);
105 
114 extern std::string abs_path(std::string const & filename);
115 
117 extern bool is_absolute(std::string pathname);
118 
120 extern std::string cwd();
121 
134 extern std::string tempname(std::string const & format);
135 
144 extern void make_dir(std::string const & abs_path, bool recursive = true);
145 
147 using permissions = int;
148 
158 extern permissions get_permissions(std::string const & filename);
159 
171 extern int set_permissions(std::string const & filename, permissions p);
172 
173 } // namespace fs
174 
175 #endif // EOF
A symbolic link.
Definition: filesys.h:53
unsigned obj_type_t
Abstract type of filesystem object types.
Definition: filesys.h:61
permissions get_permissions(std::string const &filename)
bool is_file(obj_type_t type)
Say whether an object type is a file.
Definition: filesys.h:67
bool is_dir(obj_type_t type)
Say whether an object type is a directory.
Definition: filesys.h:76
void make_dir(std::string const &abs_path, bool recursive=true)
Create a directory given an absolute path name.
A file.
Definition: filesys.h:55
bool is_absolute(std::string pathname)
Say whether a filename is absolute or relative.
std::string cwd()
Get the absolute real pathname of the current working directory.
bool is_slink(obj_type_t type)
Say whether an object type is a symbolic link.
Definition: filesys.h:85
int set_permissions(std::string const &filename, permissions p)
std::string abs_path(std::string const &filename)
Get the absolute pathname for a filename.
std::string real_path(std::string const &relname)
Get the absolute real pathname of a file or directory name.
obj_type_t obj_type(std::string const &name)
Get the type of the object putatively designated by a filename.
std::string tempname(std::string const &format)
Create a tempory filename from a template.
A directory.
Definition: filesys.h:57
No such object.
Definition: filesys.h:51
int permissions
Type of file permissions mask.
Definition: filesys.h:147