summaryrefslogtreecommitdiff
path: root/sal/osl/all
diff options
context:
space:
mode:
authorTino Rachui <tra@openoffice.org>2001-10-30 07:54:31 +0000
committerTino Rachui <tra@openoffice.org>2001-10-30 07:54:31 +0000
commit4f0ffbeb8faae05434867457eb4a60ead519204b (patch)
tree03d061a4b852f3465b6a6af399cf4b4e531879d4 /sal/osl/all
parentc773083b45d8b71ff988996d8fae8e9fb0432cc0 (diff)
#91782#now returning sequences without trailing 0
Diffstat (limited to 'sal/osl/all')
-rw-r--r--sal/osl/all/readline.c91
1 files changed, 35 insertions, 56 deletions
diff --git a/sal/osl/all/readline.c b/sal/osl/all/readline.c
index 0502bad9e..70e2fd25e 100644
--- a/sal/osl/all/readline.c
+++ b/sal/osl/all/readline.c
@@ -2,9 +2,9 @@
*
* $RCSfile: readline.c,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: tra $ $Date: 2001-10-24 11:48:59 $
+ * last change: $Author: tra $ $Date: 2001-10-30 08:54:31 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -78,8 +78,8 @@
Reads a line from given file. The new line delimiter(s) are NOT returned!
@param Handle [in] Handle to an open file.
- @param ppSequence [in/out] a pointer to a valid sequence. Will hold the line read on return.
- including a terminating '\0'
+ @param ppSequence [in/out] a pointer to a valid sequence.
+
@return osl_File_E_None on success otherwise one of the following errorcodes:<p>
osl_File_E_INVAL the format of the parameters was not valid<br>
@@ -108,7 +108,6 @@ oslFileError SAL_CALL osl_readLine( oslFileHandle Handle, sal_Sequence** ppSeq )
sal_uInt64 nRead = 0;
sal_uInt32 sizeBuff = INITIAL_BUFF_SIZE;
sal_Char *pchBuff = 0;
- sal_Char *pchLastInBuff = 0;
OSL_PRECOND( ppSeq, "invalid parameter detected" );
@@ -119,9 +118,9 @@ oslFileError SAL_CALL osl_readLine( oslFileHandle Handle, sal_Sequence** ppSeq )
return osl_File_E_NOMEM;
/* read character by character */
-
+
for( ;; )
- {
+ {
/* read the next character fro file into buffer */
ferr = osl_readFile( Handle, pchBuff + nReadTotal, 1, &nRead );
@@ -131,36 +130,29 @@ oslFileError SAL_CALL osl_readLine( oslFileHandle Handle, sal_Sequence** ppSeq )
rtl_freeMemory( pchBuff );
return ferr;
}
-
+
if ( 0 == nRead )
{
if ( nReadTotal > 0 )
- {
- *(pchBuff + nReadTotal) = '\0';
- rtl_byte_sequence_constructFromArray( ppSeq, (sal_Int8*)pchBuff, (sal_Int32)(nReadTotal + 1) );
- }
- else
- {
- rtl_byte_sequence_construct( ppSeq, 0 );
- }
+ rtl_byte_sequence_constructFromArray( ppSeq, (sal_Int8*)pchBuff, (sal_Int32)nReadTotal );
+ else
+ rtl_byte_sequence_construct( ppSeq, 0 );
rtl_freeMemory( pchBuff );
return osl_File_E_None;
}
OSL_ASSERT( 1 == nRead );
-
- nReadTotal += nRead;
- pchLastInBuff = pchBuff + nReadTotal - 1;
- if ( LF == *pchLastInBuff )
- {
- *pchLastInBuff = '\0';
- rtl_byte_sequence_constructFromArray( ppSeq, (sal_Int8*)pchBuff, (sal_Int32)nReadTotal );
+ nReadTotal++;
+
+ if ( LF == *(pchBuff + nReadTotal - 1) )
+ {
+ rtl_byte_sequence_constructFromArray( ppSeq, (sal_Int8*)pchBuff, (sal_Int32)(nReadTotal - 1) );
rtl_freeMemory( pchBuff );
return osl_File_E_None;
}
- else if ( CR == *pchLastInBuff )
+ else if ( CR == *(pchBuff + nReadTotal - 1) )
{
/* read one more character to detect possible '\n' */
@@ -172,47 +164,34 @@ oslFileError SAL_CALL osl_readLine( oslFileHandle Handle, sal_Sequence** ppSeq )
return ferr;
}
- if ( 0 == nRead )
+ if ( nRead > 0 )
{
- *pchLastInBuff = '\0';
- rtl_byte_sequence_constructFromArray( ppSeq, (sal_Int8*)pchBuff, (sal_Int32)nReadTotal );
- rtl_freeMemory( pchBuff );
- return osl_File_E_None;
- }
+ OSL_ASSERT( 1 == nRead );
+
+ /* we don't increment nReadTotal, so now last in buff is pchBuff + nReadTotal !!! */
- OSL_ASSERT( 1 == nRead );
+ if ( LF != *(pchBuff + nReadTotal) )
+ {
+ /* correct the file pointer */
- nReadTotal += nRead;
- pchLastInBuff = pchBuff + nReadTotal - 1;
+ ferr = osl_setFilePos( Handle, osl_Pos_Current, -1 );
- if ( LF == *pchLastInBuff )
- {
- *(pchLastInBuff - 1) = '\0';
- rtl_byte_sequence_constructFromArray( ppSeq, (sal_Int8*)pchBuff, (sal_Int32)(nReadTotal - 1) );
- rtl_freeMemory( pchBuff );
- return osl_File_E_None;
+ if ( ferr != osl_File_E_None )
+ {
+ rtl_freeMemory( pchBuff );
+ return ferr;
+ }
+ }
}
- else /* any other character */
- {
- /* correct the file pointer */
- ferr = osl_setFilePos( Handle, osl_Pos_Current, -1 );
-
- if ( ferr != osl_File_E_None )
- {
- rtl_freeMemory( pchBuff );
- return ferr;
- }
- *(pchLastInBuff - 1) = '\0';
- rtl_byte_sequence_constructFromArray( ppSeq, (sal_Int8*)pchBuff, (sal_Int32)(nReadTotal - 1) );
- rtl_freeMemory( pchBuff );
- return osl_File_E_None;
- }
+ rtl_byte_sequence_constructFromArray( ppSeq, (sal_Int8*)pchBuff, (sal_Int32)(nReadTotal - 1));
+ rtl_freeMemory( pchBuff );
+ return osl_File_E_None;
}
-
+
/* buffer handling */
- if ( nReadTotal == (sizeBuff - 1) )
+ if ( nReadTotal == sizeBuff )
{
sal_Char *pchTmp = (sal_Char*)rtl_reallocateMemory(
pchBuff, sizeBuff * ENLARGEMENT_FACTOR );