+#ifndef __WIN32__
+
+// Under Unix-ish systems (basically everything except Windows) we may work
+// either with the file itself or its target if it's a symbolic link and we
+// should dereference it, as determined by wxFileName::ShouldFollowLink() and
+// the absence of the wxFILE_EXISTS_NO_FOLLOW flag. StatAny() can be used to
+// stat the appropriate file with an extra twist that it also works when there
+// is no wxFileName object at all, as is the case in static methods.
+
+// Private implementation, don't call directly, use one of the overloads below.
+bool DoStatAny(wxStructStat& st, wxString path, bool dereference)
+{
+ // We need to remove any trailing slashes from the path because they could
+ // interfere with the symlink following decision: even if we use lstat(),
+ // it would still follow the symlink if we pass it a path with a slash at
+ // the end because the symlink resolution would happen while following the
+ // path and not for the last path element itself.
+
+ while ( wxEndsWithPathSeparator(path) )
+ {
+ const size_t posLast = path.length() - 1;
+ if ( !posLast )
+ {
+ // Don't turn "/" into empty string.
+ break;
+ }
+
+ path.erase(posLast);
+ }
+
+ int ret = dereference ? wxStat(path, &st) : wxLstat(path, &st);
+ return ret == 0;
+}
+
+// Overloads to use for a case when we don't have wxFileName object and when we
+// do have one.
+inline
+bool StatAny(wxStructStat& st, const wxString& path, int flags)
+{
+ return DoStatAny(st, path, !(flags & wxFILE_EXISTS_NO_FOLLOW));
+}
+
+inline
+bool StatAny(wxStructStat& st, const wxFileName& fn)
+{
+ return DoStatAny(st, fn.GetFullPath(), fn.ShouldFollowLink());
+}
+
+#endif // !__WIN32__
+