2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2005 Net Integration Technologies, Inc.
5 * Various little file functions...
9 #ifndef __WVFILEUTILS_H
10 #define __WVFILEUTILS_H
13 #include "wvstringlist.h"
16 * Like mkdir(), but has the same parameters in both Unix and Windows.
18 int wvmkdir(WvStringParm _dir
, int create_mode
= 0700);
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
27 int mkdirp(WvStringParm _dir
, int create_mode
= 0700);
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
);
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
);
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);
54 * Reads the contents of a symlink. Returns the contents, or
55 * WvString::null on error.
57 WvString
wvreadlink(WvStringParm path
);
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
);
71 * Runs fnmatch against everything in the patterns list. We also interpret
72 * .cvsignore-style '!' patterns, which makes us very fancy.
75 bool wvfnmatch(WvStringList
&patterns
, WvStringParm name
, int flags
= 0);
79 * Replacement for tmpfile() that works correctly in win32 as well as Unix.
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
);
92 * Basically our own implementation of the NetBSD lchmod() call.
94 int wvchmod(const char *path
, mode_t mode
);
98 * A simple helper function to get the current umask.
104 #endif // __WVFILEUTILS_H