summaryrefslogtreecommitdiff
path: root/sal/osl/unx/readwrite_helper.c
diff options
context:
space:
mode:
authorJulien Chaffraix <julien.chaffraix@gmail.com>2011-04-23 07:26:44 -0700
committerMichael Meeks <michael.meeks@novell.com>2011-04-26 15:13:59 +0100
commit44f720b12b685ce942e53866ae452c6c00b8b18c (patch)
tree8619885faf94b60ea1a5f83b8c17768a8f362332 /sal/osl/unx/readwrite_helper.c
parent50a89f08b0df7cff80e9bf6b6f932211e2b66ce9 (diff)
Refactored the safeWrite method in a new file.
This enables other files to use it, which will be added in a follow-up step.
Diffstat (limited to 'sal/osl/unx/readwrite_helper.c')
-rw-r--r--sal/osl/unx/readwrite_helper.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/sal/osl/unx/readwrite_helper.c b/sal/osl/unx/readwrite_helper.c
new file mode 100644
index 000000000000..4777d08614a1
--- /dev/null
+++ b/sal/osl/unx/readwrite_helper.c
@@ -0,0 +1,50 @@
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is
+ * Julien Chaffraix <julien.chaffraix@gmail.com>
+ * Portions created by the Initial Developer are Copyright (C) 2011 the
+ * Initial Developer. All Rights Reserved.
+ *
+ * Major Contributor(s):
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#include "readwrite_helper.h"
+
+#include <osl/diagnose.h>
+#include <system.h>
+
+sal_Bool safeWrite(int fd, void* data, sal_uInt32 dataSize)
+{
+ sal_Int32 nToWrite = dataSize;
+ // Check for overflow as we convert a signed to an unsigned.
+ OSL_ASSERT(dataSize == (sal_uInt32)nToWrite);
+ while ( nToWrite ) {
+ sal_Int32 nWritten = write(fd, data, nToWrite);
+ if ( nWritten < 0 )
+ return sal_False;
+
+ OSL_ASSERT(nWritten > 0);
+ nToWrite -= nWritten;
+ }
+
+ return sal_True;
+}