Re: Re: Need help with streams
| From: | Sara Golemon | Date: | Mon, 14 Jun 2004 19:18:11 +0000 |
| Subject: | Re: Re: Need help with streams | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-10454@lists.php.net to get a copy of this message | ||
> Both solutions will pad the string with ' ', but I need to pad it with
'\0'.
>
Ah, misunderstood you, try this one:
if (Z_STRLEN_PP(data) > 30) {
php_stream_write(stream, Z_STRVAL_PP(data), 30);
} else {
char blanks[30];
memset(blanks, 0, 30);
php_stream_write(stream, Z_STRVAL_PP(data), Z_STRLEN_PP(data));
php_stream_write(stream, blanks, 30 - Z_STRLEN_PP(data));
}
iirc there may be a printf means to specify NULL as the padding character,
or to repeat an aribtrary character for a certain number of characters, but
it's escaping me at the moment. For the size of your padding this method
should introduce to horrible of a penalty.
-Sara