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
47extern "C" {
48#endif /* __cplusplus */
49
50
51
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. */
58typedef 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 */
78typedef 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 */
105svn_io_dirent2_t *
106svn_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 */
112svn_io_dirent2_t *
113svn_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 */
123typedef 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 */
153svn_error_t *
154svn_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 */
164svn_error_t *
165svn_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(). */
172svn_error_t *
173svn_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 */
230svn_error_t *
231svn_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 */
267svn_error_t *
268svn_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 */
283SVN_DEPRECATED
284svn_error_t *
285svn_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 */
300SVN_DEPRECATED
301svn_error_t *
302svn_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 */
316svn_error_t *
317svn_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 */
330svn_error_t *
331svn_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 */
339svn_error_t *
340svn_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 */
349svn_error_t *
350svn_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 */
361svn_error_t *
362svn_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 */
375svn_error_t *
376svn_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 */
391svn_error_t *
392svn_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 */
408svn_error_t *
409svn_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 */
417svn_error_t *
418svn_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 */
426svn_error_t *
427svn_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 */
444svn_error_t *
445svn_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 */
465svn_error_t *
466svn_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 */
493SVN_DEPRECATED
494svn_error_t *
495svn_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 */
525svn_error_t *
526svn_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 */
537svn_error_t *
538svn_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 */
551svn_error_t *
552svn_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 */
564svn_error_t *
565svn_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 */
575svn_error_t *
576svn_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 */
594void
595svn_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 */
606svn_error_t *
607svn_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 */
625svn_error_t *
626svn_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 */
639svn_error_t *
640svn_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 */
652SVN_DEPRECATED
653svn_error_t *
654svn_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 */
662svn_error_t *
663svn_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 */
676svn_error_t *
677svn_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 file at utf8-encoded @a file with contents @a contents.
686 * @a file must not already exist.
687 * Use @a pool for memory allocations.
688 */
689svn_error_t *
690svn_io_file_create(const char *file,
691                   const char *contents,
692                   apr_pool_t *pool);
693
694/**
695 * Lock file at @a lock_file. If @a exclusive is TRUE,
696 * obtain exclusive lock, otherwise obtain shared lock.
697 * Lock will be automatically released when @a pool is cleared or destroyed.
698 * Use @a pool for memory allocations.
699 *
700 * @deprecated Provided for backward compatibility with the 1.0 API.
701 */
702SVN_DEPRECATED
703svn_error_t *
704svn_io_file_lock(const char *lock_file,
705                 svn_boolean_t exclusive,
706                 apr_pool_t *pool);
707
708/**
709 * Lock file at @a lock_file. If @a exclusive is TRUE,
710 * obtain exclusive lock, otherwise obtain shared lock.
711 *
712 * If @a nonblocking is TRUE, do not wait for the lock if it
713 * is not available: throw an error instead.
714 *
715 * Lock will be automatically released when @a pool is cleared or destroyed.
716 * Use @a pool for memory allocations.
717 *
718 * @since New in 1.1.
719 */
720svn_error_t *
721svn_io_file_lock2(const char *lock_file,
722                  svn_boolean_t exclusive,
723                  svn_boolean_t nonblocking,
724                  apr_pool_t *pool);
725
726/**
727 * Lock the file @a lockfile_handle. If @a exclusive is TRUE,
728 * obtain exclusive lock, otherwise obtain shared lock.
729 *
730 * If @a nonblocking is TRUE, do not wait for the lock if it
731 * is not available: throw an error instead.
732 *
733 * Lock will be automatically released when @a pool is cleared or destroyed.
734 * You may also explicitly call svn_io_unlock_open_file().
735 * Use @a pool for memory allocations. @a pool must be the pool that
736 * @a lockfile_handle has been created in or one of its sub-pools.
737 *
738 * @since New in 1.8.
739 */
740svn_error_t *
741svn_io_lock_open_file(apr_file_t *lockfile_handle,
742                      svn_boolean_t exclusive,
743                      svn_boolean_t nonblocking,
744                      apr_pool_t *pool);
745
746/**
747 * Unlock the file @a lockfile_handle.
748 *
749 * Use @a pool for memory allocations. @a pool must be the pool that
750 * was passed to svn_io_lock_open_file().
751 *
752 * @since New in 1.8.
753 */
754svn_error_t *
755svn_io_unlock_open_file(apr_file_t *lockfile_handle,
756                        apr_pool_t *pool);
757
758/**
759 * Flush any unwritten data from @a file to disk.  Use @a pool for
760 * memory allocations.
761 *
762 * @since New in 1.1.
763 */
764svn_error_t *
765svn_io_file_flush_to_disk(apr_file_t *file,
766                          apr_pool_t *pool);
767
768/** Copy the file whose basename (or relative path) is @a file within
769 * directory @a src_path to the same basename (or relative path) within
770 * directory @a dest_path.  Overwrite the destination file if it already
771 * exists.  The destination directory (including any directory
772 * components in @a name) must already exist.  Set the destination
773 * file's permissions to match those of the source.  Use @a pool for
774 * memory allocations.
775 */
776svn_error_t *
777svn_io_dir_file_copy(const char *src_path,
778                     const char *dest_path,
779                     const char *file,
780                     apr_pool_t *pool);
781
782
783/** Generic byte-streams
784 *
785 * @defgroup svn_io_byte_streams Generic byte streams
786 * @{
787 */
788
789/** An abstract stream of bytes--either incoming or outgoing or both.
790 *
791 * The creator of a stream sets functions to handle read and write.
792 * Both of these handlers accept a baton whose value is determined at
793 * stream creation time; this baton can point to a structure
794 * containing data associated with the stream.  If a caller attempts
795 * to invoke a handler which has not been set, it will generate a
796 * runtime assertion failure.  The creator can also set a handler for
797 * close requests so that it can flush buffered data or whatever;
798 * if a close handler is not specified, a close request on the stream
799 * will simply be ignored.  Note that svn_stream_close() does not
800 * deallocate the memory used to allocate the stream structure; free
801 * the pool you created the stream in to free that memory.
802 *
803 * The read and write handlers accept length arguments via pointer.
804 * On entry to the handler, the pointed-to value should be the amount
805 * of data which can be read or the amount of data to write.  When the
806 * handler returns, the value is reset to the amount of data actually
807 * read or written.  Handlers are obliged to complete a read or write
808 * to the maximum extent possible; thus, a short read with no
809 * associated error implies the end of the input stream, and a short
810 * write should never occur without an associated error.
811 *
812 * In Subversion 1.7 reset support was added as an optional feature of
813 * streams. If a stream implements resetting it allows reading the data
814 * again after a successful call to svn_stream_reset().
815 */
816typedef struct svn_stream_t svn_stream_t;
817
818
819
820/** Read handler function for a generic stream.  @see svn_stream_t. */
821typedef svn_error_t *(*svn_read_fn_t)(void *baton,
822                                      char *buffer,
823                                      apr_size_t *len);
824
825/** Skip data handler function for a generic stream.  @see svn_stream_t
826 * and svn_stream_skip().
827 * @since New in 1.7.
828 */
829typedef svn_error_t *(*svn_stream_skip_fn_t)(void *baton,
830                                             apr_size_t len);
831
832/** Write handler function for a generic stream.  @see svn_stream_t. */
833typedef svn_error_t *(*svn_write_fn_t)(void *baton,
834                                       const char *data,
835                                       apr_size_t *len);
836
837/** Close handler function for a generic stream.  @see svn_stream_t. */
838typedef svn_error_t *(*svn_close_fn_t)(void *baton);
839
840/** An opaque type which represents a mark on a stream.  There is no
841 * concrete definition of this type, it is a named type for stream
842 * implementation specific baton pointers.
843 *
844 * @see svn_stream_mark().
845 * @since New in 1.7.
846 */
847typedef struct svn_stream_mark_t svn_stream_mark_t;
848
849/** Mark handler function for a generic stream. @see svn_stream_t and
850 * svn_stream_mark().
851 *
852 * @since New in 1.7.
853 */
854typedef svn_error_t *(*svn_stream_mark_fn_t)(void *baton,
855                                         svn_stream_mark_t **mark,
856                                         apr_pool_t *pool);
857
858/** Seek handler function for a generic stream. @see svn_stream_t and
859 * svn_stream_seek().
860 *
861 * @since New in 1.7.
862 */
863typedef svn_error_t *(*svn_stream_seek_fn_t)(void *baton,
864                                         const svn_stream_mark_t *mark);
865
866/** Create a generic stream.  @see svn_stream_t. */
867svn_stream_t *
868svn_stream_create(void *baton,
869                  apr_pool_t *pool);
870
871/** Set @a stream's baton to @a baton */
872void
873svn_stream_set_baton(svn_stream_t *stream,
874                     void *baton);
875
876/** Set @a stream's read function to @a read_fn */
877void
878svn_stream_set_read(svn_stream_t *stream,
879                    svn_read_fn_t read_fn);
880
881/** Set @a stream's skip function to @a skip_fn
882 *
883 * @since New in 1.7
884 */
885void
886svn_stream_set_skip(svn_stream_t *stream,
887                    svn_stream_skip_fn_t skip_fn);
888
889/** Set @a stream's write function to @a write_fn */
890void
891svn_stream_set_write(svn_stream_t *stream,
892                     svn_write_fn_t write_fn);
893
894/** Set @a stream's close function to @a close_fn */
895void
896svn_stream_set_close(svn_stream_t *stream,
897                     svn_close_fn_t close_fn);
898
899/** Set @a stream's mark function to @a mark_fn
900 *
901 * @since New in 1.7.
902 */
903void
904svn_stream_set_mark(svn_stream_t *stream,
905                    svn_stream_mark_fn_t mark_fn);
906
907/** Set @a stream's seek function to @a seek_fn
908 *
909 * @since New in 1.7.
910 */
911void
912svn_stream_set_seek(svn_stream_t *stream,
913                    svn_stream_seek_fn_t seek_fn);
914
915/** Create a stream that is empty for reading and infinite for writing. */
916svn_stream_t *
917svn_stream_empty(apr_pool_t *pool);
918
919/** Return a stream allocated in @a pool which forwards all requests
920 * to @a stream.  Destruction is explicitly excluded from forwarding.
921 *
922 * @see http://subversion.apache.org/docs/community-guide/conventions.html#destruction-of-stacked-resources
923 *
924 * @since New in 1.4.
925 */
926svn_stream_t *
927svn_stream_disown(svn_stream_t *stream,
928                  apr_pool_t *pool);
929
930
931/** Create a stream to read the file at @a path. It will be opened using
932 * the APR_BUFFERED and APR_BINARY flag, and APR_OS_DEFAULT for the perms.
933 * If you'd like to use different values, then open the file yourself, and
934 * use the svn_stream_from_aprfile2() interface.
935 *
936 * The stream will be returned in @a stream, and allocated from @a result_pool.
937 * Temporary allocations will be performed in @a scratch_pool.
938 *
939 * @since New in 1.6
940 */
941svn_error_t *
942svn_stream_open_readonly(svn_stream_t **stream,
943                         const char *path,
944                         apr_pool_t *result_pool,
945                         apr_pool_t *scratch_pool);
946
947
948/** Create a stream to write a file at @a path. The file will be *created*
949 * using the APR_BUFFERED and APR_BINARY flag, and APR_OS_DEFAULT for the
950 * perms. The file will be created "exclusively", so if it already exists,
951 * then an error will be thrown. If you'd like to use different values, or
952 * open an existing file, then open the file yourself, and use the
953 * svn_stream_from_aprfile2() interface.
954 *
955 * The stream will be returned in @a stream, and allocated from @a result_pool.
956 * Temporary allocations will be performed in @a scratch_pool.
957 *
958 * @since New in 1.6
959 */
960svn_error_t *
961svn_stream_open_writable(svn_stream_t **stream,
962                         const char *path,
963                         apr_pool_t *result_pool,
964                         apr_pool_t *scratch_pool);
965
966
967/** Create a writable stream to a file in the directory @a dirpath.
968 * The file will have an arbitrary and unique name, and the full path
969 * will be returned in @a temp_path. The stream will be returned in
970 * @a stream. Both will be allocated from @a result_pool.
971 *
972 * If @a dirpath is @c NULL, use the path returned from svn_io_temp_dir().
973 * (Note that when using the system-provided temp directory, it may not
974 * be possible to atomically rename the resulting file due to cross-device
975 * issues.)
976 *
977 * The file will be deleted according to @a delete_when.  If that is
978 * #svn_io_file_del_on_pool_cleanup, it refers to @a result_pool.
979 *
980 * Temporary allocations will be performed in @a scratch_pool.
981 *
982 * @since New in 1.6
983 * @see svn_io_open_unique_file3()
984 */
985svn_error_t *
986svn_stream_open_unique(svn_stream_t **stream,
987                       const char **temp_path,
988                       const char *dirpath,
989                       svn_io_file_del_t delete_when,
990                       apr_pool_t *result_pool,
991                       apr_pool_t *scratch_pool);
992
993
994/** Create a stream from an APR file.  For convenience, if @a file is
995 * @c NULL, an empty stream created by svn_stream_empty() is returned.
996 *
997 * This function should normally be called with @a disown set to FALSE,
998 * in which case closing the stream will also close the underlying file.
999 *
1000 * If @a disown is TRUE, the stream will disown the underlying file,
1001 * meaning that svn_stream_close() will not close the file.
1002 *
1003 * @since New in 1.4.
1004 */
1005svn_stream_t *
1006svn_stream_from_aprfile2(apr_file_t *file,
1007                         svn_boolean_t disown,
1008                         apr_pool_t *pool);
1009
1010/** Similar to svn_stream_from_aprfile2(), except that the file will
1011 * always be disowned.
1012 *
1013 * @note The stream returned is not considered to "own" the underlying
1014 *       file, meaning that svn_stream_close() on the stream will not
1015 *       close the file.
1016 *
1017 * @deprecated Provided for backward compatibility with the 1.3 API.
1018 */
1019SVN_DEPRECATED
1020svn_stream_t *
1021svn_stream_from_aprfile(apr_file_t *file,
1022                        apr_pool_t *pool);
1023
1024/** Set @a *in to a generic stream connected to stdin, allocated in
1025 * @a pool.  The stream and its underlying APR handle will be closed
1026 * when @a pool is cleared or destroyed.
1027 *
1028 * @since New in 1.7.
1029 */
1030svn_error_t *
1031svn_stream_for_stdin(svn_stream_t **in,
1032                     apr_pool_t *pool);
1033
1034/** Set @a *err to a generic stream connected to stderr, allocated in
1035 * @a pool.  The stream and its underlying APR handle will be closed
1036 * when @a pool is cleared or destroyed.
1037 *
1038 * @since New in 1.7.
1039 */
1040svn_error_t *
1041svn_stream_for_stderr(svn_stream_t **err,
1042                      apr_pool_t *pool);
1043
1044/** Set @a *out to a generic stream connected to stdout, allocated in
1045 * @a pool.  The stream and its underlying APR handle will be closed
1046 * when @a pool is cleared or destroyed.
1047 */
1048svn_error_t *
1049svn_stream_for_stdout(svn_stream_t **out,
1050                      apr_pool_t *pool);
1051
1052/** Return a generic stream connected to stringbuf @a str.  Allocate the
1053 * stream in @a pool.
1054 */
1055svn_stream_t *
1056svn_stream_from_stringbuf(svn_stringbuf_t *str,
1057                          apr_pool_t *pool);
1058
1059/** Return a generic read-only stream connected to string @a str.
1060 *  Allocate the stream in @a pool.
1061 */
1062svn_stream_t *
1063svn_stream_from_string(const svn_string_t *str,
1064                       apr_pool_t *pool);
1065
1066/** Return a generic stream which implements buffered reads and writes.
1067 *  The stream will preferentially store data in-memory, but may use
1068 *  disk storage as backup if the amount of data is large.
1069 *  Allocate the stream in @a result_pool
1070 *
1071 * @since New in 1.8.
1072 */
1073svn_stream_t *
1074svn_stream_buffered(apr_pool_t *result_pool);
1075
1076/** Return a stream that decompresses all data read and compresses all
1077 * data written. The stream @a stream is used to read and write all
1078 * compressed data. All compression data structures are allocated on
1079 * @a pool. If compression support is not compiled in then
1080 * svn_stream_compressed() returns @a stream unmodified. Make sure you
1081 * call svn_stream_close() on the stream returned by this function,
1082 * so that all data are flushed and cleaned up.
1083 *
1084 * @note From 1.4, compression support is always compiled in.
1085 */
1086svn_stream_t *
1087svn_stream_compressed(svn_stream_t *stream,
1088                      apr_pool_t *pool);
1089
1090/** Return a stream that calculates checksums for all data read
1091 * and written.  The stream @a stream is used to read and write all data.
1092 * The stream and the resulting digests are allocated in @a pool.
1093 *
1094 * When the stream is closed, @a *read_checksum and @a *write_checksum
1095 * are set to point to the resulting checksums, of type @a read_checksum_kind
1096 * and @a write_checksum_kind, respectively.
1097 *
1098 * Both @a read_checksum and @a write_checksum can be @c NULL, in which case
1099 * the respective checksum isn't calculated.
1100 *
1101 * If @a read_all is TRUE, make sure that all data available on @a
1102 * stream is read (and checksummed) when the stream is closed.
1103 *
1104 * Read and write operations can be mixed without interfering.
1105 *
1106 * The @a stream passed into this function is closed when the created
1107 * stream is closed.
1108 *
1109 * @since New in 1.6.
1110 */
1111svn_stream_t *
1112svn_stream_checksummed2(svn_stream_t *stream,
1113                        svn_checksum_t **read_checksum,
1114                        svn_checksum_t **write_checksum,
1115                        svn_checksum_kind_t checksum_kind,
1116                        svn_boolean_t read_all,
1117                        apr_pool_t *pool);
1118
1119/**
1120 * Similar to svn_stream_checksummed2(), but always returning the MD5
1121 * checksum in @a read_digest and @a write_digest.
1122 *
1123 * @since New in 1.4.
1124 * @deprecated Provided for backward compatibility with the 1.5 API.
1125 */
1126SVN_DEPRECATED
1127svn_stream_t *
1128svn_stream_checksummed(svn_stream_t *stream,
1129                       const unsigned char **read_digest,
1130                       const unsigned char **write_digest,
1131                       svn_boolean_t read_all,
1132                       apr_pool_t *pool);
1133
1134/** Read from a generic stream. @see svn_stream_t. */
1135svn_error_t *
1136svn_stream_read(svn_stream_t *stream,
1137                char *buffer,
1138                apr_size_t *len);
1139
1140/**
1141 * Skip @a len bytes from a generic @a stream. If the stream is exhausted
1142 * before @a len bytes have been read, return an error.
1143 *
1144 * @note  No assumption can be made on the semantics of this function
1145 * other than that the stream read pointer will be advanced by *len
1146 * bytes. Depending on the capabilities of the underlying stream
1147 * implementation, this may for instance be translated into a sequence
1148 * of reads or a simple seek operation. If the stream implementation has
1149 * not provided a skip function, this will read from the stream and
1150 * discard the data.
1151 */
1152svn_error_t *
1153svn_stream_skip(svn_stream_t *stream,
1154                apr_size_t len);
1155
1156/** Write to a generic stream. @see svn_stream_t. */
1157svn_error_t *
1158svn_stream_write(svn_stream_t *stream,
1159                 const char *data,
1160                 apr_size_t *len);
1161
1162/** Close a generic stream. @see svn_stream_t. */
1163svn_error_t *
1164svn_stream_close(svn_stream_t *stream);
1165
1166/** Reset a generic stream back to its origin. (E.g. On a file this would be
1167 * implemented as a seek to position 0).  This function returns a
1168 * #SVN_ERR_STREAM_SEEK_NOT_SUPPORTED error when the stream doesn't
1169 * implement resetting.
1170 *
1171 * @since New in 1.7.
1172 */
1173svn_error_t *
1174svn_stream_reset(svn_stream_t *stream);
1175
1176/** Returns @c TRUE if the generic @a stream supports svn_stream_mark().
1177 *
1178 * @see svn_stream_mark()
1179 * @since New in 1.7.
1180 */
1181svn_boolean_t
1182svn_stream_supports_mark(svn_stream_t *stream);
1183
1184/** Set a @a mark at the current position of a generic @a stream,
1185 * which can later be sought back to using svn_stream_seek().
1186 * The @a mark is allocated in @a pool.
1187 *
1188 * This function returns the #SVN_ERR_STREAM_SEEK_NOT_SUPPORTED error
1189 * if the stream doesn't implement seeking.
1190 *
1191 * @see svn_stream_seek()
1192 * @since New in 1.7.
1193 */
1194svn_error_t *
1195svn_stream_mark(svn_stream_t *stream,
1196                svn_stream_mark_t **mark,
1197                apr_pool_t *pool);
1198
1199/** Seek to a @a mark in a generic @a stream.
1200 * This function returns the #SVN_ERR_STREAM_SEEK_NOT_SUPPORTED error
1201 * if the stream doesn't implement seeking. Passing NULL as @a mark,
1202 * seeks to the start of the stream.
1203 *
1204 * @see svn_stream_mark()
1205 * @since New in 1.7.
1206 */
1207svn_error_t *
1208svn_stream_seek(svn_stream_t *stream, const svn_stream_mark_t *mark);
1209
1210/** Return a writable stream which, when written to, writes to both of the
1211 * underlying streams.  Both of these streams will be closed upon closure of
1212 * the returned stream; use svn_stream_disown() if this is not the desired
1213 * behavior.  One or both of @a out1 and @a out2 may be @c NULL.  If both are
1214 * @c NULL, @c NULL is returned.
1215 *
1216 * @since New in 1.7.
1217 */
1218svn_stream_t *
1219svn_stream_tee(svn_stream_t *out1,
1220               svn_stream_t *out2,
1221               apr_pool_t *pool);
1222
1223/** Write NULL-terminated string @a str to @a stream.
1224 *
1225 * @since New in 1.8.
1226 *
1227 */
1228svn_error_t *
1229svn_stream_puts(svn_stream_t *stream,
1230                const char *str);
1231
1232/** Write to @a stream using a printf-style @a fmt specifier, passed through
1233 * apr_psprintf() using memory from @a pool.
1234 */
1235svn_error_t *
1236svn_stream_printf(svn_stream_t *stream,
1237                  apr_pool_t *pool,
1238                  const char *fmt,
1239                  ...)
1240       __attribute__((format(printf, 3, 4)));
1241
1242/** Write to @a stream using a printf-style @a fmt specifier, passed through
1243 * apr_psprintf() using memory from @a pool.  The resulting string
1244 * will be translated to @a encoding before it is sent to @a stream.
1245 *
1246 * @note Use @c APR_LOCALE_CHARSET to translate to the encoding of the
1247 * current locale.
1248 *
1249 * @since New in 1.3.
1250 */
1251svn_error_t *
1252svn_stream_printf_from_utf8(svn_stream_t *stream,
1253                            const char *encoding,
1254                            apr_pool_t *pool,
1255                            const char *fmt,
1256                            ...)
1257       __attribute__((format(printf, 4, 5)));
1258
1259/** Allocate @a *stringbuf in @a pool, and read into it one line (terminated
1260 * by @a eol) from @a stream. The line-terminator is read from the stream,
1261 * but is not added to the end of the stringbuf.  Instead, the stringbuf
1262 * ends with a usual '\\0'.
1263 *
1264 * If @a stream runs out of bytes before encountering a line-terminator,
1265 * then set @a *eof to @c TRUE, otherwise set @a *eof to FALSE.
1266 */
1267svn_error_t *
1268svn_stream_readline(svn_stream_t *stream,
1269                    svn_stringbuf_t **stringbuf,
1270                    const char *eol,
1271                    svn_boolean_t *eof,
1272                    apr_pool_t *pool);
1273
1274/**
1275 * Read the contents of the readable stream @a from and write them to the
1276 * writable stream @a to calling @a cancel_func before copying each chunk.
1277 *
1278 * @a cancel_func may be @c NULL.
1279 *
1280 * @note both @a from and @a to will be closed upon successful completion of
1281 * the copy (but an error may still be returned, based on trying to close
1282 * the two streams). If the closure is not desired, then you can use
1283 * svn_stream_disown() to protect either or both of the streams from
1284 * being closed.
1285 *
1286 * @since New in 1.6.
1287 */
1288svn_error_t *
1289svn_stream_copy3(svn_stream_t *from,
1290                 svn_stream_t *to,
1291                 svn_cancel_func_t cancel_func,
1292                 void *cancel_baton,
1293                 apr_pool_t *pool);
1294
1295/**
1296 * Same as svn_stream_copy3() but the streams are not closed.
1297 *
1298 * @since New in 1.5.
1299 * @deprecated Provided for backward compatibility with the 1.5 API.
1300 */
1301SVN_DEPRECATED
1302svn_error_t *
1303svn_stream_copy2(svn_stream_t *from,
1304                 svn_stream_t *to,
1305                 svn_cancel_func_t cancel_func,
1306                 void *cancel_baton,
1307                 apr_pool_t *pool);
1308
1309/**
1310 * Same as svn_stream_copy3(), but without the cancellation function
1311 * or stream closing.
1312 *
1313 * @since New in 1.1.
1314 * @deprecated Provided for backward compatibility with the 1.4 API.
1315 */
1316SVN_DEPRECATED
1317svn_error_t *
1318svn_stream_copy(svn_stream_t *from,
1319                svn_stream_t *to,
1320                apr_pool_t *pool);
1321
1322
1323/** Set @a *same to TRUE if @a stream1 and @a stream2 have the same
1324 * contents, else set it to FALSE.
1325 *
1326 * Both streams will be closed before this function returns (regardless of
1327 * the result, or any possible error).
1328 *
1329 * Use @a scratch_pool for temporary allocations.
1330 *
1331 * @since New in 1.7.
1332 */
1333svn_error_t *
1334svn_stream_contents_same2(svn_boolean_t *same,
1335                          svn_stream_t *stream1,
1336                          svn_stream_t *stream2,
1337                          apr_pool_t *pool);
1338
1339
1340/**
1341 * Same as svn_stream_contents_same2(), but the streams will not be closed.
1342 *
1343 * @since New in 1.4.
1344 * @deprecated Provided for backward compatibility with the 1.6 API.
1345 */
1346SVN_DEPRECATED
1347svn_error_t *
1348svn_stream_contents_same(svn_boolean_t *same,
1349                         svn_stream_t *stream1,
1350                         svn_stream_t *stream2,
1351                         apr_pool_t *pool);
1352
1353
1354/** Read the contents of @a stream into memory, returning the data in
1355 * @a result. The stream will be closed when it has been successfully and
1356 * completely read.
1357 *
1358 * The returned memory is allocated in @a result_pool, and any temporary
1359 * allocations are performed in @a scratch_pool.
1360 *
1361 * @note due to memory pseudo-reallocation behavior (due to pools), this
1362 *   can be a memory-intensive operation for large files.
1363 *
1364 * @since New in 1.6
1365 */
1366svn_error_t *
1367svn_string_from_stream(svn_string_t **result,
1368                       svn_stream_t *stream,
1369                       apr_pool_t *result_pool,
1370                       apr_pool_t *scratch_pool);
1371
1372
1373/** A function type provided for use as a callback from
1374 * @c svn_stream_lazyopen_create().
1375 *
1376 * The callback function shall open a new stream and set @a *stream to
1377 * the stream object, allocated in @a result_pool.  @a baton is the
1378 * callback baton that was passed to svn_stream_lazyopen_create().
1379 *
1380 * @a result_pool is the result pool that was passed to
1381 * svn_stream_lazyopen_create().  The callback function may use
1382 * @a scratch_pool for temporary allocations; the caller may clear or
1383 * destroy @a scratch_pool any time after the function returns.
1384 *
1385 * @since New in 1.8.
1386 */
1387typedef svn_error_t *
1388(*svn_stream_lazyopen_func_t)(svn_stream_t **stream,
1389                              void *baton,
1390                              apr_pool_t *result_pool,
1391                              apr_pool_t *scratch_pool);
1392
1393
1394/** Return a generic stream which wraps another primary stream,
1395 * delaying the "opening" of that stream until the first time the
1396 * returned stream is accessed.
1397 *
1398 * @a open_func and @a open_baton are a callback function/baton pair
1399 * which will be invoked upon the first access of the returned
1400 * stream (read, write, mark, seek, skip, or possibly close).  The
1401 * callback shall open the primary stream.
1402 *
1403 * If the only "access" the returned stream gets is to close it
1404 * then @a open_func will only be called if @a open_on_close is TRUE.
1405 *
1406 * @since New in 1.8.
1407 */
1408svn_stream_t *
1409svn_stream_lazyopen_create(svn_stream_lazyopen_func_t open_func,
1410                           void *open_baton,
1411                           svn_boolean_t open_on_close,
1412                           apr_pool_t *result_pool);
1413
1414/** @} */
1415
1416/** Set @a *result to a string containing the contents of @a
1417 * filename, which is either "-" (indicating that stdin should be
1418 * read) or the utf8-encoded path of a real file.
1419 *
1420 * @warning Callers should be aware of possible unexpected results
1421 * when using this function to read from stdin where additional
1422 * stdin-reading processes abound.  For example, if a program tries
1423 * both to invoke an external editor and to read from stdin, stdin
1424 * could be trashed and the editor might act funky or die outright.
1425 *
1426 * @note due to memory pseudo-reallocation behavior (due to pools), this
1427 *   can be a memory-intensive operation for large files.
1428 *
1429 * @since New in 1.5.
1430 */
1431svn_error_t *
1432svn_stringbuf_from_file2(svn_stringbuf_t **result,
1433                         const char *filename,
1434                         apr_pool_t *pool);
1435
1436/** Similar to svn_stringbuf_from_file2(), except that if @a filename
1437 * is "-", return the error #SVN_ERR_UNSUPPORTED_FEATURE and don't
1438 * touch @a *result.
1439 *
1440 * @deprecated Provided for backwards compatibility with the 1.4 API.
1441 */
1442SVN_DEPRECATED
1443svn_error_t *
1444svn_stringbuf_from_file(svn_stringbuf_t **result,
1445                        const char *filename,
1446                        apr_pool_t *pool);
1447
1448/** Sets @a *result to a string containing the contents of the already opened
1449 * @a file.  Reads from the current position in file to the end.  Does not
1450 * close the file or reset the cursor position.
1451 *
1452 * @note due to memory pseudo-reallocation behavior (due to pools), this
1453 *   can be a memory-intensive operation for large files.
1454 */
1455svn_error_t *
1456svn_stringbuf_from_aprfile(svn_stringbuf_t **result,
1457                           apr_file_t *file,
1458                           apr_pool_t *pool);
1459
1460/** Remove file @a path, a utf8-encoded path.  This wraps apr_file_remove(),
1461 * converting any error to a Subversion error. If @a ignore_enoent is TRUE, and
1462 * the file is not present (APR_STATUS_IS_ENOENT returns TRUE), then no
1463 * error will be returned.
1464 *
1465 * The file will be removed even if it is not writable.  (On Windows and
1466 * OS/2, this function first clears the file's read-only bit.)
1467 *
1468 * @since New in 1.7.
1469 */
1470svn_error_t *
1471svn_io_remove_file2(const char *path,
1472                    svn_boolean_t ignore_enoent,
1473                    apr_pool_t *scratch_pool);
1474
1475/** Similar to svn_io_remove_file2(), except with @a ignore_enoent set to FALSE.
1476 *
1477 * @deprecated Provided for backwards compatibility with the 1.6 API.
1478 */
1479SVN_DEPRECATED
1480svn_error_t *
1481svn_io_remove_file(const char *path,
1482                   apr_pool_t *pool);
1483
1484/** Recursively remove directory @a path.  @a path is utf8-encoded.
1485 * If @a ignore_enoent is @c TRUE, don't fail if the target directory
1486 * doesn't exist.  Use @a pool for temporary allocations.
1487 *
1488 * Because recursive delete of a directory tree can be a lengthy operation,
1489 * provide @a cancel_func and @a cancel_baton for interruptibility.
1490 *
1491 * @since New in 1.5.
1492 */
1493svn_error_t *
1494svn_io_remove_dir2(const char *path,
1495                   svn_boolean_t ignore_enoent,
1496                   svn_cancel_func_t cancel_func,
1497                   void *cancel_baton,
1498                   apr_pool_t *pool);
1499
1500/** Similar to svn_io_remove_dir2(), but with @a ignore_enoent set to
1501 * @c FALSE and @a cancel_func and @a cancel_baton set to @c NULL.
1502 *
1503 * @deprecated Provided for backward compatibility with the 1.4 API
1504 */
1505SVN_DEPRECATED
1506svn_error_t *
1507svn_io_remove_dir(const char *path,
1508                  apr_pool_t *pool);
1509
1510/** Read all of the disk entries in directory @a path, a utf8-encoded
1511 * path.  Set @a *dirents to a hash mapping dirent names (<tt>char *</tt>) to
1512 * undefined non-NULL values, allocated in @a pool.
1513 *
1514 * @note The `.' and `..' directories normally returned by
1515 * apr_dir_read() are NOT returned in the hash.
1516 *
1517 * @since New in 1.4.
1518 * @deprecated Provided for backward compatibility with the 1.6 API.
1519 */
1520SVN_DEPRECATED
1521svn_error_t *
1522svn_io_get_dir_filenames(apr_hash_t **dirents,
1523                         const char *path,
1524                         apr_pool_t *pool);
1525
1526/** Read all of the disk entries in directory @a path, a utf8-encoded
1527 * path.  Set @a *dirents to a hash mapping dirent names (<tt>char *</tt>) to
1528 * #svn_io_dirent2_t structures, allocated in @a pool.
1529 *
1530 * If @a only_check_type is set to @c TRUE, only the kind and special
1531 * fields of the svn_io_dirent2_t are filled.
1532 *
1533 * @note The `.' and `..' directories normally returned by
1534 * apr_dir_read() are NOT returned in the hash.
1535 *
1536 * @note The kind field in the @a dirents is set according to the mapping
1537 *       as documented for svn_io_check_path().
1538 *
1539 * @since New in 1.7.
1540 */
1541svn_error_t *
1542svn_io_get_dirents3(apr_hash_t **dirents,
1543                    const char *path,
1544                    svn_boolean_t only_check_type,
1545                    apr_pool_t *result_pool,
1546                    apr_pool_t *scratch_pool);
1547
1548
1549/** Similar to svn_io_get_dirents3, but returns a mapping to svn_io_dirent_t
1550 * structures instead of svn_io_dirent2_t and with only a single pool.
1551 *
1552 * @since New in 1.3.
1553 * @deprecated Provided for backward compatibility with the 1.6 API.
1554 */
1555SVN_DEPRECATED
1556svn_error_t *
1557svn_io_get_dirents2(apr_hash_t **dirents,
1558                    const char *path,
1559                    apr_pool_t *pool);
1560
1561/** Similar to svn_io_get_dirents2(), but @a *dirents is a hash table
1562 * with #svn_node_kind_t values.
1563 *
1564 * @deprecated Provided for backwards compatibility with the 1.2 API.
1565 */
1566SVN_DEPRECATED
1567svn_error_t *
1568svn_io_get_dirents(apr_hash_t **dirents,
1569                   const char *path,
1570                   apr_pool_t *pool);
1571
1572/** Create a svn_io_dirent2_t instance for path. Specialized variant of
1573 * svn_io_stat() that directly translates node_kind and special.
1574 *
1575 * If @a verify_truename is @c TRUE, an additional check is performed to
1576 * verify the truename of the last path component on case insensitive
1577 * filesystems. This check is expensive compared to a just a stat,
1578 * but certainly cheaper than a full truename calculation using
1579 * apr_filepath_merge() which verifies all path components.
1580 *
1581 * If @a ignore_enoent is set to @c TRUE, set *dirent_p->kind to
1582 * svn_node_none instead of returning an error.
1583 *
1584 * @since New in 1.8.
1585 */
1586svn_error_t *
1587svn_io_stat_dirent2(const svn_io_dirent2_t **dirent_p,
1588                    const char *path,
1589                    svn_boolean_t verify_truename,
1590                    svn_boolean_t ignore_enoent,
1591                    apr_pool_t *result_pool,
1592                    apr_pool_t *scratch_pool);
1593
1594
1595/** Similar to svn_io_stat_dirent2(), but always passes FALSE for
1596 * @a verify_truename.
1597 *
1598 * @since New in 1.7.
1599 * @deprecated Provided for backwards compatibility with the 1.7 API.
1600 */
1601SVN_DEPRECATED
1602svn_error_t *
1603svn_io_stat_dirent(const svn_io_dirent2_t **dirent_p,
1604                   const char *path,
1605                   svn_boolean_t ignore_enoent,
1606                   apr_pool_t *result_pool,
1607                   apr_pool_t *scratch_pool);
1608
1609
1610/** Callback function type for svn_io_dir_walk() */
1611typedef svn_error_t * (*svn_io_walk_func_t)(void *baton,
1612                                            const char *path,
1613                                            const apr_finfo_t *finfo,
1614                                            apr_pool_t *pool);
1615
1616/** Recursively walk the directory rooted at @a dirname, a
1617 * utf8-encoded path, invoking @a walk_func (with @a walk_baton) for
1618 * each item in the tree.  For a given directory, invoke @a walk_func
1619 * on the directory itself before invoking it on any children thereof.
1620 *
1621 * Deliver to @a walk_func the information specified by @a wanted,
1622 * which is a combination of @c APR_FINFO_* flags, plus the
1623 * information specified by @c APR_FINFO_TYPE and @c APR_FINFO_NAME.
1624 *
1625 * Use @a pool for all allocations.
1626 *
1627 * @note This function does not currently pass all file types to @a
1628 * walk_func -- only APR_DIR, APR_REG, and APR_LNK.  We reserve the
1629 * right to pass additional file types through this interface in the
1630 * future, though, so implementations of this callback should
1631 * explicitly test FINFO->filetype.  See the APR library's
1632 * apr_filetype_e enum for the various filetypes and their meanings.
1633 *
1634 * @since New in 1.7.
1635 */
1636svn_error_t *
1637svn_io_dir_walk2(const char *dirname,
1638                 apr_int32_t wanted,
1639                 svn_io_walk_func_t walk_func,
1640                 void *walk_baton,
1641                 apr_pool_t *pool);
1642
1643/** Similar to svn_io_dir_walk(), but only calls @a walk_func for
1644 * files of type APR_DIR (directory) and APR_REG (regular file).
1645 *
1646 * @deprecated Provided for backwards compatibility with the 1.6 API.
1647 */
1648SVN_DEPRECATED
1649svn_error_t *
1650svn_io_dir_walk(const char *dirname,
1651                apr_int32_t wanted,
1652                svn_io_walk_func_t walk_func,
1653                void *walk_baton,
1654                apr_pool_t *pool);
1655
1656/**
1657 * Start @a cmd with @a args, using utf8-encoded @a path as working
1658 * directory.  Return the process handle for the invoked program in @a
1659 * *cmd_proc.
1660 *
1661 * If @a infile_pipe is TRUE, connect @a cmd's stdin to a pipe;
1662 * otherwise, connect it to @a infile (which may be NULL).  If
1663 * @a outfile_pipe is TRUE, connect @a cmd's stdout to a pipe; otherwise,
1664 * connect it to @a outfile (which may be NULL).  If @a errfile_pipe
1665 * is TRUE, connect @a cmd's stderr to a pipe; otherwise, connect it
1666 * to @a errfile (which may be NULL).  (Callers must pass FALSE for
1667 * each of these boolean values for which the corresponding file
1668 * handle is non-NULL.)
1669 *
1670 * @a args is a list of utf8-encoded <tt>const char *</tt> arguments,
1671 * terminated by @c NULL.  @a args[0] is the name of the program, though it
1672 * need not be the same as @a cmd.
1673 *
1674 * If @a inherit is TRUE, the invoked program inherits its environment from
1675 * the caller and @a cmd, if not absolute, is searched for in PATH.
1676 *
1677 * If @a inherit is FALSE @a cmd must be an absolute path and the invoked
1678 * program inherits the environment defined by @a env or runs with an empty
1679 * environment in @a env is NULL.
1680 *
1681 * @note On some platforms, failure to execute @a cmd in the child process
1682 * will result in error output being written to @a errfile, if non-NULL, and
1683 * a non-zero exit status being returned to the parent process.
1684 *
1685 * @note An APR bug affects Windows: passing a NULL @a env does not
1686 * guarantee the invoked program to run with an empty environment when
1687 * @a inherit is FALSE, the program may inherit its parent's environment.
1688 * Explicitly pass an empty @a env to get an empty environment.
1689 *
1690 * @since New in 1.8.
1691 */
1692svn_error_t *svn_io_start_cmd3(apr_proc_t *cmd_proc,
1693                               const char *path,
1694                               const char *cmd,
1695                               const char *const *args,
1696                               const char *const *env,
1697                               svn_boolean_t inherit,
1698                               svn_boolean_t infile_pipe,
1699                               apr_file_t *infile,
1700                               svn_boolean_t outfile_pipe,
1701                               apr_file_t *outfile,
1702                               svn_boolean_t errfile_pipe,
1703                               apr_file_t *errfile,
1704                               apr_pool_t *pool);
1705
1706
1707/**
1708 * Similar to svn_io_start_cmd3() but with @a env always set to NULL.
1709 *
1710 * @deprecated Provided for backward compatibility with the 1.7 API
1711 * @since New in 1.7.
1712 */
1713SVN_DEPRECATED
1714svn_error_t *svn_io_start_cmd2(apr_proc_t *cmd_proc,
1715                               const char *path,
1716                               const char *cmd,
1717                               const char *const *args,
1718                               svn_boolean_t inherit,
1719                               svn_boolean_t infile_pipe,
1720                               apr_file_t *infile,
1721                               svn_boolean_t outfile_pipe,
1722                               apr_file_t *outfile,
1723                               svn_boolean_t errfile_pipe,
1724                               apr_file_t *errfile,
1725                               apr_pool_t *pool);
1726
1727/**
1728 * Similar to svn_io_start_cmd2() but with @a infile_pipe, @a
1729 * outfile_pipe, and @a errfile_pipe always FALSE.
1730 *
1731 * @deprecated Provided for backward compatibility with the 1.6 API
1732 * @since New in 1.3.
1733 */
1734SVN_DEPRECATED
1735svn_error_t *
1736svn_io_start_cmd(apr_proc_t *cmd_proc,
1737                 const char *path,
1738                 const char *cmd,
1739                 const char *const *args,
1740                 svn_boolean_t inherit,
1741                 apr_file_t *infile,
1742                 apr_file_t *outfile,
1743                 apr_file_t *errfile,
1744                 apr_pool_t *pool);
1745
1746/**
1747 * Wait for the process @a *cmd_proc to complete and optionally retrieve
1748 * its exit code.  @a cmd is used only in error messages.
1749 *
1750 * If @a exitcode is not NULL, set @a *exitcode to the exit code of the
1751 * process and do not consider any exit code to be an error.  If @a exitcode
1752 * is NULL, then if the exit code of the process is non-zero then return an
1753 * #SVN_ERR_EXTERNAL_PROGRAM error.
1754 *
1755 * If @a exitwhy is not NULL, set @a *exitwhy to indicate why the process
1756 * terminated and do not consider any reason to be an error.  If @a exitwhy
1757 * is NULL, then if the termination reason is not @c APR_PROC_CHECK_EXIT()
1758 * then return an #SVN_ERR_EXTERNAL_PROGRAM error.
1759 *
1760 * @since New in 1.3.
1761 */
1762svn_error_t *
1763svn_io_wait_for_cmd(apr_proc_t *cmd_proc,
1764                    const char *cmd,
1765                    int *exitcode,
1766                    apr_exit_why_e *exitwhy,
1767                    apr_pool_t *pool);
1768
1769/** Run a command to completion, by first calling svn_io_start_cmd() and
1770 * then calling svn_io_wait_for_cmd().  The parameters correspond to
1771 * the same-named parameters of those two functions.
1772 */
1773svn_error_t *
1774svn_io_run_cmd(const char *path,
1775               const char *cmd,
1776               const char *const *args,
1777               int *exitcode,
1778               apr_exit_why_e *exitwhy,
1779               svn_boolean_t inherit,
1780               apr_file_t *infile,
1781               apr_file_t *outfile,
1782               apr_file_t *errfile,
1783               apr_pool_t *pool);
1784
1785/** Invoke the configured @c diff program, with @a user_args (an array
1786 * of utf8-encoded @a num_user_args arguments) if they are specified
1787 * (that is, if @a user_args is non-NULL), or "-u" if they are not.
1788 * If @a user_args is NULL, the value of @a num_user_args is ignored.
1789 *
1790 * Diff runs in utf8-encoded @a dir, and its exit status is stored in
1791 * @a exitcode, if it is not @c NULL.
1792 *
1793 * If @a label1 and/or @a label2 are not NULL they will be passed to the diff
1794 * process as the arguments of "-L" options.  @a label1 and @a label2 are also
1795 * in utf8, and will be converted to native charset along with the other args.
1796 *
1797 * @a from is the first file passed to diff, and @a to is the second.  The
1798 * stdout of diff will be sent to @a outfile, and the stderr to @a errfile.
1799 *
1800 * @a diff_cmd must be non-NULL.
1801 *
1802 * Do all allocation in @a pool.
1803 * @since New in 1.6.0.
1804 */
1805svn_error_t *
1806svn_io_run_diff2(const char *dir,
1807                 const char *const *user_args,
1808                 int num_user_args,
1809                 const char *label1,
1810                 const char *label2,
1811                 const char *from,
1812                 const char *to,
1813                 int *exitcode,
1814                 apr_file_t *outfile,
1815                 apr_file_t *errfile,
1816                 const char *diff_cmd,
1817                 apr_pool_t *pool);
1818
1819/** Similar to svn_io_run_diff2() but with @a diff_cmd encoded in internal
1820 * encoding used by APR.
1821 *
1822 * @deprecated Provided for backwards compatibility with the 1.5 API. */
1823SVN_DEPRECATED
1824svn_error_t *
1825svn_io_run_diff(const char *dir,
1826                const char *const *user_args,
1827                int num_user_args,
1828                const char *label1,
1829                const char *label2,
1830                const char *from,
1831                const char *to,
1832                int *exitcode,
1833                apr_file_t *outfile,
1834                apr_file_t *errfile,
1835                const char *diff_cmd,
1836                apr_pool_t *pool);
1837
1838
1839
1840/** Invoke the configured @c diff3 program, in utf8-encoded @a dir
1841 * like this:
1842 *
1843 *          diff3 -E -m @a mine @a older @a yours > @a merged
1844 *
1845 * (See the diff3 documentation for details.)
1846 *
1847 * If @a user_args is non-NULL, replace "-E" with the <tt>const char*</tt>
1848 * elements that @a user_args contains.
1849 *
1850 * @a mine, @a older and @a yours are utf8-encoded paths (relative to
1851 * @a dir or absolute) to three files that already exist.
1852 *
1853 * @a merged is an open file handle, and is left open after the merge
1854 * result is written to it. (@a merged should *not* be the same file
1855 * as @a mine, or nondeterministic things may happen!)
1856 *
1857 * @a mine_label, @a older_label, @a yours_label are utf8-encoded label
1858 * parameters for diff3's -L option.  Any of them may be @c NULL, in
1859 * which case the corresponding @a mine, @a older, or @a yours parameter is
1860 * used instead.
1861 *
1862 * Set @a *exitcode to diff3's exit status.  If @a *exitcode is anything
1863 * other than 0 or 1, then return #SVN_ERR_EXTERNAL_PROGRAM.  (Note the
1864 * following from the diff3 info pages: "An exit status of 0 means
1865 * `diff3' was successful, 1 means some conflicts were found, and 2
1866 * means trouble.")
1867 *
1868 * @a diff3_cmd must be non-NULL.
1869 *
1870 * Do all allocation in @a pool.
1871 *
1872 * @since New in 1.4.
1873 */
1874svn_error_t *
1875svn_io_run_diff3_3(int *exitcode,
1876                   const char *dir,
1877                   const char *mine,
1878                   const char *older,
1879                   const char *yours,
1880                   const char *mine_label,
1881                   const char *older_label,
1882                   const char *yours_label,
1883                   apr_file_t *merged,
1884                   const char *diff3_cmd,
1885                   const apr_array_header_t *user_args,
1886                   apr_pool_t *pool);
1887
1888/** Similar to svn_io_run_diff3_3(), but with @a diff3_cmd encoded in
1889 * internal encoding used by APR.
1890 *
1891 * @deprecated Provided for backwards compatibility with the 1.5 API.
1892 * @since New in 1.4.
1893 */
1894SVN_DEPRECATED
1895svn_error_t *
1896svn_io_run_diff3_2(int *exitcode,
1897                   const char *dir,
1898                   const char *mine,
1899                   const char *older,
1900                   const char *yours,
1901                   const char *mine_label,
1902                   const char *older_label,
1903                   const char *yours_label,
1904                   apr_file_t *merged,
1905                   const char *diff3_cmd,
1906                   const apr_array_header_t *user_args,
1907                   apr_pool_t *pool);
1908
1909/** Similar to svn_io_run_diff3_2(), but with @a user_args set to @c NULL.
1910 *
1911 * @deprecated Provided for backwards compatibility with the 1.3 API.
1912 */
1913SVN_DEPRECATED
1914svn_error_t *
1915svn_io_run_diff3(const char *dir,
1916                 const char *mine,
1917                 const char *older,
1918                 const char *yours,
1919                 const char *mine_label,
1920                 const char *older_label,
1921                 const char *yours_label,
1922                 apr_file_t *merged,
1923                 int *exitcode,
1924                 const char *diff3_cmd,
1925                 apr_pool_t *pool);
1926
1927
1928/** Parse utf8-encoded @a mimetypes_file as a MIME types file (such as
1929 * is provided with Apache HTTP Server), and set @a *type_map to a
1930 * hash mapping <tt>const char *</tt> filename extensions to
1931 * <tt>const char *</tt> MIME types.
1932 *
1933 * @since New in 1.5.
1934 */
1935svn_error_t *
1936svn_io_parse_mimetypes_file(apr_hash_t **type_map,
1937                            const char *mimetypes_file,
1938                            apr_pool_t *pool);
1939
1940
1941/** Examine utf8-encoded @a file to determine if it can be described by a
1942 * known (as in, known by this function) Multipurpose Internet Mail
1943 * Extension (MIME) type.  If so, set @a *mimetype to a character string
1944 * describing the MIME type, else set it to @c NULL.
1945 *
1946 * If not @c NULL, @a mimetype_map is a hash mapping <tt>const char *</tt>
1947 * filename extensions to <tt>const char *</tt> MIME types, and is the
1948 * first source consulted regarding @a file's MIME type.
1949 *
1950 * Use @a pool for any necessary allocations.
1951 *
1952 * @since New in 1.5.
1953 */
1954svn_error_t *
1955svn_io_detect_mimetype2(const char **mimetype,
1956                        const char *file,
1957                        apr_hash_t *mimetype_map,
1958                        apr_pool_t *pool);
1959
1960
1961/** Like svn_io_detect_mimetype2, but with @a mimetypes_map set to
1962 * @c NULL.
1963 *
1964 * @deprecated Provided for backward compatibility with the 1.4 API
1965 */
1966SVN_DEPRECATED
1967svn_error_t *
1968svn_io_detect_mimetype(const char **mimetype,
1969                       const char *file,
1970                       apr_pool_t *pool);
1971
1972
1973/** Examine up to @a len bytes of data in @a buf to determine if the
1974 * can be considered binary data, in which case return TRUE.
1975 * If the data can be considered plain-text data, return FALSE.
1976 *
1977 * @since New in 1.7.
1978 */
1979svn_boolean_t
1980svn_io_is_binary_data(const void *buf, apr_size_t len);
1981
1982
1983/** Wrapper for apr_file_open().  @a fname is utf8-encoded.
1984    Always passed flag | APR_BINARY to apr. */
1985svn_error_t *
1986svn_io_file_open(apr_file_t **new_file,
1987                 const char *fname,
1988                 apr_int32_t flag,
1989                 apr_fileperms_t perm,
1990                 apr_pool_t *pool);
1991
1992
1993/** Wrapper for apr_file_close(). */
1994svn_error_t *
1995svn_io_file_close(apr_file_t *file,
1996                  apr_pool_t *pool);
1997
1998
1999/** Wrapper for apr_file_getc(). */
2000svn_error_t *
2001svn_io_file_getc(char *ch,
2002                 apr_file_t *file,
2003                 apr_pool_t *pool);
2004
2005
2006/** Wrapper for apr_file_putc().
2007  * @since New in 1.7
2008  */
2009svn_error_t *
2010svn_io_file_putc(char ch,
2011                 apr_file_t *file,
2012                 apr_pool_t *pool);
2013
2014
2015/** Wrapper for apr_file_info_get(). */
2016svn_error_t *
2017svn_io_file_info_get(apr_finfo_t *finfo,
2018                     apr_int32_t wanted,
2019                     apr_file_t *file,
2020                     apr_pool_t *pool);
2021
2022
2023/** Wrapper for apr_file_read(). */
2024svn_error_t *
2025svn_io_file_read(apr_file_t *file,
2026                 void *buf,
2027                 apr_size_t *nbytes,
2028                 apr_pool_t *pool);
2029
2030
2031/** Wrapper for apr_file_read_full().
2032 *
2033 * If @a hit_eof is not NULL, EOF will be indicated there and no
2034 * svn_error_t error object will be created upon EOF.
2035 *
2036 * @since New in 1.7
2037 */
2038svn_error_t *
2039svn_io_file_read_full2(apr_file_t *file,
2040                       void *buf,
2041                       apr_size_t nbytes,
2042                       apr_size_t *bytes_read,
2043                       svn_boolean_t *hit_eof,
2044                       apr_pool_t *pool);
2045
2046
2047/** Similar to svn_io_file_read_full2 with hit_eof being set
2048 * to @c NULL.
2049 *
2050 * @deprecated Provided for backward compatibility with the 1.6 API
2051 */
2052SVN_DEPRECATED
2053svn_error_t *
2054svn_io_file_read_full(apr_file_t *file,
2055                      void *buf,
2056                      apr_size_t nbytes,
2057                      apr_size_t *bytes_read,
2058                      apr_pool_t *pool);
2059
2060
2061/** Wrapper for apr_file_seek(). */
2062svn_error_t *
2063svn_io_file_seek(apr_file_t *file,
2064                 apr_seek_where_t where,
2065                 apr_off_t *offset,
2066                 apr_pool_t *pool);
2067
2068
2069/** Wrapper for apr_file_write(). */
2070svn_error_t *
2071svn_io_file_write(apr_file_t *file,
2072                  const void *buf,
2073                  apr_size_t *nbytes,
2074                  apr_pool_t *pool);
2075
2076
2077/** Wrapper for apr_file_write_full(). */
2078svn_error_t *
2079svn_io_file_write_full(apr_file_t *file,
2080                       const void *buf,
2081                       apr_size_t nbytes,
2082                       apr_size_t *bytes_written,
2083                       apr_pool_t *pool);
2084
2085/**
2086 * Open a unique file in @a dirpath, and write @a nbytes from @a buf to
2087 * the file before flushing it to disk and closing it.  Return the name
2088 * of the newly created file in @a *tmp_path, allocated in @a pool.
2089 *
2090 * If @a dirpath is @c NULL, use the path returned from svn_io_temp_dir().
2091 * (Note that when using the system-provided temp directory, it may not
2092 * be possible to atomically rename the resulting file due to cross-device
2093 * issues.)
2094 *
2095 * The file will be deleted according to @a delete_when.
2096 *
2097 * @since New in 1.6.
2098 */
2099svn_error_t *
2100svn_io_write_unique(const char **tmp_path,
2101                    const char *dirpath,
2102                    const void *buf,
2103                    apr_size_t nbytes,
2104                    svn_io_file_del_t delete_when,
2105                    apr_pool_t *pool);
2106
2107/** Wrapper for apr_file_trunc().
2108  * @since New in 1.6. */
2109svn_error_t *
2110svn_io_file_trunc(apr_file_t *file,
2111                  apr_off_t offset,
2112                  apr_pool_t *pool);
2113
2114
2115/** Wrapper for apr_stat().  @a fname is utf8-encoded. */
2116svn_error_t *
2117svn_io_stat(apr_finfo_t *finfo,
2118            const char *fname,
2119            apr_int32_t wanted,
2120            apr_pool_t *pool);
2121
2122
2123/** Rename and/or move the node (not necessarily a regular file) at
2124 * @a from_path to a new path @a to_path within the same filesystem.
2125 * In some cases, an existing node at @a to_path will be overwritten.
2126 *
2127 * A wrapper for apr_file_rename().  @a from_path and @a to_path are
2128 * utf8-encoded.
2129 */
2130svn_error_t *
2131svn_io_file_rename(const char *from_path,
2132                   const char *to_path,
2133                   apr_pool_t *pool);
2134
2135
2136/** Move the file from @a from_path to @a to_path, even across device
2137 * boundaries. Overwrite @a to_path if it exists.
2138 *
2139 * @note This function is different from svn_io_file_rename in that the
2140 * latter fails in the 'across device boundaries' case.
2141 *
2142 * @since New in 1.3.
2143 */
2144svn_error_t *
2145svn_io_file_move(const char *from_path,
2146                 const char *to_path,
2147                 apr_pool_t *pool);
2148
2149
2150/** Wrapper for apr_dir_make().  @a path is utf8-encoded. */
2151svn_error_t *
2152svn_io_dir_make(const char *path,
2153                apr_fileperms_t perm,
2154                apr_pool_t *pool);
2155
2156/** Same as svn_io_dir_make(), but sets the hidden attribute on the
2157    directory on systems that support it. */
2158svn_error_t *
2159svn_io_dir_make_hidden(const char *path,
2160                       apr_fileperms_t perm,
2161                       apr_pool_t *pool);
2162
2163/**
2164 * Same as svn_io_dir_make(), but attempts to set the sgid on the
2165 * directory on systems that support it.  Does not return an error if
2166 * the attempt to set the sgid bit fails.  On Unix filesystems,
2167 * setting the sgid bit on a directory ensures that files and
2168 * subdirectories created within inherit group ownership from the
2169 * parent instead of from the primary gid.
2170 *
2171 * @since New in 1.1.
2172 */
2173svn_error_t *
2174svn_io_dir_make_sgid(const char *path,
2175                     apr_fileperms_t perm,
2176                     apr_pool_t *pool);
2177
2178/** Wrapper for apr_dir_open().  @a dirname is utf8-encoded. */
2179svn_error_t *
2180svn_io_dir_open(apr_dir_t **new_dir,
2181                const char *dirname,
2182                apr_pool_t *pool);
2183
2184/** Wrapper for apr_dir_close().
2185 *
2186 * @since New in 1.7.
2187 */
2188svn_error_t *
2189svn_io_dir_close(apr_dir_t *thedir);
2190
2191/** Wrapper for apr_dir_remove().  @a dirname is utf8-encoded.
2192 * @note This function has this name to avoid confusion with
2193 * svn_io_remove_dir2(), which is recursive.
2194 */
2195svn_error_t *
2196svn_io_dir_remove_nonrecursive(const char *dirname,
2197                               apr_pool_t *pool);
2198
2199
2200/** Wrapper for apr_dir_read().  Ensures that @a finfo->name is
2201 * utf8-encoded, which means allocating @a finfo->name in @a pool,
2202 * which may or may not be the same as @a finfo's pool.  Use @a pool
2203 * for error allocation as well.
2204 */
2205svn_error_t *
2206svn_io_dir_read(apr_finfo_t *finfo,
2207                apr_int32_t wanted,
2208                apr_dir_t *thedir,
2209                apr_pool_t *pool);
2210
2211/** Wrapper for apr_file_name_get().  @a *filename is utf8-encoded.
2212 *
2213 * @note The file name may be NULL.
2214 *
2215 * @since New in 1.7. */
2216svn_error_t *
2217svn_io_file_name_get(const char **filename,
2218                     apr_file_t *file,
2219                     apr_pool_t *pool);
2220
2221
2222
2223/** Version/format files.
2224 *
2225 * @defgroup svn_io_format_files Version/format files
2226 * @{
2227 */
2228
2229/** Set @a *version to the integer that starts the file at @a path.  If the
2230 * file does not begin with a series of digits followed by a newline,
2231 * return the error #SVN_ERR_BAD_VERSION_FILE_FORMAT.  Use @a pool for
2232 * all allocations.
2233 */
2234svn_error_t *
2235svn_io_read_version_file(int *version,
2236                         const char *path,
2237                         apr_pool_t *pool);
2238
2239/** Create (or overwrite) the file at @a path with new contents,
2240 * formatted as a non-negative integer @a version followed by a single
2241 * newline.  On successful completion the file will be read-only.  Use
2242 * @a pool for all allocations.
2243 */
2244svn_error_t *
2245svn_io_write_version_file(const char *path,
2246                          int version,
2247                          apr_pool_t *pool);
2248
2249/** Read a line of text from a file, up to a specified length.
2250 *
2251 * Allocate @a *stringbuf in @a result_pool, and read into it one line
2252 * from @a file. Reading stops either after a line-terminator was found
2253 * or after @a max_len bytes have been read.
2254 *
2255 * If end-of-file is reached or @a max_len bytes have been read, and @a eof
2256 * is not NULL, then set @a *eof to @c TRUE.
2257 *
2258 * The line-terminator is not stored in @a *stringbuf.
2259 * The line-terminator is detected automatically and stored in @a *eol
2260 * if @a eol is not NULL. If EOF is reached and @a file does not end
2261 * with a newline character, and @a eol is not NULL, @ *eol is set to NULL.
2262 *
2263 * @a scratch_pool is used for temporary allocations.
2264 *
2265 * Hint: To read all data until a line-terminator is hit, pass APR_SIZE_MAX
2266 * for @a max_len.
2267 *
2268 * @since New in 1.8.
2269 */
2270svn_error_t *
2271svn_io_file_readline(apr_file_t *file,
2272                     svn_stringbuf_t **stringbuf,
2273                     const char **eol,
2274                     svn_boolean_t *eof,
2275                     apr_size_t max_len,
2276                     apr_pool_t *result_pool,
2277                     apr_pool_t *scratch_pool);
2278
2279/** @} */
2280
2281#ifdef __cplusplus
2282}
2283#endif /* __cplusplus */
2284
2285#endif /* SVN_IO_H */
2286