]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/configreader.cpp
Use iostream instead of C-style file operations.
[user/henk/code/inspircd.git] / src / configreader.cpp
index bd83201372d936bed986b15e9e2a53af45e68731..905eb786af84b0646b6ae4eca423e172cb903935 100644 (file)
@@ -773,14 +773,31 @@ bool ServerConfig::FileExists(const char* file)
        if ((sb.st_mode & S_IFDIR) > 0)
                return false;
 
-       FILE *input = fopen(file, "r");
-       if (input == NULL)
-               return false;
-       else
+       return !access(file, F_OK);
+}
+
+std::string ServerConfig::Escape(const std::string& str, bool xml)
+{
+       std::string escaped;
+       for (std::string::const_iterator it = str.begin(); it != str.end(); ++it)
        {
-               fclose(input);
-               return true;
+               switch (*it)
+               {
+                       case '"':
+                               escaped += xml ? """ : "\"";
+                               break;
+                       case '&':
+                               escaped += xml ? "&" : "&";
+                               break;
+                       case '\\':
+                               escaped += xml ? "\\" : "\\\\";
+                               break;
+                       default:
+                               escaped += *it;
+                               break;
+               }
        }
+       return escaped;
 }
 
 const char* ServerConfig::CleanFilename(const char* name)