X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ffs%2Futils.cpp;h=b66b82dd70c90c1ed96b6f0cd13a27087ad4ebf5;hb=427991f60b200fe4a6517e6fb1fe1980ab14983b;hp=694a8f12a6c6c67b4f77dd89e0e9a8168d1fcf1e;hpb=af94bc926e301e9b871dc18662b4fa6e5614fdbf;p=libs%2Fcore.git diff --git a/source/fs/utils.cpp b/source/fs/utils.cpp index 694a8f1..b66b82d 100644 --- a/source/fs/utils.cpp +++ b/source/fs/utils.cpp @@ -1,18 +1,5 @@ -/* $Id$ - -This file is part of libmspfs -Copyright © 2006-2008 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#include #include -#include -#ifndef WIN32 -#include -#else -#include -#endif +#include #include #include "dir.h" #include "path.h" @@ -90,12 +77,12 @@ Path readlink(const Path &link) { #ifdef WIN32 (void)link; - throw Exception("No symbolic links on win32"); + throw logic_error("no symbolic links on win32"); #else char buf[4096]; int len = ::readlink(link.str().c_str(), buf, sizeof(buf)); if(len==-1) - throw SystemError("readlink failed", errno); + throw system_error("readlink"); return string(buf, len); #endif } @@ -122,11 +109,10 @@ Path realpath(const Path &path) Path next = real/queue.front(); queue.pop_front(); - struct stat st = lstat(next); - if(S_ISLNK(st.st_mode)) + if(is_link(next)) { if(++n_links>64) - throw Exception("Ludicrous amount of symlinks detected in realpath, giving up"); + throw runtime_error("too many symbolic links"); Path link = readlink(next); queue.insert(queue.begin(), link.begin(), link.end()); } @@ -141,13 +127,13 @@ Path realpath(const Path &path) void rename(const Path &from, const Path &to) { if(::rename(from.str().c_str(), to.str().c_str())==-1) - throw SystemError("rename failed", errno); + throw system_error("rename"); } void unlink(const Path &path) { if(::unlink(path.str().c_str())==-1) - throw SystemError("unlink failed", errno); + throw system_error("unlink"); } Path relative(const Path &path, const Path &base)