myserver-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myserver-commit] [SCM] GNU MyServer branch, master, updated. b1465eb769


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. b1465eb76903a8499ccbd53c711e7e4461dfe2c2
Date: Thu, 20 Aug 2009 13:52:03 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU MyServer".

The branch, master has been updated
       via  b1465eb76903a8499ccbd53c711e7e4461dfe2c2 (commit)
       via  5ba71f91a83d0f9bccbbb5ff0fde2026dbe3928d (commit)
      from  21e0a612e723e213010fccbbb29b794a5c55f8f0 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------


commit b1465eb76903a8499ccbd53c711e7e4461dfe2c2
Author: Giuseppe Scrivano <address@hidden>
Date:   Thu Aug 20 15:50:06 2009 +0200

    Removed global getOSVersion() function.

diff --git a/myserver/include/base/utility.h b/myserver/include/base/utility.h
index 6b8b7c9..a6f22bc 100644
--- a/myserver/include/base/utility.h
+++ b/myserver/include/base/utility.h
@@ -29,31 +29,21 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>.
 
 using namespace std;
 
-/*!
-*Macros to do simple transformations.
-*/
-#define MYSERVER_KB(x) (x << 10)       //x * 1024
-#define MYSERVER_MB(x) (x << 20)       //x * 1024 * 1024
+#define MYSERVER_KB(x) (x << 10)
+#define MYSERVER_MB(x) (x << 20)
 #define MYSERVER_SEC(x) (x * 1000)
-#define OS_WINDOWS_9X      1
-#define OS_WINDOWS_2000    2
-#define OS_WINDOWS_NT3     3
-#define OS_WINDOWS_XP      4
-#define OS_GNU_LINUX       100
-#define OS_FREEBSD         200
-
-int preparePrintError();
-int endPrintError();
-
-int getOSVersion();
-u_long getCPUCount();
-u_long getTicks();
-int setcwdBuffer();
-int getdefaultwdlen();
-char *getdefaultwd(char* dwd,int maxlen);
-int getdefaultwd(string&);
-int setcwd(const char * cwd);
-int freecwdBuffer();
+
+int preparePrintError ();
+int endPrintError ();
+
+u_long getCPUCount ();
+u_long getTicks ();
+int setcwdBuffer ();
+int getdefaultwdlen ();
+char *getdefaultwd (char* dwd,int maxlen);
+int getdefaultwd (string&);
+int setcwd (const char * cwd);
+int freecwdBuffer ();
 
 int readFileHandle (SocketHandle s, Handle* fd);
 int writeFileHandle (SocketHandle s, Handle fd);
diff --git a/myserver/src/base/utility.cpp b/myserver/src/base/utility.cpp
index 0608dc7..f28f896 100644
--- a/myserver/src/base/utility.cpp
+++ b/myserver/src/base/utility.cpp
@@ -20,89 +20,42 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>.
 #include <include/base/utility.h>
 #include <include/base/string/securestr.h>
 
