~svn/ubuntu/raring/subversion/ppa

« back to all changes in this revision

Viewing changes to subversion/libsvn_subr/stream.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:26:14 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205012614-qom4xfypgtsqc2xq
Tags: 1.2.3dfsg1-3ubuntu1
Merge with the final Debian release of 1.2.3dfsg1-3, bringing in
fixes to the clean target, better documentation of the libdb4.3
upgrade and build fixes to work with swig1.3_1.3.27.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * stream.c:   svn_stream operations
 
3
 *
 
4
 * ====================================================================
 
5
 * Copyright (c) 2000-2004 CollabNet.  All rights reserved.
 
6
 *
 
7
 * This software is licensed as described in the file COPYING, which
 
8
 * you should have received as part of this distribution.  The terms
 
9
 * are also available at http://subversion.tigris.org/license-1.html.
 
10
 * If newer versions of this license are posted there, you may use a
 
11
 * newer version instead, at your option.
 
12
 *
 
13
 * This software consists of voluntary contributions made by many
 
14
 * individuals.  For exact contribution history, see the revision
 
15
 * history and logs, available at http://subversion.tigris.org/.
 
16
 * ====================================================================
 
17
 */
 
18
 
 
19
#include "svn_private_config.h"
 
20
 
 
21
#include <assert.h>
 
22
#include <stdio.h>
 
23
 
 
24
#include <apr.h>
 
25
#include <apr_pools.h>
 
26
#include <apr_strings.h>
 
27
#include <apr_file_io.h>
 
28
#include <apr_errno.h>
 
29
 
 
30
#ifdef SVN_HAVE_ZLIB
 
31
#include <zlib.h>
 
32
#endif
 
33
 
 
34
#include "svn_pools.h"
 
35
#include "svn_io.h"
 
36
#include "svn_error.h"
 
37
#include "svn_string.h"
 
38
 
 
39
 
 
40
struct svn_stream_t {
 
41
  void *baton;
 
42
  svn_read_fn_t read_fn;
 
43
  svn_write_fn_t write_fn;
 
44
  svn_close_fn_t close_fn;
 
45
};
 
46
 
 
47
 
 
48
 
 
49
/*** Generic streams. ***/
 
50
 
 
51
svn_stream_t *
 
52
svn_stream_create (void *baton, apr_pool_t *pool)
 
53
{
 
54
  svn_stream_t *stream;
 
55
 
 
56
  stream = apr_palloc (pool, sizeof (*stream));
 
57
  stream->baton = baton;
 
58
  stream->read_fn = NULL;
 
59
  stream->write_fn = NULL;
 
60
  stream->close_fn = NULL;
 
61
  return stream;
 
62
}
 
63
 
 
64
 
 
65
void
 
66
svn_stream_set_baton (svn_stream_t *stream, void *baton)
 
67
{
 
68
  stream->baton = baton;
 
69
}
 
70
 
 
71
 
 
72
void
 
73
svn_stream_set_read (svn_stream_t *stream, svn_read_fn_t read_fn)
 
74
{
 
75
  stream->read_fn = read_fn;
 
76
}
 
77
 
 
78
 
 
79
void
 
80
svn_stream_set_write (svn_stream_t *stream, svn_write_fn_t write_fn)
 
81
{
 
82
  stream->write_fn = write_fn;
 
83
}
 
84
 
 
85
 
 
86
void
 
87
svn_stream_set_close (svn_stream_t *stream, svn_close_fn_t close_fn)
 
88
{
 
89
  stream->close_fn = close_fn;
 
90
}
 
91
 
 
92
 
 
93
svn_error_t *
 
94
svn_stream_read (svn_stream_t *stream, char *buffer, apr_size_t *len)
 
95
{
 
96
  assert (stream->read_fn != NULL);
 
97
  return stream->read_fn (stream->baton, buffer, len);
 
98
}
 
99
 
 
100
 
 
101
svn_error_t *
 
102
svn_stream_write (svn_stream_t *stream, const char *data, apr_size_t *len)
 
103
{
 
104
  assert (stream->write_fn != NULL);
 
105
  return stream->write_fn (stream->baton, data, len);
 
106
}
 
107
 
 
108
 
 
109
svn_error_t *
 
110
svn_stream_close (svn_stream_t *stream)
 
