OSDN Git Service

kErrorLog feature.
authorvisor <visor@users.sourceforge.jp>
Sat, 30 Apr 2011 14:29:31 +0000 (23:29 +0900)
committervisor <visor@users.sourceforge.jp>
Sat, 30 Apr 2011 14:29:31 +0000 (23:29 +0900)
cgi/main.cc
lib/app.cc
lib/app.h
ml/main.cc

index 200efde..ac816ba 100644 (file)
@@ -188,8 +188,9 @@ int  main (int argc, char** argv) {
     ustring  scriptfilename;
 
 #ifdef kErrorLog
-    close (2);
-    open (cDataTop kErrorLog, O_WRONLY | O_APPEND | O_CREAT, 0666);
+//    close (2);
+//    open (kErrorLog, O_WRONLY | O_APPEND | O_CREAT, 0666);
+    aenv.setErrorLog (ustring (CharConst (kErrorLog)));
 #endif
 
 #ifdef UTF8JP
index 1f8e82b..9eb38a4 100644 (file)
@@ -7,6 +7,7 @@
 #include <string.h>
 #include <iostream>
 #include <stdlib.h>
+#include <fcntl.h>
 
 static bool  pcmp (char** a, const char* b, int n) {
     int  rc = strncmp (*a, b, n);
@@ -201,3 +202,12 @@ void  AppEnv::dump (std::ostream& out) {
        out << "        dump\n";
 #endif
 }
+
+void  AppEnv::setErrorLog (const ustring& path, bool fappend) {
+    int  flag = O_WRONLY | O_CREAT;
+
+    if (fappend)
+       flag |= O_APPEND;
+    close (2);
+    open (path.c_str (), flag, 0666);
+}
index 920d7df..49acde2 100644 (file)
--- a/lib/app.h
+++ b/lib/app.h
@@ -41,6 +41,7 @@ class  AppEnv {
     virtual void  setDefault ();
     virtual ustring  scriptName ();
     virtual void  dump (std::ostream& out);
+    virtual void  setErrorLog (const ustring& path, bool fappend = false);
 };
 
 #endif /* APP_H */
index 558eb71..31b345f 100644 (file)
@@ -38,6 +38,9 @@ int  main (int argc, char** argv) {
 #endif
     MotorEnv  env (&aenv, form, &motor, out);
 
+#ifdef kErrorLog
+    aenv.setErrorLog (ustring (CharConst (kErrorLog)));
+#endif
     try {
        aenv.readOption (argc, argv, &env);