mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-28 07:58:08 +01:00
add stringFromStreamHere()
This commit is contained in:
parent
20f96a658d
commit
2f8320cba8
2 changed files with 21 additions and 3 deletions
|
@ -98,16 +98,33 @@ signedFromStream( XWStreamCtxt* stream, XP_U16 nBits )
|
||||||
XP_UCHAR*
|
XP_UCHAR*
|
||||||
stringFromStream( MPFORMAL XWStreamCtxt* stream )
|
stringFromStream( MPFORMAL XWStreamCtxt* stream )
|
||||||
{
|
{
|
||||||
|
XP_UCHAR buf[0xFF];
|
||||||
XP_UCHAR* str = (XP_UCHAR*)NULL;
|
XP_UCHAR* str = (XP_UCHAR*)NULL;
|
||||||
XP_U16 len = stream_getU8( stream );
|
XP_U16 len = stringFromStreamHere( stream, buf, sizeof(buf) );
|
||||||
|
|
||||||
if ( len > 0 ) {
|
if ( len > 0 ) {
|
||||||
str = (XP_UCHAR*)XP_MALLOC( mpool, len + 1 );
|
str = (XP_UCHAR*)XP_MALLOC( mpool, len + 1 );
|
||||||
stream_getBytes( stream, str, len );
|
XP_MEMCPY( str, buf, len + 1 );
|
||||||
str[len] = '\0';
|
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
} /* makeStringFromStream */
|
} /* makeStringFromStream */
|
||||||
|
|
||||||
|
XP_U16
|
||||||
|
stringFromStreamHere( XWStreamCtxt* stream, XP_UCHAR* buf, XP_U16 buflen )
|
||||||
|
{
|
||||||
|
XP_U16 len = stream_getU8( stream );
|
||||||
|
if ( len > 0 ) {
|
||||||
|
XP_ASSERT( len < buflen );
|
||||||
|
if ( len >= buflen ) {
|
||||||
|
/* better to leave stream in bad state than overwrite stack */
|
||||||
|
len = buflen - 1;
|
||||||
|
}
|
||||||
|
stream_getBytes( stream, buf, len );
|
||||||
|
buf[len] = '\0';
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
stringToStream( XWStreamCtxt* stream, XP_UCHAR* str )
|
stringToStream( XWStreamCtxt* stream, XP_UCHAR* str )
|
||||||
{
|
{
|
||||||
|
|
|
@ -38,6 +38,7 @@ XP_S32 signedFromStream( XWStreamCtxt* stream, XP_U16 nBits );
|
||||||
void signedToStream( XWStreamCtxt* stream, XP_U16 nBits, XP_S32 num );
|
void signedToStream( XWStreamCtxt* stream, XP_U16 nBits, XP_S32 num );
|
||||||
|
|
||||||
XP_UCHAR* stringFromStream( MPFORMAL XWStreamCtxt* stream );
|
XP_UCHAR* stringFromStream( MPFORMAL XWStreamCtxt* stream );
|
||||||
|
XP_U16 stringFromStreamHere( XWStreamCtxt* stream, XP_UCHAR* buf, XP_U16 len );
|
||||||
void stringToStream( XWStreamCtxt* stream, XP_UCHAR* str );
|
void stringToStream( XWStreamCtxt* stream, XP_UCHAR* str );
|
||||||
|
|
||||||
XP_UCHAR* copyString( MPFORMAL XP_UCHAR* instr );
|
XP_UCHAR* copyString( MPFORMAL XP_UCHAR* instr );
|
||||||
|
|
Loading…
Add table
Reference in a new issue