111
{
 
112
  if (stream->close_fn == NULL)
 
113
    return SVN_NO_ERROR;
 
114
  return stream->close_fn (stream->baton);
 
115
}
 
116
 
 
117
 
 
118
svn_error_t *
 
119
svn_stream_printf (svn_stream_t *stream,
 
120
                   apr_pool_t *pool,
 
121
                   const char *fmt,
 
122
                   ...)
 
123
{
 
124
  const char *message;
 
125
  va_list ap;
 
126
  apr_size_t len;
 
127
 
 
128
  va_start (ap, fmt);
 
129
  message = apr_pvsprintf (pool, fmt, ap);
 
130
  va_end (ap);
 
131
  
 
132
  len = strlen(message);
 
133
  return svn_stream_write (stream, message, &len);
 
134
}
 
135
 
 
136
 
 
137
svn_error_t *
 
138
svn_stream_readline (svn_stream_t *stream,
 
139
                     svn_stringbuf_t **stringbuf,
 
140
                     const char *eol,
 
141
                     svn_boolean_t *eof,
 
142
                     apr_pool_t *pool)
 
143
{
 
144
  apr_size_t numbytes;
 
145
  const char *match;
 
146
  char c;
 
147
  svn_stringbuf_t *str = svn_stringbuf_create ("", pool);
 
148
 
 
149
  /* Since we're reading one character at a time, let's at least
 
150
     optimize for the 90% case.  90% of the time, we can avoid the
 
151
     stringbuf ever having to realloc() itself if we start it out at
 
152
     80 chars.  */
 
153
  svn_stringbuf_ensure (str, 80);
 
154
 
 
155
  match = eol;
 
156
  while (*match)
 
157
    {
 
158
      numbytes = 1;
 
159
      SVN_ERR (svn_stream_read (stream, &c, &numbytes));
 
160
      if (numbytes != 1)
 
161
        {
 
162
          /* a 'short' read means the stream has run out. */
 
163
          *eof = TRUE;
 
164
          *stringbuf = str;
 
165
          return SVN_NO_ERROR;
 
166
        }
 
167
 
 
168
      if (c == *match)
 
169
        match++;
 
170
      else
 
171
        match = eol;
 
172
 
 
173
      svn_stringbuf_appendbytes (str, &c, 1);
 
174
    }
 
175
 
 
176
  *eof = FALSE;
 
177
  svn_stringbuf_chop (str, match - eol);
 
178
  *stringbuf = str;
 
179
  return SVN_NO_ERROR;
 
180
}
 
181
 
 
182
 
 
183
svn_error_t *svn_stream_copy (svn_stream_t *from, svn_stream_t *to,
 
184
                              apr_pool_t *pool)
 
185
{
 
186
  char *buf = apr_palloc (pool, SVN_STREAM_CHUNK_SIZE);
 
187
  apr_size_t len;
 
188
 
 
189
  /* Read and write chunks until we get a short read, indicating the
 
190
     end of the stream.  (We can't get a short write without an
 
191
     associated error.) */
 
192
  while (1)
 
193
    {
 
194
      len = SVN_STREAM_CHUNK_SIZE;
 
195
      SVN_ERR (svn_stream_read (from, buf, &len));
 
196
      if (len > 0)
 
197
        SVN_ERR (svn_stream_write (to, buf, &len));
 
198
      if (len != SVN_STREAM_CHUNK_SIZE)
 
199
        break;
 
200
    }
 
201
  return SVN_NO_ERROR;
 
202
}
 
203
 
 
204
 
 
205
 
 
206
 
 
207
/*** Generic readable empty stream ***/
 
208
 
 
209
static svn_error_t *
 
210
read_handler_empty (void *baton, char *buffer, apr_size_t *len)
 
211
{
 
212
  *len = 0;
 
213
  return SVN_NO_ERROR;
 
214
}
 
215
 
 
216
 
 
217
static svn_error_t *
 
218
write_handler_empty (void *baton, const char *data, apr_size_t *len)
 
219
{
 
220
  return SVN_NO_ERROR;
 
221
}
 
222
 
 
223
 
 
224
svn_stream_t *
 
225
svn_stream_empty (apr_pool_t *pool)
 
