On Thu, Nov 14, 2002 at 01:10:55PM -0600, cmpilato@tigris.org wrote:
>...
> +++ trunk/subversion/include/svn_io.h Thu Nov 14 13:10:43 2002
> @@ -334,6 +334,11 @@
>
> svn_stream_t *svn_stream_from_stdio (FILE *fp, apr_pool_t *pool);
>
> +/* Return a generic readable stream from a hunk of DATA and its
> + length, LEN. Allocate the stream in POOL. */
> +svn_stream_t *svn_stream_from_string (const char *data,
> + apr_size_t len,
> + apr_pool_t *pool);
You should probably doc that 'data' needs to live as long as the stream
does -- a copy is not made.
Cheers,
-g
> +++ trunk/subversion/libsvn_subr/io.c Thu Nov 14 13:10:43 2002
> @@ -1007,6 +1007,47 @@
>
>
>
> +/* Miscellaneous stream functions. */
> +struct string_stream_baton
> +{
> + const char *data;
> + apr_size_t len;
> + apr_size_t amt_read;
> +};
You could replace the sizes with 'const char *end;' and change:
> +static svn_error_t *
> +read_handler_string (void *baton, char *buffer, apr_size_t *len)
> +{
> + struct string_stream_baton *btn = baton;
> + apr_size_t left_to_read = btn->len - btn->amt_read;
> + *len = (*len > left_to_read) ? left_to_read : *len;
> + memcpy (buffer, btn->data + btn->amt_read, *len);
> + btn->amt_read += *len;
> + return SVN_NO_ERROR;
> +}
{
struct string_stream_baton *btn = baton;
const char *last = btn->data + *len;
if (last > btn->end)
last = btn->end;
*len = last - btn->data;
memcpy (buffer, btn->data, *len);
btn->data = last;
return SVN_NO_ERROR;
}
and:
> +
> +svn_stream_t *
> +svn_stream_from_string (const char *data,
> + apr_size_t len,
> + apr_pool_t *pool)
> +{
> + svn_stream_t *stream;
> + struct string_stream_baton *baton;
> +
> + if (! (data && len))
> + return svn_stream_empty (pool);
> +
> + baton = apr_palloc (pool, sizeof (*baton));
> + baton->data = data;
> + baton->len = len;
> + baton->amt_read = 0;
baton->end = data + len;
Using an end pointer feels a bit simpler than a length and a remaining
amount to read. Not a lot simpler, but some...
Cheers,
-g
--
Greg Stein, http://www.lyra.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Fri Nov 15 01:47:54 2002