kernel on win32

ooo bzr diff -r1 -pa/:b/ ndb/src/kernel |di -X Make
--- a/ndb/src/kernel/blocks/dbdict/Dbdict.cpp	2007-08-29 07:25:53 +0000
+++ b/ndb/src/kernel/blocks/dbdict/Dbdict.cpp	2007-09-06 13:30:49 +0000
@@ -1098,7 +1098,7 @@
     if (!ok)
     {
       char reason_msg[128];
-      snprintf(reason_msg, sizeof(reason_msg),
+      BaseString::snprintf(reason_msg, sizeof(reason_msg),
                "schema file corrupt, page %u (%s, "
                "sz=%u sz0=%u pn=%u)",
                n, reason, sf->FileSize, sf0->FileSize, sf->PageNumber);

--- a/ndb/src/kernel/blocks/dbdict/printSchemaFile.cpp	2007-08-29 07:25:53 +0000
+++ b/ndb/src/kernel/blocks/dbdict/printSchemaFile.cpp	2007-09-06 13:30:49 +0000
@@ -17,6 +17,11 @@
 #include <ndb_global.h>
 #include <ndb_version.h>
 
+#ifdef NDB_WIN32
+#include <sys/types.h>
+#include <sys/stat.h>
+#endif
+
 #include <NdbMain.h>
 #include <NdbOut.hpp>
 #include <SchemaFile.hpp>
@@ -203,8 +208,13 @@
     const char * filename = argv[1];
     argc--, argv++;
 
+#ifndef NDB_WIN32
     struct stat sbuf;
     const int res = stat(filename, &sbuf);
+#else
+    struct _stat sbuf;
+    const int res = _stat(filename, &sbuf);
+#endif
     if (res != 0) {
       ndbout << filename << ": not found errno=" << errno << endl;
       exitcode = 1;

--- a/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp	2007-08-29 07:25:53 +0000
+++ b/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp	2007-09-06 13:30:50 +0000
@@ -14,6 +14,7 @@
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
 #define DBDIH_C
+#include <ndb_global.h>
 #include <ndb_limits.h>
 #include <ndb_version.h>
 #include <NdbOut.hpp>
@@ -13662,8 +13663,8 @@
     buf2[0]= 0;
     for(Uint32 i = 0; i<length; i++)
     {
-      snprintf(buf, 100, "%s %.8x", buf2, signal->theData[i]);
-      snprintf(buf2, 100, "%s", buf);
+      BaseString::snprintf(buf, 100, "%s %.8x", buf2, signal->theData[i]);
+      BaseString::snprintf(buf2, 100, "%s", buf);
     }
     warningEvent("gsn: %d block: %s, length: %d theData: %s", 
 		 gsn, getBlockName(block, "UNKNOWN"), length, buf);

--- a/ndb/src/kernel/blocks/dbdih/printSysfile/printSysfile.cpp	2007-08-29 07:25:53 +0000
+++ b/ndb/src/kernel/blocks/dbdih/printSysfile/printSysfile.cpp	2007-09-06 13:30:50 +0000
@@ -16,6 +16,11 @@
 
 #include <ndb_global.h>
 
+#ifdef NDB_WIN32
+#include <sys/types.h>
+#include <sys/stat.h>
+#endif
+
 #include <NdbMain.h>
 #include <NdbOut.hpp>
 #include <Sysfile.hpp>
@@ -125,8 +130,13 @@
   for(int i = 1; i<argc; i++){
     const char * filename = argv[i];
     
+#ifndef NDB_WIN32
     struct stat sbuf;
     const int res = stat(filename, &sbuf);
+#else
+    struct _stat sbuf;
+    const int res = _stat(filename, &sbuf);
+#endif
     if(res != 0){
       ndbout << "Could not find file: \"" << filename << "\"" << endl;
       continue;

--- a/ndb/src/kernel/blocks/ndbfs/AsyncFile.cpp	2007-08-29 07:25:53 +0000
+++ b/ndb/src/kernel/blocks/ndbfs/AsyncFile.cpp	2007-09-06 13:30:50 +0000
@@ -218,7 +218,7 @@
       rmrfReq(request, (char*)theFileName.c_str(), request->par.rmrf.own_directory);
       break;
     case Request:: end:
-      if (theFd > 0)
+      if (isOpen())
         closeReq(request);
       endReq();
       return;
@@ -510,6 +510,14 @@
   }
   DEBUG(ndbout_c("extendfile: maxOffset=%d, size=%d", maxOffset, maxSize));
 
+#ifdef NDB_WIN32
+  int return_value;
+  if (SetFilePointer(hFile, maxOffset + maxSize, NULL, 
+                     FILE_BEGIN) == INVALID_SET_FILE_POINTER &&
+      (return_value = GetLastError()) != NO_ERROR)
+  if (!SetEndOfFile(hFile))
+    return GetLastError();
+#else
   // Allocate a buffer and fill it with zeros
   void* pbuf = ndbd_malloc(maxSize);
   memset(pbuf, 0, maxSize);
@@ -531,6 +539,7 @@
     }
   }
   ndbd_free(pbuf,maxSize);
+#endif
   
   DEBUG(ndbout_c("extendfile: \"%s\" OK!", theFileName.c_str()));
   return 0;

--- a/ndb/src/kernel/main.cpp	2007-08-29 07:25:53 +0000
+++ b/ndb/src/kernel/main.cpp	2007-09-08 12:13:46 +0000
@@ -100,7 +100,10 @@
   fprintf(child_info_file_w, "\n");
   fclose(child_info_file_r);
   fclose(child_info_file_w);
+#ifndef NDB_WIN32
+  /* bad practice to use absolute numbers for signals */
   signal(6, SIG_DFL);
+#endif
   abort();
 }
 
@@ -262,10 +265,12 @@
     char *logfile=  NdbConfig_StdoutFileName(globalData.ownId);
     NdbAutoPtr<char> tmp_aptr1(lockfile), tmp_aptr2(logfile);
 
-    if (NdbDaemon_Make(lockfile, logfile, 0) == -1) {
+#ifndef NDB_WIN32
+	if (NdbDaemon_Make(lockfile, logfile, 0) == -1) {
       ndbout << "Cannot become daemon: " << NdbDaemon_ErrorText << endl;
       return 1;
     }
+#endif
   }
 
 #ifndef NDB_WIN32

--- a/ndb/src/kernel/vm/Emulator.cpp	2007-08-29 07:25:53 +0000
+++ b/ndb/src/kernel/vm/Emulator.cpp	2007-09-06 13:30:50 +0000
@@ -240,8 +240,10 @@
     
     if(type != NST_Normal && type != NST_Restart){
       // Signal parent that error occured during startup
+#ifndef NDB_WIN32
       if (type == NST_ErrorHandlerStartup)
 	kill(getppid(), SIGUSR1);
+#endif
       g_eventLogger.info("Error handler shutdown completed - %s", exitAbort);
       if (opt_core)
       {

--- a/ndb/src/kernel/vm/SimulatedBlock.cpp	2007-08-29 07:25:53 +0000
+++ b/ndb/src/kernel/vm/SimulatedBlock.cpp	2007-09-06 13:30:50 +0000
@@ -855,7 +855,7 @@
 SimulatedBlock::execSIGNAL_DROPPED_REP(Signal * signal){
   char msg[64];
   const SignalDroppedRep * const rep = (SignalDroppedRep *)&signal->theData[0];
-  snprintf(msg, sizeof(msg), "%s GSN: %u (%u,%u)", getBlockName(number()),
+  BaseString::snprintf(msg, sizeof(msg), "%s GSN: %u (%u,%u)", getBlockName(number()),
 	   rep->originalGsn, rep->originalLength,rep->originalSectionCount);
   ErrorReporter::handleError(NDBD_EXIT_OUT_OF_LONG_SIGNAL_MEMORY,
 			     msg,

--- a/ndb/src/kernel/vm/TransporterCallback.cpp	2007-08-29 07:25:53 +0000
+++ b/ndb/src/kernel/vm/TransporterCallback.cpp	2007-09-06 13:30:50 +0000
@@ -233,6 +233,7 @@
   
   bool ok = true;
   Ptr<SectionSegment> secPtr[3];
+  bzero(secPtr, sizeof(secPtr));
   switch(secCount){
   case 3:
     ok &= import(secPtr[2], ptr[2].p, ptr[2].sz);
@@ -343,7 +344,7 @@
   case TE_SIGNAL_LOST_SEND_BUFFER_FULL:
   {
     char msg[64];
-    snprintf(msg, sizeof(msg), "Remote note id %d.%s%s", nodeId,
+    BaseString::snprintf(msg, sizeof(msg), "Remote note id %d.%s%s", nodeId,
 	     info ? " " : "", info ? info : "");
     ErrorReporter::handleError(NDBD_EXIT_SIGNAL_LOST_SEND_BUFFER_FULL,
 			       msg, __FILE__, NST_ErrorHandler);
@@ -351,7 +352,7 @@
   case TE_SIGNAL_LOST:
   {
     char msg[64];
-    snprintf(msg, sizeof(msg), "Remote node id %d,%s%s", nodeId,
+    BaseString::snprintf(msg, sizeof(msg), "Remote node id %d,%s%s", nodeId,
 	     info ? " " : "", info ? info : "");
     ErrorReporter::handleError(NDBD_EXIT_SIGNAL_LOST,
 			       msg, __FILE__, NST_ErrorHandler);
@@ -359,7 +360,7 @@
   case TE_SHM_IPC_PERMANENT:
   {
     char msg[128];
-    snprintf(msg, sizeof(msg),
+    BaseString::snprintf(msg, sizeof(msg),
 	     "Remote node id %d.%s%s",
 	     nodeId, info ? " " : "", info ? info : "");
     ErrorReporter::handleError(NDBD_EXIT_CONNECTION_SETUP_FAILED,

--- a/ndb/src/kernel/vm/WatchDog.cpp	2007-08-29 07:25:53 +0000
+++ b/ndb/src/kernel/vm/WatchDog.cpp	2007-09-06 13:30:50 +0000
@@ -16,7 +16,9 @@
 
 #include <ndb_global.h>
 #include <my_pthread.h>
+#ifndef NDB_WIN32
 #include <sys/times.h>
+#endif
 
 #include "WatchDog.hpp"
 #include "GlobalData.hpp"
@@ -130,6 +132,7 @@
         break;
       }//switch
       g_eventLogger.warning("Ndb kernel is stuck in: %s", last_stuck_action);
+#ifndef NDB_WIN32
       {
         struct tms my_tms;
         times(&my_tms);
@@ -137,6 +140,7 @@
                            (Uint64)my_tms.tms_utime,
                            (Uint64)my_tms.tms_stime);
       }
+#endif
       if(alerts == 3){
 	shutdownSystem(last_stuck_action);
       }