226
{
 
227
  svn_stream_t *stream;
 
228
 
 
229
  stream = svn_stream_create (NULL, pool);
 
230
  svn_stream_set_read (stream, read_handler_empty);
 
231
  svn_stream_set_write (stream, write_handler_empty);
 
232
  return stream;
 
233
}
 
234
 
 
235
 
 
236
 
 
237
/*** Generic stream for APR files ***/
 
238
struct baton_apr {
 
239
  apr_file_t *file;
 
240
  apr_pool_t *pool;
 
241
};
 
242
 
 
243
 
 
244
static svn_error_t *
 
245
read_handler_apr (void *baton, char *buffer, apr_size_t *len)
 
246
{
 
247
  struct baton_apr *btn = baton;
 
248
  svn_error_t *err;
 
249
 
 
250
  err = svn_io_file_read_full (btn->file, buffer, *len, len, btn->pool);
 
251
  if (err && APR_STATUS_IS_EOF(err->apr_err))
 
252
    {
 
253
      svn_error_clear (err);
 
254
      err = SVN_NO_ERROR;
 
255
    }
 
256
 
 
257
  return err;
 
258
}
 
259
 
 
260
 
 
261
static svn_error_t *
 
262
write_handler_apr (void *baton, const char *data, apr_size_t *len)
 
263
{
 
264
  struct baton_apr *btn = baton;
 
265
 
 
266
  return svn_io_file_write_full (btn->file, data, *len, len, btn->pool);
 
267
}
 
268
 
 
269
 
 
270
svn_stream_t *
 
271
svn_stream_from_aprfile (apr_file_t *file, apr_pool_t *pool)
 
272
{
 
273
  struct baton_apr *baton;
 
274
  svn_stream_t *stream;
 
275
 
 
276
  if (file == NULL)
 
277
    return svn_stream_empty(pool);
 
278
  baton = apr_palloc (pool, sizeof (*baton));
 
279
  baton->file = file;
 
280
  baton->pool = pool;
 
281
  stream = svn_stream_create (baton, pool);
 
282
  svn_stream_set_read (stream, read_handler_apr);
 
283
  svn_stream_set_write (stream, write_handler_apr);
 
284
  return stream;
 
285
}
 
286
 
 
287
 
 
288
/* Compressed stream support */
 
289
 
 
290
#ifdef SVN_HAVE_ZLIB
 
291
 
 
292
#define ZBUFFER_SIZE 4096       /* The size of the buffer the
 
293
                                   compressed stream uses to read from
 
294
                                   the substream. Basically an
 
295
                                   arbitrary value, picked to be about
 
296
                                   page-sized. */
 
297
 
 
298
struct zbaton {
 
299
  z_stream *in;                 /* compressed stream for reading */
 
300
  z_stream *out;                /* compressed stream for writing */
 
301
  svn_read_fn_t read;           /* substream's read function */
 
302
  svn_write_fn_t write;         /* substream's write function */
 
303
  svn_close_fn_t close;         /* substream's close function */
 
304
  void *read_buffer;            /* buffer   used   for  reading   from
 
305
                                   substream */
 
306
  int read_flush;               /* what flush mode to use while
 
307
                                   reading */
 
308
  apr_pool_t *pool;             /* The pool this baton is allocated
 
309
                                   on */
 
310
  void *subbaton;               /* The substream's baton */
 
311
};
 
312
 
 
313
/* zlib alloc function. opaque is the pool we need. */
 
314
static voidpf
 
315
zalloc(voidpf opaque, uInt items, uInt size)
 
316
{
 
317
  apr_pool_t *pool = opaque;
 
318
  
 
319
  return apr_palloc(pool, items * size);
 
320
}
 
321
 
 
322
/* zlib free function */
 
323
static void
 
324
zfree(voidpf opaque, voidpf address)
 
325
{
 
326
  /* Empty, since we allocate on the pool */
 
327
}
 
328
 
 
329
/* Converts a zlib error to an svn_error_t. zerr is the error code,
 
330
   function is the function name, and stream is the z_stream we are
 
331
   using.  */
 
332
static svn_error_t *
 
333
zerr_to_svn_error (int zerr, const char *function, z_stream *stream)
 
