Ice 3.7 C++11 API Reference
Loading...
Searching...
No Matches
FileUtil.h
Go to the documentation of this file.
1//
2// Copyright (c) ZeroC, Inc. All rights reserved.
3//
4
5#ifndef ICE_FILE_UTIL_H
6#define ICE_FILE_UTIL_H
7
8#include <IceUtil/Config.h>
9#include <IceUtil/Shared.h>
10#include <IceUtil/Handle.h>
11
12#include <sys/stat.h>
13#include <fcntl.h>
14#include <stdio.h>
15
16namespace IceUtilInternal
17{
18
19extern const ICE_API std::string pathsep;
20extern const ICE_API std::string separator;
21
22//
23// Detemine if path is an absolute path.
24//
25ICE_API bool isAbsolutePath(const std::string&);
26
27//
28// Determine if a file exists.
29//
30ICE_API bool fileExists(const std::string&);
31
32//
33// Determine if a directory exists.
34//
35ICE_API bool directoryExists(const std::string&);
36
37//
38// Determine if a directory exists and is empty.
39//
40ICE_API bool isEmptyDirectory(const std::string&);
41
42#ifdef _WIN32
43
44#if defined(__MINGW32__)
45typedef struct _stat structstat;
46#else
47typedef struct _stat64i32 structstat;
48#endif
49
50#ifdef _MSC_VER
51#ifndef O_RDONLY
52# define O_RDONLY _O_RDONLY
53#endif
54
55#ifndef O_BINARY
56# define O_BINARY _O_BINARY
57#endif
58
59#ifndef S_ISDIR
60# define S_ISDIR(mode) ((mode) & _S_IFDIR)
61#endif
62
63#ifndef S_ISREG
64# define S_ISREG(mode) ((mode) & _S_IFREG)
65#endif
66#endif
67
68#else
69
70typedef struct stat structstat;
71# define O_BINARY 0
72
73#endif
74
75//
76// OS stat
77//
78ICE_API int stat(const std::string&, structstat*);
79ICE_API int remove(const std::string&);
80ICE_API int rename(const std::string&, const std::string&);
81ICE_API int rmdir(const std::string&);
82
83ICE_API int mkdir(const std::string&, int);
84ICE_API FILE* fopen(const std::string&, const std::string&);
85ICE_API FILE* freopen(const std::string&, const std::string&, FILE*);
86ICE_API int open(const std::string&, int);
87ICE_API int getcwd(std::string&);
88
89ICE_API int unlink(const std::string&);
90ICE_API int close(int);
91
92//
93// This class is used to implement process file locking. This class
94// is not intended to do file locking within the same process.
95//
96class ICE_API FileLock : public IceUtil::Shared, public IceUtil::noncopyable
97{
98public:
99 //
100 // The constructor opens the given file (eventually creating it)
101 // and acquires a lock on the file or throws FileLockException if
102 // the file couldn't be locked.
103 //
104 // If the lock can be acquired, the process pid is written to the
105 // file.
106 //
107 FileLock(const std::string&);
108
109 //
110 // The destructor releases the lock and removes the file.
111 //
112 virtual ~FileLock();
113
114private:
115
116#ifdef _WIN32
117 HANDLE _fd;
118#else
119 int _fd;
120#endif
121 std::string _path;
122};
123
124typedef IceUtil::Handle<FileLock> FileLockPtr;
125
126//
127// Use streamFilename to construct the filename given to std stream classes
128// like ifstream and ofstream.
129//
130#if defined(_WIN32) && !defined(__MINGW32__)
131ICE_API std::wstring streamFilename(const std::string&);
132#else
133inline std::string streamFilename(const std::string& filename)
134{
135 return filename;
136}
137#endif
138
139}
140#endif
#define ICE_API
Definition Config.h:197
Definition Shared.h:78
Definition Config.h:313