1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include "readwrite_helper.h"
12 #include <osl/diagnose.h>
15 sal_Bool
safeWrite(int fd
, void* data
, sal_uInt32 dataSize
)
17 sal_Int32 nToWrite
= dataSize
;
18 unsigned char* dataToWrite
= data
;
20 // Check for overflow as we convert a signed to an unsigned.
21 OSL_ASSERT(dataSize
== (sal_uInt32
)nToWrite
);
23 sal_Int32 nWritten
= write(fd
, dataToWrite
, nToWrite
);
32 OSL_ASSERT(nWritten
> 0);
34 dataToWrite
+= nWritten
;
40 sal_Bool
safeRead( int fd
, void* buffer
, sal_uInt32 count
)
42 sal_Int32 nToRead
= count
;
43 unsigned char* bufferForReading
= buffer
;
45 // Check for overflow as we convert a signed to an unsigned.
46 OSL_ASSERT(count
== (sal_uInt32
)nToRead
);
48 sal_Int32 nRead
= read(fd
, bufferForReading
, nToRead
);
50 // We were interrupted before reading, retry.
57 // If we reach the EOF, we consider this a partial transfer and thus
63 bufferForReading
+= nRead
;
69 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */