Re: [PHP-DEV] Re: Need help with streams

2004-06-14 Thread Stephan Schmidt
Hi, 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. Works like a charm, thanks.

Re: [PHP-DEV] Re: Need help with streams

2004-06-14 Thread Sara Golemon
> 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),

Re: [PHP-DEV] Re: Need help with streams

2004-06-14 Thread Stephan Schmidt
Hi, /* Not binary safe, but depending on your data that may be okay */ if (Z_STRLEN_PP(data) > 30) { php_stream_write(stream, Z_STRVAL_PP(data), 30); } else { php_stream_printf(stream TSRMLS_CC, "%-30s", Z_STRVAL_PP(data)); } Both solutions will pad the string with ' ', but I need to pad it wit

Re: [PHP-DEV] Re: Need help with streams

2004-06-14 Thread Sara Golemon
> I'm currently using: > > php_stream_write(stream, Z_STRVAL_P(*data), 30); > > As the string is terminated with a zero-byte, it already works, but it > would be better to fill the unused space with zero-bytes. > Actually, that'll also open the door to a potential segfault since you may overrun the

Re: [PHP-DEV] Re: Need help with streams

2004-06-14 Thread Stephan Schmidt
Hi, That's because you're telling it to write one character from the position POINTED TO by the integer value. (i.e. Treat the integer like a pointer) You're lucky you're getting data at all and not a segfault. Try: php_stream_putc(stream, (char)(Z_LVAL_P(*data) & 0xFF)); You are a livesaver! Th