OSDN Git Service

Update TortoiseUDiff to version 16491
[tortoisegit/TortoiseGitJp.git] / src / TortoiseMerge / svninclude / svn_io.h
1 /**\r
2  * @copyright\r
3  * ====================================================================\r
4  * Copyright (c) 2000-2008 CollabNet.  All rights reserved.\r
5  *\r
6  * This software is licensed as described in the file COPYING, which\r
7  * you should have received as part of this distribution.  The terms\r
8  * are also available at http://subversion.tigris.org/license-1.html.\r
9  * If newer versions of this license are posted there, you may use a\r
10  * newer version instead, at your option.\r
11  *\r
12  * This software consists of voluntary contributions made by many\r
13  * individuals.  For exact contribution history, see the revision\r
14  * history and logs, available at http://subversion.tigris.org/.\r
15  * ====================================================================\r
16  * @endcopyright\r
17  *\r
18  * @file svn_io.h\r
19  * @brief General file I/O for Subversion\r
20  */\r
21 \r
22 /* ==================================================================== */\r
23 \r
24 \r
25 #ifndef SVN_IO_H\r
26 #define SVN_IO_H\r
27 \r
28 #include <apr.h>\r
29 #include <apr_pools.h>\r
30 #include <apr_time.h>\r
31 #include <apr_hash.h>\r
32 #include <apr_tables.h>\r
33 #include <apr_file_io.h>\r
34 #include <apr_file_info.h>\r
35 #include <apr_thread_proc.h>  /* for apr_proc_t, apr_exit_why_e */\r
36 \r
37 #include "svn_types.h"\r
38 #include "svn_string.h"\r
39 #include "svn_checksum.h"\r
40 \r
41 #ifdef __cplusplus\r
42 extern "C" {\r
43 #endif /* __cplusplus */\r
44 \r
45 \r
46 \f\r
47 /** Used as an argument when creating temporary files to indicate\r
48  * when a file should be removed.\r
49  *\r
50  * @since New in 1.4.\r
51  *\r
52  * Not specifying any of these means no removal at all. */\r
53 typedef enum svn_io_file_del_t\r
54 {\r
55   /** No deletion ever */\r
56   svn_io_file_del_none = 0,\r
57   /** Remove when the file is closed */\r
58   svn_io_file_del_on_close,\r
59   /** Remove when the associated pool is cleared */\r
60   svn_io_file_del_on_pool_cleanup\r
61 } svn_io_file_del_t;\r
62 \r
63 \r
64 \f\r
65 /** Represents the kind and special status of a directory entry.\r
66  *\r
67  * @since New in 1.3.\r
68  */\r
69 typedef struct svn_io_dirent_t {\r
70   /** The kind of this entry. */\r
71   svn_node_kind_t kind;\r
72   /** If @c kind is @c svn_node_file, whether this entry is a special file;\r
73    * else FALSE.\r
74    *\r
75    * @see svn_io_check_special_path().\r
76    */\r
77   svn_boolean_t special;\r
78 } svn_io_dirent_t;\r
79 \r
80 /** Determine the @a kind of @a path.  @a path should be UTF-8 encoded.\r
81  *\r
82  * If @a path is a file, set @a *kind to @c svn_node_file.\r
83  *\r
84  * If @a path is a directory, set @a *kind to @c svn_node_dir.\r
85  *\r
86  * If @a path does not exist, set @a *kind to @c svn_node_none.\r
87  *\r
88  * If @a path exists but is none of the above, set @a *kind to @c\r
89  * svn_node_unknown.\r
90  *\r
91  * If unable to determine @a path's kind, return an error, with @a *kind's\r
92  * value undefined.\r
93  *\r
94  * Use @a pool for temporary allocations.\r
95  *\r
96  * @see svn_node_kind_t\r
97  */\r
98 svn_error_t *\r
99 svn_io_check_path(const char *path,\r
100                   svn_node_kind_t *kind,\r
101                   apr_pool_t *pool);\r
102 \r
103 /**\r
104  * Like svn_io_check_path(), but also set *is_special to @c TRUE if\r
105  * the path is not a normal file.\r
106  *\r
107  * @since New in 1.1.\r
108  */\r
109 svn_error_t *\r
110 svn_io_check_special_path(const char *path,\r
111                           svn_node_kind_t *kind,\r
112                           svn_boolean_t *is_special,\r
113                           apr_pool_t *pool);\r
114 \r
115 /** Like svn_io_check_path(), but resolve symlinks.  This returns the\r
116     same varieties of @a kind as svn_io_check_path(). */\r
117 svn_error_t *\r
118 svn_io_check_resolved_path(const char *path,\r
119                            svn_node_kind_t *kind,\r
120                            apr_pool_t *pool);\r
121 \r
122 \r
123 /** Open a new file (for reading and writing) with a unique name based on\r
124  * utf-8 encoded @a filename, in the directory @a dirpath.  The file handle is\r
125  * returned in @a *file, and the name, which ends with @a suffix, is returned\r
126  * in @a *unique_name, also utf8-encoded.  Either @a file or @a unique_name\r
127  * may be @c NULL.\r
128  *\r
129  * If @a delete_when is @c svn_io_file_del_on_close, then the @c APR_DELONCLOSE\r
130  * flag will be used when opening the file.  The @c APR_BUFFERED flag will\r
131  * always be used.\r
132  *\r
133  * The first attempt will just append @a suffix.  If the result is not\r
134  * a unique name, then subsequent attempts will append a dot,\r
135  * followed by an iteration number ("2", then "3", and so on),\r
136  * followed by the suffix.  For example, successive calls to\r
137  *\r
138  *    svn_io_open_uniquely_named(&f, &u, "tests/t1/A/D/G", "pi", ".tmp", ...)\r
139  *\r
140  * will open\r
141  *\r
142  *    tests/t1/A/D/G/pi.tmp\r
143  *    tests/t1/A/D/G/pi.2.tmp\r
144  *    tests/t1/A/D/G/pi.3.tmp\r
145  *    tests/t1/A/D/G/pi.4.tmp\r
146  *    tests/t1/A/D/G/pi.5.tmp\r
147  *    ...\r
148  *\r
149  * Assuming @a suffix is non-empty, @a *unique_name will never be exactly\r
150  * the same as @a filename, even if @a filename does not exist.\r
151  *\r
152  * If @a dirpath is NULL, then the directory returned by svn_io_temp_dir()\r
153  * will be used.\r
154  *\r
155  * If @a filename is NULL, then "tempfile" will be used.\r
156  *\r
157  * If @a suffix is NULL, then ".tmp" will be used.\r
158  *\r
159  * Allocates @a *file and @a *unique_name in @a result_pool. All\r
160  * intermediate allocations will be performed in @a scratch_pool.\r
161  *\r
162  * If no unique name can be found, @c SVN_ERR_IO_UNIQUE_NAMES_EXHAUSTED is\r
163  * the error returned.\r
164  *\r
165  * Claim of Historical Inevitability: this function was written\r
166  * because\r
167  *\r
168  *    - tmpnam() is not thread-safe.\r
169  *    - tempname() tries standard system tmp areas first.\r
170  *\r
171  * @since New in 1.6\r
172  */\r
173 svn_error_t *\r
174 svn_io_open_uniquely_named(apr_file_t **file,\r
175                            const char **unique_name,\r
176                            const char *dirpath,\r
177                            const char *filename,\r
178                            const char *suffix,\r
179                            svn_io_file_del_t delete_when,\r
180                            apr_pool_t *result_pool,\r
181                            apr_pool_t *scratch_pool);\r
182 \r
183 \r
184 /** Create a writable file in the directory @a dirpath. The file will have\r
185  * an arbitrary and unique name, and the full path will be returned in\r
186  * @a temp_path. The file will be returned in @a file. Both will be\r
187  * allocated from @a result_pool.\r
188  *\r
189  * If @a dirpath is @c NULL, use the path returned from svn_io_temp_dir().\r
190  * (Note that when using the system-provided temp directory, it may not\r
191  * be possibly to atomically rename the resulting file due to cross-device\r
192  * issues.)\r
193  *\r
194  * The file will be deleted according to @a delete_when.\r
195  *\r
196  * Temporary allocations will be performed in @a scratch_pool.\r
197  *\r
198  * @since New in 1.6\r
199  * @see svn_stream_open_unique()\r
200  */\r
201 svn_error_t *\r
202 svn_io_open_unique_file3(apr_file_t **file,\r
203                          const char **temp_path,\r
204                          const char *dirpath,\r
205                          svn_io_file_del_t delete_when,\r
206                          apr_pool_t *result_pool,\r
207                          apr_pool_t *scratch_pool);\r
208 \r
209 \r
210 /** Like svn_io_open_uniquely_named(), but takes a joined dirpath and\r
211  * filename, and a single pool.\r
212  *\r
213  * @since New in 1.4\r
214  *\r
215  * @deprecated Provided for backward compatibility with the 1.5 API\r
216  */\r
217 SVN_DEPRECATED\r
218 svn_error_t *\r
219 svn_io_open_unique_file2(apr_file_t **f,\r
220                          const char **unique_name_p,\r
221                          const char *path,\r
222                          const char *suffix,\r
223                          svn_io_file_del_t delete_when,\r
224                          apr_pool_t *pool);\r
225 \r
226 /** Like svn_io_open_unique_file2, but can't delete on pool cleanup.\r
227  *\r
228  * @deprecated Provided for backward compatibility with the 1.0 API\r
229  *\r
230  * @note In 1.4 the API was extended to require either @a f or\r
231  *       @a unique_name_p (the other can be NULL).  Before that, both were\r
232  *       required.\r
233  */\r
234 SVN_DEPRECATED\r
235 svn_error_t *\r
236 svn_io_open_unique_file(apr_file_t **f,\r
237                         const char **unique_name_p,\r
238                         const char *path,\r
239                         const char *suffix,\r
240                         svn_boolean_t delete_on_close,\r
241                         apr_pool_t *pool);\r
242 \r
243 \r
244 /**\r
245  * Like svn_io_open_unique_file(), except that instead of creating a\r
246  * file, a symlink is generated that references the path @a dest.\r
247  *\r
248  * @since New in 1.1.\r
249  */\r
250 svn_error_t *\r
251 svn_io_create_unique_link(const char **unique_name_p,\r
252                           const char *path,\r
253                           const char *dest,\r
254                           const char *suffix,\r
255                           apr_pool_t *pool);\r
256 \r
257 \r
258 /**\r
259  * Set @a *dest to the path that the symlink at @a path references.\r
260  * Allocate the string from @a pool.\r
261  *\r
262  * @since New in 1.1.\r
263  */\r
264 svn_error_t *\r
265 svn_io_read_link(svn_string_t **dest,\r
266                  const char *path,\r
267                  apr_pool_t *pool);\r
268 \r
269 \r
270 /** Set @a *dir to a directory path (allocated in @a pool) deemed\r
271  * usable for the creation of temporary files and subdirectories.\r
272  */\r
273 svn_error_t *\r
274 svn_io_temp_dir(const char **dir,\r
275                 apr_pool_t *pool);\r
276 \r
277 \r
278 /** Copy @a src to @a dst atomically, in a "byte-for-byte" manner.\r
279  * Overwrite @a dst if it exists, else create it.  Both @a src and @a dst\r
280  * are utf8-encoded filenames.  If @a copy_perms is TRUE, set @a dst's\r
281  * permissions to match those of @a src.\r
282  */\r
283 svn_error_t *\r
284 svn_io_copy_file(const char *src,\r
285                  const char *dst,\r
286                  svn_boolean_t copy_perms,\r
287                  apr_pool_t *pool);\r
288 \r
289 \r
290 /** Copy permission flags from @a src onto the file at @a dst. Both\r
291  * filenames are utf8-encoded filenames.\r
292  */\r
293 svn_error_t *\r
294 svn_io_copy_perms(const char *src,\r
295                   const char *dst,\r
296                   apr_pool_t *pool);\r
297 \r
298 \r
299 /**\r
300  * Copy symbolic link @a src to @a dst atomically.  Overwrite @a dst\r
301  * if it exists, else create it.  Both @a src and @a dst are\r
302  * utf8-encoded filenames.  After copying, the @a dst link will point\r
303  * to the same thing @a src does.\r
304  *\r
305  * @since New in 1.1.\r
306  */\r
307 svn_error_t *\r
308 svn_io_copy_link(const char *src,\r
309                  const char *dst,\r
310                  apr_pool_t *pool);\r
311 \r
312 \r
313 /** Recursively copy directory @a src into @a dst_parent, as a new entry named\r
314  * @a dst_basename.  If @a dst_basename already exists in @a dst_parent,\r
315  * return error.  @a copy_perms will be passed through to svn_io_copy_file()\r
316  * when any files are copied.  @a src, @a dst_parent, and @a dst_basename are\r
317  * all utf8-encoded.\r
318  *\r
319  * If @a cancel_func is non-NULL, invoke it with @a cancel_baton at\r
320  * various points during the operation.  If it returns any error\r
321  * (typically @c SVN_ERR_CANCELLED), return that error immediately.\r
322  */\r
323 svn_error_t *\r
324 svn_io_copy_dir_recursively(const char *src,\r
325                             const char *dst_parent,\r
326                             const char *dst_basename,\r
327                             svn_boolean_t copy_perms,\r
328                             svn_cancel_func_t cancel_func,\r
329                             void *cancel_baton,\r
330                             apr_pool_t *pool);\r
331 \r
332 \r
333 /** Create directory @a path on the file system, creating intermediate\r
334  * directories as required, like <tt>mkdir -p</tt>.  Report no error if @a\r
335  * path already exists.  @a path is utf8-encoded.\r
336  *\r
337  * This is essentially a wrapper for apr_dir_make_recursive(), passing\r
338  * @c APR_OS_DEFAULT as the permissions.\r
339  */\r
340 svn_error_t *\r
341 svn_io_make_dir_recursively(const char *path,\r
342                             apr_pool_t *pool);\r
343 \r
344 \r
345 /** Set @a *is_empty_p to @c TRUE if directory @a path is empty, else to\r
346  * @c FALSE if it is not empty.  @a path must be a directory, and is\r
347  * utf8-encoded.  Use @a pool for temporary allocation.\r
348  */\r
349 svn_error_t *\r
350 svn_io_dir_empty(svn_boolean_t *is_empty_p,\r
351                  const char *path,\r
352                  apr_pool_t *pool);\r
353 \r
354 \r
355 /** Append @a src to @a dst.  @a dst will be appended to if it exists, else it\r
356  * will be created.  Both @a src and @a dst are utf8-encoded.\r
357  */\r
358 svn_error_t *\r
359 svn_io_append_file(const char *src,\r
360                    const char *dst,\r
361                    apr_pool_t *pool);\r
362 \r
363 \r
364 /** Make a file as read-only as the operating system allows.\r
365  * @a path is the utf8-encoded path to the file. If @a ignore_enoent is\r
366  * @c TRUE, don't fail if the target file doesn't exist.\r
367  *\r
368  * If @a path is a symlink, do nothing.\r
369  *\r
370  * @note If @a path is a directory, act on it as though it were a\r
371  * file, as described above, but note that you probably don't want to\r
372  * call this function on directories.  We have left it effective on\r
373  * directories for compatibility reasons, but as its name implies, it\r
374  * should be used only for files.\r
375  */\r
376 svn_error_t *\r
377 svn_io_set_file_read_only(const char *path,\r
378                           svn_boolean_t ignore_enoent,\r
379                           apr_pool_t *pool);\r
380 \r
381 \r
382 /** Make a file as writable as the operating system allows.\r
383  * @a path is the utf8-encoded path to the file.  If @a ignore_enoent is\r
384  * @c TRUE, don't fail if the target file doesn't exist.\r
385  * @warning On Unix this function will do the equivalent of chmod a+w path.\r
386  * If this is not what you want you should not use this function, but rather\r
387  * use apr_file_perms_set().\r
388  *\r
389  * If @a path is a symlink, do nothing.\r
390  *\r
391  * @note If @a path is a directory, act on it as though it were a\r
392  * file, as described above, but note that you probably don't want to\r
393  * call this function on directories.  We have left it effective on\r
394  * directories for compatibility reasons, but as its name implies, it\r
395  * should be used only for files.\r
396  */\r
397 svn_error_t *\r
398 svn_io_set_file_read_write(const char *path,\r
399                            svn_boolean_t ignore_enoent,\r
400                            apr_pool_t *pool);\r
401 \r
402 \r
403 /** Similar to svn_io_set_file_read_* functions.\r
404  * Change the read-write permissions of a file.\r
405  * @since New in 1.1.\r
406  *\r
407  * When making @a path read-write on operating systems with unix style\r
408  * permissions, set the permissions on @a path to the permissions that\r
409  * are set when a new file is created (effectively honoring the user's\r
410  * umask).\r
411  *\r
412  * When making the file read-only on operating systems with unix style\r
413  * permissions, remove all write permissions.\r
414  *\r
415  * On other operating systems, toggle the file's "writability" as much as\r
416  * the operating system allows.\r
417  *\r
418  * @a path is the utf8-encoded path to the file.  If @a enable_write\r
419  * is @c TRUE, then make the file read-write.  If @c FALSE, make it\r
420  * read-only.  If @a ignore_enoent is @c TRUE, don't fail if the target\r
421  * file doesn't exist.\r
422  *\r
423  * @deprecated Provided for backward compatibility with the 1.3 API.\r
424  */\r
425 SVN_DEPRECATED\r
426 svn_error_t *\r
427 svn_io_set_file_read_write_carefully(const char *path,\r
428                                      svn_boolean_t enable_write,\r
429                                      svn_boolean_t ignore_enoent,\r
430                                      apr_pool_t *pool);\r
431 \r
432 /** Set @a path's "executability" (but do nothing if it is a symlink).\r
433  *\r
434  * @a path is the utf8-encoded path to the file.  If @a executable\r
435  * is @c TRUE, then make the file executable.  If @c FALSE, make it\r
436  * non-executable.  If @a ignore_enoent is @c TRUE, don't fail if the target\r
437  * file doesn't exist.\r
438  *\r
439  * When making the file executable on operating systems with unix style\r
440  * permissions, never add an execute permission where there is not\r
441  * already a read permission: that is, only make the file executable\r
442  * for the user, group or world if the corresponding read permission\r
443  * is already set for user, group or world.\r
444  *\r
445  * When making the file non-executable on operating systems with unix style\r
446  * permissions, remove all execute permissions.\r
447  *\r
448  * On other operating systems, toggle the file's "executability" as much as\r
449  * the operating system allows.\r
450  *\r
451  * @note If @a path is a directory, act on it as though it were a\r
452  * file, as described above, but note that you probably don't want to\r
453  * call this function on directories.  We have left it effective on\r
454  * directories for compatibility reasons, but as its name implies, it\r
455  * should be used only for files.\r
456  */\r
457 svn_error_t *\r
458 svn_io_set_file_executable(const char *path,\r
459                            svn_boolean_t executable,\r
460                            svn_boolean_t ignore_enoent,\r
461                            apr_pool_t *pool);\r
462 \r
463 /** Determine whether a file is executable by the current user.\r
464  * Set @a *executable to @c TRUE if the file @a path is executable by the\r
465  * current user, otherwise set it to @c FALSE.\r
466  *\r
467  * On Windows and on platforms without userids, always returns @c FALSE.\r
468  */\r
469 svn_error_t *\r
470 svn_io_is_file_executable(svn_boolean_t *executable,\r
471                           const char *path,\r
472                           apr_pool_t *pool);\r
473 \r
474 \r
475 /** Read a line from @a file into @a buf, but not exceeding @a *limit bytes.\r
476  * Does not include newline, instead '\\0' is put there.\r
477  * Length (as in strlen) is returned in @a *limit.\r
478  * @a buf should be pre-allocated.\r
479  * @a file should be already opened.\r
480  *\r
481  * When the file is out of lines, @c APR_EOF will be returned.\r
482  */\r
483 svn_error_t *\r
484 svn_io_read_length_line(apr_file_t *file,\r
485                         char *buf,\r
486                         apr_size_t *limit,\r
487                         apr_pool_t *pool);\r
488 \r
489 \r
490 /** Set @a *apr_time to the time of last modification of the contents of the\r
491  * file @a path.  @a path is utf8-encoded.\r
492  *\r
493  * @note This is the APR mtime which corresponds to the traditional mtime\r
494  * on Unix, and the last write time on Windows.\r
495  */\r
496 svn_error_t *\r
497 svn_io_file_affected_time(apr_time_t *apr_time,\r
498                           const char *path,\r
499                           apr_pool_t *pool);\r
500 \r
501 /** Set the timestamp of file @a path to @a apr_time.  @a path is\r
502  *  utf8-encoded.\r
503  *\r
504  * @note This is the APR mtime which corresponds to the traditional mtime\r
505  * on Unix, and the last write time on Windows.\r
506  */\r
507 svn_error_t *\r
508 svn_io_set_file_affected_time(apr_time_t apr_time,\r
509                               const char *path,\r
510                               apr_pool_t *pool);\r
511 \r
512 /** Sleep to ensure that any files modified after we exit have a different\r
513  * timestamp than the one we recorded. If @a path is not NULL, check if we\r
514  * can determine how long we should wait for a new timestamp on the filesystem\r
515  * containing @a path, an existing file or directory. If @a path is NULL or we\r
516  * can't determine the timestamp resolution, sleep until the next second.\r
517  *\r
518  * Use @a pool for any necessary allocations. @a pool can be null if @a path\r
519  * is NULL.\r
520  *\r
521  * Errors while retrieving the timestamp resolution will result in sleeping\r
522  * to the next second, to keep the working copy stable in error conditions.\r
523  *\r
524  * @since New in 1.6.\r
525  */\r
526 void\r
527 svn_io_sleep_for_timestamps(const char *path, apr_pool_t *pool);\r
528 \r
529 /** Set @a *different_p to non-zero if @a file1 and @a file2 have different\r
530  * sizes, else set to zero.  Both @a file1 and @a file2 are utf8-encoded.\r
531  *\r
532  * Setting @a *different_p to zero does not mean the files definitely\r
533  * have the same size, it merely means that the sizes are not\r
534  * definitely different.  That is, if the size of one or both files\r
535  * cannot be determined, then the sizes are not known to be different,\r
536  * so @a *different_p is set to 0.\r
537  */\r
538 svn_error_t *\r
539 svn_io_filesizes_different_p(svn_boolean_t *different_p,\r
540                              const char *file1,\r
541                              const char *file2,\r
542                              apr_pool_t *pool);\r
543 \r
544 \r
545 /** Return in @a *checksum the checksum of type @a kind of @a file\r
546  * Use @a pool for temporary allocations and to allocate @a *checksum.\r
547  *\r
548  * @since New in 1.6.\r
549  */\r
550 svn_error_t *\r
551 svn_io_file_checksum2(svn_checksum_t **checksum,\r
552                       const char *file,\r
553                       svn_checksum_kind_t kind,\r
554                       apr_pool_t *pool);\r
555 \r
556 \r
557 /** Put the md5 checksum of @a file into @a digest.\r
558  * @a digest points to @c APR_MD5_DIGESTSIZE bytes of storage.\r
559  * Use @a pool only for temporary allocations.\r
560  *\r
561  * @deprecated Provided for backward compatibility with the 1.5 API.\r
562  */\r
563 SVN_DEPRECATED\r
564 svn_error_t *\r
565 svn_io_file_checksum(unsigned char digest[],\r
566                      const char *file,\r
567                      apr_pool_t *pool);\r
568 \r
569 \r
570 /** Set @a *same to TRUE if @a file1 and @a file2 have the same\r
571  * contents, else set it to FALSE.  Use @a pool for temporary allocations.\r
572  */\r
573 svn_error_t *\r
574 svn_io_files_contents_same_p(svn_boolean_t *same,\r
575                              const char *file1,\r
576                              const char *file2,\r
577                              apr_pool_t *pool);\r
578 \r
579 /** Create file at utf8-encoded @a file with contents @a contents.\r
580  * @a file must not already exist.\r
581  * Use @a pool for memory allocations.\r
582  */\r
583 svn_error_t *\r
584 svn_io_file_create(const char *file,\r
585                    const char *contents,\r
586                    apr_pool_t *pool);\r
587 \r
588 /**\r
589  * Lock file at @a lock_file. If @a exclusive is TRUE,\r
590  * obtain exclusive lock, otherwise obtain shared lock.\r
591  * Lock will be automatically released when @a pool is cleared or destroyed.\r
592  * Use @a pool for memory allocations.\r
593  *\r
594  * @deprecated Provided for backward compatibility with the 1.0 API.\r
595  */\r
596 SVN_DEPRECATED\r
597 svn_error_t *\r
598 svn_io_file_lock(const char *lock_file,\r
599                  svn_boolean_t exclusive,\r
600                  apr_pool_t *pool);\r
601 \r
602 /**\r
603  * Lock file at @a lock_file. If @a exclusive is TRUE,\r
604  * obtain exclusive lock, otherwise obtain shared lock.\r
605  *\r
606  * If @a nonblocking is TRUE, do not wait for the lock if it\r
607  * is not available: throw an error instead.\r
608  *\r
609  * Lock will be automatically released when @a pool is cleared or destroyed.\r
610  * Use @a pool for memory allocations.\r
611  *\r
612  * @since New in 1.1.\r
613  */\r
614 svn_error_t *\r
615 svn_io_file_lock2(const char *lock_file,\r
616                   svn_boolean_t exclusive,\r
617                   svn_boolean_t nonblocking,\r
618                   apr_pool_t *pool);\r
619 /**\r
620  * Flush any unwritten data from @a file to disk.  Use @a pool for\r
621  * memory allocations.\r
622  *\r
623  * @since New in 1.1.\r
624  */\r
625 svn_error_t *\r
626 svn_io_file_flush_to_disk(apr_file_t *file,\r
627                           apr_pool_t *pool);\r
628 \r
629 /** Copy file @a file from location @a src_path to location @a dest_path.\r
630  * Use @a pool for memory allocations.\r
631  */\r
632 svn_error_t *\r
633 svn_io_dir_file_copy(const char *src_path,\r
634                      const char *dest_path,\r
635                      const char *file,\r
636                      apr_pool_t *pool);\r
637 \r
638 \f\r
639 /** Generic byte-streams\r
640  *\r
641  * @defgroup svn_io_byte_streams Generic byte streams\r
642  * @{\r
643  */\r
644 \r
645 /** An abstract stream of bytes--either incoming or outgoing or both.\r
646  *\r
647  * The creator of a stream sets functions to handle read and write.\r
648  * Both of these handlers accept a baton whose value is determined at\r
649  * stream creation time; this baton can point to a structure\r
650  * containing data associated with the stream.  If a caller attempts\r
651  * to invoke a handler which has not been set, it will generate a\r
652  * runtime assertion failure.  The creator can also set a handler for\r
653  * close requests so that it can flush buffered data or whatever;\r
654  * if a close handler is not specified, a close request on the stream\r
655  * will simply be ignored.  Note that svn_stream_close() does not\r
656  * deallocate the memory used to allocate the stream structure; free\r
657  * the pool you created the stream in to free that memory.\r
658  *\r
659  * The read and write handlers accept length arguments via pointer.\r
660  * On entry to the handler, the pointed-to value should be the amount\r
661  * of data which can be read or the amount of data to write.  When the\r
662  * handler returns, the value is reset to the amount of data actually\r
663  * read or written.  Handlers are obliged to complete a read or write\r
664  * to the maximum extent possible; thus, a short read with no\r
665  * associated error implies the end of the input stream, and a short\r
666  * write should never occur without an associated error.\r
667  */\r
668 typedef struct svn_stream_t svn_stream_t;\r
669 \r
670 \r
671 \r
672 /** Read handler function for a generic stream.  @see svn_stream_t. */\r
673 typedef svn_error_t *(*svn_read_fn_t)(void *baton,\r
674                                       char *buffer,\r
675                                       apr_size_t *len);\r
676 \r
677 /** Write handler function for a generic stream.  @see svn_stream_t. */\r
678 typedef svn_error_t *(*svn_write_fn_t)(void *baton,\r
679                                        const char *data,\r
680                                        apr_size_t *len);\r
681 \r
682 /** Close handler function for a generic stream.  @see svn_stream_t. */\r
683 typedef svn_error_t *(*svn_close_fn_t)(void *baton);\r
684 \r
685 \r
686 /** Create a generic stream.  @see svn_stream_t. */\r
687 svn_stream_t *\r
688 svn_stream_create(void *baton,\r
689                   apr_pool_t *pool);\r
690 \r
691 /** Set @a stream's baton to @a baton */\r
692 void\r
693 svn_stream_set_baton(svn_stream_t *stream,\r
694                      void *baton);\r
695 \r
696 /** Set @a stream's read function to @a read_fn */\r
697 void\r
698 svn_stream_set_read(svn_stream_t *stream,\r
699                     svn_read_fn_t read_fn);\r
700 \r
701 /** Set @a stream's write function to @a write_fn */\r
702 void\r
703 svn_stream_set_write(svn_stream_t *stream,\r
704                      svn_write_fn_t write_fn);\r
705 \r
706 /** Set @a stream's close function to @a close_fn */\r
707 void\r
708 svn_stream_set_close(svn_stream_t *stream,\r
709                      svn_close_fn_t close_fn);\r
710 \r
711 \r
712 /** Create a stream that is empty for reading and infinite for writing. */\r
713 svn_stream_t *\r
714 svn_stream_empty(apr_pool_t *pool);\r
715 \r
716 /** Return a stream allocated in @a pool which forwards all requests\r
717  * to @a stream.  Destruction is explicitly excluded from forwarding.\r
718  *\r
719  * @see notes/destruction-of-stacked-resources\r
720  *\r
721  * @since New in 1.4.\r
722  */\r
723 svn_stream_t *\r
724 svn_stream_disown(svn_stream_t *stream,\r
725                   apr_pool_t *pool);\r
726 \r
727 \r
728 /** Create a stream to read the file at @a path. It will be opened using\r
729  * the APR_BUFFERED and APR_BINARY flag, and APR_OS_DEFAULT for the perms.\r
730  * If you'd like to use different values, then open the file yourself, and\r
731  * use the svn_stream_from_aprfile2() interface.\r
732  *\r
733  * The stream will be returned in @a stream, and allocated from @a result_pool.\r
734  * Temporary allocations will be performed in @a scratch_pool.\r
735  *\r
736  * @since New in 1.6\r
737  */\r
738 svn_error_t *\r
739 svn_stream_open_readonly(svn_stream_t **stream,\r
740                          const char *path,\r
741                          apr_pool_t *result_pool,\r
742                          apr_pool_t *scratch_pool);\r
743 \r
744 \r
745 /** Create a stream to write a file at @a path. The file will be *created*\r
746  * using the APR_BUFFERED and APR_BINARY flag, and APR_OS_DEFAULT for the\r
747  * perms. The file will be created "exclusively", so if it already exists,\r
748  * then an error will be thrown. If you'd like to use different values, or\r
749  * open an existing file, then open the file yourself, and use the\r
750  * svn_stream_from_aprfile2() interface.\r
751  *\r
752  * The stream will be returned in @a stream, and allocated from @a result_pool.\r
753  * Temporary allocations will be performed in @a scratch_pool.\r
754  *\r
755  * @since New in 1.6\r
756  */\r
757 svn_error_t *\r
758 svn_stream_open_writable(svn_stream_t **stream,\r
759                          const char *path,\r
760                          apr_pool_t *result_pool,\r
761                          apr_pool_t *scratch_pool);\r
762 \r
763 \r
764 /** Create a writable stream to a file in the directory @a dirpath.\r
765  * The file will have an arbitrary and unique name, and the full path\r
766  * will be returned in @a temp_path. The stream will be returned in\r
767  * @a stream. Both will be allocated from @a result_pool.\r
768  *\r
769  * If @a dirpath is @c NULL, use the path returned from svn_io_temp_dir().\r
770  * (Note that when using the system-provided temp directory, it may not\r
771  * be possibly to atomically rename the resulting file due to cross-device\r
772  * issues.)\r
773  *\r
774  * The file will be deleted according to @a delete_when.\r
775  *\r
776  * Temporary allocations will be performed in @a scratch_pool.\r
777  *\r
778  * @since New in 1.6\r
779  * @see svn_io_open_unique_file3()\r
780  */\r
781 svn_error_t *\r
782 svn_stream_open_unique(svn_stream_t **stream,\r
783                        const char **temp_path,\r
784                        const char *dirpath,\r
785                        svn_io_file_del_t delete_when,\r
786                        apr_pool_t *result_pool,\r
787                        apr_pool_t *scratch_pool);\r
788 \r
789 \r
790 /** Create a stream from an APR file.  For convenience, if @a file is\r
791  * @c NULL, an empty stream created by svn_stream_empty() is returned.\r
792  *\r
793  * This function should normally be called with @a disown set to FALSE,\r
794  * in which case closing the stream will also close the underlying file.\r
795  *\r
796  * If @a disown is TRUE, the stream will disown the underlying file,\r
797  * meaning that svn_stream_close() will not close the file.\r
798  *\r
799  * @since New in 1.4.\r
800  */\r
801 svn_stream_t *\r
802 svn_stream_from_aprfile2(apr_file_t *file,\r
803                          svn_boolean_t disown,\r
804                          apr_pool_t *pool);\r
805 \r
806 /** Similar to svn_stream_from_aprfile2(), except that the file will\r
807  * always be disowned.\r
808  *\r
809  * @note The stream returned is not considered to "own" the underlying\r
810  *       file, meaning that svn_stream_close() on the stream will not\r
811  *       close the file.\r
812  *\r
813  * @deprecated Provided for backward compatibility with the 1.3 API.\r
814  */\r
815 SVN_DEPRECATED\r
816 svn_stream_t *\r
817 svn_stream_from_aprfile(apr_file_t *file,\r
818                         apr_pool_t *pool);\r
819 \r
820 /** Set @a *out to a generic stream connected to stdout, allocated in\r
821  * @a pool.  The stream and its underlying APR handle will be closed\r
822  * when @a pool is cleared or destroyed.\r
823  */\r
824 svn_error_t *\r
825 svn_stream_for_stdout(svn_stream_t **out,\r
826                       apr_pool_t *pool);\r
827 \r
828 /** Return a generic stream connected to stringbuf @a str.  Allocate the\r
829  * stream in @a pool.\r
830  */\r
831 svn_stream_t *\r
832 svn_stream_from_stringbuf(svn_stringbuf_t *str,\r
833                           apr_pool_t *pool);\r
834 \r
835 /** Return a generic read-only stream connected to string @a str.\r
836  *  Allocate the stream in @a pool.\r
837  */\r
838 svn_stream_t *\r
839 svn_stream_from_string(const svn_string_t *str,\r
840                        apr_pool_t *pool);\r
841 \r
842 /** Return a stream that decompresses all data read and compresses all\r
843  * data written. The stream @a stream is used to read and write all\r
844  * compressed data. All compression data structures are allocated on\r
845  * @a pool. If compression support is not compiled in then\r
846  * svn_stream_compressed() returns @a stream unmodified. Make sure you\r
847  * call svn_stream_close() on the stream returned by this function,\r
848  * so that all data are flushed and cleaned up.\r
849  *\r
850  * @note From 1.4, compression support is always compiled in.\r
851  */\r
852 svn_stream_t *\r
853 svn_stream_compressed(svn_stream_t *stream,\r
854                       apr_pool_t *pool);\r
855 \r
856 /** Return a stream that calculates checksums for all data read\r
857  * and written.  The stream @a stream is used to read and write all data.\r
858  * The stream and the resulting digests are allocated in @a pool.\r
859  *\r
860  * When the stream is closed, @a *read_checksum and @a *write_checksum\r
861  * are set to point to the resulting checksums, of type @a read_checksum_kind\r
862  * and @a write_checksum_kind, respectively.\r
863  *\r
864  * Both @a read_checksum and @a write_checksum can be @c NULL, in which case\r
865  * the respective checksum isn't calculated.\r
866  *\r
867  * If @a read_all is TRUE, make sure that all data available on @a\r
868  * stream is read (and checksummed) when the stream is closed.\r
869  *\r
870  * Read and write operations can be mixed without interfering.\r
871  *\r
872  * The @a stream passed into this function is closed when the created\r
873  * stream is closed.\r
874  *\r
875  * @since New in 1.6.\r
876  */\r
877 svn_stream_t *\r
878 svn_stream_checksummed2(svn_stream_t *stream,\r
879                         svn_checksum_t **read_checksum,\r
880                         svn_checksum_t **write_checksum,\r
881                         svn_checksum_kind_t checksum_kind,\r
882                         svn_boolean_t read_all,\r
883                         apr_pool_t *pool);\r
884 \r
885 /**\r
886  * Similar to svn_stream_checksummed2(), but always returning the MD5\r
887  * checksum in @a read_digest and @a write_digest.\r
888  *\r
889  * @since New in 1.4.\r
890  * @deprecated Provided for backward compatibility with the 1.5 API.\r
891  */\r
892 SVN_DEPRECATED\r
893 svn_stream_t *\r
894 svn_stream_checksummed(svn_stream_t *stream,\r
895                        const unsigned char **read_digest,\r
896                        const unsigned char **write_digest,\r
897                        svn_boolean_t read_all,\r
898                        apr_pool_t *pool);\r
899 \r
900 /** Read from a generic stream. @see svn_stream_t. */\r
901 svn_error_t *\r
902 svn_stream_read(svn_stream_t *stream,\r
903                 char *buffer,\r
904                 apr_size_t *len);\r
905 \r
906 /** Write to a generic stream. @see svn_stream_t. */\r
907 svn_error_t *\r
908 svn_stream_write(svn_stream_t *stream,\r
909                  const char *data,\r
910                  apr_size_t *len);\r
911 \r
912 /** Close a generic stream. @see svn_stream_t. */\r
913 svn_error_t *\r
914 svn_stream_close(svn_stream_t *stream);\r
915 \r
916 \r
917 /** Write to @a stream using a printf-style @a fmt specifier, passed through\r
918  * apr_psprintf() using memory from @a pool.\r
919  */\r
920 svn_error_t *\r
921 svn_stream_printf(svn_stream_t *stream,\r
922                   apr_pool_t *pool,\r
923                   const char *fmt,\r
924                   ...)\r
925        __attribute__((format(printf, 3, 4)));\r
926 \r
927 /** Write to @a stream using a printf-style @a fmt specifier, passed through\r
928  * apr_psprintf() using memory from @a pool.  The resulting string\r
929  * will be translated to @a encoding before it is sent to @a stream.\r
930  *\r
931  * @note Use @c APR_LOCALE_CHARSET to translate to the encoding of the\r
932  * current locale.\r
933  *\r
934  * @since New in 1.3.\r
935  */\r
936 svn_error_t *\r
937 svn_stream_printf_from_utf8(svn_stream_t *stream,\r
938                             const char *encoding,\r
939                             apr_pool_t *pool,\r
940                             const char *fmt,\r
941                             ...)\r
942        __attribute__((format(printf, 4, 5)));\r
943 \r
944 /** Allocate @a *stringbuf in @a pool, and read into it one line (terminated\r
945  * by @a eol) from @a stream. The line-terminator is read from the stream,\r
946  * but is not added to the end of the stringbuf.  Instead, the stringbuf\r
947  * ends with a usual '\\0'.\r
948  *\r
949  * If @a stream runs out of bytes before encountering a line-terminator,\r
950  * then set @a *eof to @c TRUE, otherwise set @a *eof to FALSE.\r
951  */\r
952 svn_error_t *\r
953 svn_stream_readline(svn_stream_t *stream,\r
954                     svn_stringbuf_t **stringbuf,\r
955                     const char *eol,\r
956                     svn_boolean_t *eof,\r
957                     apr_pool_t *pool);\r
958 \r
959 \r
960 /**\r
961  * Read the contents of the readable stream @a from and write them to the\r
962  * writable stream @a to calling @a cancel_func before copying each chunk.\r
963  *\r
964  * @a cancel_func may be @c NULL.\r
965  *\r
966  * @note both @a from and @a to will be closed upon successful completion of\r
967  * the copy (but an error may still be returned, based on trying to close\r
968  * the two streams). If the closure is not desired, then you can use\r
969  * svn_stream_disown() to protect either or both of the streams from\r
970  * being closed.\r
971  * ### TODO: should close the streams ALWAYS, even on error exit\r
972  *\r
973  * @since New in 1.6.\r
974  */\r
975 svn_error_t *\r
976 svn_stream_copy3(svn_stream_t *from,\r
977                  svn_stream_t *to,\r
978                  svn_cancel_func_t cancel_func,\r
979                  void *cancel_baton,\r
980                  apr_pool_t *pool);\r
981 \r
982 /**\r
983  * Same as svn_stream_copy3() but the streams are not closed.\r
984  *\r
985  * @since New in 1.5.\r
986  * @deprecated Provided for backward compatibility with the 1.5 API.\r
987  */\r
988 SVN_DEPRECATED\r
989 svn_error_t *\r
990 svn_stream_copy2(svn_stream_t *from,\r
991                  svn_stream_t *to,\r
992                  svn_cancel_func_t cancel_func,\r
993                  void *cancel_baton,\r
994                  apr_pool_t *pool);\r
995 \r
996 /**\r
997  * Same as svn_stream_copy3(), but without the cancellation function\r
998  * or stream closing.\r
999  *\r
1000  * @since New in 1.1.\r
1001  * @deprecated Provided for backward compatibility with the 1.4 API.\r
1002  */\r
1003 SVN_DEPRECATED\r
1004 svn_error_t *\r
1005 svn_stream_copy(svn_stream_t *from,\r
1006                 svn_stream_t *to,\r
1007                 apr_pool_t *pool);\r
1008 \r
1009 \r
1010 /** Set @a *same to TRUE if @a stream1 and @a stream2 have the same\r
1011  * contents, else set it to FALSE.  Use @a pool for temporary allocations.\r
1012  *\r
1013  * @since New in 1.4.\r
1014  */\r
1015 svn_error_t *\r
1016 svn_stream_contents_same(svn_boolean_t *same,\r
1017                          svn_stream_t *stream1,\r
1018                          svn_stream_t *stream2,\r
1019                          apr_pool_t *pool);\r
1020 \r
1021 \r
1022 /** Read the contents of @a stream into memory, returning the data in\r
1023  * @a result. The stream will be closed when it has been successfully and\r
1024  * completely read.\r
1025  *\r
1026  * The returned memory is allocated in @a result_pool, and any temporary\r
1027  * allocations are performed in @a scratch_pool.\r
1028  *\r
1029  * @note due to memory pseudo-reallocation behavior (due to pools), this\r
1030  *   can be a memory-intensive operation for large files.\r
1031  *\r
1032  * @since New in 1.6\r
1033  */\r
1034 svn_error_t *\r
1035 svn_string_from_stream(svn_string_t **result,\r
1036                        svn_stream_t *stream,\r
1037                        apr_pool_t *result_pool,\r
1038                        apr_pool_t *scratch_pool);\r
1039 \r
1040 \r
1041 /** @} */\r
1042 \r
1043 /** Set @a *result to a string containing the contents of @a\r
1044  * filename, which is either "-" (indicating that stdin should be\r
1045  * read) or the utf8-encoded path of a real file.\r
1046  *\r
1047  * @warning Callers should be aware of possible unexpected results\r
1048  * when using this function to read from stdin where additional\r
1049  * stdin-reading processes abound.  For example, if a program tries\r
1050  * both to invoke an external editor and to read from stdin, stdin\r
1051  * could be trashed and the editor might act funky or die outright.\r
1052  *\r
1053  * @note due to memory pseudo-reallocation behavior (due to pools), this\r
1054  *   can be a memory-intensive operation for large files.\r
1055  *\r
1056  * @since New in 1.5.\r
1057  */\r
1058 svn_error_t *\r
1059 svn_stringbuf_from_file2(svn_stringbuf_t **result,\r
1060                          const char *filename,\r
1061                          apr_pool_t *pool);\r
1062 \r
1063 /** Similar to svn_stringbuf_from_file2(), except that if @a filename\r
1064  * is "-", return the error @c SVN_ERR_UNSUPPORTED_FEATURE and don't\r
1065  * touch @a *result.\r
1066  *\r
1067  * @deprecated Provided for backwards compatibility with the 1.4 API.\r
1068  */\r
1069 SVN_DEPRECATED\r
1070 svn_error_t *\r
1071 svn_stringbuf_from_file(svn_stringbuf_t **result,\r
1072                         const char *filename,\r
1073                         apr_pool_t *pool);\r
1074 \r
1075 /** Sets @a *result to a string containing the contents of the already opened\r
1076  * @a file.  Reads from the current position in file to the end.  Does not\r
1077  * close the file or reset the cursor position.\r
1078  *\r
1079  * @note due to memory pseudo-reallocation behavior (due to pools), this\r
1080  *   can be a memory-intensive operation for large files.\r
1081  */\r
1082 svn_error_t *\r
1083 svn_stringbuf_from_aprfile(svn_stringbuf_t **result,\r
1084                            apr_file_t *file,\r
1085                            apr_pool_t *pool);\r
1086 \r
1087 /** Remove file @a path, a utf8-encoded path.  This wraps apr_file_remove(),\r
1088  * converting any error to a Subversion error.\r
1089  */\r
1090 svn_error_t *\r
1091 svn_io_remove_file(const char *path,\r
1092                    apr_pool_t *pool);\r
1093 \r
1094 /** Recursively remove directory @a path.  @a path is utf8-encoded.\r
1095  * If @a ignore_enoent is @c TRUE, don't fail if the target directory\r
1096  * doesn't exist.  Use @a pool for temporary allocations.\r
1097  *\r
1098  * Because recursive delete of a directory tree can be a lengthy operation,\r
1099  * provide @a cancel_func and @a cancel_baton for interruptability.\r
1100  *\r
1101  * @since New in 1.5.\r
1102  */\r
1103 svn_error_t *\r
1104 svn_io_remove_dir2(const char *path,\r
1105                    svn_boolean_t ignore_enoent,\r
1106                    svn_cancel_func_t cancel_func,\r
1107                    void *cancel_baton,\r
1108                    apr_pool_t *pool);\r
1109 \r
1110 /** Similar to svn_io_remove_dir2(), but with @a ignore_enoent set to\r
1111  * @c FALSE and @a cancel_func and @a cancel_baton set to @c NULL.\r
1112  *\r
1113  * @deprecated Provided for backward compatibility with the 1.4 API\r
1114  */\r
1115 SVN_DEPRECATED\r
1116 svn_error_t *\r
1117 svn_io_remove_dir(const char *path,\r
1118                   apr_pool_t *pool);\r
1119 \r
1120 /** Read all of the disk entries in directory @a path, a utf8-encoded\r
1121  * path.  Set @a *dirents to a hash mapping dirent names (<tt>char *</tt>) to\r
1122  * undefined non-NULL values, allocated in @a pool.\r
1123  *\r
1124  * @note The `.' and `..' directories normally returned by\r
1125  * apr_dir_read() are NOT returned in the hash.\r
1126  *\r
1127  * @since New in 1.4.\r
1128  */\r
1129 svn_error_t *\r
1130 svn_io_get_dir_filenames(apr_hash_t **dirents,\r
1131                          const char *path,\r
1132                          apr_pool_t *pool);\r
1133 \r
1134 /** Read all of the disk entries in directory @a path, a utf8-encoded\r
1135  * path.  Set @a *dirents to a hash mapping dirent names (<tt>char *</tt>) to\r
1136  * @c svn_io_dirent_t structures, allocated in @a pool.\r
1137  *\r
1138  * @note The `.' and `..' directories normally returned by\r
1139  * apr_dir_read() are NOT returned in the hash.\r
1140  *\r
1141  * @note The kind field in the @a dirents is set according to the mapping\r
1142  *       as documented for svn_io_check_path()\r
1143  *\r
1144  * @since New in 1.3.\r
1145  */\r
1146 svn_error_t *\r
1147 svn_io_get_dirents2(apr_hash_t **dirents,\r
1148                     const char *path,\r
1149                     apr_pool_t *pool);\r
1150 \r
1151 /** Similar to svn_io_get_dirents2(), but @a *dirents is a hash table\r
1152  * with @c svn_node_kind_t values.\r
1153  *\r
1154  * @deprecated Provided for backwards compatibility with the 1.2 API.\r
1155  */\r
1156 SVN_DEPRECATED\r
1157 svn_error_t *\r
1158 svn_io_get_dirents(apr_hash_t **dirents,\r
1159                    const char *path,\r
1160                    apr_pool_t *pool);\r
1161 \r
1162 \r
1163 /** Callback function type for svn_io_dir_walk() */\r
1164 typedef svn_error_t * (*svn_io_walk_func_t)(void *baton,\r
1165                                             const char *path,\r
1166                                             const apr_finfo_t *finfo,\r
1167                                             apr_pool_t *pool);\r
1168 \r
1169 /** This function will recursively walk over the files and directories\r
1170  * rooted at @a dirname, a utf8-encoded path. For each file or directory,\r
1171  * @a walk_func is invoked, passing in the @a walk_baton, the utf8-encoded\r
1172  * full path to the entry, an @c apr_finfo_t structure, and a temporary\r
1173  * pool for allocations.  For any directory, @a walk_func will be invoked\r
1174  * on the directory itself before being invoked on any subdirectories or\r
1175  * files within the directory.\r
1176  *\r
1177  * The set of information passed to @a walk_func is specified by @a wanted,\r
1178  * and the items specified by @c APR_FINFO_TYPE and @c APR_FINFO_NAME.\r
1179  *\r
1180  * All allocations will be performed in @a pool.\r
1181  */\r
1182 svn_error_t *\r
1183 svn_io_dir_walk(const char *dirname,\r
1184                 apr_int32_t wanted,\r
1185                 svn_io_walk_func_t walk_func,\r
1186                 void *walk_baton,\r
1187                 apr_pool_t *pool);\r
1188 \r
1189 /**\r
1190  * Start @a cmd with @a args, using utf8-encoded @a path as working\r
1191  * directory.  Connect @a cmd's stdin, stdout, and stderr to @a infile,\r
1192  * @a outfile, and @a errfile, except where they are NULL.  Return the\r
1193  * process handle for the invoked program in @a *cmd_proc.\r
1194  *\r
1195  * @a args is a list of utf8-encoded <tt>const char *</tt> arguments,\r
1196  * terminated by @c NULL.  @a args[0] is the name of the program, though it\r
1197  * need not be the same as @a cmd.\r
1198  *\r
1199  * If @a inherit is TRUE, the invoked program inherits its environment from\r
1200  * the caller and @a cmd, if not absolute, is searched for in PATH.\r
1201  * Otherwise, the invoked program runs with an empty environment and @a cmd\r
1202  * must be an absolute path.\r
1203  *\r
1204  * @note On some platforms, failure to execute @a cmd in the child process\r
1205  * will result in error output being written to @a errfile, if non-NULL, and\r
1206  * a non-zero exit status being returned to the parent process.\r
1207  *\r
1208  * @since New in 1.3.\r
1209  */\r
1210 svn_error_t *\r
1211 svn_io_start_cmd(apr_proc_t *cmd_proc,\r
1212                  const char *path,\r
1213                  const char *cmd,\r
1214                  const char *const *args,\r
1215                  svn_boolean_t inherit,\r
1216                  apr_file_t *infile,\r
1217                  apr_file_t *outfile,\r
1218                  apr_file_t *errfile,\r
1219                  apr_pool_t *pool);\r
1220 \r
1221 /**\r
1222  * Wait for the process @a *cmd_proc to complete and optionally retrieve\r
1223  * its exit code.  @a cmd is used only in error messages.\r
1224  *\r
1225  * If @a exitcode is not NULL, @a *exitcode will contain the exit code\r
1226  * of the process upon return, and if @a exitwhy is not NULL, @a\r
1227  * *exitwhy will indicate why the process terminated.  If @a exitwhy is\r
1228  * NULL, and the exit reason is not @c APR_PROC_CHECK_EXIT(), or if\r
1229  * @a exitcode is NULL and the exit code is non-zero, then an\r
1230  * @c SVN_ERR_EXTERNAL_PROGRAM error will be returned.\r
1231  *\r
1232  * @since New in 1.3.\r
1233  */\r
1234 svn_error_t *\r
1235 svn_io_wait_for_cmd(apr_proc_t *cmd_proc,\r
1236                     const char *cmd,\r
1237                     int *exitcode,\r
1238                     apr_exit_why_e *exitwhy,\r
1239                     apr_pool_t *pool);\r
1240 \r
1241 /** Run a command to completion, by first calling svn_io_start_cmd() and\r
1242  * then calling svn_io_wait_for_cmd().  The parameters correspond to\r
1243  * the same-named parameters of those two functions.\r
1244  */\r
1245 svn_error_t *\r
1246 svn_io_run_cmd(const char *path,\r
1247                const char *cmd,\r
1248                const char *const *args,\r
1249                int *exitcode,\r
1250                apr_exit_why_e *exitwhy,\r
1251                svn_boolean_t inherit,\r
1252                apr_file_t *infile,\r
1253                apr_file_t *outfile,\r
1254                apr_file_t *errfile,\r
1255                apr_pool_t *pool);\r
1256 \r
1257 /** Invoke the configured @c diff program, with @a user_args (an array\r
1258  * of utf8-encoded @a num_user_args arguments) if they are specified\r
1259  * (that is, if @a user_args is non-NULL), or "-u" if they are not.\r
1260  * If @a user_args is NULL, the value of @a num_user_args is ignored.\r
1261  *\r
1262  * Diff runs in utf8-encoded @a dir, and its exit status is stored in\r
1263  * @a exitcode, if it is not @c NULL.\r
1264  *\r
1265  * If @a label1 and/or @a label2 are not NULL they will be passed to the diff\r
1266  * process as the arguments of "-L" options.  @a label1 and @a label2 are also\r
1267  * in utf8, and will be converted to native charset along with the other args.\r
1268  *\r
1269  * @a from is the first file passed to diff, and @a to is the second.  The\r
1270  * stdout of diff will be sent to @a outfile, and the stderr to @a errfile.\r
1271  *\r
1272  * @a diff_cmd must be non-NULL.\r
1273  *\r
1274  * Do all allocation in @a pool.\r
1275  * @since New in 1.6.0.\r
1276  */\r
1277 svn_error_t *\r
1278 svn_io_run_diff2(const char *dir,\r
1279                  const char *const *user_args,\r
1280                  int num_user_args,\r
1281                  const char *label1,\r
1282                  const char *label2,\r
1283                  const char *from,\r
1284                  const char *to,\r
1285                  int *exitcode,\r
1286                  apr_file_t *outfile,\r
1287                  apr_file_t *errfile,\r
1288                  const char *diff_cmd,\r
1289                  apr_pool_t *pool);\r
1290 \r
1291 /** Similar to svn_io_run_diff2() but with @diff_cmd encoded in internal\r
1292  * encoding used by APR.\r
1293  *\r
1294  * @deprecated Provided for backwards compatibility with the 1.5 API. */\r
1295 SVN_DEPRECATED\r
1296 svn_error_t *\r
1297 svn_io_run_diff(const char *dir,\r
1298                 const char *const *user_args,\r
1299                 int num_user_args,\r
1300                 const char *label1,\r
1301                 const char *label2,\r
1302                 const char *from,\r
1303                 const char *to,\r
1304                 int *exitcode,\r
1305                 apr_file_t *outfile,\r
1306                 apr_file_t *errfile,\r
1307                 const char *diff_cmd,\r
1308                 apr_pool_t *pool);\r
1309 \r
1310 \r
1311 \r
1312 /** Invoke the configured @c diff3 program, in utf8-encoded @a dir\r
1313  * like this:\r
1314  *\r
1315  *          diff3 -E -m @a mine @a older @a yours > @a merged\r
1316  *\r
1317  * (See the diff3 documentation for details.)\r
1318  *\r
1319  * If @a user_args is non-NULL, replace "-E" with the <tt>const char*</tt>\r
1320  * elements that @a user_args contains.\r
1321  *\r
1322  * @a mine, @a older and @a yours are utf8-encoded paths (relative to\r
1323  * @a dir or absolute) to three files that already exist.\r
1324  *\r
1325  * @a merged is an open file handle, and is left open after the merge\r
1326  * result is written to it. (@a merged should *not* be the same file\r
1327  * as @a mine, or nondeterministic things may happen!)\r
1328  *\r
1329  * @a mine_label, @a older_label, @a yours_label are utf8-encoded label\r
1330  * parameters for diff3's -L option.  Any of them may be @c NULL, in\r
1331  * which case the corresponding @a mine, @a older, or @a yours parameter is\r
1332  * used instead.\r
1333  *\r
1334  * Set @a *exitcode to diff3's exit status.  If @a *exitcode is anything\r
1335  * other than 0 or 1, then return @c SVN_ERR_EXTERNAL_PROGRAM.  (Note the\r
1336  * following from the diff3 info pages: "An exit status of 0 means\r
1337  * `diff3' was successful, 1 means some conflicts were found, and 2\r
1338  * means trouble.")\r
1339  *\r
1340  * @a diff3_cmd must be non-NULL.\r
1341  *\r
1342  * Do all allocation in @a pool.\r
1343  *\r
1344  * @since New in 1.4.\r
1345  */\r
1346 svn_error_t *\r
1347 svn_io_run_diff3_3(int *exitcode,\r
1348                    const char *dir,\r
1349                    const char *mine,\r
1350                    const char *older,\r
1351                    const char *yours,\r
1352                    const char *mine_label,\r
1353                    const char *older_label,\r
1354                    const char *yours_label,\r
1355                    apr_file_t *merged,\r
1356                    const char *diff3_cmd,\r
1357                    const apr_array_header_t *user_args,\r
1358                    apr_pool_t *pool);\r
1359 \r
1360 /** Similar to svn_io_run_diff3_3(), but with @a diff3_cmd encoded in\r
1361  * internal encoding used by APR.\r
1362  *\r
1363  * @deprecated Provided for backwards compatibility with the 1.5 API.\r
1364  * @since New in 1.4.\r
1365  */\r
1366 SVN_DEPRECATED\r
1367 svn_error_t *\r
1368 svn_io_run_diff3_2(int *exitcode,\r
1369                    const char *dir,\r
1370                    const char *mine,\r
1371                    const char *older,\r
1372                    const char *yours,\r
1373                    const char *mine_label,\r
1374                    const char *older_label,\r
1375                    const char *yours_label,\r
1376                    apr_file_t *merged,\r
1377                    const char *diff3_cmd,\r
1378                    const apr_array_header_t *user_args,\r
1379                    apr_pool_t *pool);\r
1380 \r
1381 /** Similar to svn_io_run_diff3_2(), but with @a user_args set to @c NULL.\r
1382  *\r
1383  * @deprecated Provided for backwards compatibility with the 1.3 API.\r
1384  */\r
1385 SVN_DEPRECATED\r
1386 svn_error_t *\r
1387 svn_io_run_diff3(const char *dir,\r
1388                  const char *mine,\r
1389                  const char *older,\r
1390                  const char *yours,\r
1391                  const char *mine_label,\r
1392                  const char *older_label,\r
1393                  const char *yours_label,\r
1394                  apr_file_t *merged,\r
1395                  int *exitcode,\r
1396                  const char *diff3_cmd,\r
1397                  apr_pool_t *pool);\r
1398 \r
1399 \r
1400 /** Parse utf8-encoded @a mimetypes_file as a MIME types file (such as\r
1401  * is provided with Apache HTTP Server), and set @a *type_map to a\r
1402  * hash mapping <tt>const char *</tt> filename extensions to\r
1403  * <tt>const char *</tt> MIME types.\r
1404  *\r
1405  * @since New in 1.5.\r
1406  */\r
1407 svn_error_t *\r
1408 svn_io_parse_mimetypes_file(apr_hash_t **type_map,\r
1409                             const char *mimetypes_file,\r
1410                             apr_pool_t *pool);\r
1411 \r
1412 \r
1413 /** Examine utf8-encoded @a file to determine if it can be described by a\r
1414  * known (as in, known by this function) Multipurpose Internet Mail\r
1415  * Extension (MIME) type.  If so, set @a *mimetype to a character string\r
1416  * describing the MIME type, else set it to @c NULL.\r
1417  *\r
1418  * If not @c NULL, @a mimetype_map is a hash mapping <tt>const char *</tt>\r
1419  * filename extensions to <tt>const char *</tt> MIME types, and is the\r
1420  * first source consulted regarding @a file's MIME type.\r
1421  *\r
1422  * Use @a pool for any necessary allocations.\r
1423  *\r
1424  * @since New in 1.5.\r
1425  */\r
1426 svn_error_t *\r
1427 svn_io_detect_mimetype2(const char **mimetype,\r
1428                         const char *file,\r
1429                         apr_hash_t *mimetype_map,\r
1430                         apr_pool_t *pool);\r
1431 \r
1432 \r
1433 /** Like svn_io_detect_mimetype2, but with @a mimetypes_map set to\r
1434  * @c NULL.\r
1435  *\r
1436  * @deprecated Provided for backward compatibility with the 1.4 API\r
1437  */\r
1438 SVN_DEPRECATED\r
1439 svn_error_t *\r
1440 svn_io_detect_mimetype(const char **mimetype,\r
1441                        const char *file,\r
1442                        apr_pool_t *pool);\r
1443 \r
1444 \r
1445 /** Wrapper for apr_file_open().  @a fname is utf8-encoded. */\r
1446 svn_error_t *\r
1447 svn_io_file_open(apr_file_t **new_file,\r
1448                  const char *fname,\r
1449                  apr_int32_t flag,\r
1450                  apr_fileperms_t perm,\r
1451                  apr_pool_t *pool);\r
1452 \r
1453 \r
1454 /** Wrapper for apr_file_close(). */\r
1455 svn_error_t *\r
1456 svn_io_file_close(apr_file_t *file,\r
1457                   apr_pool_t *pool);\r
1458 \r
1459 \r
1460 /** Wrapper for apr_file_getc(). */\r
1461 svn_error_t *\r
1462 svn_io_file_getc(char *ch,\r
1463                  apr_file_t *file,\r
1464                  apr_pool_t *pool);\r
1465 \r
1466 \r
1467 /** Wrapper for apr_file_info_get(). */\r
1468 svn_error_t *\r
1469 svn_io_file_info_get(apr_finfo_t *finfo,\r
1470                      apr_int32_t wanted,\r
1471                      apr_file_t *file,\r
1472                      apr_pool_t *pool);\r
1473 \r
1474 \r
1475 /** Wrapper for apr_file_read(). */\r
1476 svn_error_t *\r
1477 svn_io_file_read(apr_file_t *file,\r
1478                  void *buf,\r
1479                  apr_size_t *nbytes,\r
1480                  apr_pool_t *pool);\r
1481 \r
1482 \r
1483 /** Wrapper for apr_file_read_full(). */\r
1484 svn_error_t *\r
1485 svn_io_file_read_full(apr_file_t *file,\r
1486                       void *buf,\r
1487                       apr_size_t nbytes,\r
1488                       apr_size_t *bytes_read,\r
1489                       apr_pool_t *pool);\r
1490 \r
1491 \r
1492 /** Wrapper for apr_file_seek(). */\r
1493 svn_error_t *\r
1494 svn_io_file_seek(apr_file_t *file,\r
1495                  apr_seek_where_t where,\r
1496                  apr_off_t *offset,\r
1497                  apr_pool_t *pool);\r
1498 \r
1499 \r
1500 /** Wrapper for apr_file_write(). */\r
1501 svn_error_t *\r
1502 svn_io_file_write(apr_file_t *file,\r
1503                   const void *buf,\r
1504                   apr_size_t *nbytes,\r
1505                   apr_pool_t *pool);\r
1506 \r
1507 \r
1508 /** Wrapper for apr_file_write_full(). */\r
1509 svn_error_t *\r
1510 svn_io_file_write_full(apr_file_t *file,\r
1511                        const void *buf,\r
1512                        apr_size_t nbytes,\r
1513                        apr_size_t *bytes_written,\r
1514                        apr_pool_t *pool);\r
1515 \r
1516 /**\r
1517  * Open a unique file in @a dirpath, and write @a nbytes from @a buf to\r
1518  * the file before closing it.  Return the name of the newly created file\r
1519  * in @a *tmp_path, allocated in @a pool.\r
1520  *\r
1521  * If @a dirpath is @c NULL, use the path returned from svn_io_temp_dir().\r
1522  * (Note that when using the system-provided temp directory, it may not\r
1523  * be possibly to atomically rename the resulting file due to cross-device\r
1524  * issues.)\r
1525  *\r
1526  * The file will be deleted according to @a delete_when.\r
1527  *\r
1528  * @since New in 1.6.\r
1529  */\r
1530 svn_error_t *\r
1531 svn_io_write_unique(const char **tmp_path,\r
1532                     const char *dirpath,\r
1533                     const void *buf,\r
1534                     apr_size_t nbytes,\r
1535                     svn_io_file_del_t delete_when,\r
1536                     apr_pool_t *pool);\r
1537 \r
1538 /** Wrapper for apr_file_trunc().\r
1539   * @since New in 1.6. */\r
1540 svn_error_t *\r
1541 svn_io_file_trunc(apr_file_t *file,\r
1542                   apr_off_t offset,\r
1543                   apr_pool_t *pool);\r
1544 \r
1545 \r
1546 /** Wrapper for apr_stat().  @a fname is utf8-encoded. */\r
1547 svn_error_t *\r
1548 svn_io_stat(apr_finfo_t *finfo,\r
1549             const char *fname,\r
1550             apr_int32_t wanted,\r
1551             apr_pool_t *pool);\r
1552 \r
1553 \r
1554 /** Wrapper for apr_file_rename().  @a from_path and @a to_path are\r
1555  * utf8-encoded.\r
1556  */\r
1557 svn_error_t *\r
1558 svn_io_file_rename(const char *from_path,\r
1559                    const char *to_path,\r
1560                    apr_pool_t *pool);\r
1561 \r
1562 \r
1563 /** Move the file from @a from_path to @a to_path, even across device\r
1564  * boundaries. Overwrite @a to_path if it exists.\r
1565  *\r
1566  * @note This function is different from svn_io_file_rename in that the\r
1567  * latter fails in the 'across device boundaries' case.\r
1568  *\r
1569  * @since New in 1.3.\r
1570  */\r
1571 svn_error_t *\r
1572 svn_io_file_move(const char *from_path,\r
1573                  const char *to_path,\r
1574                  apr_pool_t *pool);\r
1575 \r
1576 \r
1577 /** Wrapper for apr_dir_make().  @a path is utf8-encoded. */\r
1578 svn_error_t *\r
1579 svn_io_dir_make(const char *path,\r
1580                 apr_fileperms_t perm,\r
1581                 apr_pool_t *pool);\r
1582 \r
1583 /** Same as svn_io_dir_make(), but sets the hidden attribute on the\r
1584     directory on systems that support it. */\r
1585 svn_error_t *\r
1586 svn_io_dir_make_hidden(const char *path,\r
1587                        apr_fileperms_t perm,\r
1588                        apr_pool_t *pool);\r
1589 \r
1590 /**\r
1591  * Same as svn_io_dir_make(), but attempts to set the sgid on the\r
1592  * directory on systems that support it.  Does not return an error if\r
1593  * the attempt to set the sgid bit fails.  On Unix filesystems,\r
1594  * setting the sgid bit on a directory ensures that files and\r
1595  * subdirectories created within inherit group ownership from the\r
1596  * parent instead of from the primary gid.\r
1597  *\r
1598  * @since New in 1.1.\r
1599  */\r
1600 svn_error_t *\r
1601 svn_io_dir_make_sgid(const char *path,\r
1602                      apr_fileperms_t perm,\r
1603                      apr_pool_t *pool);\r
1604 \r
1605 /** Wrapper for apr_dir_open().  @a dirname is utf8-encoded. */\r
1606 svn_error_t *\r
1607 svn_io_dir_open(apr_dir_t **new_dir,\r
1608                 const char *dirname,\r
1609                 apr_pool_t *pool);\r
1610 \r
1611 \r
1612 /** Wrapper for apr_dir_remove().  @a dirname is utf8-encoded.\r
1613  * @note This function has this name to avoid confusion with\r
1614  * svn_io_remove_dir2(), which is recursive.\r
1615  */\r
1616 svn_error_t *\r
1617 svn_io_dir_remove_nonrecursive(const char *dirname,\r
1618                                apr_pool_t *pool);\r
1619 \r
1620 \r
1621 /** Wrapper for apr_dir_read().  Ensures that @a finfo->name is\r
1622  * utf8-encoded, which means allocating @a finfo->name in @a pool,\r
1623  * which may or may not be the same as @a finfo's pool.  Use @a pool\r
1624  * for error allocation as well.\r
1625  */\r
1626 svn_error_t *\r
1627 svn_io_dir_read(apr_finfo_t *finfo,\r
1628                 apr_int32_t wanted,\r
1629                 apr_dir_t *thedir,\r
1630                 apr_pool_t *pool);\r
1631 \r
1632 \r
1633 \f\r
1634 /** Version/format files.\r
1635  *\r
1636  * @defgroup svn_io_format_files Version/format files\r
1637  * @{\r
1638  */\r
1639 \r
1640 /** Set @a *version to the integer that starts the file at @a path.  If the\r
1641  * file does not begin with a series of digits followed by a newline,\r
1642  * return the error @c SVN_ERR_BAD_VERSION_FILE_FORMAT.  Use @a pool for\r
1643  * all allocations.\r
1644  */\r
1645 svn_error_t *\r
1646 svn_io_read_version_file(int *version,\r
1647                          const char *path,\r
1648                          apr_pool_t *pool);\r
1649 \r
1650 /** Create (or overwrite) the file at @a path with new contents,\r
1651  * formatted as a non-negative integer @a version followed by a single\r
1652  * newline.  On successful completion the file will be read-only.  Use\r
1653  * @a pool for all allocations.\r
1654  */\r
1655 svn_error_t *\r
1656 svn_io_write_version_file(const char *path,\r
1657                           int version,\r
1658                           apr_pool_t *pool);\r
1659 \r
1660 /** @} */\r
1661 \r
1662 #ifdef __cplusplus\r
1663 }\r
1664 #endif /* __cplusplus */\r
1665 \r
1666 #endif /* SVN_IO_H */\r