334
{
 
335
  apr_status_t status;
 
336
  const char *message;
 
337
 
 
338
  if (zerr == Z_OK)
 
339
    return SVN_NO_ERROR;
 
340
  
 
341
  switch (zerr)
 
342
    {
 
343
    case Z_STREAM_ERROR:
 
344
      status = SVN_ERR_STREAM_MALFORMED_DATA;
 
345
      message = "stream error";
 
346
      break;
 
347
      
 
348
    case Z_MEM_ERROR:
 
349
      status = APR_ENOMEM;
 
350
      message = "out of memory";
 
351
      break;
 
352
      
 
353
    case Z_BUF_ERROR:
 
354
      status = APR_ENOMEM;
 
355
      message = "buffer error";
 
356
      break;
 
357
      
 
358
    case Z_VERSION_ERROR:
 
359
      status = SVN_ERR_STREAM_UNRECOGNIZED_DATA;
 
360
      message = "version error";
 
361
      break;
 
362
      
 
363
    case Z_DATA_ERROR:
 
364
      status = SVN_ERR_STREAM_MALFORMED_DATA;
 
365
      message = "corrupted data";
 
366
      break;
 
367
      
 
368
    default:
 
369
      status = SVN_ERR_STREAM_UNRECOGNIZED_DATA;
 
370
      message = "error";
 
371
      break;
 
372
    }
 
373
  
 
374
  if (stream->msg != NULL)
 
375
    return svn_error_createf (status, NULL, "zlib (%s): %s: %s", function,
 
376
                              message, stream->msg);
 
377
  else
 
378
    return svn_error_createf (status, NULL, "zlib (%s): %s", function, 
 
379
                              message);
 
380
}
 
381
 
 
382
/* Helper function to figure out the sync mode */
 
383
static svn_error_t *
 
384
read_helper_gz (svn_read_fn_t read_fn,
 
385
                void *baton,
 
386
                char *buffer, 
 
387
                uInt *len, int *zflush)
 
388
{
 
389
  uInt orig_len = *len;
 
390
 
 
391
  /* There's no reason this value should grow bigger than the range of
 
392
     uInt, but Subversion's API requires apr_size_t. */
 
393
  apr_size_t apr_len = (apr_size_t) *len;
 
394
  
 
395
  SVN_ERR ((*read_fn) (baton, buffer, &apr_len));
 
396
  
 
397
  /* Type cast back to uInt type that zlib uses.  On LP64 platforms
 
398
     apr_size_t will be bigger than uInt. */
 
399
  *len = (uInt) apr_len;
 
400
  
 
401
  /* I wanted to use Z_FINISH here, but we need to know our buffer is
 
402
     big enough */
 
403
  *zflush = (*len) < orig_len ? Z_SYNC_FLUSH : Z_SYNC_FLUSH; 
 
404
  
 
405
  return SVN_NO_ERROR;
 
406
}
 
407
 
 
408
/* Handle reading from a compressed stream */
 
409
static svn_error_t *
 
410
read_handler_gz (void *baton, char *buffer, apr_size_t *len)
 
411
{
 
412
  struct zbaton *btn = baton;
 
413
  int zerr;
 
414
 
 
415
  if (btn->in == NULL)
 
416
    {
 
417
      btn->in = apr_palloc (btn->pool, sizeof (z_stream));
 
418
      btn->in->zalloc = zalloc;
 
419
      btn->in->zfree = zfree;
 
420
      btn->in->opaque = btn->pool;
 
421
      btn->read_buffer = apr_palloc(btn->pool, ZBUFFER_SIZE);
 
422
      btn->in->next_in = btn->read_buffer;
 
423
      btn->in->avail_in = ZBUFFER_SIZE;
 
424
      
 
425
      SVN_ERR (read_helper_gz (btn->read, btn->subbaton, btn->read_buffer,
 
426
                               &btn->in->avail_in, &btn->read_flush));
 
427
                               
 
428
      zerr = inflateInit (btn->in);
 
429
      SVN_ERR (zerr_to_svn_error (zerr, "inflateInit", btn->in));
 
430
    }
 
431
  
 
432
  btn->in->next_out = (Bytef *) buffer;
 
433
  btn->in->avail_out = *len;
 
434
  
 
435
  while (btn->in->avail_out > 0) 
 
436
    {
 
437
      if (btn->in->avail_in <= 0)
 
438
        {
 
439
          btn->in->avail_in = ZBUFFER_SIZE;
 
440
          btn->in->next_in = btn->read_buffer;
 
441
          SVN_ERR (read_helper_gz (btn->read, btn->subbaton, btn->read_buffer, 
 
442
                                   &btn->in->avail_in, &btn->read_flush));
 
443
        }
 
444
      
 
445
      zerr = inflate (btn->in, btn->read_flush);
 
446
      if (zerr == Z_STREAM_END)
 
447
        break;
 
448
      else if (zerr != Z_OK)
 
449
        return zerr_to_svn_error(zerr, "inflate", btn->in);
 
450
    }
 
451
 
 
452
  *len -= btn->in->avail_out;
 
453
  return SVN_NO_ERROR;
 
454
}
 
