1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * Version: MPL 1.1 / GPLv3+ / LGPLv3+
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License or as specified alternatively below. You may obtain a copy of
8 * the License at http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Initial Developer of the Original Code is
16 * Julien Chaffraix <julien.chaffraix@gmail.com>
17 * Portions created by the Initial Developer are Copyright (C) 2011 the
18 * Initial Developer. All Rights Reserved.
20 * Major Contributor(s):
22 * For minor contributions see the git repository.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
26 * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
27 * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
28 * instead of those above.
31 #include "readwrite_helper.h"
33 #include <osl/diagnose.h>
36 sal_Bool
safeWrite(int fd
, void* data
, sal_uInt32 dataSize
)
38 sal_Int32 nToWrite
= dataSize
;
39 unsigned char* dataToWrite
= data
;
41 // Check for overflow as we convert a signed to an unsigned.
42 OSL_ASSERT(dataSize
== (sal_uInt32
)nToWrite
);
44 sal_Int32 nWritten
= write(fd
, dataToWrite
, nToWrite
);
53 OSL_ASSERT(nWritten
> 0);
55 dataToWrite
+= nWritten
;
61 sal_Bool
safeRead( int fd
, void* buffer
, sal_uInt32 count
)
63 sal_Int32 nToRead
= count
;
64 unsigned char* bufferForReading
= buffer
;
66 // Check for overflow as we convert a signed to an unsigned.
67 OSL_ASSERT(count
== (sal_uInt32
)nToRead
);
69 sal_Int32 nRead
= read(fd
, bufferForReading
, nToRead
);
71 // We were interrupted before reading, retry.
78 // If we reach the EOF, we consider this a partial transfer and thus
84 bufferForReading
+= nRead
;
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */