source file of the Flower Library
- (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
Jan Nieuwenhuizen <janneke@gnu.org>
*/
#include <cstdio>
#include <cerrno>
#include <unistd.h>
+#include <limits.h>
using namespace std;
dos_to_posix (string file_name)
{
char buf[PATH_MAX] = "";
- char s[PATH_MAX];
+ char s[PATH_MAX] = {0};
file_name.copy (s, PATH_MAX - 1);
/* ugh: char const* argument gets modified. */
int fail = cygwin_conv_to_posix_path (s, buf);
if (n && s[n - 1] == '/')
s[n - 1] = 0;
if (s.rfind ('/') != NPOS)
- {
- s = s.substr (0, s.rfind ('/'));
- }
+ s = s.substr (0, s.rfind ('/'));
else
s = "";
return (dir_.length () && dir_[0] == DIRSEP) || root_.length ();
}
+
+
+File_name
+File_name::canonicalized () const
+{
+ File_name c = *this;
+
+ replace_all (c.dir_, string ("//"), string ("/"));
+
+ vector<string> components = string_split (c.dir_, '/');
+ vector<string> new_components;
+
+ for (vsize i = 0; i < components.size (); i++)
+ {
+ if (components[i] == "..")
+ new_components.pop_back ();
+ else
+ new_components.push_back (components[i]);
+ }
+
+ c.dir_ = string_join (new_components, "/");
+ return c;
+}