455
 
 
456
/* Compress data and write it to the substream */
 
457
static svn_error_t *
 
458
write_handler_gz (void *baton, const char *buffer, apr_size_t *len)
 
459
{
 
460
  struct zbaton *btn = baton;
 
461
  apr_pool_t *subpool;
 
462
  void *write_buf;
 
463
  apr_size_t buf_size, write_len;
 
464
  int zerr;
 
465
 
 
466
  if (btn->out == NULL)
 
467
    {
 
468
      btn->out = apr_palloc (btn->pool, sizeof (z_stream));
 
469
      btn->out->zalloc = zalloc;
 
470
      btn->out->zfree = zfree;
 
471
      btn->out->opaque =  btn->pool;
 
472
      
 
473
      zerr = deflateInit (btn->out, Z_DEFAULT_COMPRESSION);
 
474
      SVN_ERR (zerr_to_svn_error (zerr, "deflateInit", btn->out));
 
475
    }
 
476
  
 
477
  /* The largest buffer we should need is 0.1% larger than the
 
478
     compressed data, + 12 bytes. This info comes from zlib.h.  */
 
479
  buf_size = *len + (*len / 1000) + 13;
 
480
  subpool = svn_pool_create (btn->pool);
 
481
  write_buf = apr_palloc (subpool, buf_size);
 
482
  
 
483
  btn->out->next_in = (Bytef *) buffer;  /* Casting away const! */
 
484
  btn->out->avail_in = *len;
 
485
  
 
486
  while (btn->out->avail_in > 0)
 
487
    {
 
488
      btn->out->next_out = write_buf;
 
489
      btn->out->avail_out = buf_size;
 
490
      
 
491
      zerr = deflate (btn->out, Z_NO_FLUSH);
 
492
      SVN_ERR (zerr_to_svn_error (zerr, "deflate", btn->out));
 
493
      write_len = buf_size - btn->out->avail_out;
 
494
      if (write_len > 0)
 
495
        SVN_ERR (btn->write (btn->subbaton, write_buf, &write_len));
 
496
    }
 
497
      
 
498
  svn_pool_destroy (subpool);
 
499
 
 
500
  return SVN_NO_ERROR;
 
501
}
 
502
 
 
503
/* Handle flushing and closing the stream */
 
504
static svn_error_t *
 
505
close_handler_gz (void *baton)
 
506
{
 
507
  struct zbaton *btn = baton;
 
508
  int zerr;
 
509
  
 
510
  if (btn->in != NULL)
 
511
    {
 
512
      zerr = inflateEnd(btn->in);
 
513
      SVN_ERR (zerr_to_svn_error (zerr, "inflateEnd", btn->in));
 
514
    }
 
515
 
 
516
  if (btn->out != NULL)
 
517
    {
 
518
      void *buf;
 
519
      apr_size_t write_len;
 
520
      
 
521
      buf = apr_palloc (btn->pool, ZBUFFER_SIZE);
 
522
      
 
523
      while (TRUE)
 
524
        {
 
525
          btn->out->next_out = buf;
 
526
          btn->out->avail_out = ZBUFFER_SIZE;
 
527
          
 
528
          zerr = deflate (btn->out, Z_FINISH);
 
529
          if (zerr != Z_STREAM_END && zerr != Z_OK)
 
530
            return zerr_to_svn_error (zerr, "deflate", btn->out);
 
531
          write_len = ZBUFFER_SIZE - btn->out->avail_out;
 
532
          if (write_len > 0)
 
533
            SVN_ERR (btn->write (btn->subbaton, buf, &write_len));
 
534
          if (zerr == Z_STREAM_END)
 
535
            break;
 
536
        }
 
537
      
 
538
      zerr = deflateEnd(btn->out);
 
539
      SVN_ERR (zerr_to_svn_error (zerr, "deflateEnd", btn->out));
 
540
    }
 
541
 
 
542
  if (btn->close != NULL)
 
543
    return btn->close (btn->subbaton);
 
544
  else
 
545
    return SVN_NO_ERROR;
 
546
}
 
