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. 0_9_1-71-g


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9_1-71-g6701d1f
Date: Fri, 12 Feb 2010 22:13: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  6701d1f6664ddd69aa658b9ad646365654614411 (commit)
       via  2f057ab63ec78a61f53f090899c1e7b739ce4ce7 (commit)
      from  9287fdf621aff6e4577d1e84aadf4072b2046637 (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 6701d1f6664ddd69aa658b9ad646365654614411
Author: Giuseppe Scrivano <address@hidden>
Date:   Fri Feb 12 23:14:16 2010 +0100

    Test if binary files are handled correctly.

diff --git a/myserver/src/base/file/file.cpp b/myserver/src/base/file/file.cpp
index 3a60ad0..cc91636 100644
--- a/myserver/src/base/file/file.cpp
+++ b/myserver/src/base/file/file.cpp
@@ -63,25 +63,31 @@ const u_long File::FILE_CREATE_ALWAYS = (1<<7);
 const u_long File::NO_INHERIT = (1<<8);
 
 
+/*!
+ *Costructor of the class.
+ */
 File::File ()
 {
   handle = (FileHandle) -1;
 }
 
+/*!
+ *D'tor.
+ */
 File::~File ()
 {
   close ();
 }
 
 /*!
- * Write data to a file.
- * buffer is the pointer to the data to write
- * buffersize is the number of byte to write
- * nbw is a pointer to an unsigned long that receive the number of the
- * bytes written correctly.
- * \param buffer The buffer where write.
- * \param buffersize The length of the buffer in bytes.
- * \param nbw How many bytes were written to the file.
+ *Write data to a file.
+ *buffer is the pointer to the data to write
+ *buffersize is the number of byte to write
+ *nbw is a pointer to an unsigned long that receive the number of the
+ *bytes written correctly.
+ *\param buffer The buffer where write.
+ *\param buffersize The length of the buffer in bytes.
+ *\param nbw How many bytes were written to the file.
  */
 int File::writeToFile (const char* buffer, u_long buffersize, u_long* nbw)
 {
@@ -101,9 +107,9 @@ int File::writeToFile (const char* buffer, u_long 
buffersize, u_long* nbw)
 }
 
 /*!
- * Constructor for the class.
- * \param nfilename Filename to open.
- * \param opt Specify how open the file.
+ *Constructor for the class.
+ *\param nfilename Filename to open.
+ *\param opt Specify how open the file.
  */
 File::File (char *nfilename, int opt)
   : handle ((FileHandle) -1)
@@ -113,7 +119,7 @@ File::File (char *nfilename, int opt)
 
 /*!
  * Truncate the file.
- * \param size Specify the new file size.
+ *\param size Specify the new file size.
  */
 int File::truncate (u_long size)
 {
@@ -125,11 +131,11 @@ int File::truncate (u_long size)
 }
 
 /*!
- * Open (or create if not exists) a file, but must explicitly use read and/or
- * write flags and open flag.
- * \param nfilename Filename to open.
- * \param opt Specify how open the file.
- * It returns 0 if the call was successful, any other value on errors.
+ *Open (or create if not exists) a file, but must explicitly use read and/or
+ *write flags and open flag.
+ *\param nfilename Filename to open.
+ *\param opt Specify how open the file.
+ *openFile returns 0 if the call was successful, any other value on errors.
  */
 int File::openFile (const char* nfilename,u_long opt)
 {
@@ -148,33 +154,28 @@ int File::openFile (const char* nfilename,u_long opt)
   /* FIXME: how avoid a stat?  */
   bool exists = stat (filename.c_str (), &fStats) == 0;
 
-  if ((opt & File::OPEN_IF_EXISTS) && !exists)
+  if (opt & File::OPEN_IF_EXISTS && !exists)
     return 1;
 
   if (exists && (opt & File::APPEND))
     flags |= O_APPEND;
 
-#if O_BINARY
-  flags |= O_BINARY;
-#endif
-
   if (exists)
-    handle = open (filename.c_str (), flags);
+    handle = open (filename.c_str (), O_APPEND | flags);
   else
     handle = open (filename.c_str (), O_CREAT | flags, S_IRUSR | S_IWUSR);
 
   if (opt & File::FILE_CREATE_ALWAYS)
     truncate ();
 
-  /* It will be removed on close.  */
   if (opt & File::TEMPORARY)
-    unlink (filename.c_str ());
+    unlink (filename.c_str ()); /* It will be removed on close.  */
 
   return handle < 0;
 }
 
 /*!
- * Returns the file handle.
+ *Returns the file handle.
  */
 Handle File::getHandle ()
 {
@@ -182,9 +183,9 @@ Handle File::getHandle ()
 }
 
 /*!
- * Set the base/file/file.handle.
- * Return a non null-value on errors.
- * \param hl The new base/file/file.handle.
+ *Set the base/file/file.handle.
+ *Return a non null-value on errors.
+ *\param hl The new base/file/file.handle.
  */
 int File::setHandle (Handle hl)
 {
@@ -193,8 +194,8 @@ int File::setHandle (Handle hl)
 }
 
 /*!
- * Define the operator =.
- * \param f The file to copy.
+ *define the operator =.
+ *\param f The file to copy.
  */
 int File::operator =(File f)
 {
@@ -204,9 +205,9 @@ int File::operator =(File f)
 }
 
 /*!
- * Set the name of the file
- * Return Non-zero on errors.
- * \param nfilename The new file name.
+ *Set the name of the file
+ *Return Non-zero on errors.
+ *\param nfilename The new file name.
  */
 int File::setFilename (const char* nfilename)
 {
@@ -215,7 +216,7 @@ int File::setFilename (const char* nfilename)
 }
 
 /*!
- * Returns the file path.
+ *Returns the file path.
  */
 const char *File::getFilename ()
 {
@@ -223,8 +224,8 @@ const char *File::getFilename ()
 }
 
 /*!
- * Create a temporary file.
- * \param filename The new temporary file name.
+ *Create a temporary file.
+ *\param filename The new temporary file name.
  */
 int File::createTemporaryFile (const char* filename)
 {
@@ -232,10 +233,10 @@ int File::createTemporaryFile (const char* filename)
     FilesUtility::deleteFile (filename);
 
   return openFile (filename, File::READ
-                   | File::WRITE
-                   | File::FILE_CREATE_ALWAYS
-                   | File::TEMPORARY
-                   | File::NO_INHERIT);
+                  | File::WRITE
+                  | File::FILE_CREATE_ALWAYS
+                  | File::TEMPORARY
+                  | File::NO_INHERIT);
 }
 
 /*!
@@ -270,8 +271,8 @@ u_long File::getFileSize ()
 }
 
 /*!
- * Change the position of the pointer to the file.
- * \param initialByte The new file pointer position.
+ *Change the position of the pointer to the file.
+ *\param initialByte The new file pointer position.
  */
 int File::seek (u_long initialByte)
 {
@@ -283,7 +284,7 @@ int File::seek (u_long initialByte)
 /*!
  * Get the current file pointer position.
  *
- * \return The current file pointer position.
+ *\return The current file pointer position.
  */
 u_long File::getSeek ()
 {
@@ -291,7 +292,7 @@ u_long File::getSeek ()
 }
 
 /*!
- * Get the time of the last modifify did to the file.
+ *Get the time of the last modifify did to the file.
  */
 time_t File::getLastModTime ()
 {
@@ -299,7 +300,7 @@ time_t File::getLastModTime ()
 }
 
 /*!
- * This function returns the creation time of the file.
+ *This function returns the creation time of the file.
  */
 time_t File::getCreationTime ()
 {
@@ -307,7 +308,7 @@ time_t File::getCreationTime ()
 }
 
 /*!
- * Returns the time of the last access to the file.
+ *Returns the time of the last access to the file.
  */
 time_t File::getLastAccTime ()
 {
@@ -315,7 +316,7 @@ time_t File::getLastAccTime ()
 }
 
 /*!
- * Inherited from Stream.
+ *Inherited from Stream.
  */
 int File::write (const char* buffer, u_long len, u_long *nbw)
 {
@@ -323,16 +324,16 @@ int File::write (const char* buffer, u_long len, u_long 
*nbw)
 }
 
 /*!
- * Read data from a file to a buffer.
- * Return a negative value on errors.
- * Return 0 on success.
- * \param buffer The buffer where write.
- * \param buffersize The length of the buffer in bytes.
- * \param nbr How many bytes were read to the buffer.
+ *Read data from a file to a buffer.
+ *Return a negative value on errors.
+ *Return 0 on success.
+ *\param buffer The buffer where write.
+ *\param buffersize The length of the buffer in bytes.
+ *\param nbr How many bytes were read to the buffer.
  */
 int File::read (char* buffer, u_long buffersize, u_long* nbr)
 {
-  int ret = ::read (handle, buffer, buffersize);
+  int ret  = ::read (handle, buffer, buffersize);
   if (ret < 0)
     return ret;
 
diff --git a/myserver/tests/test_file.cpp b/myserver/tests/test_file.cpp
index 76ae60c..a45dd06 100644
--- a/myserver/tests/test_file.cpp
+++ b/myserver/tests/test_file.cpp
@@ -41,6 +41,7 @@ class TestFile : public CppUnit::TestFixture
 
   CPPUNIT_TEST (testCreateTemporaryFile);
   CPPUNIT_TEST (testOnFile);
+  CPPUNIT_TEST (testBinary);
   CPPUNIT_TEST (testTruncate);
   CPPUNIT_TEST (testCreationTime);
   CPPUNIT_TEST (testLastAccessTime);
@@ -128,6 +129,22 @@ public:
     CPPUNIT_ASSERT_EQUAL (tfile->getSeek (), 1ul);
   }
 
+  void testBinary ()
+  {
+    const char *data = "this\0text\0is\0NUL\0separed\0\0";
+    char buffer[32];
+    u_long nbw, nbr;
+    CPPUNIT_ASSERT_EQUAL (openHelper (), 0);
+    CPPUNIT_ASSERT_EQUAL (tfile->write (data, 26, &nbw), 0);
+    CPPUNIT_ASSERT_EQUAL (nbw, 26ul);
+
+    CPPUNIT_ASSERT_EQUAL (tfile->seek (0), 0);
+
+    CPPUNIT_ASSERT_EQUAL (tfile->read (buffer, 26, &nbr), 0);
+    CPPUNIT_ASSERT_EQUAL (nbr, 26ul);
+    CPPUNIT_ASSERT_EQUAL (memcmp (data, buffer, 26), 0);
+  }
+
   void testTruncate ()
   {
     u_long nbw;



commit 2f057ab63ec78a61f53f090899c1e7b739ce4ce7
Author: Giuseppe Scrivano <address@hidden>
Date:   Fri Feb 12 23:05:46 2010 +0100

    If O_BINARY is defined, use it when a file is opened.

diff --git a/myserver/src/base/file/file.cpp b/myserver/src/base/file/file.cpp
index cc91636..3a60ad0 100644
--- a/myserver/src/base/file/file.cpp
+++ b/myserver/src/base/file/file.cpp
@@ -63,31 +63,25 @@ const u_long File::FILE_CREATE_ALWAYS = (1<<7);
 const u_long File::NO_INHERIT = (1<<8);
 
 
-/*!
- *Costructor of the class.
- */
 File::File ()
 {
   handle = (FileHandle) -1;
 }
 
-/*!
- *D'tor.
- */
 File::~File ()
 {
   close ();
 }
 
 /*!
- *Write data to a file.
- *buffer is the pointer to the data to write
- *buffersize is the number of byte to write
- *nbw is a pointer to an unsigned long that receive the number of the
- *bytes written correctly.
- *\param buffer The buffer where write.
- *\param buffersize The length of the buffer in bytes.
- *\param nbw How many bytes were written to the file.
+ * Write data to a file.
+ * buffer is the pointer to the data to write
+ * buffersize is the number of byte to write
+ * nbw is a pointer to an unsigned long that receive the number of the
+ * bytes written correctly.
+ * \param buffer The buffer where write.
+ * \param buffersize The length of the buffer in bytes.
+ * \param nbw How many bytes were written to the file.
  */
 int File::writeToFile (const char* buffer, u_long buffersize, u_long* nbw)
 {
@@ -107,9 +101,9 @@ int File::writeToFile (const char* buffer, u_long 
buffersize, u_long* nbw)
 }
 
 /*!
- *Constructor for the class.
- *\param nfilename Filename to open.
- *\param opt Specify how open the file.
+ * Constructor for the class.
+ * \param nfilename Filename to open.
+ * \param opt Specify how open the file.
  */
 File::File (char *nfilename, int opt)
   : handle ((FileHandle) -1)
@@ -119,7 +113,7 @@ File::File (char *nfilename, int opt)
 
 /*!
  * Truncate the file.
- *\param size Specify the new file size.
+ * \param size Specify the new file size.
  */
 int File::truncate (u_long size)
 {
@@ -131,11 +125,11 @@ int File::truncate (u_long size)
 }
 
 /*!
- *Open (or create if not exists) a file, but must explicitly use read and/or
- *write flags and open flag.
- *\param nfilename Filename to open.
- *\param opt Specify how open the file.
- *openFile returns 0 if the call was successful, any other value on errors.
+ * Open (or create if not exists) a file, but must explicitly use read and/or
+ * write flags and open flag.
+ * \param nfilename Filename to open.
+ * \param opt Specify how open the file.
+ * It returns 0 if the call was successful, any other value on errors.
  */
 int File::openFile (const char* nfilename,u_long opt)
 {
@@ -154,28 +148,33 @@ int File::openFile (const char* nfilename,u_long opt)
   /* FIXME: how avoid a stat?  */
   bool exists = stat (filename.c_str (), &fStats) == 0;
 
-  if (opt & File::OPEN_IF_EXISTS && !exists)
+  if ((opt & File::OPEN_IF_EXISTS) && !exists)
     return 1;
 
   if (exists && (opt & File::APPEND))
     flags |= O_APPEND;
 
+#if O_BINARY
+  flags |= O_BINARY;
+#endif
+
   if (exists)
-    handle = open (filename.c_str (), O_APPEND | flags);
+    handle = open (filename.c_str (), flags);
   else
     handle = open (filename.c_str (), O_CREAT | flags, S_IRUSR | S_IWUSR);
 
   if (opt & File::FILE_CREATE_ALWAYS)
     truncate ();
 
+  /* It will be removed on close.  */
   if (opt & File::TEMPORARY)
-    unlink (filename.c_str ()); /* It will be removed on close.  */
+    unlink (filename.c_str ());
 
   return handle < 0;
 }
 
 /*!
- *Returns the file handle.
+ * Returns the file handle.
  */
 Handle File::getHandle ()
 {
@@ -183,9 +182,9 @@ Handle File::getHandle ()
 }
 
 /*!
- *Set the base/file/file.handle.
- *Return a non null-value on errors.
- *\param hl The new base/file/file.handle.
+ * Set the base/file/file.handle.
+ * Return a non null-value on errors.
+ * \param hl The new base/file/file.handle.
  */
 int File::setHandle (Handle hl)
 {
@@ -194,8 +193,8 @@ int File::setHandle (Handle hl)
 }
 
 /*!
- *define the operator =.
- *\param f The file to copy.
+ * Define the operator =.
+ * \param f The file to copy.
  */
 int File::operator =(File f)
 {
@@ -205,9 +204,9 @@ int File::operator =(File f)
 }
 
 /*!
- *Set the name of the file
- *Return Non-zero on errors.
- *\param nfilename The new file name.
+ * Set the name of the file
+ * Return Non-zero on errors.
+ * \param nfilename The new file name.
  */
 int File::setFilename (const char* nfilename)
 {
@@ -216,7 +215,7 @@ int File::setFilename (const char* nfilename)
 }
 
 /*!
- *Returns the file path.
+ * Returns the file path.
  */
 const char *File::getFilename ()
 {
@@ -224,8 +223,8 @@ const char *File::getFilename ()
 }
 
 /*!
- *Create a temporary file.
- *\param filename The new temporary file name.
+ * Create a temporary file.
+ * \param filename The new temporary file name.
  */
 int File::createTemporaryFile (const char* filename)
 {
@@ -233,10 +232,10 @@ int File::createTemporaryFile (const char* filename)
     FilesUtility::deleteFile (filename);
 
   return openFile (filename, File::READ
-                  | File::WRITE
-                  | File::FILE_CREATE_ALWAYS
-                  | File::TEMPORARY
-                  | File::NO_INHERIT);
+                   | File::WRITE
+                   | File::FILE_CREATE_ALWAYS
+                   | File::TEMPORARY
+                   | File::NO_INHERIT);
 }
 
 /*!
@@ -271,8 +270,8 @@ u_long File::getFileSize ()
 }
 
 /*!
- *Change the position of the pointer to the file.
- *\param initialByte The new file pointer position.
+ * Change the position of the pointer to the file.
+ * \param initialByte The new file pointer position.
  */
 int File::seek (u_long initialByte)
 {
@@ -284,7 +283,7 @@ int File::seek (u_long initialByte)
 /*!
  * Get the current file pointer position.
  *
- *\return The current file pointer position.
+ * \return The current file pointer position.
  */
 u_long File::getSeek ()
 {
@@ -292,7 +291,7 @@ u_long File::getSeek ()
 }
 
 /*!
- *Get the time of the last modifify did to the file.
+ * Get the time of the last modifify did to the file.
  */
 time_t File::getLastModTime ()
 {
@@ -300,7 +299,7 @@ time_t File::getLastModTime ()
 }
 
 /*!
- *This function returns the creation time of the file.
+ * This function returns the creation time of the file.
  */
 time_t File::getCreationTime ()
 {
@@ -308,7 +307,7 @@ time_t File::getCreationTime ()
 }
 
 /*!
- *Returns the time of the last access to the file.
+ * Returns the time of the last access to the file.
  */
 time_t File::getLastAccTime ()
 {
@@ -316,7 +315,7 @@ time_t File::getLastAccTime ()
 }
 
 /*!
- *Inherited from Stream.
+ * Inherited from Stream.
  */
 int File::write (const char* buffer, u_long len, u_long *nbw)
 {
@@ -324,16 +323,16 @@ int File::write (const char* buffer, u_long len, u_long 
*nbw)
 }
 
 /*!
- *Read data from a file to a buffer.
- *Return a negative value on errors.
- *Return 0 on success.
- *\param buffer The buffer where write.
- *\param buffersize The length of the buffer in bytes.
- *\param nbr How many bytes were read to the buffer.
+ * Read data from a file to a buffer.
+ * Return a negative value on errors.
+ * Return 0 on success.
+ * \param buffer The buffer where write.
+ * \param buffersize The length of the buffer in bytes.
+ * \param nbr How many bytes were read to the buffer.
  */
 int File::read (char* buffer, u_long buffersize, u_long* nbr)
 {
-  int ret  = ::read (handle, buffer, buffersize);
+  int ret = ::read (handle, buffer, buffersize);
   if (ret < 0)
     return ret;
 

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

Summary of changes:
 myserver/tests/test_file.cpp |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

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