-extern "C" {
+extern "C"
+{
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+
 #ifndef WIN32
-#include <unistd.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/time.h>
-#ifdef ERRORH
-#include <error.h>
-#endif
-#include <errno.h>
+# include <unistd.h>
+# include <signal.h>
+# include <sys/types.h>
+# include <sys/wait.h>
+# include <sys/time.h>
+# include <errno.h>
+
+# ifdef ERRORH
+#  include <error.h>
+# endif
 #endif
 }
 
 #ifdef WIN32
-#include <direct.h>
+# include <direct.h>
 #endif
 
 #include <iostream>
 using namespace std;
 
 /*
- *Various utility functions.
+ * Various utility functions.
  */
 static char *currentPath = 0;
 
 /*!
- *Returns the version of the operating system.
- *Return 0 if it is not recognized.
- */
-int getOSVersion()
-{
-  int ret = 0;
-  /*!
-   *This is the code for the win32 platform.
-   */
-#ifdef WIN32
-  OSVERSIONINFO osvi;
-  osvi.dwOSVersionInfoSize = sizeof(osvi);
-  ret = GetVersionEx(&osvi);
-  if(!ret)
-    return 0;  
-  switch(osvi.dwMinorVersion)
-  {
-  case 0:
-    if(osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
-      ret = OS_WINDOWS_9X;
-    else
-      ret = OS_WINDOWS_2000;
-    break;
-  case 10:
-    ret = OS_WINDOWS_9X;
-    break;  
-  case 90:
-    ret = OS_WINDOWS_9X;
-    break;
-  case 51:
-    ret = OS_WINDOWS_NT3;
-    break;
-  case 1:
-    ret = OS_WINDOWS_XP;
-    break;
-  }
-#endif
-
-#ifdef __linux__
-  ret = OS_GNU_LINUX;
-#endif
-
-#ifdef __FreeBSD__
-  ret = OS_FREEBSD;
-#endif
-
-  return ret;
-}  
-
-/*!
- *Returns the number of processors available on the local machine.
+ * Returns the number of processors available on the local machine.
  */
-u_long getCPUCount()
+u_long getCPUCount ()
 {
   /*! By default use 1 processor.  */
   u_long ret = 1;
@@ -113,7 +66,7 @@ u_long getCPUCount()
 #endif
 
 #ifdef _SC_NPROCESSORS_CONF
-  ret = (u_long)sysconf(_SC_NPROCESSORS_CONF); 
+  ret = (u_long)sysconf(_SC_NPROCESSORS_CONF);
   /*! Use only a processor if some error happens.  */
   if(ret == (u_long)-1)
     ret = 1;
@@ -139,14 +92,14 @@ u_long getCPUCount()
 }
 
 /*!
- *Save the current working directory.
- *Return -1 on fails.
- *Return 0 on success.
+ * Save the current working directory.
+ * Return -1 on fails.
+ * Return 0 on success.
  */
-int setcwdBuffer()
+int setcwdBuffer ()
 {
 #ifdef WIN32
-  /*! Under windows there is MAX_PATH, we will use it.  */
+  /* Under windows there is MAX_PATH, we will use it.  */
   currentPath = new char [MAX_PATH];
   if(currentPath == 0)
     return (-1);
@@ -166,7 +119,7 @@ int setcwdBuffer()
 #endif
 
 #ifdef __OpenBSD__
-  currentPath = getcwd(0, 0);
+  currentPath = getcwd (0, 0);
   return currentPath ? 0 : 1;
 #endif
 
@@ -178,55 +131,56 @@ int setcwdBuffer()
   {
     /*! Allocation problem is up.  */
     if(currentPath == 0)
-    {
-      return (-1);
-    }
-    ret = getcwd(currentPath, size);
-    /*! Realloc the buffer if it cannot contain the current directory.  */
+      return -1;
+
+    ret = getcwd (currentPath, size);
+    /* Realloc the buffer if it cannot contain the current directory.  */
     if(ret == 0)
-    {
-      size *= 2;
-      delete [] currentPath;
-      currentPath = new char[size];
-    }
-  }while( (ret == 0) && (errno == ERANGE) );
-  if(currentPath[strlen(currentPath)] == '/') 
+      {
+        size *= 2;
+        delete [] currentPath;
+        currentPath = new char[size];
+      }
+  }
+  while((ret == 0) && (errno == ERANGE));
+
+  if(currentPath[strlen(currentPath)] == '/')
     currentPath[strlen(currentPath)] = '\0';
   return 0;
 #endif
 }
 
 /*!
- *Get the defult directory using a string as output.
- *Return 0 on success.
- *\param out The string where write.
+ * Get the defult directory using a string as output.
+ * Return 0 on success.
+ * \param out The string where write.
  */
-int getdefaultwd(string& out)
+int getdefaultwd (string& out)
 {
-  char *wd = getdefaultwd(0, 0);
+  char *wd = getdefaultwd (NULL, NULL);
 
-  if(wd == 0)
+  if (wd == 0)
     return -1;
 
-  out.assign(wd);
+  out.assign (wd);
   return 0;
 }
 
 /*!
- *free the cwd buffer.
+ * Free the cwd buffer.
  */
 int freecwdBuffer()
 {
   delete [] currentPath;
-  return 0;  
+  return 0;
 }
 
 /*!
  *Get the default working directory length.
  */
-int getdefaultwdlen()
+int getdefaultwdlen ()
 {
-  return strlen(currentPath) + 1;
+  return strlen (currentPath) + 1;
 }
 
 /*!
@@ -234,96 +188,96 @@ int getdefaultwdlen()
  *\param path The buffer where write.
  *\param len The length of the buffer.
  */
-char *getdefaultwd(char *path, int len)
+char *getdefaultwd (char *path, int len)
 {
-
-  if(path)
-  {
-    /*! If len is equal to zero we assume no limit.  */
-    if(len)
-      myserver_strlcpy(path, currentPath, len);
-    else
-      strcpy(path, currentPath);
-  }
+  if (path)
+    {
+    /* If len is equal to zero we assume no limit.  */
+      if (len)
+        myserver_strlcpy(path, currentPath, len);
+      else
+        strcpy(path, currentPath);
+    }
   return currentPath;
 }
 
-
 /*!
- *Set the current working directory. Returns Zero if successful.
- *\param dir The current working directory.
+ * Set the current working directory. Returns Zero if successful.
+ * \param dir The current working directory.
  */
-int setcwd(const char *dir)
+int setcwd (const char *dir)
 {
-#ifdef WIN32  
+#ifdef WIN32
   return _chdir(dir);
 #endif
+
 #ifndef WIN32
   return chdir(dir);
 #endif
 }
 
 /*!
- *Set the text color to red on black.
- *Return 0 on success.
+ * Set the text color to red on black.
+ * Return 0 on success.
  */
-int preparePrintError()
+int preparePrintError ()
 {
-#ifdef WIN32
-  int ret = SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 
-                                    FOREGROUND_RED | 
-                                    FOREGROUND_INTENSITY);
-  if(ret)
-    return 0;
-#endif
 #ifndef WIN32
   cout << "\033[31;1m";
   return 0;
+#else
+  int ret = SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
+                                     FOREGROUND_RED | FOREGROUND_INTENSITY);
+  if (ret)
+    return 0;
 #endif
 