547
 
 
548
#endif /* SVN_HAVE_ZLIB */
 
549
 
 
550
svn_stream_t *
 
551
svn_stream_compressed (svn_stream_t *stream, apr_pool_t *pool)
 
552
{
 
553
#ifdef SVN_HAVE_ZLIB
 
554
 
 
555
  struct svn_stream_t *zstream;
 
556
  struct zbaton *baton;
 
557
 
 
558
  assert(stream != NULL);
 
559
  
 
560
  baton = apr_palloc (pool, sizeof (*baton));
 
561
  baton->in = baton->out = NULL;
 
562
  baton->read = stream->read_fn;
 
563
  baton->write = stream->write_fn;
 
564
  baton->close = stream->close_fn;
 
565
  baton->subbaton = stream->baton;
 
566
  baton->pool = pool;
 
567
  baton->read_buffer = NULL;
 
568
  baton->read_flush = Z_SYNC_FLUSH;
 
569
  
 
570
  zstream = svn_stream_create(baton, pool);
 
571
  svn_stream_set_read(zstream, read_handler_gz);
 
572
  svn_stream_set_write(zstream, write_handler_gz);
 
573
  svn_stream_set_close(zstream, close_handler_gz);
 
574
  
 
575
  return zstream;
 
576
 
 
577
#else
 
578
  
 
579
  return stream;
 
580
 
 
581
#endif /* SVN_HAVE_ZLIB */
 
582
}
 
583
 
 
584
 
 
585
/* Miscellaneous stream functions. */
 
586
struct string_stream_baton
 
587
{
 
588
  svn_stringbuf_t *str;
 
589
  apr_size_t amt_read;
 
590
};
 
591
 
 
592
static svn_error_t *
 
593
read_handler_string (void *baton, char *buffer, apr_size_t *len)
 
594
{
 
595
  struct string_stream_baton *btn = baton;
 
596
  apr_size_t left_to_read = btn->str->len - btn->amt_read;
 
597
 
 
598
  *len = (*len > left_to_read) ? left_to_read : *len;
 
599
  memcpy (buffer, btn->str->data + btn->amt_read, *len);
 
600
  btn->amt_read += *len;
 
601
  return SVN_NO_ERROR;
 
602
}
 
603
 
 
604
static svn_error_t *
 
605
write_handler_string (void *baton, const char *data, apr_size_t *len)
 
606
{
 
607
  struct string_stream_baton *btn = baton;
 
608
 
 
609
  svn_stringbuf_appendbytes (btn->str, data, *len);
 
610
  return SVN_NO_ERROR;
 
611
}
 
612
 
 
613
svn_stream_t *
 
614
svn_stream_from_stringbuf (svn_stringbuf_t *str,
 
615
                           apr_pool_t *pool)
 
616
{
 
617
  svn_stream_t *stream;
 
618
  struct string_stream_baton *baton;
 
619
 
 
620
  if (! str)
 
621
    return svn_stream_empty (pool);
 
622
 
 
623
  baton = apr_palloc (pool, sizeof (*baton));
 
624
  baton->str = str;
 
625
  baton->amt_read = 0;
 
626
  stream = svn_stream_create (baton, pool);
 
627
  svn_stream_set_read (stream, read_handler_string);
 
628
  svn_stream_set_write (stream, write_handler_string);
 
629
  return stream;
 
630
}
 
631
 
 
632
 
 
633
svn_error_t *
 
634
svn_stream_for_stdout (svn_stream_t **out, apr_pool_t *pool)
 
635
{
 
636
  apr_file_t *stdout_file;
 
637
  apr_status_t apr_err;
 
638
 
 
639
  apr_err = apr_file_open_stdout (&stdout_file, pool);
 
640
  if (apr_err)
 
641
    return svn_error_wrap_apr (apr_err, "Can't open stdout");
 
642
 
 
643
  *out = svn_stream_from_aprfile (stdout_file, pool);
 
644
 
 
645
  return SVN_NO_ERROR;
 
646
}