Make WvStreams compile with gcc 4.4.
[wvstreams.git] / include / wvfileutils.h
blobf02da5b93fa660eb5ec5059289692b004c2d0be5
1 /* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2005 Net Integration Technologies, Inc.
5 * Various little file functions...
7 */
9 #ifndef __WVFILEUTILS_H
10 #define __WVFILEUTILS_H
12 #include "wvstring.h"
13 #include "wvstringlist.h"
15 /**
16 * Like mkdir(), but has the same parameters in both Unix and Windows.
18 int wvmkdir(WvStringParm _dir, int create_mode = 0700);
20 /**
21 * Create a directory and any subdirectories required along the way.
22 * (Equivalent to mkdir -p).
24 * The default permissions on created directories is 0700, but this can be
25 * changed at will.
27 int mkdirp(WvStringParm _dir, int create_mode = 0700);
29 /**
30 * Safely remove an entire filesystem directory hierarchy.
31 * (Equivalent to rm -rf). Just like "rm -rf", it may or may not successfully
32 * delete everything. It's your job to check that afterwards.
34 void rm_rf(WvStringParm _dir);
36 /**
37 * Copy from src to dst preserving permissions and time stamp. This does not
38 * preserve ownership, however.
40 * Two versions of this are provided. One for giving two filenames/paths, and
41 * another for giving two starting directories and a relative path from there.
43 bool fcopy(WvStringParm src, WvStringParm dst);
44 bool fcopy(WvStringParm srcdir, WvStringParm dstdir, WvStringParm relname);
46 /**
47 * Create the file if it doesn't exist, or update the file's modification and
48 * access times if it does.
49 * (Equivalent to touch).
51 bool ftouch(WvStringParm file, time_t mtime = 0);
53 /**
54 * Reads the contents of a symlink. Returns the contents, or
55 * WvString::null on error.
57 WvString wvreadlink(WvStringParm path);
59 /**
60 * Check whether two files have the same date/time stamp. This can be used as a
61 * quick check whether files are unchanged / the same, though obviously it
62 * doesn't verify that they are indeed the same file.
64 * Two versions are provided, one for giving two files, and another for giving
65 * two starting directories and a relative path from there.
67 bool samedate(WvStringParm file1, WvStringParm file2);
68 bool samedate(WvStringParm dir1, WvStringParm dir2, WvStringParm relname);
70 /**
71 * Runs fnmatch against everything in the patterns list. We also interpret
72 * .cvsignore-style '!' patterns, which makes us very fancy.
74 #ifndef _WIN32
75 bool wvfnmatch(WvStringList &patterns, WvStringParm name, int flags = 0);
76 #endif
78 /**
79 * Replacement for tmpfile() that works correctly in win32 as well as Unix.
81 FILE *wvtmpfile();
83 /* Returns a unique filename suitable for a temporary file. Obviously there is
84 * the caveat that someone else may claim this file name before you open it:
85 * do not use this routine where that race may be a real concern (this would
86 * apply only to security-sensitive code)
88 WvString wvtmpfilename(WvStringParm prefix);
90 #ifndef _WIN32
91 /**
92 * Basically our own implementation of the NetBSD lchmod() call.
94 int wvchmod(const char *path, mode_t mode);
95 #endif
97 /**
98 * A simple helper function to get the current umask.
100 #ifndef _WIN32
101 mode_t get_umask();
102 #endif
104 #endif // __WVFILEUTILS_H