+  return -1;
 }
 
 /*!
- *Set the text color to white on black.
- *Return 0 on success.
+ * Set the text color to white on black.
+ * Return 0 on success.
  */
-int endPrintError()
+int endPrintError ()
 {
-#ifdef WIN32
-  int ret = SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 
-                                    FOREGROUND_RED | 
-                                    FOREGROUND_GREEN | 
-                                    FOREGROUND_BLUE);
-  if(ret)
-    return 0;
-#else
+#ifndef WIN32
   cout << "\033[0m";
   return 0;
+#else
+  int ret = SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
+                                     FOREGROUND_RED |
+                                     FOREGROUND_GREEN |
+                                     FOREGROUND_BLUE);
+  if (ret)
+    return 0;
 #endif
+
+  return -1;
 }
 
 /*!
- *Return the ticks count. Used to check time variations.
- *Return 0 on errors.
+ * Return the ticks count in milliseconds.
+ * Return 0 on errors.
  */
-u_long getTicks()
+u_long getTicks ()
 {
 #ifdef WIN32
-  return GetTickCount();
+  return GetTickCount ();
 #else
   struct timeval tval;
-  int ret = gettimeofday(&tval, 0);
-  if(ret == -1)
+  int ret = gettimeofday (&tval, 0);
+  if (ret == -1)
     return 0;
   return  (tval.tv_sec * 1000) + (tval.tv_usec / 1000);
 #endif
 }
 
 /*!
- *Read a file handle from a socket.
- *\param s Socket handle to read from.
- *\param File handle received.
- *\return 0 on success.
+ * Read a file handle from a socket.
+ * \param s Socket handle to read from.
+ * \param File handle received.
+ * \return 0 on success.
  */
 int readFileHandle (SocketHandle s, Handle* fd)
 {
@@ -356,10 +310,10 @@ int readFileHandle (SocketHandle s, Handle* fd)
 }
 
 /*!
- *Write a file handle to a socket.
- *\param s Socket handle to write to.
- *\param File handle received.
- *\return 0 on success.
+ * Write a file handle to a socket.
+ * \param s Socket handle to write to.
+ * \param File handle received.
+ * \return 0 on success.
  */
 int writeFileHandle (SocketHandle s, Handle fd)
 {
diff --git a/myserver/tests/test_utility.cpp b/myserver/tests/test_utility.cpp
index 80ab962..ff22f77 100644
--- a/myserver/tests/test_utility.cpp
+++ b/myserver/tests/test_utility.cpp
@@ -1,16 +1,16 @@
 /*
  MyServer
- Copyright (C) 2008 Free Software Foundation, Inc.
+ Copyright (C) 2008, 2009 Free Software Foundation, Inc.
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 3 of the License, or
  (at your option) any later version.
- 
- This program is distributed in the hope that it will be useful, 
+
+ This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
- 
+
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
@@ -32,14 +32,13 @@ class TestUtility : public CppUnit::TestFixture
 {
   CPPUNIT_TEST_SUITE( TestUtility );
   CPPUNIT_TEST( testGetTicks );
-  CPPUNIT_TEST( testGetOsVersion );
   CPPUNIT_TEST( testCWD );
   CPPUNIT_TEST_SUITE_END();
 
 public:
   void setUp()
   {
- 
+
   }
 
   void tearDown()
@@ -59,12 +58,6 @@ public:
     CPPUNIT_ASSERT(ticks2 > ticks);
   }
 
-  void testGetOsVersion()
-  {
-    CPPUNIT_ASSERT(getOSVersion() >= 0);
-  }
-
-
   void testGetCPUCount()
   {
     CPPUNIT_ASSERT(getCPUCount() > 0);
@@ -96,7 +89,7 @@ public:
     CPPUNIT_ASSERT_EQUAL(ret, 0);
 
     CPPUNIT_ASSERT(strBuff.length() > 0);
-    
+
 
 
     freecwdBuffer();



commit 5ba71f91a83d0f9bccbbb5ff0fde2026dbe3928d
Author: Giuseppe Scrivano <address@hidden>
Date:   Thu Aug 20 15:34:50 2009 +0200

    Add notice that the localedir.h file is auto-generated.

diff --git a/myserver/Makefile.am b/myserver/Makefile.am
index 1d37779..f7579dd 100644
--- a/myserver/Makefile.am
+++ b/myserver/Makefile.am
@@ -20,7 +20,8 @@ ACLOCAL_AMFLAGS = -I m4
 
 
 localedir.h: Makefile
-       echo '#define LOCALEDIR "$(localedir)"' >$@
+       echo '/* This file is auto-generated by Makefile!  */' >$@
+       echo '#define LOCALEDIR "$(localedir)"' >> $@
 
 all: localedir.h
 # Generate the localedir.h file before any other rule.

-----------------------------------------------------------------------

Summary of changes:
 myserver/Makefile.am            |    3 +-
 myserver/include/base/utility.h |   38 +++----
 myserver/src/base/utility.cpp   |  242 ++++++++++++++++-----------------------
 myserver/tests/test_utility.cpp |   19 +--
 4 files changed, 120 insertions(+), 182 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

[Prev in Thread] Current Thread [Next in Thread]