]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/subversion/subversion/include/svn_io.h
MFC r275385 (by bapt):
[FreeBSD/stable/10.git] / contrib / subversion / subversion / include / svn_io.h
1 /**
2  * @copyright
3  * ====================================================================
4  *    Licensed to the Apache Software Foundation (ASF) under one
5  *    or more contributor license agreements.  See the NOTICE file
6  *    distributed with this work for additional information
7  *    regarding copyright ownership.  The ASF licenses this file
8  *    to you under the Apache License, Version 2.0 (the
9  *    "License"); you may not use this file except in compliance
10  *    with the License.  You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *    Unless required by applicable law or agreed to in writing,
15  *    software distributed under the License is distributed on an
16  *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  *    KIND, either express or implied.  See the License for the
18  *    specific language governing permissions and limitations
19  *    under the License.
20  * ====================================================================
21  * @endcopyright
22  *
23  * @file svn_io.h
24  * @brief General file I/O for Subversion
25  */
26
27 /* ==================================================================== */
28
29
30 #ifndef SVN_IO_H
31 #define SVN_IO_H
32
33 #include <apr.h>
34 #include <apr_pools.h>
35 #include <apr_time.h>
36 #include <apr_hash.h>
37 #include <apr_tables.h>
38 #include <apr_file_io.h>
39 #include <apr_file_info.h>
40 #include <apr_thread_proc.h>  /* for apr_proc_t, apr_exit_why_e */
41
42 #include "svn_types.h"
43 #include "svn_string.h"
44 #include "svn_checksum.h"
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif /* __cplusplus */
49
50
51 \f
52 /** Used as an argument when creating temporary files to indicate
53  * when a file should be removed.
54  *
55  * @since New in 1.4.
56  *
57  * Not specifying any of these means no removal at all. */
58 typedef enum svn_io_file_del_t
59 {
60   /** No deletion ever */
61   svn_io_file_del_none = 0,
62   /** Remove when the file is closed */
63   svn_io_file_del_on_close,
64   /** Remove when the associated pool is cleared */
65   svn_io_file_del_on_pool_cleanup
66 } svn_io_file_del_t;
67
68 /** A set of directory entry data elements as returned by svn_io_get_dirents
69  *
70  * Note that the first two fields are exactly identical to svn_io_dirent_t
71  * to allow returning a svn_io_dirent2_t as a svn_io_dirent_t.
72  *
73  * Use svn_io_dirent2_create() to create new svn_dirent2_t instances or
74  * svn_io_dirent2_dup() to duplicate an existing instance.
75  *
76  * @since New in 1.7.
77  */
78 typedef struct svn_io_dirent2_t {
79   /* New fields must be added at the end to preserve binary compatibility */
80
81   /** The kind of this entry. */
82   svn_node_kind_t kind;
83
84   /** If @c kind is #svn_node_file, whether this entry is a special file;
85    * else FALSE.
86    *
87    * @see svn_io_check_special_path().
88    */
89   svn_boolean_t special;
90
91   /** The filesize of this entry or undefined for a directory */
92   svn_filesize_t filesize;
93
94   /** The time the file was last modified */
95   apr_time_t mtime;
96
97   /* Don't forget to update svn_io_dirent2_dup() when adding new fields */
98 } svn_io_dirent2_t;
99
100
101 /** Creates a new #svn_io_dirent2_t structure
102  *
103  * @since New in 1.7.
104  */
105 svn_io_dirent2_t *
106 svn_io_dirent2_create(apr_pool_t *result_pool);
107
108 /** Duplicates a @c svn_io_dirent2_t structure into @a result_pool.
109  *
110  * @since New in 1.7.
111  */
112 svn_io_dirent2_t *
113 svn_io_dirent2_dup(const svn_io_dirent2_t *item,
114                    apr_pool_t *result_pool);
115
116 /** Represents the kind and special status of a directory entry.
117  *
118  * Note that the first two fields are exactly identical to svn_io_dirent2_t
119  * to allow returning a svn_io_dirent2_t as a svn_io_dirent_t.
120  *
121  * @since New in 1.3.
122  */
123 typedef struct svn_io_dirent_t {
124   /** The kind of this entry. */
125   svn_node_kind_t kind;
126   /** If @c kind is #svn_node_file, whether this entry is a special file;
127    * else FALSE.
128    *
129    * @see svn_io_check_special_path().
130    */
131   svn_boolean_t special;
132 } svn_io_dirent_t;
133
134 /** Determine the @a kind of @a path.  @a path should be UTF-8 encoded.
135  *
136  * If @a path is a file, set @a *kind to #svn_node_file.
137  *
138  * If @a path is a directory, set @a *kind to #svn_node_dir.
139  *
140  * If @a path does not exist, set @a *kind to #svn_node_none.
141  *
142  * If @a path exists but is none of the above, set @a *kind to
143  * #svn_node_unknown.
144  *
145  * If @a path is not a valid pathname, set @a *kind to #svn_node_none.  If
146  * unable to determine @a path's kind for any other reason, return an error,
147  * with @a *kind's value undefined.
148  *
149  * Use @a pool for temporary allocations.
150  *
151  * @see svn_node_kind_t
152  */
153 svn_error_t *
154 svn_io_check_path(const char *path,
155                   svn_node_kind_t *kind,
156                   apr_pool_t *pool);
157
158 /**
159  * Like svn_io_check_path(), but also set *is_special to @c TRUE if
160  * the path is not a normal file.
161  *
162  * @since New in 1.1.
163  */
164 svn_error_t *
165 svn_io_check_special_path(const char *path,
166                           svn_node_kind_t *kind,
167                           svn_boolean_t *is_special,
168                           apr_pool_t *pool);
169
170 /** Like svn_io_check_path(), but resolve symlinks.  This returns the
171     same varieties of @a kind as svn_io_check_path(). */
172 svn_error_t *
173 svn_io_check_resolved_path(const char *path,
174                            svn_node_kind_t *kind,
175                            apr_pool_t *pool);
176
177
178 /** Open a new file (for reading and writing) with a unique name based on
179  * utf-8 encoded @a filename, in the directory @a dirpath.  The file handle is
180  * returned in @a *file, and the name, which ends with @a suffix, is returned
181  * in @a *unique_name, also utf8-encoded.  Either @a file or @a unique_name
182  * may be @c NULL.  If @a file is @c NULL, the file will be created but not
183  * open.
184  *
185  * The file will be deleted according to @a delete_when.  If that is
186  * #svn_io_file_del_on_pool_cleanup, it refers to @a result_pool.
187  *
188  * The @c APR_BUFFERED flag will always be used when opening the file.
189  *
190  * The first attempt will just append @a suffix.  If the result is not
191  * a unique name, then subsequent attempts will append a dot,
192  * followed by an iteration number ("2", then "3", and so on),
193  * followed by the suffix.  For example, successive calls to
194  *
195  *    svn_io_open_uniquely_named(&f, &u, "tests/t1/A/D/G", "pi", ".tmp", ...)
196  *
197  * will open
198  *
199  *    tests/t1/A/D/G/pi.tmp
200  *    tests/t1/A/D/G/pi.2.tmp
201  *    tests/t1/A/D/G/pi.3.tmp
202  *    tests/t1/A/D/G/pi.4.tmp
203  *    tests/t1/A/D/G/pi.5.tmp
204  *    ...
205  *
206  * Assuming @a suffix is non-empty, @a *unique_name will never be exactly
207  * the same as @a filename, even if @a filename does not exist.
208  *
209  * If @a dirpath is NULL, then the directory returned by svn_io_temp_dir()
210  * will be used.
211  *
212  * If @a filename is NULL, then "tempfile" will be used.
213  *
214  * If @a suffix is NULL, then ".tmp" will be used.
215  *
216  * Allocates @a *file and @a *unique_name in @a result_pool. All
217  * intermediate allocations will be performed in @a scratch_pool.
218  *
219  * If no unique name can be found, #SVN_ERR_IO_UNIQUE_NAMES_EXHAUSTED is
220  * the error returned.
221  *
222  * Claim of Historical Inevitability: this function was written
223  * because
224  *
225  *    - tmpnam() is not thread-safe.
226  *    - tempname() tries standard system tmp areas first.
227  *
228  * @since New in 1.6
229  */
230 svn_error_t *
231 svn_io_open_uniquely_named(apr_file_t **file,
232                            const char **unique_name,
233                            const char *dirpath,
234                            const char *filename,
235                            const char *suffix,
236                            svn_io_file_del_t delete_when,
237                            apr_pool_t *result_pool,
238                            apr_pool_t *scratch_pool);
239
240
241 /** Create a writable file, with an arbitrary and unique name, in the
242  * directory @a dirpath.  Set @a *temp_path to its full path, and set
243  * @a *file to the file handle, both allocated from @a result_pool.  Either
244  * @a file or @a temp_path may be @c NULL.  If @a file is @c NULL, the file
245  * will be created but not open.
246  *
247  * If @a dirpath is @c NULL, use the path returned from svn_io_temp_dir().
248  * (Note that when using the system-provided temp directory, it may not
249  * be possible to atomically rename the resulting file due to cross-device
250  * issues.)
251  *
252  * The file will be deleted according to @a delete_when.  If that is
253  * #svn_io_file_del_on_pool_cleanup, it refers to @a result_pool.  If it
254  * is #svn_io_file_del_on_close and @a file is @c NULL, the file will be
255  * deleted before this function returns.
256  *
257  * When passing @c svn_io_file_del_none please don't forget to eventually
258  * remove the temporary file to avoid filling up the system temp directory.
259  * It is often appropriate to bind the lifetime of the temporary file to
260  * the lifetime of a pool by using @c svn_io_file_del_on_pool_cleanup.
261  *
262  * Temporary allocations will be performed in @a scratch_pool.
263  *
264  * @since New in 1.6
265  * @see svn_stream_open_unique()
266  */
267 svn_error_t *
268 svn_io_open_unique_file3(apr_file_t **file,
269                          const char **temp_path,
270                          const char *dirpath,
271                          svn_io_file_del_t delete_when,
272                          apr_pool_t *result_pool,
273                          apr_pool_t *scratch_pool);
274
275
276 /** Like svn_io_open_uniquely_named(), but takes a joined dirpath and
277  * filename, and a single pool.
278  *
279  * @since New in 1.4
280  *
281  * @deprecated Provided for backward compatibility with the 1.5 API
282  */
283 SVN_DEPRECATED
284 svn_error_t *
285 svn_io_open_unique_file2(apr_file_t **f,
286                          const char **unique_name_p,
287                          const char *path,
288                          const char *suffix,
289                          svn_io_file_del_t delete_when,
290                          apr_pool_t *pool);
291
292 /** Like svn_io_open_unique_file2, but can't delete on pool cleanup.
293  *
294  * @deprecated Provided for backward compatibility with the 1.3 API
295  *
296  * @note In 1.4 the API was extended to require either @a f or
297  *       @a unique_name_p (the other can be NULL).  Before that, both were
298  *       required.
299  */
300 SVN_DEPRECATED
301 svn_error_t *
302 svn_io_open_unique_file(apr_file_t **f,
303                         const char **unique_name_p,
304                         const char *path,
305                         const char *suffix,
306                         svn_boolean_t delete_on_close,
307                         apr_pool_t *pool);
308
309
310 /**
311  * Like svn_io_open_unique_file(), except that instead of creating a
312  * file, a symlink is generated that references the path @a dest.
313  *
314  * @since New in 1.1.
315  */
316 svn_error_t *
317 svn_io_create_unique_link(const char **unique_name_p,
318                           const char *path,
319                           const char *dest,
320                           const char *suffix,
321                           apr_pool_t *pool);
322
323
324 /**
325  * Set @a *dest to the path that the symlink at @a path references.
326  * Allocate the string from @a pool.
327  *
328  * @since New in 1.1.
329  */
330 svn_error_t *
331 svn_io_read_link(svn_string_t **dest,
332                  const char *path,
333                  apr_pool_t *pool);
334
335
336 /** Set @a *dir to a directory path (allocated in @a pool) deemed
337  * usable for the creation of temporary files and subdirectories.
338  */
339 svn_error_t *
340 svn_io_temp_dir(const char **dir,
341                 apr_pool_t *pool);
342
343
344 /** Copy @a src to @a dst atomically, in a "byte-for-byte" manner.
345  * Overwrite @a dst if it exists, else create it.  Both @a src and @a dst
346  * are utf8-encoded filenames.  If @a copy_perms is TRUE, set @a dst's
347  * permissions to match those of @a src.
348  */
349 svn_error_t *
350 svn_io_copy_file(const char *src,
351                  const char *dst,
352                  svn_boolean_t copy_perms,
353                  apr_pool_t *pool);
354
355
356 /** Copy permission flags from @a src onto the file at @a dst. Both
357  * filenames are utf8-encoded filenames.
358  *
359  * @since New in 1.6.
360  */
361 svn_error_t *
362 svn_io_copy_perms(const char *src,
363                   const char *dst,
364                   apr_pool_t *pool);
365
366
367 /**
368  * Copy symbolic link @a src to @a dst atomically.  Overwrite @a dst
369  * if it exists, else create it.  Both @a src and @a dst are
370  * utf8-encoded filenames.  After copying, the @a dst link will point
371  * to the same thing @a src does.
372  *
373  * @since New in 1.1.
374  */
375 svn_error_t *
376 svn_io_copy_link(const char *src,
377                  const char *dst,
378                  apr_pool_t *pool);
379
380
381 /** Recursively copy directory @a src into @a dst_parent, as a new entry named
382  * @a dst_basename.  If @a dst_basename already exists in @a dst_parent,
383  * return error.  @a copy_perms will be passed through to svn_io_copy_file()
384  * when any files are copied.  @a src, @a dst_parent, and @a dst_basename are
385  * all utf8-encoded.
386  *
387  * If @a cancel_func is non-NULL, invoke it with @a cancel_baton at
388  * various points during the operation.  If it returns any error
389  * (typically #SVN_ERR_CANCELLED), return that error immediately.
390  */
391 svn_error_t *
392 svn_io_copy_dir_recursively(const char *src,
393                             const char *dst_parent,
394                             const char *dst_basename,
395                             svn_boolean_t copy_perms,
396                             svn_cancel_func_t cancel_func,
397                             void *cancel_baton,
398                             apr_pool_t *pool);
399
400
401 /** Create directory @a path on the file system, creating intermediate
402  * directories as required, like <tt>mkdir -p</tt>.  Report no error if @a
403  * path already exists.  @a path is utf8-encoded.
404  *
405  * This is essentially a wrapper for apr_dir_make_recursive(), passing
406  * @c APR_OS_DEFAULT as the permissions.
407  */
408 svn_error_t *
409 svn_io_make_dir_recursively(const char *path,
410                             apr_pool_t *pool);
411
412
413 /** Set @a *is_empty_p to @c TRUE if directory @a path is empty, else to
414  * @c FALSE if it is not empty.  @a path must be a directory, and is
415  * utf8-encoded.  Use @a pool for temporary allocation.
416  */
417 svn_error_t *
418 svn_io_dir_empty(svn_boolean_t *is_empty_p,
419                  const char *path,
420                  apr_pool_t *pool);
421
422
423 /** Append @a src to @a dst.  @a dst will be appended to if it exists, else it
424  * will be created.  Both @a src and @a dst are utf8-encoded.
425  */
426 svn_error_t *
427 svn_io_append_file(const char *src,
428                    const char *dst,
429                    apr_pool_t *pool);
430
431
432 /** Make a file as read-only as the operating system allows.
433  * @a path is the utf8-encoded path to the file. If @a ignore_enoent is
434  * @c TRUE, don't fail if the target file doesn't exist.
435  *
436  * If @a path is a symlink, do nothing.
437  *
438  * @note If @a path is a directory, act on it as though it were a
439  * file, as described above, but note that you probably don't want to
440  * call this function on directories.  We have left it effective on
441  * directories for compatibility reasons, but as its name implies, it
442  * should be used only for files.
443  */
444 svn_error_t *
445 svn_io_set_file_read_only(const char *path,
446                           svn_boolean_t ignore_enoent,
447                           apr_pool_t *pool);
448
449
450 /** Make a file as writable as the operating system allows.
451  * @a path is the utf8-encoded path to the file.  If @a ignore_enoent is
452  * @c TRUE, don't fail if the target file doesn't exist.
453  * @warning On Unix this function will do the equivalent of chmod a+w path.
454  * If this is not what you want you should not use this function, but rather
455  * use apr_file_perms_set().
456  *
457  * If @a path is a symlink, do nothing.
458  *
459  * @note If @a path is a directory, act on it as though it were a
460  * file, as described above, but note that you probably don't want to
461  * call this function on directories.  We have left it effective on
462  * directories for compatibility reasons, but as its name implies, it
463  * should be used only for files.
464  */
465 svn_error_t *
466 svn_io_set_file_read_write(const char *path,
467                            svn_boolean_t ignore_enoent,
468                            apr_pool_t *pool);
469
470
471 /** Similar to svn_io_set_file_read_* functions.
472  * Change the read-write permissions of a file.
473  * @since New in 1.1.
474  *
475  * When making @a path read-write on operating systems with unix style
476  * permissions, set the permissions on @a path to the permissions that
477  * are set when a new file is created (effectively honoring the user's
478  * umask).
479  *
480  * When making the file read-only on operating systems with unix style
481  * permissions, remove all write permissions.
482  *
483  * On other operating systems, toggle the file's "writability" as much as
484  * the operating system allows.
485  *
486  * @a path is the utf8-encoded path to the file.  If @a enable_write
487  * is @c TRUE, then make the file read-write.  If @c FALSE, make it
488  * read-only.  If @a ignore_enoent is @c TRUE, don't fail if the target
489  * file doesn't exist.
490  *
491  * @deprecated Provided for backward compatibility with the 1.3 API.
492  */
493 SVN_DEPRECATED
494 svn_error_t *
495 svn_io_set_file_read_write_carefully(const char *path,
496                                      svn_boolean_t enable_write,
497                                      svn_boolean_t ignore_enoent,
498                                      apr_pool_t *pool);
499
500 /** Set @a path's "executability" (but do nothing if it is a symlink).
501  *
502  * @a path is the utf8-encoded path to the file.  If @a executable
503  * is @c TRUE, then make the file executable.  If @c FALSE, make it
504  * non-executable.  If @a ignore_enoent is @c TRUE, don't fail if the target
505  * file doesn't exist.
506  *
507  * When making the file executable on operating systems with unix style
508  * permissions, never add an execute permission where there is not
509  * already a read permission: that is, only make the file executable
510  * for the user, group or world if the corresponding read permission
511  * is already set for user, group or world.
512  *
513  * When making the file non-executable on operating systems with unix style
514  * permissions, remove all execute permissions.
515  *
516  * On other operating systems, toggle the file's "executability" as much as
517  * the operating system allows.
518  *
519  * @note If @a path is a directory, act on it as though it were a
520  * file, as described above, but note that you probably don't want to
521  * call this function on directories.  We have left it effective on
522  * directories for compatibility reasons, but as its name implies, it
523  * should be used only for files.
524  */
525 svn_error_t *
526 svn_io_set_file_executable(const char *path,
527                            svn_boolean_t executable,
528                            svn_boolean_t ignore_enoent,
529                            apr_pool_t *pool);
530
531 /** Determine whether a file is executable by the current user.
532  * Set @a *executable to @c TRUE if the file @a path is executable by the
533  * current user, otherwise set it to @c FALSE.
534  *
535  * On Windows and on platforms without userids, always returns @c FALSE.
536  */
537 svn_error_t *
538 svn_io_is_file_executable(svn_boolean_t *executable,
539                           const char *path,
540                           apr_pool_t *pool);
541
542
543 /** Read a line from @a file into @a buf, but not exceeding @a *limit bytes.
544  * Does not include newline, instead '\\0' is put there.
545  * Length (as in strlen) is returned in @a *limit.
546  * @a buf should be pre-allocated.
547  * @a file should be already opened.
548  *
549  * When the file is out of lines, @c APR_EOF will be returned.
550  */
551 svn_error_t *
552 svn_io_read_length_line(apr_file_t *file,
553                         char *buf,
554                         apr_size_t *limit,
555                         apr_pool_t *pool);
556
557
558 /** Set @a *apr_time to the time of last modification of the contents of the
559  * file @a path.  @a path is utf8-encoded.
560  *
561  * @note This is the APR mtime which corresponds to the traditional mtime
562  * on Unix, and the last write time on Windows.
563  */
564 svn_error_t *
565 svn_io_file_affected_time(apr_time_t *apr_time,
566                           const char *path,
567                           apr_pool_t *pool);
568
569 /** Set the timestamp of file @a path to @a apr_time.  @a path is
570  *  utf8-encoded.
571  *
572  * @note This is the APR mtime which corresponds to the traditional mtime
573  * on Unix, and the last write time on Windows.
574  */
575 svn_error_t *
576 svn_io_set_file_affected_time(apr_time_t apr_time,
577                               const char *path,
578                               apr_pool_t *pool);
579
580 /** Sleep to ensure that any files modified after we exit have a different
581  * timestamp than the one we recorded. If @a path is not NULL, check if we
582  * can determine how long we should wait for a new timestamp on the filesystem
583  * containing @a path, an existing file or directory. If @a path is NULL or we
584  * can't determine the timestamp resolution, sleep until the next second.
585  *
586  * Use @a pool for any necessary allocations. @a pool can be null if @a path
587  * is NULL.
588  *
589  * Errors while retrieving the timestamp resolution will result in sleeping
590  * to the next second, to keep the working copy stable in error conditions.
591  *
592  * @since New in 1.6.
593  */
594 void
595 svn_io_sleep_for_timestamps(const char *path, apr_pool_t *pool);
596
597 /** Set @a *different_p to TRUE if @a file1 and @a file2 have different
598  * sizes, else set to FALSE.  Both @a file1 and @a file2 are utf8-encoded.
599  *
600  * Setting @a *different_p to zero does not mean the files definitely
601  * have the same size, it merely means that the sizes are not
602  * definitely different.  That is, if the size of one or both files
603  * cannot be determined, then the sizes are not known to be different,
604  * so @a *different_p is set to FALSE.
605  */
606 svn_error_t *
607 svn_io_filesizes_different_p(svn_boolean_t *different_p,
608                              const char *file1,
609                              const char *file2,
610                              apr_pool_t *pool);
611
612 /** Set @a *different_p12 to non-zero if @a file1 and @a file2 have different
613  * sizes, else set to zero.  Do the similar for @a *different_p23 with
614  * @a file2 and @a file3, and @a *different_p13 for @a file1 and @a file3.
615  * The filenames @a file1, @a file2 and @a file3 are utf8-encoded.
616  *
617  * Setting @a *different_p12 to zero does not mean the files definitely
618  * have the same size, it merely means that the sizes are not
619  * definitely different.  That is, if the size of one or both files
620  * cannot be determined (due to stat() returning an error), then the sizes
621  * are not known to be different, so @a *different_p12 is set to 0.
622  *
623  * @since New in 1.8.
624  */
625 svn_error_t *
626 svn_io_filesizes_three_different_p(svn_boolean_t *different_p12,
627                                    svn_boolean_t *different_p23,
628                                    svn_boolean_t *different_p13,
629                                    const char *file1,
630                                    const char *file2,
631                                    const char *file3,
632                                    apr_pool_t *scratch_pool);
633
634 /** Return in @a *checksum the checksum of type @a kind of @a file
635  * Use @a pool for temporary allocations and to allocate @a *checksum.
636  *
637  * @since New in 1.6.
638  */
639 svn_error_t *
640 svn_io_file_checksum2(svn_checksum_t **checksum,
641                       const char *file,
642                       svn_checksum_kind_t kind,
643                       apr_pool_t *pool);
644
645
646 /** Put the md5 checksum of @a file into @a digest.
647  * @a digest points to @c APR_MD5_DIGESTSIZE bytes of storage.
648  * Use @a pool only for temporary allocations.
649  *
650  * @deprecated Provided for backward compatibility with the 1.5 API.
651  */
652 SVN_DEPRECATED
653 svn_error_t *
654 svn_io_file_checksum(unsigned char digest[],
655                      const char *file,
656                      apr_pool_t *pool);
657
658
659 /** Set @a *same to TRUE if @a file1 and @a file2 have the same
660  * contents, else set it to FALSE.  Use @a pool for temporary allocations.
661  */
662 svn_error_t *
663 svn_io_files_contents_same_p(svn_boolean_t *same,
664                              const char *file1,
665                              const char *file2,
666                              apr_pool_t *pool);
667
668 /** Set @a *same12 to TRUE if @a file1 and @a file2 have the same
669  * contents, else set it to FALSE.  Do the similar for @a *same23
670  * with @a file2 and @a file3, and @a *same13 for @a file1 and @a
671  * file3. The filenames @a file1, @a file2 and @a file3 are
672  * utf8-encoded. Use @a scratch_pool for temporary allocations.
673  *
674  * @since New in 1.8.
675  */
676 svn_error_t *
677 svn_io_files_contents_three_same_p(svn_boolean_t *same12,
678                                    svn_boolean_t *same23,
679                                    svn_boolean_t *same13,
680                                    const char *file1,
681                                    const char *file2,
682                                    const char *file3,
683                                    apr_pool_t *scratch_pool);
684
685 /** Create a file at utf8-encoded path @a file with the contents given
686  * by the null-terminated string @a contents.
687  *
688  * @a file must not already exist. If an error occurs while writing or
689  * closing the file, attempt to delete the file before returning the error.
690  *
691  * Write the data in 'binary' mode (#APR_FOPEN_BINARY). If @a contents
692  * is @c NULL, create an empty file.
693  *
694  * Use @a pool for memory allocations.
695  */
696 svn_error_t *
697 svn_io_file_create(const char *file,
698                    const char *contents,
699                    apr_pool_t *pool);
700
701 /** Create a file at utf8-encoded path @a file with the contents given
702  * by @a contents of @a length bytes.
703  *
704  * @a file must not already exist. If an error occurs while writing or
705  * closing the file, attempt to delete the file before returning the error.
706  *
707  * Write the data in 'binary' mode (#APR_FOPEN_BINARY). If @a length is
708  * zero, create an empty file; in this case @a contents may be @c NULL.
709  *
710  * Use @a scratch_pool for temporary allocations.
711  *
712  * @since New in 1.9.
713  */
714 svn_error_t *
715 svn_io_file_create_bytes(const char *file,
716                          const void *contents,
717                          apr_size_t length,
718                          apr_pool_t *scratch_pool);
719
720 /** Create an empty file at utf8-encoded path @a file.
721  *
722  * @a file must not already exist. If an error occurs while
723  * closing the file, attempt to delete the file before returning the error.
724  *
725  * Use @a scratch_pool for temporary allocations.
726  *
727  * @since New in 1.9.
728  */
729 svn_error_t *
730 svn_io_file_create_empty(const char *file,
731                          apr_pool_t *scratch_pool);
732
733 /**
734  * Lock file at @a lock_file. If @a exclusive is TRUE,
735  * obtain exclusive lock, otherwise obtain shared lock.
736  * Lock will be automatically released when @a pool is cleared or destroyed.
737  * Use @a pool for memory allocations.
738  *
739  * @deprecated Provided for backward compatibility with the 1.0 API.
740  */
741 SVN_DEPRECATED
742 svn_error_t *
743 svn_io_file_lock(const char *lock_file,
744                  svn_boolean_t exclusive,
745                  apr_pool_t *pool);
746
747 /**
748  * Lock file at @a lock_file. If @a exclusive is TRUE,
749  * obtain exclusive lock, otherwise obtain shared lock.
750  *
751  * If @a nonblocking is TRUE, do not wait for the lock if it
752  * is not available: throw an error instead.
753  *
754  * Lock will be automatically released when @a pool is cleared or destroyed.
755  * Use @a pool for memory allocations.
756  *
757  * @since New in 1.1.
758  */
759 svn_error_t *
760 svn_io_file_lock2(const char *lock_file,
761                   svn_boolean_t exclusive,
762                   svn_boolean_t nonblocking,
763                   apr_pool_t *pool);
764
765 /**
766  * Lock the file @a lockfile_handle. If @a exclusive is TRUE,
767  * obtain exclusive lock, otherwise obtain shared lock.
768  *
769  * If @a nonblocking is TRUE, do not wait for the lock if it
770  * is not available: throw an error instead.
771  *
772  * Lock will be automatically released when @a pool is cleared or destroyed.
773  * You may also explicitly call svn_io_unlock_open_file().
774  * Use @a pool for memory allocations. @a pool must be the pool that
775  * @a lockfile_handle has been created in or one of its sub-pools.
776  *
777  * @since New in 1.8.
778  */
779 svn_error_t *
780 svn_io_lock_open_file(apr_file_t *lockfile_handle,
781                       svn_boolean_t exclusive,
782                       svn_boolean_t nonblocking,
783                       apr_pool_t *pool);
784
785 /**
786  * Unlock the file @a lockfile_handle.
787  *
788  * Use @a pool for memory allocations. @a pool must be the pool that
789  * was passed to svn_io_lock_open_file().
790  *
791  * @since New in 1.8.
792  */
793 svn_error_t *
794 svn_io_unlock_open_file(apr_file_t *lockfile_handle,
795                         apr_pool_t *pool);
796
797 /**
798  * Flush any unwritten data from @a file to disk.  Use @a pool for
799  * memory allocations.
800  *
801  * @note This function uses advanced file control operations to flush buffers
802  * to disk that aren't always accessible and can be very expensive on systems
803  * that implement flushing on all IO layers, like Windows. Please avoid using
804  * this function in cases where the file should just work on any network
805  * filesystem. In many cases a normal svn_io_file_flush() will work just fine.
806  *
807  * @since New in 1.1.
808  */
809 svn_error_t *
810 svn_io_file_flush_to_disk(apr_file_t *file,
811                           apr_pool_t *pool);
812
813 /** Copy the file whose basename (or relative path) is @a file within
814  * directory @a src_path to the same basename (or relative path) within
815  * directory @a dest_path.  Overwrite the destination file if it already
816  * exists.  The destination directory (including any directory
817  * components in @a name) must already exist.  Set the destination
818  * file's permissions to match those of the source.  Use @a pool for
819  * memory allocations.
820  */
821 svn_error_t *
822 svn_io_dir_file_copy(const char *src_path,
823                      const char *dest_path,
824                      const char *file,
825                      apr_pool_t *pool);
826
827 \f
828 /** Generic byte-streams
829  *
830  * @defgroup svn_io_byte_streams Generic byte streams
831  * @{
832  */
833
834 /** An abstract stream of bytes--either incoming or outgoing or both.
835  *
836  * The creator of a stream sets functions to handle read and write.
837  * Both of these handlers accept a baton whose value is determined at
838  * stream creation time; this baton can point to a structure
839  * containing data associated with the stream.  If a caller attempts
840  * to invoke a handler which has not been set, it will generate a
841  * runtime assertion failure.  The creator can also set a handler for
842  * close requests so that it can flush buffered data or whatever;
843  * if a close handler is not specified, a close request on the stream
844  * will simply be ignored.  Note that svn_stream_close() does not
845  * deallocate the memory used to allocate the stream structure; free
846  * the pool you created the stream in to free that memory.
847  *
848  * The read and write handlers accept length arguments via pointer.
849  * On entry to the handler, the pointed-to value should be the amount
850  * of data which can be read or the amount of data to write.  When the
851  * handler returns, the value is reset to the amount of data actually
852  * read or written.  The write and full read handler are obliged to
853  * complete a read or write to the maximum extent possible; thus, a
854  * short read with no associated error implies the end of the input
855  * stream, and a short write should never occur without an associated
856  * error. In Subversion 1.9 the stream api was extended to also support
857  * limited reads via the new svn_stream_read2() api.
858  *
859  * In Subversion 1.7 mark, seek and reset support was added as an optional
860  * feature of streams. If a stream implements resetting it allows reading
861  * the data again after a successful call to svn_stream_reset().
862  */
863 typedef struct svn_stream_t svn_stream_t;
864
865
866
867 /** Read handler function for a generic stream.  @see svn_stream_t. */
868 typedef svn_error_t *(*svn_read_fn_t)(void *baton,
869                                       char *buffer,
870                                       apr_size_t *len);
871
872 /** Skip data handler function for a generic stream.  @see svn_stream_t
873  * and svn_stream_skip().
874  * @since New in 1.7.
875  */
876 typedef svn_error_t *(*svn_stream_skip_fn_t)(void *baton,
877                                              apr_size_t len);
878
879 /** Write handler function for a generic stream.  @see svn_stream_t. */
880 typedef svn_error_t *(*svn_write_fn_t)(void *baton,
881                                        const char *data,
882                                        apr_size_t *len);
883
884 /** Close handler function for a generic stream.  @see svn_stream_t. */
885 typedef svn_error_t *(*svn_close_fn_t)(void *baton);
886
887 /** An opaque type which represents a mark on a stream.  There is no
888  * concrete definition of this type, it is a named type for stream
889  * implementation specific baton pointers.
890  *
891  * @see svn_stream_mark().
892  * @since New in 1.7.
893  */
894 typedef struct svn_stream_mark_t svn_stream_mark_t;
895
896 /** Mark handler function for a generic stream. @see svn_stream_t and
897  * svn_stream_mark().
898  *
899  * @since New in 1.7.
900  */
901 typedef svn_error_t *(*svn_stream_mark_fn_t)(void *baton,
902                                          svn_stream_mark_t **mark,
903                                          apr_pool_t *pool);
904
905 /** Seek handler function for a generic stream. @see svn_stream_t and
906  * svn_stream_seek().
907  *
908  * @since New in 1.7.
909  */
910 typedef svn_error_t *(*svn_stream_seek_fn_t)(void *baton,
911                                              const svn_stream_mark_t *mark);
912
913 /** Poll handler for generic streams that support incomplete reads, @see
914  * svn_stream_t and svn_stream_data_available().
915  *
916  * @since New in 1.9.
917  */
918 typedef svn_error_t *(*svn_stream_data_available_fn_t)(void *baton,
919                                               svn_boolean_t *data_available);
920
921 /** Create a generic stream.  @see svn_stream_t. */
922 svn_stream_t *
923 svn_stream_create(void *baton,
924                   apr_pool_t *pool);
925
926 /** Set @a stream's baton to @a baton */
927 void
928 svn_stream_set_baton(svn_stream_t *stream,
929                      void *baton);
930
931 /** Set @a stream's read functions to @a read_fn and @a read_full_fn. If
932  * @a read_full_fn is NULL a default implementation based on multiple calls
933  * to @a read_fn will be used.
934  *
935  * @since New in 1.9.
936  */
937 void
938 svn_stream_set_read2(svn_stream_t *stream,
939                      svn_read_fn_t read_fn,
940                      svn_read_fn_t read_full_fn);
941
942 /** Set @a stream's read function to @a read_fn.
943  *
944  * This function sets only the full read function to read_fn.
945  *
946  * @deprecated Provided for backward compatibility with the 1.8 API.
947  */
948 SVN_DEPRECATED
949 void
950 svn_stream_set_read(svn_stream_t *stream,
951                     svn_read_fn_t read_fn);
952
953 /** Set @a stream's skip function to @a skip_fn
954  *
955  * @since New in 1.7
956  */
957 void
958 svn_stream_set_skip(svn_stream_t *stream,
959                     svn_stream_skip_fn_t skip_fn);
960
961 /** Set @a stream's write function to @a write_fn */
962 void
963 svn_stream_set_write(svn_stream_t *stream,
964                      svn_write_fn_t write_fn);
965
966 /** Set @a stream's close function to @a close_fn */
967 void
968 svn_stream_set_close(svn_stream_t *stream,
969                      svn_close_fn_t close_fn);
970
971 /** Set @a stream's mark function to @a mark_fn
972  *
973  * @since New in 1.7.
974  */
975 void
976 svn_stream_set_mark(svn_stream_t *stream,
977                     svn_stream_mark_fn_t mark_fn);
978
979 /** Set @a stream's seek function to @a seek_fn
980  *
981  * @since New in 1.7.
982  */
983 void
984 svn_stream_set_seek(svn_stream_t *stream,
985                     svn_stream_seek_fn_t seek_fn);
986
987 /** Set @a stream's data available function to @a data_available_fn
988  *
989  * @since New in 1.9.
990  */
991 void
992 svn_stream_set_data_available(svn_stream_t *stream,
993                               svn_stream_data_available_fn_t data_available);
994
995 /** Create a stream that is empty for reading and infinite for writing. */
996 svn_stream_t *
997 svn_stream_empty(apr_pool_t *pool);
998
999 /** Return a stream allocated in @a pool which forwards all requests
1000  * to @a stream.  Destruction is explicitly excluded from forwarding.
1001  *
1002  * @see http://subversion.apache.org/docs/community-guide/conventions.html#destruction-of-stacked-resources
1003  *
1004  * @since New in 1.4.
1005  */
1006 svn_stream_t *
1007 svn_stream_disown(svn_stream_t *stream,
1008                   apr_pool_t *pool);
1009
1010
1011 /** Create a stream to read the file at @a path. It will be opened using
1012  * the APR_BUFFERED and APR_BINARY flag, and APR_OS_DEFAULT for the perms.
1013  * If you'd like to use different values, then open the file yourself, and
1014  * use the svn_stream_from_aprfile2() interface.
1015  *
1016  * The stream will be returned in @a stream, and allocated from @a result_pool.
1017  * Temporary allocations will be performed in @a scratch_pool.
1018  *
1019  * @since New in 1.6
1020  */
1021 svn_error_t *
1022 svn_stream_open_readonly(svn_stream_t **stream,
1023                          const char *path,
1024                          apr_pool_t *result_pool,
1025                          apr_pool_t *scratch_pool);
1026
1027
1028 /** Create a stream to write a file at @a path. The file will be *created*
1029  * using the APR_BUFFERED and APR_BINARY flag, and APR_OS_DEFAULT for the
1030  * perms. The file will be created "exclusively", so if it already exists,
1031  * then an error will be thrown. If you'd like to use different values, or
1032  * open an existing file, then open the file yourself, and use the
1033  * svn_stream_from_aprfile2() interface.
1034  *
1035  * The stream will be returned in @a stream, and allocated from @a result_pool.
1036  * Temporary allocations will be performed in @a scratch_pool.
1037  *
1038  * @since New in 1.6
1039  */
1040 svn_error_t *
1041 svn_stream_open_writable(svn_stream_t **stream,
1042                          const char *path,
1043                          apr_pool_t *result_pool,
1044                          apr_pool_t *scratch_pool);
1045
1046
1047 /** Create a writable stream to a file in the directory @a dirpath.
1048  * The file will have an arbitrary and unique name, and the full path
1049  * will be returned in @a temp_path. The stream will be returned in
1050  * @a stream. Both will be allocated from @a result_pool.
1051  *
1052  * If @a dirpath is @c NULL, use the path returned from svn_io_temp_dir().
1053  * (Note that when using the system-provided temp directory, it may not
1054  * be possible to atomically rename the resulting file due to cross-device
1055  * issues.)
1056  *
1057  * The file will be deleted according to @a delete_when.  If that is
1058  * #svn_io_file_del_on_pool_cleanup, it refers to @a result_pool.
1059  *
1060  * Temporary allocations will be performed in @a scratch_pool.
1061  *
1062  * @since New in 1.6
1063  * @see svn_io_open_unique_file3()
1064  */
1065 svn_error_t *
1066 svn_stream_open_unique(svn_stream_t **stream,
1067                        const char **temp_path,
1068                        const char *dirpath,
1069                        svn_io_file_del_t delete_when,
1070                        apr_pool_t *result_pool,
1071                        apr_pool_t *scratch_pool);
1072
1073
1074 /** Create a stream from an APR file.  For convenience, if @a file is
1075  * @c NULL, an empty stream created by svn_stream_empty() is returned.
1076  *
1077  * This function should normally be called with @a disown set to FALSE,
1078  * in which case closing the stream will also close the underlying file.
1079  *
1080  * If @a disown is TRUE, the stream will disown the underlying file,
1081  * meaning that svn_stream_close() will not close the file.
1082  *
1083  * @since New in 1.4.
1084  */
1085 svn_stream_t *
1086 svn_stream_from_aprfile2(apr_file_t *file,
1087                          svn_boolean_t disown,
1088                          apr_pool_t *pool);
1089
1090 /** Similar to svn_stream_from_aprfile2(), except that the file will
1091  * always be disowned.
1092  *
1093  * @note The stream returned is not considered to "own" the underlying
1094  *       file, meaning that svn_stream_close() on the stream will not
1095  *       close the file.
1096  *
1097  * @deprecated Provided for backward compatibility with the 1.3 API.
1098  */
1099 SVN_DEPRECATED
1100 svn_stream_t *
1101 svn_stream_from_aprfile(apr_file_t *file,
1102                         apr_pool_t *pool);
1103
1104 /** Set @a *in to a generic stream connected to stdin, allocated in
1105  * @a pool.  The stream and its underlying APR handle will be closed
1106  * when @a pool is cleared or destroyed.
1107  *
1108  * @since New in 1.7.
1109  */
1110 svn_error_t *
1111 svn_stream_for_stdin(svn_stream_t **in,
1112                      apr_pool_t *pool);
1113
1114 /** Set @a *err to a generic stream connected to stderr, allocated in
1115  * @a pool.  The stream and its underlying APR handle will be closed
1116  * when @a pool is cleared or destroyed.
1117  *
1118  * @since New in 1.7.
1119  */
1120 svn_error_t *
1121 svn_stream_for_stderr(svn_stream_t **err,
1122                       apr_pool_t *pool);
1123
1124 /** Set @a *out to a generic stream connected to stdout, allocated in
1125  * @a pool.  The stream and its underlying APR handle will be closed
1126  * when @a pool is cleared or destroyed.
1127  */
1128 svn_error_t *
1129 svn_stream_for_stdout(svn_stream_t **out,
1130                       apr_pool_t *pool);
1131
1132 /** Set @a *str to a string buffer allocated in @a result_pool that contains
1133  * all data from the current position in @a stream to its end.  @a len_hint
1134  * specifies the initial capacity of the string buffer and may be 0.  The
1135  * buffer gets automatically resized to fit the actual amount of data being
1136  * read from @a stream.
1137  *
1138  * @since New in 1.9.
1139  */
1140 svn_error_t *
1141 svn_stringbuf_from_stream(svn_stringbuf_t **str,
1142                           svn_stream_t *stream,
1143                           apr_size_t len_hint,
1144                           apr_pool_t *result_pool);
1145
1146 /** Return a generic stream connected to stringbuf @a str.  Allocate the
1147  * stream in @a pool.
1148  */
1149 svn_stream_t *
1150 svn_stream_from_stringbuf(svn_stringbuf_t *str,
1151                           apr_pool_t *pool);
1152
1153 /** Return a generic read-only stream connected to string @a str.
1154  *  Allocate the stream in @a pool.
1155  */
1156 svn_stream_t *
1157 svn_stream_from_string(const svn_string_t *str,
1158                        apr_pool_t *pool);
1159
1160 /** Return a generic stream which implements buffered reads and writes.
1161  *  The stream will preferentially store data in-memory, but may use
1162  *  disk storage as backup if the amount of data is large.
1163  *  Allocate the stream in @a result_pool
1164  *
1165  * @since New in 1.8.
1166  */
1167 svn_stream_t *
1168 svn_stream_buffered(apr_pool_t *result_pool);
1169
1170 /** Return a stream that decompresses all data read and compresses all
1171  * data written. The stream @a stream is used to read and write all
1172  * compressed data. All compression data structures are allocated on
1173  * @a pool. If compression support is not compiled in then
1174  * svn_stream_compressed() returns @a stream unmodified. Make sure you
1175  * call svn_stream_close() on the stream returned by this function,
1176  * so that all data are flushed and cleaned up.
1177  *
1178  * @note From 1.4, compression support is always compiled in.
1179  */
1180 svn_stream_t *
1181 svn_stream_compressed(svn_stream_t *stream,
1182                       apr_pool_t *pool);
1183
1184 /** Return a stream that calculates checksums for all data read
1185  * and written.  The stream @a stream is used to read and write all data.
1186  * The stream and the resulting digests are allocated in @a pool.
1187  *
1188  * When the stream is closed, @a *read_checksum and @a *write_checksum
1189  * are set to point to the resulting checksums, of type @a read_checksum_kind
1190  * and @a write_checksum_kind, respectively.
1191  *
1192  * Both @a read_checksum and @a write_checksum can be @c NULL, in which case
1193  * the respective checksum isn't calculated.
1194  *
1195  * If @a read_all is TRUE, make sure that all data available on @a
1196  * stream is read (and checksummed) when the stream is closed.
1197  *
1198  * Read and write operations can be mixed without interfering.
1199  *
1200  * The @a stream passed into this function is closed when the created
1201  * stream is closed.
1202  *
1203  * @since New in 1.6.
1204  */
1205 svn_stream_t *
1206 svn_stream_checksummed2(svn_stream_t *stream,
1207                         svn_checksum_t **read_checksum,
1208                         svn_checksum_t **write_checksum,
1209                         svn_checksum_kind_t checksum_kind,
1210                         svn_boolean_t read_all,
1211                         apr_pool_t *pool);
1212
1213 /**
1214  * Similar to svn_stream_checksummed2(), but always returning the MD5
1215  * checksum in @a read_digest and @a write_digest.
1216  *
1217  * @since New in 1.4.
1218  * @deprecated Provided for backward compatibility with the 1.5 API.
1219  */
1220 SVN_DEPRECATED
1221 svn_stream_t *
1222 svn_stream_checksummed(svn_stream_t *stream,
1223                        const unsigned char **read_digest,
1224                        const unsigned char **write_digest,
1225                        svn_boolean_t read_all,
1226                        apr_pool_t *pool);
1227
1228 /** Read from a generic stream until @a buffer is filled upto @a *len or
1229  * until EOF is reached. @see svn_stream_t
1230  *
1231  * @since New in 1.9.
1232  */
1233 svn_error_t *
1234 svn_stream_read_full(svn_stream_t *stream,
1235                      char *buffer,
1236                      apr_size_t *len);
1237
1238
1239 /** Returns @c TRUE if the generic @c stream supports svn_stream_read2().
1240  *
1241  * @since New in 1.9.
1242  */
1243 svn_boolean_t
1244 svn_stream_supports_partial_read(svn_stream_t *stream);
1245
1246 /** Read all currently available upto @a *len into @a buffer. Use
1247  * svn_stream_read_full() if you want to wait for the buffer to be filled
1248  * or EOF. If the stream doesn't support limited reads this function will
1249  * return an #SVN_ERR_STREAM_NOT_SUPPORTED error.
1250  *
1251  * A 0 byte read signals the end of the stream.
1252  *
1253  * @since New in 1.9.
1254  */
1255 svn_error_t *
1256 svn_stream_read2(svn_stream_t *stream,
1257                  char *buffer,
1258                  apr_size_t *len);
1259
1260
1261 /** Read from a generic stream until the buffer is completely filled or EOF.
1262  * @see svn_stream_t.
1263  *
1264  * @note This function is a wrapper of svn_stream_read_full() now, which name
1265  * better documents the behavior of this function.
1266  *
1267  * @deprecated Provided for backward compatibility with the 1.8 API
1268  */
1269 SVN_DEPRECATED
1270 svn_error_t *
1271 svn_stream_read(svn_stream_t *stream,
1272                 char *buffer,
1273                 apr_size_t *len);
1274
1275 /**
1276  * Skip @a len bytes from a generic @a stream. If the stream is exhausted
1277  * before @a len bytes have been read, return an error.
1278  *
1279  * @note  No assumption can be made on the semantics of this function
1280  * other than that the stream read pointer will be advanced by *len
1281  * bytes. Depending on the capabilities of the underlying stream
1282  * implementation, this may for instance be translated into a sequence
1283  * of reads or a simple seek operation. If the stream implementation has
1284  * not provided a skip function, this will read from the stream and
1285  * discard the data.
1286  *
1287  * @since New in 1.7.
1288  */
1289 svn_error_t *
1290 svn_stream_skip(svn_stream_t *stream,
1291                 apr_size_t len);
1292
1293 /** Write to a generic stream. @see svn_stream_t. */
1294 svn_error_t *
1295 svn_stream_write(svn_stream_t *stream,
1296                  const char *data,
1297                  apr_size_t *len);
1298
1299 /** Close a generic stream. @see svn_stream_t. */
1300 svn_error_t *
1301 svn_stream_close(svn_stream_t *stream);
1302
1303 /** Reset a generic stream back to its origin. (E.g. On a file this would be
1304  * implemented as a seek to position 0).  This function returns a
1305  * #SVN_ERR_STREAM_SEEK_NOT_SUPPORTED error when the stream doesn't
1306  * implement resetting.
1307  *
1308  * @since New in 1.7.
1309  */
1310 svn_error_t *
1311 svn_stream_reset(svn_stream_t *stream);
1312
1313 /** Returns @c TRUE if the generic @a stream supports svn_stream_mark().
1314  *
1315  * @see svn_stream_mark()
1316  * @since New in 1.7.
1317  */
1318 svn_boolean_t
1319 svn_stream_supports_mark(svn_stream_t *stream);
1320
1321 /** Set a @a mark at the current position of a generic @a stream,
1322  * which can later be sought back to using svn_stream_seek().
1323  * The @a mark is allocated in @a pool.
1324  *
1325  * This function returns the #SVN_ERR_STREAM_SEEK_NOT_SUPPORTED error
1326  * if the stream doesn't implement seeking.
1327  *
1328  * @see svn_stream_seek()
1329  * @since New in 1.7.
1330  */
1331 svn_error_t *
1332 svn_stream_mark(svn_stream_t *stream,
1333                 svn_stream_mark_t **mark,
1334                 apr_pool_t *pool);
1335
1336 /** Seek to a @a mark in a generic @a stream.
1337  * This function returns the #SVN_ERR_STREAM_SEEK_NOT_SUPPORTED error
1338  * if the stream doesn't implement seeking. Passing NULL as @a mark,
1339  * seeks to the start of the stream.
1340  *
1341  * @see svn_stream_mark()
1342  * @since New in 1.7.
1343  */
1344 svn_error_t *
1345 svn_stream_seek(svn_stream_t *stream, const svn_stream_mark_t *mark);
1346
1347 /** When a stream supports polling for available data, obtain a boolean
1348  * indicating whether data is waiting to be read. If the stream doesn't
1349  * support polling this function returns a #SVN_ERR_STREAM_NOT_SUPPORTED
1350  * error.
1351  *
1352  * If the data_available callback is implemented and the stream is at the end
1353  * the stream will set @a *data_available to FALSE.
1354  *
1355  * @since New in 1.9.
1356  */
1357 svn_error_t *
1358 svn_stream_data_available(svn_stream_t *stream,
1359                           svn_boolean_t *data_available);
1360
1361 /** Return a writable stream which, when written to, writes to both of the
1362  * underlying streams.  Both of these streams will be closed upon closure of
1363  * the returned stream; use svn_stream_disown() if this is not the desired
1364  * behavior.  One or both of @a out1 and @a out2 may be @c NULL.  If both are
1365  * @c NULL, @c NULL is returned.
1366  *
1367  * @since New in 1.7.
1368  */
1369 svn_stream_t *
1370 svn_stream_tee(svn_stream_t *out1,
1371                svn_stream_t *out2,
1372                apr_pool_t *pool);
1373
1374 /** Write NULL-terminated string @a str to @a stream.
1375  *
1376  * @since New in 1.8.
1377  *
1378  */
1379 svn_error_t *
1380 svn_stream_puts(svn_stream_t *stream,
1381                 const char *str);
1382
1383 /** Write to @a stream using a printf-style @a fmt specifier, passed through
1384  * apr_psprintf() using memory from @a pool.
1385  */
1386 svn_error_t *
1387 svn_stream_printf(svn_stream_t *stream,
1388                   apr_pool_t *pool,
1389                   const char *fmt,
1390                   ...)
1391        __attribute__((format(printf, 3, 4)));
1392
1393 /** Write to @a stream using a printf-style @a fmt specifier, passed through
1394  * apr_psprintf() using memory from @a pool.  The resulting string
1395  * will be translated to @a encoding before it is sent to @a stream.
1396  *
1397  * @note Use @c APR_LOCALE_CHARSET to translate to the encoding of the
1398  * current locale.
1399  *
1400  * @since New in 1.3.
1401  */
1402 svn_error_t *
1403 svn_stream_printf_from_utf8(svn_stream_t *stream,
1404                             const char *encoding,
1405                             apr_pool_t *pool,
1406                             const char *fmt,
1407                             ...)
1408        __attribute__((format(printf, 4, 5)));
1409
1410 /** Allocate @a *stringbuf in @a pool, and read into it one line (terminated
1411  * by @a eol) from @a stream. The line-terminator is read from the stream,
1412  * but is not added to the end of the stringbuf.  Instead, the stringbuf
1413  * ends with a usual '\\0'.
1414  *
1415  * If @a stream runs out of bytes before encountering a line-terminator,
1416  * then set @a *eof to @c TRUE, otherwise set @a *eof to FALSE.
1417  */
1418 svn_error_t *
1419 svn_stream_readline(svn_stream_t *stream,
1420                     svn_stringbuf_t **stringbuf,
1421                     const char *eol,
1422                     svn_boolean_t *eof,
1423                     apr_pool_t *pool);
1424
1425 /**
1426  * Read the contents of the readable stream @a from and write them to the
1427  * writable stream @a to calling @a cancel_func before copying each chunk.
1428  *
1429  * @a cancel_func may be @c NULL.
1430  *
1431  * @note both @a from and @a to will be closed upon successful completion of
1432  * the copy (but an error may still be returned, based on trying to close
1433  * the two streams). If the closure is not desired, then you can use
1434  * svn_stream_disown() to protect either or both of the streams from
1435  * being closed.
1436  *
1437  * @since New in 1.6.
1438  */
1439 svn_error_t *
1440 svn_stream_copy3(svn_stream_t *from,
1441                  svn_stream_t *to,
1442                  svn_cancel_func_t cancel_func,
1443                  void *cancel_baton,
1444                  apr_pool_t *pool);
1445
1446 /**
1447  * Same as svn_stream_copy3() but the streams are not closed.
1448  *
1449  * @since New in 1.5.
1450  * @deprecated Provided for backward compatibility with the 1.5 API.
1451  */
1452 SVN_DEPRECATED
1453 svn_error_t *
1454 svn_stream_copy2(svn_stream_t *from,
1455                  svn_stream_t *to,
1456                  svn_cancel_func_t cancel_func,
1457                  void *cancel_baton,
1458                  apr_pool_t *pool);
1459
1460 /**
1461  * Same as svn_stream_copy3(), but without the cancellation function
1462  * or stream closing.
1463  *
1464  * @since New in 1.1.
1465  * @deprecated Provided for backward compatibility with the 1.4 API.
1466  */
1467 SVN_DEPRECATED
1468 svn_error_t *
1469 svn_stream_copy(svn_stream_t *from,
1470                 svn_stream_t *to,
1471                 apr_pool_t *pool);
1472
1473
1474 /** Set @a *same to TRUE if @a stream1 and @a stream2 have the same
1475  * contents, else set it to FALSE.
1476  *
1477  * Both streams will be closed before this function returns (regardless of
1478  * the result, or any possible error).
1479  *
1480  * Use @a scratch_pool for temporary allocations.
1481  *
1482  * @since New in 1.7.
1483  */
1484 svn_error_t *
1485 svn_stream_contents_same2(svn_boolean_t *same,
1486                           svn_stream_t *stream1,
1487                           svn_stream_t *stream2,
1488                           apr_pool_t *pool);
1489
1490
1491 /**
1492  * Same as svn_stream_contents_same2(), but the streams will not be closed.
1493  *
1494  * @since New in 1.4.
1495  * @deprecated Provided for backward compatibility with the 1.6 API.
1496  */
1497 SVN_DEPRECATED
1498 svn_error_t *
1499 svn_stream_contents_same(svn_boolean_t *same,
1500                          svn_stream_t *stream1,
1501                          svn_stream_t *stream2,
1502                          apr_pool_t *pool);
1503
1504
1505 /** Read the contents of @a stream into memory, returning the data in
1506  * @a result. The stream will be closed when it has been successfully and
1507  * completely read.
1508  *
1509  * The returned memory is allocated in @a result_pool, and any temporary
1510  * allocations are performed in @a scratch_pool.
1511  *
1512  * @note due to memory pseudo-reallocation behavior (due to pools), this
1513  *   can be a memory-intensive operation for large files.
1514  *
1515  * @since New in 1.6
1516  */
1517 svn_error_t *
1518 svn_string_from_stream(svn_string_t **result,
1519                        svn_stream_t *stream,
1520                        apr_pool_t *result_pool,
1521                        apr_pool_t *scratch_pool);
1522
1523
1524 /** A function type provided for use as a callback from
1525  * @c svn_stream_lazyopen_create().
1526  *
1527  * The callback function shall open a new stream and set @a *stream to
1528  * the stream object, allocated in @a result_pool.  @a baton is the
1529  * callback baton that was passed to svn_stream_lazyopen_create().
1530  *
1531  * @a result_pool is the result pool that was passed to
1532  * svn_stream_lazyopen_create().  The callback function may use
1533  * @a scratch_pool for temporary allocations; the caller may clear or
1534  * destroy @a scratch_pool any time after the function returns.
1535  *
1536  * @since New in 1.8.
1537  */
1538 typedef svn_error_t *
1539 (*svn_stream_lazyopen_func_t)(svn_stream_t **stream,
1540                               void *baton,
1541                               apr_pool_t *result_pool,
1542                               apr_pool_t *scratch_pool);
1543
1544
1545 /** Return a generic stream which wraps another primary stream,
1546  * delaying the "opening" of that stream until the first time the
1547  * returned stream is accessed.
1548  *
1549  * @a open_func and @a open_baton are a callback function/baton pair
1550  * which will be invoked upon the first access of the returned
1551  * stream (read, write, mark, seek, skip, or possibly close).  The
1552  * callback shall open the primary stream.
1553  *
1554  * If the only "access" the returned stream gets is to close it
1555  * then @a open_func will only be called if @a open_on_close is TRUE.
1556  *
1557  * Allocate the returned stream in @a result_pool. Also arrange for
1558  * @a result_pool to be passed as the @c result_pool parameter to
1559  * @a open_func when it is called.
1560  *
1561  * @since New in 1.8.
1562  */
1563 svn_stream_t *
1564 svn_stream_lazyopen_create(svn_stream_lazyopen_func_t open_func,
1565                            void *open_baton,
1566                            svn_boolean_t open_on_close,
1567                            apr_pool_t *result_pool);
1568
1569 /** @} */
1570
1571 /** Set @a *result to a string containing the contents of @a
1572  * filename, which is either "-" (indicating that stdin should be
1573  * read) or the utf8-encoded path of a real file.
1574  *
1575  * @warning Callers should be aware of possible unexpected results
1576  * when using this function to read from stdin where additional
1577  * stdin-reading processes abound.  For example, if a program tries
1578  * both to invoke an external editor and to read from stdin, stdin
1579  * could be trashed and the editor might act funky or die outright.
1580  *
1581  * @note due to memory pseudo-reallocation behavior (due to pools), this
1582  *   can be a memory-intensive operation for large files.
1583  *
1584  * @since New in 1.5.
1585  */
1586 svn_error_t *
1587 svn_stringbuf_from_file2(svn_stringbuf_t **result,
1588                          const char *filename,
1589                          apr_pool_t *pool);
1590
1591 /** Similar to svn_stringbuf_from_file2(), except that if @a filename
1592  * is "-", return the error #SVN_ERR_UNSUPPORTED_FEATURE and don't
1593  * touch @a *result.
1594  *
1595  * @deprecated Provided for backwards compatibility with the 1.4 API.
1596  */
1597 SVN_DEPRECATED
1598 svn_error_t *
1599 svn_stringbuf_from_file(svn_stringbuf_t **result,
1600                         const char *filename,
1601                         apr_pool_t *pool);
1602
1603 /** Sets @a *result to a string containing the contents of the already opened
1604  * @a file.  Reads from the current position in file to the end.  Does not
1605  * close the file or reset the cursor position.
1606  *
1607  * @note due to memory pseudo-reallocation behavior (due to pools), this
1608  *   can be a memory-intensive operation for large files.
1609  */
1610 svn_error_t *
1611 svn_stringbuf_from_aprfile(svn_stringbuf_t **result,
1612                            apr_file_t *file,
1613                            apr_pool_t *pool);
1614
1615 /** Remove file @a path, a utf8-encoded path.  This wraps apr_file_remove(),
1616  * converting any error to a Subversion error. If @a ignore_enoent is TRUE, and
1617  * the file is not present (APR_STATUS_IS_ENOENT returns TRUE), then no
1618  * error will be returned.
1619  *
1620  * The file will be removed even if it is not writable.  (On Windows and
1621  * OS/2, this function first clears the file's read-only bit.)
1622  *
1623  * @since New in 1.7.
1624  */
1625 svn_error_t *
1626 svn_io_remove_file2(const char *path,
1627                     svn_boolean_t ignore_enoent,
1628                     apr_pool_t *scratch_pool);
1629
1630 /** Similar to svn_io_remove_file2(), except with @a ignore_enoent set to FALSE.
1631  *
1632  * @deprecated Provided for backwards compatibility with the 1.6 API.
1633  */
1634 SVN_DEPRECATED
1635 svn_error_t *
1636 svn_io_remove_file(const char *path,
1637                    apr_pool_t *pool);
1638
1639 /** Recursively remove directory @a path.  @a path is utf8-encoded.
1640  * If @a ignore_enoent is @c TRUE, don't fail if the target directory
1641  * doesn't exist.  Use @a pool for temporary allocations.
1642  *
1643  * Because recursive delete of a directory tree can be a lengthy operation,
1644  * provide @a cancel_func and @a cancel_baton for interruptibility.
1645  *
1646  * @since New in 1.5.
1647  */
1648 svn_error_t *
1649 svn_io_remove_dir2(const char *path,
1650                    svn_boolean_t ignore_enoent,
1651                    svn_cancel_func_t cancel_func,
1652                    void *cancel_baton,
1653                    apr_pool_t *pool);
1654
1655 /** Similar to svn_io_remove_dir2(), but with @a ignore_enoent set to
1656  * @c FALSE and @a cancel_func and @a cancel_baton set to @c NULL.
1657  *
1658  * @deprecated Provided for backward compatibility with the 1.4 API
1659  */
1660 SVN_DEPRECATED
1661 svn_error_t *
1662 svn_io_remove_dir(const char *path,
1663                   apr_pool_t *pool);
1664
1665 /** Read all of the disk entries in directory @a path, a utf8-encoded
1666  * path.  Set @a *dirents to a hash mapping dirent names (<tt>char *</tt>) to
1667  * undefined non-NULL values, allocated in @a pool.
1668  *
1669  * @note The `.' and `..' directories normally returned by
1670  * apr_dir_read() are NOT returned in the hash.
1671  *
1672  * @since New in 1.4.
1673  * @deprecated Provided for backward compatibility with the 1.6 API.
1674  */
1675 SVN_DEPRECATED
1676 svn_error_t *
1677 svn_io_get_dir_filenames(apr_hash_t **dirents,
1678                          const char *path,
1679                          apr_pool_t *pool);
1680
1681 /** Read all of the disk entries in directory @a path, a utf8-encoded
1682  * path.  Set @a *dirents to a hash mapping dirent names (<tt>char *</tt>) to
1683  * #svn_io_dirent2_t structures, allocated in @a pool.
1684  *
1685  * If @a only_check_type is set to @c TRUE, only the kind and special
1686  * fields of the svn_io_dirent2_t are filled.
1687  *
1688  * @note The `.' and `..' directories normally returned by
1689  * apr_dir_read() are NOT returned in the hash.
1690  *
1691  * @note The kind field in the @a dirents is set according to the mapping
1692  *       as documented for svn_io_check_path().
1693  *
1694  * @since New in 1.7.
1695  */
1696 svn_error_t *
1697 svn_io_get_dirents3(apr_hash_t **dirents,
1698                     const char *path,
1699                     svn_boolean_t only_check_type,
1700                     apr_pool_t *result_pool,
1701                     apr_pool_t *scratch_pool);
1702
1703
1704 /** Similar to svn_io_get_dirents3, but returns a mapping to svn_io_dirent_t
1705  * structures instead of svn_io_dirent2_t and with only a single pool.
1706  *
1707  * @since New in 1.3.
1708  * @deprecated Provided for backward compatibility with the 1.6 API.
1709  */
1710 SVN_DEPRECATED
1711 svn_error_t *
1712 svn_io_get_dirents2(apr_hash_t **dirents,
1713                     const char *path,
1714                     apr_pool_t *pool);
1715
1716 /** Similar to svn_io_get_dirents2(), but @a *dirents is a hash table
1717  * with #svn_node_kind_t values.
1718  *
1719  * @deprecated Provided for backwards compatibility with the 1.2 API.
1720  */
1721 SVN_DEPRECATED
1722 svn_error_t *
1723 svn_io_get_dirents(apr_hash_t **dirents,
1724                    const char *path,
1725                    apr_pool_t *pool);
1726
1727 /** Create a svn_io_dirent2_t instance for path. Specialized variant of
1728  * svn_io_stat() that directly translates node_kind and special.
1729  *
1730  * If @a verify_truename is @c TRUE, an additional check is performed to
1731  * verify the truename of the last path component on case insensitive
1732  * filesystems. This check is expensive compared to a just a stat,
1733  * but certainly cheaper than a full truename calculation using
1734  * apr_filepath_merge() which verifies all path components.
1735  *
1736  * If @a ignore_enoent is set to @c TRUE, set *dirent_p->kind to
1737  * svn_node_none instead of returning an error.
1738  *
1739  * @since New in 1.8.
1740  */
1741 svn_error_t *
1742 svn_io_stat_dirent2(const svn_io_dirent2_t **dirent_p,
1743                     const char *path,
1744                     svn_boolean_t verify_truename,
1745                     svn_boolean_t ignore_enoent,
1746                     apr_pool_t *result_pool,
1747                     apr_pool_t *scratch_pool);
1748
1749
1750 /** Similar to svn_io_stat_dirent2(), but always passes FALSE for
1751  * @a verify_truename.
1752  *
1753  * @since New in 1.7.
1754  * @deprecated Provided for backwards compatibility with the 1.7 API.
1755  */
1756 SVN_DEPRECATED
1757 svn_error_t *
1758 svn_io_stat_dirent(const svn_io_dirent2_t **dirent_p,
1759                    const char *path,
1760                    svn_boolean_t ignore_enoent,
1761                    apr_pool_t *result_pool,
1762                    apr_pool_t *scratch_pool);
1763
1764
1765 /** Callback function type for svn_io_dir_walk() */
1766 typedef svn_error_t * (*svn_io_walk_func_t)(void *baton,
1767                                             const char *path,
1768                                             const apr_finfo_t *finfo,
1769                                             apr_pool_t *pool);
1770
1771 /** Recursively walk the directory rooted at @a dirname, a
1772  * utf8-encoded path, invoking @a walk_func (with @a walk_baton) for
1773  * each item in the tree.  For a given directory, invoke @a walk_func
1774  * on the directory itself before invoking it on any children thereof.
1775  *
1776  * Deliver to @a walk_func the information specified by @a wanted,
1777  * which is a combination of @c APR_FINFO_* flags, plus the
1778  * information specified by @c APR_FINFO_TYPE and @c APR_FINFO_NAME.
1779  *
1780  * Use @a pool for all allocations.
1781  *
1782  * @note This function does not currently pass all file types to @a
1783  * walk_func -- only APR_DIR, APR_REG, and APR_LNK.  We reserve the
1784  * right to pass additional file types through this interface in the
1785  * future, though, so implementations of this callback should
1786  * explicitly test FINFO->filetype.  See the APR library's
1787  * apr_filetype_e enum for the various filetypes and their meanings.
1788  *
1789  * @since New in 1.7.
1790  */
1791 svn_error_t *
1792 svn_io_dir_walk2(const char *dirname,
1793                  apr_int32_t wanted,
1794                  svn_io_walk_func_t walk_func,
1795                  void *walk_baton,
1796                  apr_pool_t *pool);
1797
1798 /** Similar to svn_io_dir_walk(), but only calls @a walk_func for
1799  * files of type APR_DIR (directory) and APR_REG (regular file).
1800  *
1801  * @deprecated Provided for backwards compatibility with the 1.6 API.
1802  */
1803 SVN_DEPRECATED
1804 svn_error_t *
1805 svn_io_dir_walk(const char *dirname,
1806                 apr_int32_t wanted,
1807                 svn_io_walk_func_t walk_func,
1808                 void *walk_baton,
1809                 apr_pool_t *pool);
1810
1811 /**
1812  * Start @a cmd with @a args, using utf8-encoded @a path as working
1813  * directory.  Return the process handle for the invoked program in @a
1814  * *cmd_proc.
1815  *
1816  * If @a infile_pipe is TRUE, connect @a cmd's stdin to a pipe;
1817  * otherwise, connect it to @a infile (which may be NULL).  If
1818  * @a outfile_pipe is TRUE, connect @a cmd's stdout to a pipe; otherwise,
1819  * connect it to @a outfile (which may be NULL).  If @a errfile_pipe
1820  * is TRUE, connect @a cmd's stderr to a pipe; otherwise, connect it
1821  * to @a errfile (which may be NULL).  (Callers must pass FALSE for
1822  * each of these boolean values for which the corresponding file
1823  * handle is non-NULL.)
1824  *
1825  * @a args is a list of utf8-encoded <tt>const char *</tt> arguments,
1826  * terminated by @c NULL.  @a args[0] is the name of the program, though it
1827  * need not be the same as @a cmd.
1828  *
1829  * If @a inherit is TRUE, the invoked program inherits its environment from
1830  * the caller and @a cmd, if not absolute, is searched for in PATH.
1831  *
1832  * If @a inherit is FALSE @a cmd must be an absolute path and the invoked
1833  * program inherits the environment defined by @a env or runs with an empty
1834  * environment in @a env is NULL.
1835  *
1836  * @note On some platforms, failure to execute @a cmd in the child process
1837  * will result in error output being written to @a errfile, if non-NULL, and
1838  * a non-zero exit status being returned to the parent process.
1839  *
1840  * @note An APR bug affects Windows: passing a NULL @a env does not
1841  * guarantee the invoked program to run with an empty environment when
1842  * @a inherit is FALSE, the program may inherit its parent's environment.
1843  * Explicitly pass an empty @a env to get an empty environment.
1844  *
1845  * @since New in 1.8.
1846  */
1847 svn_error_t *svn_io_start_cmd3(apr_proc_t *cmd_proc,
1848                                const char *path,
1849                                const char *cmd,
1850                                const char *const *args,
1851                                const char *const *env,
1852                                svn_boolean_t inherit,
1853                                svn_boolean_t infile_pipe,
1854                                apr_file_t *infile,
1855                                svn_boolean_t outfile_pipe,
1856                                apr_file_t *outfile,
1857                                svn_boolean_t errfile_pipe,
1858                                apr_file_t *errfile,
1859                                apr_pool_t *pool);
1860
1861
1862 /**
1863  * Similar to svn_io_start_cmd3() but with @a env always set to NULL.
1864  *
1865  * @deprecated Provided for backward compatibility with the 1.7 API
1866  * @since New in 1.7.
1867  */
1868 SVN_DEPRECATED
1869 svn_error_t *svn_io_start_cmd2(apr_proc_t *cmd_proc,
1870                                const char *path,
1871                                const char *cmd,
1872                                const char *const *args,
1873                                svn_boolean_t inherit,
1874                                svn_boolean_t infile_pipe,
1875                                apr_file_t *infile,
1876                                svn_boolean_t outfile_pipe,
1877                                apr_file_t *outfile,
1878                                svn_boolean_t errfile_pipe,
1879                                apr_file_t *errfile,
1880                                apr_pool_t *pool);
1881
1882 /**
1883  * Similar to svn_io_start_cmd2() but with @a infile_pipe, @a
1884  * outfile_pipe, and @a errfile_pipe always FALSE.
1885  *
1886  * @deprecated Provided for backward compatibility with the 1.6 API
1887  * @since New in 1.3.
1888  */
1889 SVN_DEPRECATED
1890 svn_error_t *
1891 svn_io_start_cmd(apr_proc_t *cmd_proc,
1892                  const char *path,
1893                  const char *cmd,
1894                  const char *const *args,
1895                  svn_boolean_t inherit,
1896                  apr_file_t *infile,
1897                  apr_file_t *outfile,
1898                  apr_file_t *errfile,
1899                  apr_pool_t *pool);
1900
1901 /**
1902  * Wait for the process @a *cmd_proc to complete and optionally retrieve
1903  * its exit code.  @a cmd is used only in error messages.
1904  *
1905  * If @a exitcode is not NULL, set @a *exitcode to the exit code of the
1906  * process and do not consider any exit code to be an error.  If @a exitcode
1907  * is NULL, then if the exit code of the process is non-zero then return an
1908  * #SVN_ERR_EXTERNAL_PROGRAM error.
1909  *
1910  * If @a exitwhy is not NULL, set @a *exitwhy to indicate why the process
1911  * terminated and do not consider any reason to be an error.  If @a exitwhy
1912  * is NULL, then if the termination reason is not @c APR_PROC_CHECK_EXIT()
1913  * then return an #SVN_ERR_EXTERNAL_PROGRAM error.
1914  *
1915  * @since New in 1.3.
1916  */
1917 svn_error_t *
1918 svn_io_wait_for_cmd(apr_proc_t *cmd_proc,
1919                     const char *cmd,
1920                     int *exitcode,
1921                     apr_exit_why_e *exitwhy,
1922                     apr_pool_t *pool);
1923
1924 /** Run a command to completion, by first calling svn_io_start_cmd() and
1925  * then calling svn_io_wait_for_cmd().  The parameters correspond to
1926  * the same-named parameters of those two functions.
1927  */
1928 svn_error_t *
1929 svn_io_run_cmd(const char *path,
1930                const char *cmd,
1931                const char *const *args,
1932                int *exitcode,
1933                apr_exit_why_e *exitwhy,
1934                svn_boolean_t inherit,
1935                apr_file_t *infile,
1936                apr_file_t *outfile,
1937                apr_file_t *errfile,
1938                apr_pool_t *pool);
1939
1940 /** Invoke the configured @c diff program, with @a user_args (an array
1941  * of utf8-encoded @a num_user_args arguments) if they are specified
1942  * (that is, if @a user_args is non-NULL), or "-u" if they are not.
1943  * If @a user_args is NULL, the value of @a num_user_args is ignored.
1944  *
1945  * Diff runs in utf8-encoded @a dir, and its exit status is stored in
1946  * @a exitcode, if it is not @c NULL.
1947  *
1948  * If @a label1 and/or @a label2 are not NULL they will be passed to the diff
1949  * process as the arguments of "-L" options.  @a label1 and @a label2 are also
1950  * in utf8, and will be converted to native charset along with the other args.
1951  *
1952  * @a from is the first file passed to diff, and @a to is the second.  The
1953  * stdout of diff will be sent to @a outfile, and the stderr to @a errfile.
1954  *
1955  * @a diff_cmd must be non-NULL.
1956  *
1957  * Do all allocation in @a pool.
1958  * @since New in 1.6.0.
1959  */
1960 svn_error_t *
1961 svn_io_run_diff2(const char *dir,
1962                  const char *const *user_args,
1963                  int num_user_args,
1964                  const char *label1,
1965                  const char *label2,
1966                  const char *from,
1967                  const char *to,
1968                  int *exitcode,
1969                  apr_file_t *outfile,
1970                  apr_file_t *errfile,
1971                  const char *diff_cmd,
1972                  apr_pool_t *pool);
1973
1974 /** Similar to svn_io_run_diff2() but with @a diff_cmd encoded in internal
1975  * encoding used by APR.
1976  *
1977  * @deprecated Provided for backwards compatibility with the 1.5 API. */
1978 SVN_DEPRECATED
1979 svn_error_t *
1980 svn_io_run_diff(const char *dir,
1981                 const char *const *user_args,
1982                 int num_user_args,
1983                 const char *label1,
1984                 const char *label2,
1985                 const char *from,
1986                 const char *to,
1987                 int *exitcode,
1988                 apr_file_t *outfile,
1989                 apr_file_t *errfile,
1990                 const char *diff_cmd,
1991                 apr_pool_t *pool);
1992
1993
1994
1995 /** Invoke the configured @c diff3 program, in utf8-encoded @a dir
1996  * like this:
1997  *
1998  *          diff3 -E -m @a mine @a older @a yours > @a merged
1999  *
2000  * (See the diff3 documentation for details.)
2001  *
2002  * If @a user_args is non-NULL, replace "-E" with the <tt>const char*</tt>
2003  * elements that @a user_args contains.
2004  *
2005  * @a mine, @a older and @a yours are utf8-encoded paths (relative to
2006  * @a dir or absolute) to three files that already exist.
2007  *
2008  * @a merged is an open file handle, and is left open after the merge
2009  * result is written to it. (@a merged should *not* be the same file
2010  * as @a mine, or nondeterministic things may happen!)
2011  *
2012  * @a mine_label, @a older_label, @a yours_label are utf8-encoded label
2013  * parameters for diff3's -L option.  Any of them may be @c NULL, in
2014  * which case the corresponding @a mine, @a older, or @a yours parameter is
2015  * used instead.
2016  *
2017  * Set @a *exitcode to diff3's exit status.  If @a *exitcode is anything
2018  * other than 0 or 1, then return #SVN_ERR_EXTERNAL_PROGRAM.  (Note the
2019  * following from the diff3 info pages: "An exit status of 0 means
2020  * `diff3' was successful, 1 means some conflicts were found, and 2
2021  * means trouble.")
2022  *
2023  * @a diff3_cmd must be non-NULL.
2024  *
2025  * Do all allocation in @a pool.
2026  *
2027  * @since New in 1.4.
2028  */
2029 svn_error_t *
2030 svn_io_run_diff3_3(int *exitcode,
2031                    const char *dir,
2032                    const char *mine,
2033                    const char *older,
2034                    const char *yours,
2035                    const char *mine_label,
2036                    const char *older_label,
2037                    const char *yours_label,
2038                    apr_file_t *merged,
2039                    const char *diff3_cmd,
2040                    const apr_array_header_t *user_args,
2041                    apr_pool_t *pool);
2042
2043 /** Similar to svn_io_run_diff3_3(), but with @a diff3_cmd encoded in
2044  * internal encoding used by APR.
2045  *
2046  * @deprecated Provided for backwards compatibility with the 1.5 API.
2047  * @since New in 1.4.
2048  */
2049 SVN_DEPRECATED
2050 svn_error_t *
2051 svn_io_run_diff3_2(int *exitcode,
2052                    const char *dir,
2053                    const char *mine,
2054                    const char *older,
2055                    const char *yours,
2056                    const char *mine_label,
2057                    const char *older_label,
2058                    const char *yours_label,
2059                    apr_file_t *merged,
2060                    const char *diff3_cmd,
2061                    const apr_array_header_t *user_args,
2062                    apr_pool_t *pool);
2063
2064 /** Similar to svn_io_run_diff3_2(), but with @a user_args set to @c NULL.
2065  *
2066  * @deprecated Provided for backwards compatibility with the 1.3 API.
2067  */
2068 SVN_DEPRECATED
2069 svn_error_t *
2070 svn_io_run_diff3(const char *dir,
2071                  const char *mine,
2072                  const char *older,
2073                  const char *yours,
2074                  const char *mine_label,
2075                  const char *older_label,
2076                  const char *yours_label,
2077                  apr_file_t *merged,
2078                  int *exitcode,
2079                  const char *diff3_cmd,
2080                  apr_pool_t *pool);
2081
2082
2083 /** Parse utf8-encoded @a mimetypes_file as a MIME types file (such as
2084  * is provided with Apache HTTP Server), and set @a *type_map to a
2085  * hash mapping <tt>const char *</tt> filename extensions to
2086  * <tt>const char *</tt> MIME types.
2087  *
2088  * @since New in 1.5.
2089  */
2090 svn_error_t *
2091 svn_io_parse_mimetypes_file(apr_hash_t **type_map,
2092                             const char *mimetypes_file,
2093                             apr_pool_t *pool);
2094
2095
2096 /** Examine utf8-encoded @a file to determine if it can be described by a
2097  * known (as in, known by this function) Multipurpose Internet Mail
2098  * Extension (MIME) type.  If so, set @a *mimetype to a character string
2099  * describing the MIME type, else set it to @c NULL.
2100  *
2101  * If not @c NULL, @a mimetype_map is a hash mapping <tt>const char *</tt>
2102  * filename extensions to <tt>const char *</tt> MIME types, and is the
2103  * first source consulted regarding @a file's MIME type.
2104  *
2105  * Use @a pool for any necessary allocations.
2106  *
2107  * @since New in 1.5.
2108  */
2109 svn_error_t *
2110 svn_io_detect_mimetype2(const char **mimetype,
2111                         const char *file,
2112                         apr_hash_t *mimetype_map,
2113                         apr_pool_t *pool);
2114
2115
2116 /** Like svn_io_detect_mimetype2, but with @a mimetypes_map set to
2117  * @c NULL.
2118  *
2119  * @deprecated Provided for backward compatibility with the 1.4 API
2120  */
2121 SVN_DEPRECATED
2122 svn_error_t *
2123 svn_io_detect_mimetype(const char **mimetype,
2124                        const char *file,
2125                        apr_pool_t *pool);
2126
2127
2128 /** Examine up to @a len bytes of data in @a buf to determine if the
2129  * can be considered binary data, in which case return TRUE.
2130  * If the data can be considered plain-text data, return FALSE.
2131  *
2132  * @since New in 1.7.
2133  */
2134 svn_boolean_t
2135 svn_io_is_binary_data(const void *buf, apr_size_t len);
2136
2137
2138 /** Wrapper for apr_file_open().  @a fname is utf8-encoded.
2139     Always passed flag | APR_BINARY to apr. */
2140 svn_error_t *
2141 svn_io_file_open(apr_file_t **new_file,
2142                  const char *fname,
2143                  apr_int32_t flag,
2144                  apr_fileperms_t perm,
2145                  apr_pool_t *pool);
2146
2147
2148 /** Wrapper for apr_file_close(). */
2149 svn_error_t *
2150 svn_io_file_close(apr_file_t *file,
2151                   apr_pool_t *pool);
2152
2153
2154 /** Wrapper for apr_file_getc(). */
2155 svn_error_t *
2156 svn_io_file_getc(char *ch,
2157                  apr_file_t *file,
2158                  apr_pool_t *pool);
2159
2160
2161 /** Wrapper for apr_file_putc().
2162   * @since New in 1.7
2163   */
2164 svn_error_t *
2165 svn_io_file_putc(char ch,
2166                  apr_file_t *file,
2167                  apr_pool_t *pool);
2168
2169
2170 /** Wrapper for apr_file_info_get(). */
2171 svn_error_t *
2172 svn_io_file_info_get(apr_finfo_t *finfo,
2173                      apr_int32_t wanted,
2174                      apr_file_t *file,
2175                      apr_pool_t *pool);
2176
2177
2178 /** Wrapper for apr_file_read(). */
2179 svn_error_t *
2180 svn_io_file_read(apr_file_t *file,
2181                  void *buf,
2182                  apr_size_t *nbytes,
2183                  apr_pool_t *pool);
2184
2185
2186 /** Wrapper for apr_file_read_full().
2187  *
2188  * If @a hit_eof is not NULL, EOF will be indicated there and no
2189  * svn_error_t error object will be created upon EOF.
2190  *
2191  * @since New in 1.7
2192  */
2193 svn_error_t *
2194 svn_io_file_read_full2(apr_file_t *file,
2195                        void *buf,
2196                        apr_size_t nbytes,
2197                        apr_size_t *bytes_read,
2198                        svn_boolean_t *hit_eof,
2199                        apr_pool_t *pool);
2200
2201
2202 /** Similar to svn_io_file_read_full2 with hit_eof being set
2203  * to @c NULL.
2204  *
2205  * @deprecated Provided for backward compatibility with the 1.6 API
2206  */
2207 SVN_DEPRECATED
2208 svn_error_t *
2209 svn_io_file_read_full(apr_file_t *file,
2210                       void *buf,
2211                       apr_size_t nbytes,
2212                       apr_size_t *bytes_read,
2213                       apr_pool_t *pool);
2214
2215
2216 /** Wrapper for apr_file_seek(). */
2217 svn_error_t *
2218 svn_io_file_seek(apr_file_t *file,
2219                  apr_seek_where_t where,
2220                  apr_off_t *offset,
2221                  apr_pool_t *pool);
2222
2223 /** Set the file pointer of the #APR_BUFFERED @a file to @a offset.  In
2224  * contrast to #svn_io_file_seek, this function will attempt to resize the
2225  * internal data buffer to @a block_size bytes and to read data aligned to
2226  * multiples of that value.  The beginning of the block will be returned
2227  * in @a buffer_start, if that is not NULL.
2228  * Uses @a scratch_pool for temporary allocations.
2229  *
2230  * @note Due to limitations of the APR API, the alignment may not be
2231  * successful.  If you never use any other seek function on @a file,
2232  * however, you are virtually guaranteed to get at least 4kByte alignment
2233  * for all reads.
2234  *
2235  * @note Calling this for non-buffered files is legal but inefficient.
2236  *
2237  * @since New in 1.9
2238  */
2239 svn_error_t *
2240 svn_io_file_aligned_seek(apr_file_t *file,
2241                          apr_off_t block_size,
2242                          apr_off_t *buffer_start,
2243                          apr_off_t offset,
2244                          apr_pool_t *scratch_pool);
2245
2246 /** Wrapper for apr_file_write(). */
2247 svn_error_t *
2248 svn_io_file_write(apr_file_t *file,
2249                   const void *buf,
2250                   apr_size_t *nbytes,
2251                   apr_pool_t *pool);
2252
2253 /** Wrapper for apr_file_flush().
2254  * @since New in 1.9
2255  */
2256 svn_error_t *
2257 svn_io_file_flush(apr_file_t *file,
2258                   apr_pool_t *scratch_pool);
2259
2260
2261
2262 /** Wrapper for apr_file_write_full(). */
2263 svn_error_t *
2264 svn_io_file_write_full(apr_file_t *file,
2265                        const void *buf,
2266                        apr_size_t nbytes,
2267                        apr_size_t *bytes_written,
2268                        apr_pool_t *pool);
2269
2270 /**
2271  * Writes @a nbytes bytes from @a *buf to a temporary file inside the same
2272  * directory as @a *final_path. Then syncs the temporary file to disk and
2273  * closes the file. After this rename the temporary file to @a final_path,
2274  * possibly replacing an existing file.
2275  *
2276  * If @a copy_perms_path is not NULL, copy the permissions applied on @a
2277  * @a copy_perms_path on the temporary file before renaming.
2278  *
2279  * @note This function uses advanced file control operations to flush buffers
2280  * to disk that aren't always accessible and can be very expensive. Avoid
2281  * using this function in cases where the file should just work on any
2282  * network filesystem.
2283  *
2284  * @since New in 1.9.
2285  */
2286 svn_error_t *
2287 svn_io_write_atomic(const char *final_path,
2288                     const void *buf,
2289                     apr_size_t nbytes,
2290                     const char* copy_perms_path,
2291                     apr_pool_t *scratch_pool);
2292
2293 /**
2294  * Open a unique file in @a dirpath, and write @a nbytes from @a buf to
2295  * the file before flushing it to disk and closing it.  Return the name
2296  * of the newly created file in @a *tmp_path, allocated in @a pool.
2297  *
2298  * If @a dirpath is @c NULL, use the path returned from svn_io_temp_dir().
2299  * (Note that when using the system-provided temp directory, it may not
2300  * be possible to atomically rename the resulting file due to cross-device
2301  * issues.)
2302  *
2303  * The file will be deleted according to @a delete_when.
2304  *
2305  * @since New in 1.6.
2306  */
2307 svn_error_t *
2308 svn_io_write_unique(const char **tmp_path,
2309                     const char *dirpath,
2310                     const void *buf,
2311                     apr_size_t nbytes,
2312                     svn_io_file_del_t delete_when,
2313                     apr_pool_t *pool);
2314
2315 /** Wrapper for apr_file_trunc().
2316   * @since New in 1.6. */
2317 svn_error_t *
2318 svn_io_file_trunc(apr_file_t *file,
2319                   apr_off_t offset,
2320                   apr_pool_t *pool);
2321
2322
2323 /** Wrapper for apr_stat().  @a fname is utf8-encoded. */
2324 svn_error_t *
2325 svn_io_stat(apr_finfo_t *finfo,
2326             const char *fname,
2327             apr_int32_t wanted,
2328             apr_pool_t *pool);
2329
2330
2331 /** Rename and/or move the node (not necessarily a regular file) at
2332  * @a from_path to a new path @a to_path within the same filesystem.
2333  * In some cases, an existing node at @a to_path will be overwritten.
2334  *
2335  * A wrapper for apr_file_rename().  @a from_path and @a to_path are
2336  * utf8-encoded.
2337  */
2338 svn_error_t *
2339 svn_io_file_rename(const char *from_path,
2340                    const char *to_path,
2341                    apr_pool_t *pool);
2342
2343
2344 /** Move the file from @a from_path to @a to_path, even across device
2345  * boundaries. Overwrite @a to_path if it exists.
2346  *
2347  * @note This function is different from svn_io_file_rename in that the
2348  * latter fails in the 'across device boundaries' case.
2349  *
2350  * @since New in 1.3.
2351  */
2352 svn_error_t *
2353 svn_io_file_move(const char *from_path,
2354                  const char *to_path,
2355                  apr_pool_t *pool);
2356
2357
2358 /** Wrapper for apr_dir_make().  @a path is utf8-encoded. */
2359 svn_error_t *
2360 svn_io_dir_make(const char *path,
2361                 apr_fileperms_t perm,
2362                 apr_pool_t *pool);
2363
2364 /** Same as svn_io_dir_make(), but sets the hidden attribute on the
2365     directory on systems that support it. */
2366 svn_error_t *
2367 svn_io_dir_make_hidden(const char *path,
2368                        apr_fileperms_t perm,
2369                        apr_pool_t *pool);
2370
2371 /**
2372  * Same as svn_io_dir_make(), but attempts to set the sgid on the
2373  * directory on systems that support it.  Does not return an error if
2374  * the attempt to set the sgid bit fails.  On Unix filesystems,
2375  * setting the sgid bit on a directory ensures that files and
2376  * subdirectories created within inherit group ownership from the
2377  * parent instead of from the primary gid.
2378  *
2379  * @since New in 1.1.
2380  */
2381 svn_error_t *
2382 svn_io_dir_make_sgid(const char *path,
2383                      apr_fileperms_t perm,
2384                      apr_pool_t *pool);
2385
2386 /** Wrapper for apr_dir_open().  @a dirname is utf8-encoded. */
2387 svn_error_t *
2388 svn_io_dir_open(apr_dir_t **new_dir,
2389                 const char *dirname,
2390                 apr_pool_t *pool);
2391
2392 /** Wrapper for apr_dir_close().
2393  *
2394  * @since New in 1.7.
2395  */
2396 svn_error_t *
2397 svn_io_dir_close(apr_dir_t *thedir);
2398
2399 /** Wrapper for apr_dir_remove().  @a dirname is utf8-encoded.
2400  * @note This function has this name to avoid confusion with
2401  * svn_io_remove_dir2(), which is recursive.
2402  */
2403 svn_error_t *
2404 svn_io_dir_remove_nonrecursive(const char *dirname,
2405                                apr_pool_t *pool);
2406
2407
2408 /** Wrapper for apr_dir_read().  Ensures that @a finfo->name is
2409  * utf8-encoded, which means allocating @a finfo->name in @a pool,
2410  * which may or may not be the same as @a finfo's pool.  Use @a pool
2411  * for error allocation as well.
2412  */
2413 svn_error_t *
2414 svn_io_dir_read(apr_finfo_t *finfo,
2415                 apr_int32_t wanted,
2416                 apr_dir_t *thedir,
2417                 apr_pool_t *pool);
2418
2419 /** Wrapper for apr_file_name_get().  @a *filename is utf8-encoded.
2420  *
2421  * @note The file name may be NULL.
2422  *
2423  * @since New in 1.7. */
2424 svn_error_t *
2425 svn_io_file_name_get(const char **filename,
2426                      apr_file_t *file,
2427                      apr_pool_t *pool);
2428
2429
2430 \f
2431 /** Version/format files.
2432  *
2433  * @defgroup svn_io_format_files Version/format files
2434  * @{
2435  */
2436
2437 /** Set @a *version to the integer that starts the file at @a path.  If the
2438  * file does not begin with a series of digits followed by a newline,
2439  * return the error #SVN_ERR_BAD_VERSION_FILE_FORMAT.  Use @a pool for
2440  * all allocations.
2441  */
2442 svn_error_t *
2443 svn_io_read_version_file(int *version,
2444                          const char *path,
2445                          apr_pool_t *pool);
2446
2447 /** Create (or overwrite) the file at @a path with new contents,
2448  * formatted as a non-negative integer @a version followed by a single
2449  * newline.  On successful completion the file will be read-only.  Use
2450  * @a pool for all allocations.
2451  */
2452 svn_error_t *
2453 svn_io_write_version_file(const char *path,
2454                           int version,
2455                           apr_pool_t *pool);
2456
2457 /** Read a line of text from a file, up to a specified length.
2458  *
2459  * Allocate @a *stringbuf in @a result_pool, and read into it one line
2460  * from @a file. Reading stops either after a line-terminator was found
2461  * or after @a max_len bytes have been read.
2462  *
2463  * If end-of-file is reached or @a max_len bytes have been read, and @a eof
2464  * is not NULL, then set @a *eof to @c TRUE.
2465  *
2466  * The line-terminator is not stored in @a *stringbuf.
2467  * The line-terminator is detected automatically and stored in @a *eol
2468  * if @a eol is not NULL. If EOF is reached and @a file does not end
2469  * with a newline character, and @a eol is not NULL, @ *eol is set to NULL.
2470  *
2471  * @a scratch_pool is used for temporary allocations.
2472  *
2473  * Hint: To read all data until a line-terminator is hit, pass APR_SIZE_MAX
2474  * for @a max_len.
2475  *
2476  * @since New in 1.8.
2477  */
2478 svn_error_t *
2479 svn_io_file_readline(apr_file_t *file,
2480                      svn_stringbuf_t **stringbuf,
2481                      const char **eol,
2482                      svn_boolean_t *eof,
2483                      apr_size_t max_len,
2484                      apr_pool_t *result_pool,
2485                      apr_pool_t *scratch_pool);
2486
2487 /** @} */
2488
2489 #ifdef __cplusplus
2490 }
2491 #endif /* __cplusplus */
2492
2493 #endif /* SVN_IO_H */