1251881Speter/** 2251881Speter * @copyright 3251881Speter * ==================================================================== 4251881Speter * Licensed to the Apache Software Foundation (ASF) under one 5251881Speter * or more contributor license agreements. See the NOTICE file 6251881Speter * distributed with this work for additional information 7251881Speter * regarding copyright ownership. The ASF licenses this file 8251881Speter * to you under the Apache License, Version 2.0 (the 9251881Speter * "License"); you may not use this file except in compliance 10251881Speter * with the License. You may obtain a copy of the License at 11251881Speter * 12251881Speter * http://www.apache.org/licenses/LICENSE-2.0 13251881Speter * 14251881Speter * Unless required by applicable law or agreed to in writing, 15251881Speter * software distributed under the License is distributed on an 16251881Speter * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17251881Speter * KIND, either express or implied. See the License for the 18251881Speter * specific language governing permissions and limitations 19251881Speter * under the License. 20251881Speter * ==================================================================== 21251881Speter * @endcopyright 22251881Speter * 23251881Speter * @file svn_io.h 24251881Speter * @brief General file I/O for Subversion 25251881Speter */ 26251881Speter 27251881Speter/* ==================================================================== */ 28251881Speter 29251881Speter 30251881Speter#ifndef SVN_IO_H 31251881Speter#define SVN_IO_H 32251881Speter 33251881Speter#include <apr.h> 34251881Speter#include <apr_pools.h> 35251881Speter#include <apr_time.h> 36251881Speter#include <apr_hash.h> 37251881Speter#include <apr_tables.h> 38251881Speter#include <apr_file_io.h> 39251881Speter#include <apr_file_info.h> 40251881Speter#include <apr_thread_proc.h> /* for apr_proc_t, apr_exit_why_e */ 41251881Speter 42251881Speter#include "svn_types.h" 43251881Speter#include "svn_string.h" 44251881Speter#include "svn_checksum.h" 45251881Speter 46251881Speter#ifdef __cplusplus 47251881Speterextern "C" { 48251881Speter#endif /* __cplusplus */ 49251881Speter 50251881Speter 51251881Speter 52251881Speter/** Used as an argument when creating temporary files to indicate 53251881Speter * when a file should be removed. 54251881Speter * 55251881Speter * @since New in 1.4. 56251881Speter * 57251881Speter * Not specifying any of these means no removal at all. */ 58251881Spetertypedef enum svn_io_file_del_t 59251881Speter{ 60251881Speter /** No deletion ever */ 61251881Speter svn_io_file_del_none = 0, 62251881Speter /** Remove when the file is closed */ 63251881Speter svn_io_file_del_on_close, 64251881Speter /** Remove when the associated pool is cleared */ 65251881Speter svn_io_file_del_on_pool_cleanup 66251881Speter} svn_io_file_del_t; 67251881Speter 68251881Speter/** A set of directory entry data elements as returned by svn_io_get_dirents 69251881Speter * 70251881Speter * Note that the first two fields are exactly identical to svn_io_dirent_t 71251881Speter * to allow returning a svn_io_dirent2_t as a svn_io_dirent_t. 72251881Speter * 73251881Speter * Use svn_io_dirent2_create() to create new svn_dirent2_t instances or 74251881Speter * svn_io_dirent2_dup() to duplicate an existing instance. 75251881Speter * 76251881Speter * @since New in 1.7. 77251881Speter */ 78251881Spetertypedef struct svn_io_dirent2_t { 79251881Speter /* New fields must be added at the end to preserve binary compatibility */ 80251881Speter 81251881Speter /** The kind of this entry. */ 82251881Speter svn_node_kind_t kind; 83251881Speter 84251881Speter /** If @c kind is #svn_node_file, whether this entry is a special file; 85251881Speter * else FALSE. 86251881Speter * 87251881Speter * @see svn_io_check_special_path(). 88251881Speter */ 89251881Speter svn_boolean_t special; 90251881Speter 91251881Speter /** The filesize of this entry or undefined for a directory */ 92251881Speter svn_filesize_t filesize; 93251881Speter 94251881Speter /** The time the file was last modified */ 95251881Speter apr_time_t mtime; 96251881Speter 97251881Speter /* Don't forget to update svn_io_dirent2_dup() when adding new fields */ 98251881Speter} svn_io_dirent2_t; 99251881Speter 100251881Speter 101251881Speter/** Creates a new #svn_io_dirent2_t structure 102251881Speter * 103251881Speter * @since New in 1.7. 104251881Speter */ 105251881Spetersvn_io_dirent2_t * 106251881Spetersvn_io_dirent2_create(apr_pool_t *result_pool); 107251881Speter 108251881Speter/** Duplicates a @c svn_io_dirent2_t structure into @a result_pool. 109251881Speter * 110251881Speter * @since New in 1.7. 111251881Speter */ 112251881Spetersvn_io_dirent2_t * 113251881Spetersvn_io_dirent2_dup(const svn_io_dirent2_t *item, 114251881Speter apr_pool_t *result_pool); 115251881Speter 116251881Speter/** Represents the kind and special status of a directory entry. 117251881Speter * 118251881Speter * Note that the first two fields are exactly identical to svn_io_dirent2_t 119251881Speter * to allow returning a svn_io_dirent2_t as a svn_io_dirent_t. 120251881Speter * 121251881Speter * @since New in 1.3. 122251881Speter */ 123251881Spetertypedef struct svn_io_dirent_t { 124251881Speter /** The kind of this entry. */ 125251881Speter svn_node_kind_t kind; 126251881Speter /** If @c kind is #svn_node_file, whether this entry is a special file; 127251881Speter * else FALSE. 128251881Speter * 129251881Speter * @see svn_io_check_special_path(). 130251881Speter */ 131251881Speter svn_boolean_t special; 132251881Speter} svn_io_dirent_t; 133251881Speter 134251881Speter/** Determine the @a kind of @a path. @a path should be UTF-8 encoded. 135251881Speter * 136251881Speter * If @a path is a file, set @a *kind to #svn_node_file. 137251881Speter * 138251881Speter * If @a path is a directory, set @a *kind to #svn_node_dir. 139251881Speter * 140251881Speter * If @a path does not exist, set @a *kind to #svn_node_none. 141251881Speter * 142251881Speter * If @a path exists but is none of the above, set @a *kind to 143251881Speter * #svn_node_unknown. 144251881Speter * 145251881Speter * If @a path is not a valid pathname, set @a *kind to #svn_node_none. If 146251881Speter * unable to determine @a path's kind for any other reason, return an error, 147251881Speter * with @a *kind's value undefined. 148251881Speter * 149251881Speter * Use @a pool for temporary allocations. 150251881Speter * 151251881Speter * @see svn_node_kind_t 152251881Speter */ 153251881Spetersvn_error_t * 154251881Spetersvn_io_check_path(const char *path, 155251881Speter svn_node_kind_t *kind, 156251881Speter apr_pool_t *pool); 157251881Speter 158251881Speter/** 159251881Speter * Like svn_io_check_path(), but also set *is_special to @c TRUE if 160251881Speter * the path is not a normal file. 161251881Speter * 162251881Speter * @since New in 1.1. 163251881Speter */ 164251881Spetersvn_error_t * 165251881Spetersvn_io_check_special_path(const char *path, 166251881Speter svn_node_kind_t *kind, 167251881Speter svn_boolean_t *is_special, 168251881Speter apr_pool_t *pool); 169251881Speter 170251881Speter/** Like svn_io_check_path(), but resolve symlinks. This returns the 171251881Speter same varieties of @a kind as svn_io_check_path(). */ 172251881Spetersvn_error_t * 173251881Spetersvn_io_check_resolved_path(const char *path, 174251881Speter svn_node_kind_t *kind, 175251881Speter apr_pool_t *pool); 176251881Speter 177251881Speter 178251881Speter/** Open a new file (for reading and writing) with a unique name based on 179251881Speter * utf-8 encoded @a filename, in the directory @a dirpath. The file handle is 180251881Speter * returned in @a *file, and the name, which ends with @a suffix, is returned 181251881Speter * in @a *unique_name, also utf8-encoded. Either @a file or @a unique_name 182251881Speter * may be @c NULL. If @a file is @c NULL, the file will be created but not 183251881Speter * open. 184251881Speter * 185262253Speter * The file will be deleted according to @a delete_when. If that is 186262253Speter * #svn_io_file_del_on_pool_cleanup, it refers to @a result_pool. 187251881Speter * 188262253Speter * The @c APR_BUFFERED flag will always be used when opening the file. 189262253Speter * 190251881Speter * The first attempt will just append @a suffix. If the result is not 191251881Speter * a unique name, then subsequent attempts will append a dot, 192251881Speter * followed by an iteration number ("2", then "3", and so on), 193251881Speter * followed by the suffix. For example, successive calls to 194251881Speter * 195251881Speter * svn_io_open_uniquely_named(&f, &u, "tests/t1/A/D/G", "pi", ".tmp", ...) 196251881Speter * 197251881Speter * will open 198251881Speter * 199251881Speter * tests/t1/A/D/G/pi.tmp 200251881Speter * tests/t1/A/D/G/pi.2.tmp 201251881Speter * tests/t1/A/D/G/pi.3.tmp 202251881Speter * tests/t1/A/D/G/pi.4.tmp 203251881Speter * tests/t1/A/D/G/pi.5.tmp 204251881Speter * ... 205251881Speter * 206251881Speter * Assuming @a suffix is non-empty, @a *unique_name will never be exactly 207251881Speter * the same as @a filename, even if @a filename does not exist. 208251881Speter * 209251881Speter * If @a dirpath is NULL, then the directory returned by svn_io_temp_dir() 210251881Speter * will be used. 211251881Speter * 212251881Speter * If @a filename is NULL, then "tempfile" will be used. 213251881Speter * 214251881Speter * If @a suffix is NULL, then ".tmp" will be used. 215251881Speter * 216251881Speter * Allocates @a *file and @a *unique_name in @a result_pool. All 217251881Speter * intermediate allocations will be performed in @a scratch_pool. 218251881Speter * 219251881Speter * If no unique name can be found, #SVN_ERR_IO_UNIQUE_NAMES_EXHAUSTED is 220251881Speter * the error returned. 221251881Speter * 222251881Speter * Claim of Historical Inevitability: this function was written 223251881Speter * because 224251881Speter * 225251881Speter * - tmpnam() is not thread-safe. 226251881Speter * - tempname() tries standard system tmp areas first. 227251881Speter * 228251881Speter * @since New in 1.6 229251881Speter */ 230251881Spetersvn_error_t * 231251881Spetersvn_io_open_uniquely_named(apr_file_t **file, 232251881Speter const char **unique_name, 233251881Speter const char *dirpath, 234251881Speter const char *filename, 235251881Speter const char *suffix, 236251881Speter svn_io_file_del_t delete_when, 237251881Speter apr_pool_t *result_pool, 238251881Speter apr_pool_t *scratch_pool); 239251881Speter 240251881Speter 241251881Speter/** Create a writable file, with an arbitrary and unique name, in the 242251881Speter * directory @a dirpath. Set @a *temp_path to its full path, and set 243251881Speter * @a *file to the file handle, both allocated from @a result_pool. Either 244251881Speter * @a file or @a temp_path may be @c NULL. If @a file is @c NULL, the file 245251881Speter * will be created but not open. 246251881Speter * 247251881Speter * If @a dirpath is @c NULL, use the path returned from svn_io_temp_dir(). 248251881Speter * (Note that when using the system-provided temp directory, it may not 249251881Speter * be possible to atomically rename the resulting file due to cross-device 250251881Speter * issues.) 251251881Speter * 252262253Speter * The file will be deleted according to @a delete_when. If that is 253262253Speter * #svn_io_file_del_on_pool_cleanup, it refers to @a result_pool. If it 254262253Speter * is #svn_io_file_del_on_close and @a file is @c NULL, the file will be 255251881Speter * deleted before this function returns. 256251881Speter * 257251881Speter * When passing @c svn_io_file_del_none please don't forget to eventually 258251881Speter * remove the temporary file to avoid filling up the system temp directory. 259251881Speter * It is often appropriate to bind the lifetime of the temporary file to 260251881Speter * the lifetime of a pool by using @c svn_io_file_del_on_pool_cleanup. 261251881Speter * 262251881Speter * Temporary allocations will be performed in @a scratch_pool. 263251881Speter * 264251881Speter * @since New in 1.6 265251881Speter * @see svn_stream_open_unique() 266251881Speter */ 267251881Spetersvn_error_t * 268251881Spetersvn_io_open_unique_file3(apr_file_t **file, 269251881Speter const char **temp_path, 270251881Speter const char *dirpath, 271251881Speter svn_io_file_del_t delete_when, 272251881Speter apr_pool_t *result_pool, 273251881Speter apr_pool_t *scratch_pool); 274251881Speter 275251881Speter 276251881Speter/** Like svn_io_open_uniquely_named(), but takes a joined dirpath and 277251881Speter * filename, and a single pool. 278251881Speter * 279251881Speter * @since New in 1.4 280251881Speter * 281251881Speter * @deprecated Provided for backward compatibility with the 1.5 API 282251881Speter */ 283251881SpeterSVN_DEPRECATED 284251881Spetersvn_error_t * 285251881Spetersvn_io_open_unique_file2(apr_file_t **f, 286251881Speter const char **unique_name_p, 287251881Speter const char *path, 288251881Speter const char *suffix, 289251881Speter svn_io_file_del_t delete_when, 290251881Speter apr_pool_t *pool); 291251881Speter 292251881Speter/** Like svn_io_open_unique_file2, but can't delete on pool cleanup. 293251881Speter * 294251881Speter * @deprecated Provided for backward compatibility with the 1.3 API 295251881Speter * 296251881Speter * @note In 1.4 the API was extended to require either @a f or 297251881Speter * @a unique_name_p (the other can be NULL). Before that, both were 298251881Speter * required. 299251881Speter */ 300251881SpeterSVN_DEPRECATED 301251881Spetersvn_error_t * 302251881Spetersvn_io_open_unique_file(apr_file_t **f, 303251881Speter const char **unique_name_p, 304251881Speter const char *path, 305251881Speter const char *suffix, 306251881Speter svn_boolean_t delete_on_close, 307251881Speter apr_pool_t *pool); 308251881Speter 309251881Speter 310251881Speter/** 311251881Speter * Like svn_io_open_unique_file(), except that instead of creating a 312251881Speter * file, a symlink is generated that references the path @a dest. 313251881Speter * 314251881Speter * @since New in 1.1. 315251881Speter */ 316251881Spetersvn_error_t * 317251881Spetersvn_io_create_unique_link(const char **unique_name_p, 318251881Speter const char *path, 319251881Speter const char *dest, 320251881Speter const char *suffix, 321251881Speter apr_pool_t *pool); 322251881Speter 323251881Speter 324251881Speter/** 325251881Speter * Set @a *dest to the path that the symlink at @a path references. 326251881Speter * Allocate the string from @a pool. 327251881Speter * 328251881Speter * @since New in 1.1. 329251881Speter */ 330251881Spetersvn_error_t * 331251881Spetersvn_io_read_link(svn_string_t **dest, 332251881Speter const char *path, 333251881Speter apr_pool_t *pool); 334251881Speter 335251881Speter 336251881Speter/** Set @a *dir to a directory path (allocated in @a pool) deemed 337251881Speter * usable for the creation of temporary files and subdirectories. 338251881Speter */ 339251881Spetersvn_error_t * 340251881Spetersvn_io_temp_dir(const char **dir, 341251881Speter apr_pool_t *pool); 342251881Speter 343251881Speter 344251881Speter/** Copy @a src to @a dst atomically, in a "byte-for-byte" manner. 345251881Speter * Overwrite @a dst if it exists, else create it. Both @a src and @a dst 346251881Speter * are utf8-encoded filenames. If @a copy_perms is TRUE, set @a dst's 347251881Speter * permissions to match those of @a src. 348251881Speter */ 349251881Spetersvn_error_t * 350251881Spetersvn_io_copy_file(const char *src, 351251881Speter const char *dst, 352251881Speter svn_boolean_t copy_perms, 353251881Speter apr_pool_t *pool); 354251881Speter 355251881Speter 356251881Speter/** Copy permission flags from @a src onto the file at @a dst. Both 357251881Speter * filenames are utf8-encoded filenames. 358251881Speter * 359251881Speter * @since New in 1.6. 360251881Speter */ 361251881Spetersvn_error_t * 362251881Spetersvn_io_copy_perms(const char *src, 363251881Speter const char *dst, 364251881Speter apr_pool_t *pool); 365251881Speter 366251881Speter 367251881Speter/** 368251881Speter * Copy symbolic link @a src to @a dst atomically. Overwrite @a dst 369251881Speter * if it exists, else create it. Both @a src and @a dst are 370251881Speter * utf8-encoded filenames. After copying, the @a dst link will point 371251881Speter * to the same thing @a src does. 372251881Speter * 373251881Speter * @since New in 1.1. 374251881Speter */ 375251881Spetersvn_error_t * 376251881Spetersvn_io_copy_link(const char *src, 377251881Speter const char *dst, 378251881Speter apr_pool_t *pool); 379251881Speter 380251881Speter 381251881Speter/** Recursively copy directory @a src into @a dst_parent, as a new entry named 382251881Speter * @a dst_basename. If @a dst_basename already exists in @a dst_parent, 383251881Speter * return error. @a copy_perms will be passed through to svn_io_copy_file() 384251881Speter * when any files are copied. @a src, @a dst_parent, and @a dst_basename are 385251881Speter * all utf8-encoded. 386251881Speter * 387251881Speter * If @a cancel_func is non-NULL, invoke it with @a cancel_baton at 388251881Speter * various points during the operation. If it returns any error 389251881Speter * (typically #SVN_ERR_CANCELLED), return that error immediately. 390251881Speter */ 391251881Spetersvn_error_t * 392251881Spetersvn_io_copy_dir_recursively(const char *src, 393251881Speter const char *dst_parent, 394251881Speter const char *dst_basename, 395251881Speter svn_boolean_t copy_perms, 396251881Speter svn_cancel_func_t cancel_func, 397251881Speter void *cancel_baton, 398251881Speter apr_pool_t *pool); 399251881Speter 400251881Speter 401251881Speter/** Create directory @a path on the file system, creating intermediate 402251881Speter * directories as required, like <tt>mkdir -p</tt>. Report no error if @a 403251881Speter * path already exists. @a path is utf8-encoded. 404251881Speter * 405251881Speter * This is essentially a wrapper for apr_dir_make_recursive(), passing 406251881Speter * @c APR_OS_DEFAULT as the permissions. 407251881Speter */ 408251881Spetersvn_error_t * 409251881Spetersvn_io_make_dir_recursively(const char *path, 410251881Speter apr_pool_t *pool); 411251881Speter 412251881Speter 413251881Speter/** Set @a *is_empty_p to @c TRUE if directory @a path is empty, else to 414251881Speter * @c FALSE if it is not empty. @a path must be a directory, and is 415251881Speter * utf8-encoded. Use @a pool for temporary allocation. 416251881Speter */ 417251881Spetersvn_error_t * 418251881Spetersvn_io_dir_empty(svn_boolean_t *is_empty_p, 419251881Speter const char *path, 420251881Speter apr_pool_t *pool); 421251881Speter 422251881Speter 423251881Speter/** Append @a src to @a dst. @a dst will be appended to if it exists, else it 424251881Speter * will be created. Both @a src and @a dst are utf8-encoded. 425251881Speter */ 426251881Spetersvn_error_t * 427251881Spetersvn_io_append_file(const char *src, 428251881Speter const char *dst, 429251881Speter apr_pool_t *pool); 430251881Speter 431251881Speter 432251881Speter/** Make a file as read-only as the operating system allows. 433251881Speter * @a path is the utf8-encoded path to the file. If @a ignore_enoent is 434251881Speter * @c TRUE, don't fail if the target file doesn't exist. 435251881Speter * 436251881Speter * If @a path is a symlink, do nothing. 437251881Speter * 438251881Speter * @note If @a path is a directory, act on it as though it were a 439251881Speter * file, as described above, but note that you probably don't want to 440251881Speter * call this function on directories. We have left it effective on 441251881Speter * directories for compatibility reasons, but as its name implies, it 442251881Speter * should be used only for files. 443251881Speter */ 444251881Spetersvn_error_t * 445251881Spetersvn_io_set_file_read_only(const char *path, 446251881Speter svn_boolean_t ignore_enoent, 447251881Speter apr_pool_t *pool); 448251881Speter 449251881Speter 450251881Speter/** Make a file as writable as the operating system allows. 451251881Speter * @a path is the utf8-encoded path to the file. If @a ignore_enoent is 452251881Speter * @c TRUE, don't fail if the target file doesn't exist. 453251881Speter * @warning On Unix this function will do the equivalent of chmod a+w path. 454251881Speter * If this is not what you want you should not use this function, but rather 455251881Speter * use apr_file_perms_set(). 456251881Speter * 457251881Speter * If @a path is a symlink, do nothing. 458251881Speter * 459251881Speter * @note If @a path is a directory, act on it as though it were a 460251881Speter * file, as described above, but note that you probably don't want to 461251881Speter * call this function on directories. We have left it effective on 462251881Speter * directories for compatibility reasons, but as its name implies, it 463251881Speter * should be used only for files. 464251881Speter */ 465251881Spetersvn_error_t * 466251881Spetersvn_io_set_file_read_write(const char *path, 467251881Speter svn_boolean_t ignore_enoent, 468251881Speter apr_pool_t *pool); 469251881Speter 470251881Speter 471251881Speter/** Similar to svn_io_set_file_read_* functions. 472251881Speter * Change the read-write permissions of a file. 473251881Speter * @since New in 1.1. 474251881Speter * 475251881Speter * When making @a path read-write on operating systems with unix style 476251881Speter * permissions, set the permissions on @a path to the permissions that 477251881Speter * are set when a new file is created (effectively honoring the user's 478251881Speter * umask). 479251881Speter * 480251881Speter * When making the file read-only on operating systems with unix style 481251881Speter * permissions, remove all write permissions. 482251881Speter * 483251881Speter * On other operating systems, toggle the file's "writability" as much as 484251881Speter * the operating system allows. 485251881Speter * 486251881Speter * @a path is the utf8-encoded path to the file. If @a enable_write 487251881Speter * is @c TRUE, then make the file read-write. If @c FALSE, make it 488251881Speter * read-only. If @a ignore_enoent is @c TRUE, don't fail if the target 489251881Speter * file doesn't exist. 490251881Speter * 491251881Speter * @deprecated Provided for backward compatibility with the 1.3 API. 492251881Speter */ 493251881SpeterSVN_DEPRECATED 494251881Spetersvn_error_t * 495251881Spetersvn_io_set_file_read_write_carefully(const char *path, 496251881Speter svn_boolean_t enable_write, 497251881Speter svn_boolean_t ignore_enoent, 498251881Speter apr_pool_t *pool); 499251881Speter 500251881Speter/** Set @a path's "executability" (but do nothing if it is a symlink). 501251881Speter * 502251881Speter * @a path is the utf8-encoded path to the file. If @a executable 503251881Speter * is @c TRUE, then make the file executable. If @c FALSE, make it 504251881Speter * non-executable. If @a ignore_enoent is @c TRUE, don't fail if the target 505251881Speter * file doesn't exist. 506251881Speter * 507251881Speter * When making the file executable on operating systems with unix style 508251881Speter * permissions, never add an execute permission where there is not 509251881Speter * already a read permission: that is, only make the file executable 510251881Speter * for the user, group or world if the corresponding read permission 511251881Speter * is already set for user, group or world. 512251881Speter * 513251881Speter * When making the file non-executable on operating systems with unix style 514251881Speter * permissions, remove all execute permissions. 515251881Speter * 516251881Speter * On other operating systems, toggle the file's "executability" as much as 517251881Speter * the operating system allows. 518251881Speter * 519251881Speter * @note If @a path is a directory, act on it as though it were a 520251881Speter * file, as described above, but note that you probably don't want to 521251881Speter * call this function on directories. We have left it effective on 522251881Speter * directories for compatibility reasons, but as its name implies, it 523251881Speter * should be used only for files. 524251881Speter */ 525251881Spetersvn_error_t * 526251881Spetersvn_io_set_file_executable(const char *path, 527251881Speter svn_boolean_t executable, 528251881Speter svn_boolean_t ignore_enoent, 529251881Speter apr_pool_t *pool); 530251881Speter 531251881Speter/** Determine whether a file is executable by the current user. 532251881Speter * Set @a *executable to @c TRUE if the file @a path is executable by the 533251881Speter * current user, otherwise set it to @c FALSE. 534251881Speter * 535251881Speter * On Windows and on platforms without userids, always returns @c FALSE. 536251881Speter */ 537251881Spetersvn_error_t * 538251881Spetersvn_io_is_file_executable(svn_boolean_t *executable, 539251881Speter const char *path, 540251881Speter apr_pool_t *pool); 541251881Speter 542251881Speter 543251881Speter/** Read a line from @a file into @a buf, but not exceeding @a *limit bytes. 544251881Speter * Does not include newline, instead '\\0' is put there. 545251881Speter * Length (as in strlen) is returned in @a *limit. 546251881Speter * @a buf should be pre-allocated. 547251881Speter * @a file should be already opened. 548251881Speter * 549251881Speter * When the file is out of lines, @c APR_EOF will be returned. 550251881Speter */ 551251881Spetersvn_error_t * 552251881Spetersvn_io_read_length_line(apr_file_t *file, 553251881Speter char *buf, 554251881Speter apr_size_t *limit, 555251881Speter apr_pool_t *pool); 556251881Speter 557251881Speter 558251881Speter/** Set @a *apr_time to the time of last modification of the contents of the 559251881Speter * file @a path. @a path is utf8-encoded. 560251881Speter * 561251881Speter * @note This is the APR mtime which corresponds to the traditional mtime 562251881Speter * on Unix, and the last write time on Windows. 563251881Speter */ 564251881Spetersvn_error_t * 565251881Spetersvn_io_file_affected_time(apr_time_t *apr_time, 566251881Speter const char *path, 567251881Speter apr_pool_t *pool); 568251881Speter 569251881Speter/** Set the timestamp of file @a path to @a apr_time. @a path is 570251881Speter * utf8-encoded. 571251881Speter * 572251881Speter * @note This is the APR mtime which corresponds to the traditional mtime 573251881Speter * on Unix, and the last write time on Windows. 574251881Speter */ 575251881Spetersvn_error_t * 576251881Spetersvn_io_set_file_affected_time(apr_time_t apr_time, 577251881Speter const char *path, 578251881Speter apr_pool_t *pool); 579251881Speter 580251881Speter/** Sleep to ensure that any files modified after we exit have a different 581251881Speter * timestamp than the one we recorded. If @a path is not NULL, check if we 582251881Speter * can determine how long we should wait for a new timestamp on the filesystem 583251881Speter * containing @a path, an existing file or directory. If @a path is NULL or we 584251881Speter * can't determine the timestamp resolution, sleep until the next second. 585251881Speter * 586251881Speter * Use @a pool for any necessary allocations. @a pool can be null if @a path 587251881Speter * is NULL. 588251881Speter * 589251881Speter * Errors while retrieving the timestamp resolution will result in sleeping 590251881Speter * to the next second, to keep the working copy stable in error conditions. 591251881Speter * 592251881Speter * @since New in 1.6. 593251881Speter */ 594251881Spetervoid 595251881Spetersvn_io_sleep_for_timestamps(const char *path, apr_pool_t *pool); 596251881Speter 597251881Speter/** Set @a *different_p to TRUE if @a file1 and @a file2 have different 598251881Speter * sizes, else set to FALSE. Both @a file1 and @a file2 are utf8-encoded. 599251881Speter * 600251881Speter * Setting @a *different_p to zero does not mean the files definitely 601251881Speter * have the same size, it merely means that the sizes are not 602251881Speter * definitely different. That is, if the size of one or both files 603251881Speter * cannot be determined, then the sizes are not known to be different, 604251881Speter * so @a *different_p is set to FALSE. 605251881Speter */ 606251881Spetersvn_error_t * 607251881Spetersvn_io_filesizes_different_p(svn_boolean_t *different_p, 608251881Speter const char *file1, 609251881Speter const char *file2, 610251881Speter apr_pool_t *pool); 611251881Speter 612251881Speter/** Set @a *different_p12 to non-zero if @a file1 and @a file2 have different 613251881Speter * sizes, else set to zero. Do the similar for @a *different_p23 with 614251881Speter * @a file2 and @a file3, and @a *different_p13 for @a file1 and @a file3. 615251881Speter * The filenames @a file1, @a file2 and @a file3 are utf8-encoded. 616251881Speter * 617251881Speter * Setting @a *different_p12 to zero does not mean the files definitely 618251881Speter * have the same size, it merely means that the sizes are not 619251881Speter * definitely different. That is, if the size of one or both files 620251881Speter * cannot be determined (due to stat() returning an error), then the sizes 621251881Speter * are not known to be different, so @a *different_p12 is set to 0. 622251881Speter * 623251881Speter * @since New in 1.8. 624251881Speter */ 625251881Spetersvn_error_t * 626251881Spetersvn_io_filesizes_three_different_p(svn_boolean_t *different_p12, 627251881Speter svn_boolean_t *different_p23, 628251881Speter svn_boolean_t *different_p13, 629251881Speter const char *file1, 630251881Speter const char *file2, 631251881Speter const char *file3, 632251881Speter apr_pool_t *scratch_pool); 633251881Speter 634251881Speter/** Return in @a *checksum the checksum of type @a kind of @a file 635251881Speter * Use @a pool for temporary allocations and to allocate @a *checksum. 636251881Speter * 637251881Speter * @since New in 1.6. 638251881Speter */ 639251881Spetersvn_error_t * 640251881Spetersvn_io_file_checksum2(svn_checksum_t **checksum, 641251881Speter const char *file, 642251881Speter svn_checksum_kind_t kind, 643251881Speter apr_pool_t *pool); 644251881Speter 645251881Speter 646251881Speter/** Put the md5 checksum of @a file into @a digest. 647251881Speter * @a digest points to @c APR_MD5_DIGESTSIZE bytes of storage. 648251881Speter * Use @a pool only for temporary allocations. 649251881Speter * 650251881Speter * @deprecated Provided for backward compatibility with the 1.5 API. 651251881Speter */ 652251881SpeterSVN_DEPRECATED 653251881Spetersvn_error_t * 654251881Spetersvn_io_file_checksum(unsigned char digest[], 655251881Speter const char *file, 656251881Speter apr_pool_t *pool); 657251881Speter 658251881Speter 659251881Speter/** Set @a *same to TRUE if @a file1 and @a file2 have the same 660251881Speter * contents, else set it to FALSE. Use @a pool for temporary allocations. 661251881Speter */ 662251881Spetersvn_error_t * 663251881Spetersvn_io_files_contents_same_p(svn_boolean_t *same, 664251881Speter const char *file1, 665251881Speter const char *file2, 666251881Speter apr_pool_t *pool); 667251881Speter 668251881Speter/** Set @a *same12 to TRUE if @a file1 and @a file2 have the same 669251881Speter * contents, else set it to FALSE. Do the similar for @a *same23 670251881Speter * with @a file2 and @a file3, and @a *same13 for @a file1 and @a 671251881Speter * file3. The filenames @a file1, @a file2 and @a file3 are 672251881Speter * utf8-encoded. Use @a scratch_pool for temporary allocations. 673251881Speter * 674251881Speter * @since New in 1.8. 675251881Speter */ 676251881Spetersvn_error_t * 677251881Spetersvn_io_files_contents_three_same_p(svn_boolean_t *same12, 678251881Speter svn_boolean_t *same23, 679251881Speter svn_boolean_t *same13, 680251881Speter const char *file1, 681251881Speter const char *file2, 682251881Speter const char *file3, 683251881Speter apr_pool_t *scratch_pool); 684251881Speter 685251881Speter/** Create file at utf8-encoded @a file with contents @a contents. 686251881Speter * @a file must not already exist. 687251881Speter * Use @a pool for memory allocations. 688251881Speter */ 689251881Spetersvn_error_t * 690251881Spetersvn_io_file_create(const char *file, 691251881Speter const char *contents, 692251881Speter apr_pool_t *pool); 693251881Speter 694251881Speter/** 695251881Speter * Lock file at @a lock_file. If @a exclusive is TRUE, 696251881Speter * obtain exclusive lock, otherwise obtain shared lock. 697251881Speter * Lock will be automatically released when @a pool is cleared or destroyed. 698251881Speter * Use @a pool for memory allocations. 699251881Speter * 700251881Speter * @deprecated Provided for backward compatibility with the 1.0 API. 701251881Speter */ 702251881SpeterSVN_DEPRECATED 703251881Spetersvn_error_t * 704251881Spetersvn_io_file_lock(const char *lock_file, 705251881Speter svn_boolean_t exclusive, 706251881Speter apr_pool_t *pool); 707251881Speter 708251881Speter/** 709251881Speter * Lock file at @a lock_file. If @a exclusive is TRUE, 710251881Speter * obtain exclusive lock, otherwise obtain shared lock. 711251881Speter * 712251881Speter * If @a nonblocking is TRUE, do not wait for the lock if it 713251881Speter * is not available: throw an error instead. 714251881Speter * 715251881Speter * Lock will be automatically released when @a pool is cleared or destroyed. 716251881Speter * Use @a pool for memory allocations. 717251881Speter * 718251881Speter * @since New in 1.1. 719251881Speter */ 720251881Spetersvn_error_t * 721251881Spetersvn_io_file_lock2(const char *lock_file, 722251881Speter svn_boolean_t exclusive, 723251881Speter svn_boolean_t nonblocking, 724251881Speter apr_pool_t *pool); 725251881Speter 726251881Speter/** 727251881Speter * Lock the file @a lockfile_handle. If @a exclusive is TRUE, 728251881Speter * obtain exclusive lock, otherwise obtain shared lock. 729251881Speter * 730251881Speter * If @a nonblocking is TRUE, do not wait for the lock if it 731251881Speter * is not available: throw an error instead. 732251881Speter * 733251881Speter * Lock will be automatically released when @a pool is cleared or destroyed. 734251881Speter * You may also explicitly call svn_io_unlock_open_file(). 735251881Speter * Use @a pool for memory allocations. @a pool must be the pool that 736251881Speter * @a lockfile_handle has been created in or one of its sub-pools. 737251881Speter * 738251881Speter * @since New in 1.8. 739251881Speter */ 740251881Spetersvn_error_t * 741251881Spetersvn_io_lock_open_file(apr_file_t *lockfile_handle, 742251881Speter svn_boolean_t exclusive, 743251881Speter svn_boolean_t nonblocking, 744251881Speter apr_pool_t *pool); 745251881Speter 746251881Speter/** 747251881Speter * Unlock the file @a lockfile_handle. 748251881Speter * 749251881Speter * Use @a pool for memory allocations. @a pool must be the pool that 750251881Speter * was passed to svn_io_lock_open_file(). 751251881Speter * 752251881Speter * @since New in 1.8. 753251881Speter */ 754251881Spetersvn_error_t * 755251881Spetersvn_io_unlock_open_file(apr_file_t *lockfile_handle, 756251881Speter apr_pool_t *pool); 757251881Speter 758251881Speter/** 759251881Speter * Flush any unwritten data from @a file to disk. Use @a pool for 760251881Speter * memory allocations. 761251881Speter * 762251881Speter * @since New in 1.1. 763251881Speter */ 764251881Spetersvn_error_t * 765251881Spetersvn_io_file_flush_to_disk(apr_file_t *file, 766251881Speter apr_pool_t *pool); 767251881Speter 768251881Speter/** Copy the file whose basename (or relative path) is @a file within 769251881Speter * directory @a src_path to the same basename (or relative path) within 770251881Speter * directory @a dest_path. Overwrite the destination file if it already 771251881Speter * exists. The destination directory (including any directory 772251881Speter * components in @a name) must already exist. Set the destination 773251881Speter * file's permissions to match those of the source. Use @a pool for 774251881Speter * memory allocations. 775251881Speter */ 776251881Spetersvn_error_t * 777251881Spetersvn_io_dir_file_copy(const char *src_path, 778251881Speter const char *dest_path, 779251881Speter const char *file, 780251881Speter apr_pool_t *pool); 781251881Speter 782251881Speter 783251881Speter/** Generic byte-streams 784251881Speter * 785251881Speter * @defgroup svn_io_byte_streams Generic byte streams 786251881Speter * @{ 787251881Speter */ 788251881Speter 789251881Speter/** An abstract stream of bytes--either incoming or outgoing or both. 790251881Speter * 791251881Speter * The creator of a stream sets functions to handle read and write. 792251881Speter * Both of these handlers accept a baton whose value is determined at 793251881Speter * stream creation time; this baton can point to a structure 794251881Speter * containing data associated with the stream. If a caller attempts 795251881Speter * to invoke a handler which has not been set, it will generate a 796251881Speter * runtime assertion failure. The creator can also set a handler for 797251881Speter * close requests so that it can flush buffered data or whatever; 798251881Speter * if a close handler is not specified, a close request on the stream 799251881Speter * will simply be ignored. Note that svn_stream_close() does not 800251881Speter * deallocate the memory used to allocate the stream structure; free 801251881Speter * the pool you created the stream in to free that memory. 802251881Speter * 803251881Speter * The read and write handlers accept length arguments via pointer. 804251881Speter * On entry to the handler, the pointed-to value should be the amount 805251881Speter * of data which can be read or the amount of data to write. When the 806251881Speter * handler returns, the value is reset to the amount of data actually 807251881Speter * read or written. Handlers are obliged to complete a read or write 808251881Speter * to the maximum extent possible; thus, a short read with no 809251881Speter * associated error implies the end of the input stream, and a short 810251881Speter * write should never occur without an associated error. 811251881Speter * 812251881Speter * In Subversion 1.7 reset support was added as an optional feature of 813251881Speter * streams. If a stream implements resetting it allows reading the data 814251881Speter * again after a successful call to svn_stream_reset(). 815251881Speter */ 816251881Spetertypedef struct svn_stream_t svn_stream_t; 817251881Speter 818251881Speter 819251881Speter 820251881Speter/** Read handler function for a generic stream. @see svn_stream_t. */ 821251881Spetertypedef svn_error_t *(*svn_read_fn_t)(void *baton, 822251881Speter char *buffer, 823251881Speter apr_size_t *len); 824251881Speter 825251881Speter/** Skip data handler function for a generic stream. @see svn_stream_t 826251881Speter * and svn_stream_skip(). 827251881Speter * @since New in 1.7. 828251881Speter */ 829251881Spetertypedef svn_error_t *(*svn_stream_skip_fn_t)(void *baton, 830251881Speter apr_size_t len); 831251881Speter 832251881Speter/** Write handler function for a generic stream. @see svn_stream_t. */ 833251881Spetertypedef svn_error_t *(*svn_write_fn_t)(void *baton, 834251881Speter const char *data, 835251881Speter apr_size_t *len); 836251881Speter 837251881Speter/** Close handler function for a generic stream. @see svn_stream_t. */ 838251881Spetertypedef svn_error_t *(*svn_close_fn_t)(void *baton); 839251881Speter 840251881Speter/** An opaque type which represents a mark on a stream. There is no 841251881Speter * concrete definition of this type, it is a named type for stream 842251881Speter * implementation specific baton pointers. 843251881Speter * 844251881Speter * @see svn_stream_mark(). 845251881Speter * @since New in 1.7. 846251881Speter */ 847251881Spetertypedef struct svn_stream_mark_t svn_stream_mark_t; 848251881Speter 849251881Speter/** Mark handler function for a generic stream. @see svn_stream_t and 850251881Speter * svn_stream_mark(). 851251881Speter * 852251881Speter * @since New in 1.7. 853251881Speter */ 854251881Spetertypedef svn_error_t *(*svn_stream_mark_fn_t)(void *baton, 855251881Speter svn_stream_mark_t **mark, 856251881Speter apr_pool_t *pool); 857251881Speter 858251881Speter/** Seek handler function for a generic stream. @see svn_stream_t and 859251881Speter * svn_stream_seek(). 860251881Speter * 861251881Speter * @since New in 1.7. 862251881Speter */ 863251881Spetertypedef svn_error_t *(*svn_stream_seek_fn_t)(void *baton, 864251881Speter const svn_stream_mark_t *mark); 865251881Speter 866251881Speter/** Create a generic stream. @see svn_stream_t. */ 867251881Spetersvn_stream_t * 868251881Spetersvn_stream_create(void *baton, 869251881Speter apr_pool_t *pool); 870251881Speter 871251881Speter/** Set @a stream's baton to @a baton */ 872251881Spetervoid 873251881Spetersvn_stream_set_baton(svn_stream_t *stream, 874251881Speter void *baton); 875251881Speter 876251881Speter/** Set @a stream's read function to @a read_fn */ 877251881Spetervoid 878251881Spetersvn_stream_set_read(svn_stream_t *stream, 879251881Speter svn_read_fn_t read_fn); 880251881Speter 881251881Speter/** Set @a stream's skip function to @a skip_fn 882251881Speter * 883251881Speter * @since New in 1.7 884251881Speter */ 885251881Spetervoid 886251881Spetersvn_stream_set_skip(svn_stream_t *stream, 887251881Speter svn_stream_skip_fn_t skip_fn); 888251881Speter 889251881Speter/** Set @a stream's write function to @a write_fn */ 890251881Spetervoid 891251881Spetersvn_stream_set_write(svn_stream_t *stream, 892251881Speter svn_write_fn_t write_fn); 893251881Speter 894251881Speter/** Set @a stream's close function to @a close_fn */ 895251881Spetervoid 896251881Spetersvn_stream_set_close(svn_stream_t *stream, 897251881Speter svn_close_fn_t close_fn); 898251881Speter 899251881Speter/** Set @a stream's mark function to @a mark_fn 900251881Speter * 901251881Speter * @since New in 1.7. 902251881Speter */ 903251881Spetervoid 904251881Spetersvn_stream_set_mark(svn_stream_t *stream, 905251881Speter svn_stream_mark_fn_t mark_fn); 906251881Speter 907251881Speter/** Set @a stream's seek function to @a seek_fn 908251881Speter * 909251881Speter * @since New in 1.7. 910251881Speter */ 911251881Spetervoid 912251881Spetersvn_stream_set_seek(svn_stream_t *stream, 913251881Speter svn_stream_seek_fn_t seek_fn); 914251881Speter 915251881Speter/** Create a stream that is empty for reading and infinite for writing. */ 916251881Spetersvn_stream_t * 917251881Spetersvn_stream_empty(apr_pool_t *pool); 918251881Speter 919251881Speter/** Return a stream allocated in @a pool which forwards all requests 920251881Speter * to @a stream. Destruction is explicitly excluded from forwarding. 921251881Speter * 922262253Speter * @see http://subversion.apache.org/docs/community-guide/conventions.html#destruction-of-stacked-resources 923251881Speter * 924251881Speter * @since New in 1.4. 925251881Speter */ 926251881Spetersvn_stream_t * 927251881Spetersvn_stream_disown(svn_stream_t *stream, 928251881Speter apr_pool_t *pool); 929251881Speter 930251881Speter 931251881Speter/** Create a stream to read the file at @a path. It will be opened using 932251881Speter * the APR_BUFFERED and APR_BINARY flag, and APR_OS_DEFAULT for the perms. 933251881Speter * If you'd like to use different values, then open the file yourself, and 934251881Speter * use the svn_stream_from_aprfile2() interface. 935251881Speter * 936251881Speter * The stream will be returned in @a stream, and allocated from @a result_pool. 937251881Speter * Temporary allocations will be performed in @a scratch_pool. 938251881Speter * 939251881Speter * @since New in 1.6 940251881Speter */ 941251881Spetersvn_error_t * 942251881Spetersvn_stream_open_readonly(svn_stream_t **stream, 943251881Speter const char *path, 944251881Speter apr_pool_t *result_pool, 945251881Speter apr_pool_t *scratch_pool); 946251881Speter 947251881Speter 948251881Speter/** Create a stream to write a file at @a path. The file will be *created* 949251881Speter * using the APR_BUFFERED and APR_BINARY flag, and APR_OS_DEFAULT for the 950251881Speter * perms. The file will be created "exclusively", so if it already exists, 951251881Speter * then an error will be thrown. If you'd like to use different values, or 952251881Speter * open an existing file, then open the file yourself, and use the 953251881Speter * svn_stream_from_aprfile2() interface. 954251881Speter * 955251881Speter * The stream will be returned in @a stream, and allocated from @a result_pool. 956251881Speter * Temporary allocations will be performed in @a scratch_pool. 957251881Speter * 958251881Speter * @since New in 1.6 959251881Speter */ 960251881Spetersvn_error_t * 961251881Spetersvn_stream_open_writable(svn_stream_t **stream, 962251881Speter const char *path, 963251881Speter apr_pool_t *result_pool, 964251881Speter apr_pool_t *scratch_pool); 965251881Speter 966251881Speter 967251881Speter/** Create a writable stream to a file in the directory @a dirpath. 968251881Speter * The file will have an arbitrary and unique name, and the full path 969251881Speter * will be returned in @a temp_path. The stream will be returned in 970251881Speter * @a stream. Both will be allocated from @a result_pool. 971251881Speter * 972251881Speter * If @a dirpath is @c NULL, use the path returned from svn_io_temp_dir(). 973251881Speter * (Note that when using the system-provided temp directory, it may not 974251881Speter * be possible to atomically rename the resulting file due to cross-device 975251881Speter * issues.) 976251881Speter * 977262253Speter * The file will be deleted according to @a delete_when. If that is 978262253Speter * #svn_io_file_del_on_pool_cleanup, it refers to @a result_pool. 979251881Speter * 980251881Speter * Temporary allocations will be performed in @a scratch_pool. 981251881Speter * 982251881Speter * @since New in 1.6 983251881Speter * @see svn_io_open_unique_file3() 984251881Speter */ 985251881Spetersvn_error_t * 986251881Spetersvn_stream_open_unique(svn_stream_t **stream, 987251881Speter const char **temp_path, 988251881Speter const char *dirpath, 989251881Speter svn_io_file_del_t delete_when, 990251881Speter apr_pool_t *result_pool, 991251881Speter apr_pool_t *scratch_pool); 992251881Speter 993251881Speter 994251881Speter/** Create a stream from an APR file. For convenience, if @a file is 995251881Speter * @c NULL, an empty stream created by svn_stream_empty() is returned. 996251881Speter * 997251881Speter * This function should normally be called with @a disown set to FALSE, 998251881Speter * in which case closing the stream will also close the underlying file. 999251881Speter * 1000251881Speter * If @a disown is TRUE, the stream will disown the underlying file, 1001251881Speter * meaning that svn_stream_close() will not close the file. 1002251881Speter * 1003251881Speter * @since New in 1.4. 1004251881Speter */ 1005251881Spetersvn_stream_t * 1006251881Spetersvn_stream_from_aprfile2(apr_file_t *file, 1007251881Speter svn_boolean_t disown, 1008251881Speter apr_pool_t *pool); 1009251881Speter 1010251881Speter/** Similar to svn_stream_from_aprfile2(), except that the file will 1011251881Speter * always be disowned. 1012251881Speter * 1013251881Speter * @note The stream returned is not considered to "own" the underlying 1014251881Speter * file, meaning that svn_stream_close() on the stream will not 1015251881Speter * close the file. 1016251881Speter * 1017251881Speter * @deprecated Provided for backward compatibility with the 1.3 API. 1018251881Speter */ 1019251881SpeterSVN_DEPRECATED 1020251881Spetersvn_stream_t * 1021251881Spetersvn_stream_from_aprfile(apr_file_t *file, 1022251881Speter apr_pool_t *pool); 1023251881Speter 1024251881Speter/** Set @a *in to a generic stream connected to stdin, allocated in 1025251881Speter * @a pool. The stream and its underlying APR handle will be closed 1026251881Speter * when @a pool is cleared or destroyed. 1027251881Speter * 1028251881Speter * @since New in 1.7. 1029251881Speter */ 1030251881Spetersvn_error_t * 1031251881Spetersvn_stream_for_stdin(svn_stream_t **in, 1032251881Speter apr_pool_t *pool); 1033251881Speter 1034251881Speter/** Set @a *err to a generic stream connected to stderr, allocated in 1035251881Speter * @a pool. The stream and its underlying APR handle will be closed 1036251881Speter * when @a pool is cleared or destroyed. 1037251881Speter * 1038251881Speter * @since New in 1.7. 1039251881Speter */ 1040251881Spetersvn_error_t * 1041251881Spetersvn_stream_for_stderr(svn_stream_t **err, 1042251881Speter apr_pool_t *pool); 1043251881Speter 1044251881Speter/** Set @a *out to a generic stream connected to stdout, allocated in 1045251881Speter * @a pool. The stream and its underlying APR handle will be closed 1046251881Speter * when @a pool is cleared or destroyed. 1047251881Speter */ 1048251881Spetersvn_error_t * 1049251881Spetersvn_stream_for_stdout(svn_stream_t **out, 1050251881Speter apr_pool_t *pool); 1051251881Speter 1052251881Speter/** Return a generic stream connected to stringbuf @a str. Allocate the 1053251881Speter * stream in @a pool. 1054251881Speter */ 1055251881Spetersvn_stream_t * 1056251881Spetersvn_stream_from_stringbuf(svn_stringbuf_t *str, 1057251881Speter apr_pool_t *pool); 1058251881Speter 1059251881Speter/** Return a generic read-only stream connected to string @a str. 1060251881Speter * Allocate the stream in @a pool. 1061251881Speter */ 1062251881Spetersvn_stream_t * 1063251881Spetersvn_stream_from_string(const svn_string_t *str, 1064251881Speter apr_pool_t *pool); 1065251881Speter 1066251881Speter/** Return a generic stream which implements buffered reads and writes. 1067251881Speter * The stream will preferentially store data in-memory, but may use 1068251881Speter * disk storage as backup if the amount of data is large. 1069251881Speter * Allocate the stream in @a result_pool 1070251881Speter * 1071251881Speter * @since New in 1.8. 1072251881Speter */ 1073251881Spetersvn_stream_t * 1074251881Spetersvn_stream_buffered(apr_pool_t *result_pool); 1075251881Speter 1076251881Speter/** Return a stream that decompresses all data read and compresses all 1077251881Speter * data written. The stream @a stream is used to read and write all 1078251881Speter * compressed data. All compression data structures are allocated on 1079251881Speter * @a pool. If compression support is not compiled in then 1080251881Speter * svn_stream_compressed() returns @a stream unmodified. Make sure you 1081251881Speter * call svn_stream_close() on the stream returned by this function, 1082251881Speter * so that all data are flushed and cleaned up. 1083251881Speter * 1084251881Speter * @note From 1.4, compression support is always compiled in. 1085251881Speter */ 1086251881Spetersvn_stream_t * 1087251881Spetersvn_stream_compressed(svn_stream_t *stream, 1088251881Speter apr_pool_t *pool); 1089251881Speter 1090251881Speter/** Return a stream that calculates checksums for all data read 1091251881Speter * and written. The stream @a stream is used to read and write all data. 1092251881Speter * The stream and the resulting digests are allocated in @a pool. 1093251881Speter * 1094251881Speter * When the stream is closed, @a *read_checksum and @a *write_checksum 1095251881Speter * are set to point to the resulting checksums, of type @a read_checksum_kind 1096251881Speter * and @a write_checksum_kind, respectively. 1097251881Speter * 1098251881Speter * Both @a read_checksum and @a write_checksum can be @c NULL, in which case 1099251881Speter * the respective checksum isn't calculated. 1100251881Speter * 1101251881Speter * If @a read_all is TRUE, make sure that all data available on @a 1102251881Speter * stream is read (and checksummed) when the stream is closed. 1103251881Speter * 1104251881Speter * Read and write operations can be mixed without interfering. 1105251881Speter * 1106251881Speter * The @a stream passed into this function is closed when the created 1107251881Speter * stream is closed. 1108251881Speter * 1109251881Speter * @since New in 1.6. 1110251881Speter */ 1111251881Spetersvn_stream_t * 1112251881Spetersvn_stream_checksummed2(svn_stream_t *stream, 1113251881Speter svn_checksum_t **read_checksum, 1114251881Speter svn_checksum_t **write_checksum, 1115251881Speter svn_checksum_kind_t checksum_kind, 1116251881Speter svn_boolean_t read_all, 1117251881Speter apr_pool_t *pool); 1118251881Speter 1119251881Speter/** 1120251881Speter * Similar to svn_stream_checksummed2(), but always returning the MD5 1121251881Speter * checksum in @a read_digest and @a write_digest. 1122251881Speter * 1123251881Speter * @since New in 1.4. 1124251881Speter * @deprecated Provided for backward compatibility with the 1.5 API. 1125251881Speter */ 1126251881SpeterSVN_DEPRECATED 1127251881Spetersvn_stream_t * 1128251881Spetersvn_stream_checksummed(svn_stream_t *stream, 1129251881Speter const unsigned char **read_digest, 1130251881Speter const unsigned char **write_digest, 1131251881Speter svn_boolean_t read_all, 1132251881Speter apr_pool_t *pool); 1133251881Speter 1134251881Speter/** Read from a generic stream. @see svn_stream_t. */ 1135251881Spetersvn_error_t * 1136251881Spetersvn_stream_read(svn_stream_t *stream, 1137251881Speter char *buffer, 1138251881Speter apr_size_t *len); 1139251881Speter 1140251881Speter/** 1141251881Speter * Skip @a len bytes from a generic @a stream. If the stream is exhausted 1142251881Speter * before @a len bytes have been read, return an error. 1143251881Speter * 1144251881Speter * @note No assumption can be made on the semantics of this function 1145251881Speter * other than that the stream read pointer will be advanced by *len 1146251881Speter * bytes. Depending on the capabilities of the underlying stream 1147251881Speter * implementation, this may for instance be translated into a sequence 1148251881Speter * of reads or a simple seek operation. If the stream implementation has 1149251881Speter * not provided a skip function, this will read from the stream and 1150251881Speter * discard the data. 1151251881Speter */ 1152251881Spetersvn_error_t * 1153251881Spetersvn_stream_skip(svn_stream_t *stream, 1154251881Speter apr_size_t len); 1155251881Speter 1156251881Speter/** Write to a generic stream. @see svn_stream_t. */ 1157251881Spetersvn_error_t * 1158251881Spetersvn_stream_write(svn_stream_t *stream, 1159251881Speter const char *data, 1160251881Speter apr_size_t *len); 1161251881Speter 1162251881Speter/** Close a generic stream. @see svn_stream_t. */ 1163251881Spetersvn_error_t * 1164251881Spetersvn_stream_close(svn_stream_t *stream); 1165251881Speter 1166251881Speter/** Reset a generic stream back to its origin. (E.g. On a file this would be 1167251881Speter * implemented as a seek to position 0). This function returns a 1168251881Speter * #SVN_ERR_STREAM_SEEK_NOT_SUPPORTED error when the stream doesn't 1169251881Speter * implement resetting. 1170251881Speter * 1171251881Speter * @since New in 1.7. 1172251881Speter */ 1173251881Spetersvn_error_t * 1174251881Spetersvn_stream_reset(svn_stream_t *stream); 1175251881Speter 1176251881Speter/** Returns @c TRUE if the generic @a stream supports svn_stream_mark(). 1177251881Speter * 1178251881Speter * @see svn_stream_mark() 1179251881Speter * @since New in 1.7. 1180251881Speter */ 1181251881Spetersvn_boolean_t 1182251881Spetersvn_stream_supports_mark(svn_stream_t *stream); 1183251881Speter 1184251881Speter/** Set a @a mark at the current position of a generic @a stream, 1185251881Speter * which can later be sought back to using svn_stream_seek(). 1186251881Speter * The @a mark is allocated in @a pool. 1187251881Speter * 1188251881Speter * This function returns the #SVN_ERR_STREAM_SEEK_NOT_SUPPORTED error 1189251881Speter * if the stream doesn't implement seeking. 1190251881Speter * 1191251881Speter * @see svn_stream_seek() 1192251881Speter * @since New in 1.7. 1193251881Speter */ 1194251881Spetersvn_error_t * 1195251881Spetersvn_stream_mark(svn_stream_t *stream, 1196251881Speter svn_stream_mark_t **mark, 1197251881Speter apr_pool_t *pool); 1198251881Speter 1199251881Speter/** Seek to a @a mark in a generic @a stream. 1200251881Speter * This function returns the #SVN_ERR_STREAM_SEEK_NOT_SUPPORTED error 1201251881Speter * if the stream doesn't implement seeking. Passing NULL as @a mark, 1202251881Speter * seeks to the start of the stream. 1203251881Speter * 1204251881Speter * @see svn_stream_mark() 1205251881Speter * @since New in 1.7. 1206251881Speter */ 1207251881Spetersvn_error_t * 1208251881Spetersvn_stream_seek(svn_stream_t *stream, const svn_stream_mark_t *mark); 1209251881Speter 1210251881Speter/** Return a writable stream which, when written to, writes to both of the 1211251881Speter * underlying streams. Both of these streams will be closed upon closure of 1212251881Speter * the returned stream; use svn_stream_disown() if this is not the desired 1213251881Speter * behavior. One or both of @a out1 and @a out2 may be @c NULL. If both are 1214251881Speter * @c NULL, @c NULL is returned. 1215251881Speter * 1216251881Speter * @since New in 1.7. 1217251881Speter */ 1218251881Spetersvn_stream_t * 1219251881Spetersvn_stream_tee(svn_stream_t *out1, 1220251881Speter svn_stream_t *out2, 1221251881Speter apr_pool_t *pool); 1222251881Speter 1223251881Speter/** Write NULL-terminated string @a str to @a stream. 1224251881Speter * 1225251881Speter * @since New in 1.8. 1226251881Speter * 1227251881Speter */ 1228251881Spetersvn_error_t * 1229251881Spetersvn_stream_puts(svn_stream_t *stream, 1230251881Speter const char *str); 1231251881Speter 1232251881Speter/** Write to @a stream using a printf-style @a fmt specifier, passed through 1233251881Speter * apr_psprintf() using memory from @a pool. 1234251881Speter */ 1235251881Spetersvn_error_t * 1236251881Spetersvn_stream_printf(svn_stream_t *stream, 1237251881Speter apr_pool_t *pool, 1238251881Speter const char *fmt, 1239251881Speter ...) 1240251881Speter __attribute__((format(printf, 3, 4))); 1241251881Speter 1242251881Speter/** Write to @a stream using a printf-style @a fmt specifier, passed through 1243251881Speter * apr_psprintf() using memory from @a pool. The resulting string 1244251881Speter * will be translated to @a encoding before it is sent to @a stream. 1245251881Speter * 1246251881Speter * @note Use @c APR_LOCALE_CHARSET to translate to the encoding of the 1247251881Speter * current locale. 1248251881Speter * 1249251881Speter * @since New in 1.3. 1250251881Speter */ 1251251881Spetersvn_error_t * 1252251881Spetersvn_stream_printf_from_utf8(svn_stream_t *stream, 1253251881Speter const char *encoding, 1254251881Speter apr_pool_t *pool, 1255251881Speter const char *fmt, 1256251881Speter ...) 1257251881Speter __attribute__((format(printf, 4, 5))); 1258251881Speter 1259251881Speter/** Allocate @a *stringbuf in @a pool, and read into it one line (terminated 1260251881Speter * by @a eol) from @a stream. The line-terminator is read from the stream, 1261251881Speter * but is not added to the end of the stringbuf. Instead, the stringbuf 1262251881Speter * ends with a usual '\\0'. 1263251881Speter * 1264251881Speter * If @a stream runs out of bytes before encountering a line-terminator, 1265251881Speter * then set @a *eof to @c TRUE, otherwise set @a *eof to FALSE. 1266251881Speter */ 1267251881Spetersvn_error_t * 1268251881Spetersvn_stream_readline(svn_stream_t *stream, 1269251881Speter svn_stringbuf_t **stringbuf, 1270251881Speter const char *eol, 1271251881Speter svn_boolean_t *eof, 1272251881Speter apr_pool_t *pool); 1273251881Speter 1274251881Speter/** 1275251881Speter * Read the contents of the readable stream @a from and write them to the 1276251881Speter * writable stream @a to calling @a cancel_func before copying each chunk. 1277251881Speter * 1278251881Speter * @a cancel_func may be @c NULL. 1279251881Speter * 1280251881Speter * @note both @a from and @a to will be closed upon successful completion of 1281251881Speter * the copy (but an error may still be returned, based on trying to close 1282251881Speter * the two streams). If the closure is not desired, then you can use 1283251881Speter * svn_stream_disown() to protect either or both of the streams from 1284251881Speter * being closed. 1285251881Speter * 1286251881Speter * @since New in 1.6. 1287251881Speter */ 1288251881Spetersvn_error_t * 1289251881Spetersvn_stream_copy3(svn_stream_t *from, 1290251881Speter svn_stream_t *to, 1291251881Speter svn_cancel_func_t cancel_func, 1292251881Speter void *cancel_baton, 1293251881Speter apr_pool_t *pool); 1294251881Speter 1295251881Speter/** 1296251881Speter * Same as svn_stream_copy3() but the streams are not closed. 1297251881Speter * 1298251881Speter * @since New in 1.5. 1299251881Speter * @deprecated Provided for backward compatibility with the 1.5 API. 1300251881Speter */ 1301251881SpeterSVN_DEPRECATED 1302251881Spetersvn_error_t * 1303251881Spetersvn_stream_copy2(svn_stream_t *from, 1304251881Speter svn_stream_t *to, 1305251881Speter svn_cancel_func_t cancel_func, 1306251881Speter void *cancel_baton, 1307251881Speter apr_pool_t *pool); 1308251881Speter 1309251881Speter/** 1310251881Speter * Same as svn_stream_copy3(), but without the cancellation function 1311251881Speter * or stream closing. 1312251881Speter * 1313251881Speter * @since New in 1.1. 1314251881Speter * @deprecated Provided for backward compatibility with the 1.4 API. 1315251881Speter */ 1316251881SpeterSVN_DEPRECATED 1317251881Spetersvn_error_t * 1318251881Spetersvn_stream_copy(svn_stream_t *from, 1319251881Speter svn_stream_t *to, 1320251881Speter apr_pool_t *pool); 1321251881Speter 1322251881Speter 1323251881Speter/** Set @a *same to TRUE if @a stream1 and @a stream2 have the same 1324251881Speter * contents, else set it to FALSE. 1325251881Speter * 1326251881Speter * Both streams will be closed before this function returns (regardless of 1327251881Speter * the result, or any possible error). 1328251881Speter * 1329251881Speter * Use @a scratch_pool for temporary allocations. 1330251881Speter * 1331251881Speter * @since New in 1.7. 1332251881Speter */ 1333251881Spetersvn_error_t * 1334251881Spetersvn_stream_contents_same2(svn_boolean_t *same, 1335251881Speter svn_stream_t *stream1, 1336251881Speter svn_stream_t *stream2, 1337251881Speter apr_pool_t *pool); 1338251881Speter 1339251881Speter 1340251881Speter/** 1341251881Speter * Same as svn_stream_contents_same2(), but the streams will not be closed. 1342251881Speter * 1343251881Speter * @since New in 1.4. 1344251881Speter * @deprecated Provided for backward compatibility with the 1.6 API. 1345251881Speter */ 1346251881SpeterSVN_DEPRECATED 1347251881Spetersvn_error_t * 1348251881Spetersvn_stream_contents_same(svn_boolean_t *same, 1349251881Speter svn_stream_t *stream1, 1350251881Speter svn_stream_t *stream2, 1351251881Speter apr_pool_t *pool); 1352251881Speter 1353251881Speter 1354251881Speter/** Read the contents of @a stream into memory, returning the data in 1355251881Speter * @a result. The stream will be closed when it has been successfully and 1356251881Speter * completely read. 1357251881Speter * 1358251881Speter * The returned memory is allocated in @a result_pool, and any temporary 1359251881Speter * allocations are performed in @a scratch_pool. 1360251881Speter * 1361251881Speter * @note due to memory pseudo-reallocation behavior (due to pools), this 1362251881Speter * can be a memory-intensive operation for large files. 1363251881Speter * 1364251881Speter * @since New in 1.6 1365251881Speter */ 1366251881Spetersvn_error_t * 1367251881Spetersvn_string_from_stream(svn_string_t **result, 1368251881Speter svn_stream_t *stream, 1369251881Speter apr_pool_t *result_pool, 1370251881Speter apr_pool_t *scratch_pool); 1371251881Speter 1372251881Speter 1373251881Speter/** A function type provided for use as a callback from 1374251881Speter * @c svn_stream_lazyopen_create(). 1375251881Speter * 1376251881Speter * The callback function shall open a new stream and set @a *stream to 1377251881Speter * the stream object, allocated in @a result_pool. @a baton is the 1378251881Speter * callback baton that was passed to svn_stream_lazyopen_create(). 1379251881Speter * 1380251881Speter * @a result_pool is the result pool that was passed to 1381251881Speter * svn_stream_lazyopen_create(). The callback function may use 1382251881Speter * @a scratch_pool for temporary allocations; the caller may clear or 1383251881Speter * destroy @a scratch_pool any time after the function returns. 1384251881Speter * 1385251881Speter * @since New in 1.8. 1386251881Speter */ 1387251881Spetertypedef svn_error_t * 1388251881Speter(*svn_stream_lazyopen_func_t)(svn_stream_t **stream, 1389251881Speter void *baton, 1390251881Speter apr_pool_t *result_pool, 1391251881Speter apr_pool_t *scratch_pool); 1392251881Speter 1393251881Speter 1394251881Speter/** Return a generic stream which wraps another primary stream, 1395251881Speter * delaying the "opening" of that stream until the first time the 1396251881Speter * returned stream is accessed. 1397251881Speter * 1398251881Speter * @a open_func and @a open_baton are a callback function/baton pair 1399251881Speter * which will be invoked upon the first access of the returned 1400251881Speter * stream (read, write, mark, seek, skip, or possibly close). The 1401251881Speter * callback shall open the primary stream. 1402251881Speter * 1403251881Speter * If the only "access" the returned stream gets is to close it 1404251881Speter * then @a open_func will only be called if @a open_on_close is TRUE. 1405251881Speter * 1406251881Speter * @since New in 1.8. 1407251881Speter */ 1408251881Spetersvn_stream_t * 1409251881Spetersvn_stream_lazyopen_create(svn_stream_lazyopen_func_t open_func, 1410251881Speter void *open_baton, 1411251881Speter svn_boolean_t open_on_close, 1412251881Speter apr_pool_t *result_pool); 1413251881Speter 1414251881Speter/** @} */ 1415251881Speter 1416251881Speter/** Set @a *result to a string containing the contents of @a 1417251881Speter * filename, which is either "-" (indicating that stdin should be 1418251881Speter * read) or the utf8-encoded path of a real file. 1419251881Speter * 1420251881Speter * @warning Callers should be aware of possible unexpected results 1421251881Speter * when using this function to read from stdin where additional 1422251881Speter * stdin-reading processes abound. For example, if a program tries 1423251881Speter * both to invoke an external editor and to read from stdin, stdin 1424251881Speter * could be trashed and the editor might act funky or die outright. 1425251881Speter * 1426251881Speter * @note due to memory pseudo-reallocation behavior (due to pools), this 1427251881Speter * can be a memory-intensive operation for large files. 1428251881Speter * 1429251881Speter * @since New in 1.5. 1430251881Speter */ 1431251881Spetersvn_error_t * 1432251881Spetersvn_stringbuf_from_file2(svn_stringbuf_t **result, 1433251881Speter const char *filename, 1434251881Speter apr_pool_t *pool); 1435251881Speter 1436251881Speter/** Similar to svn_stringbuf_from_file2(), except that if @a filename 1437251881Speter * is "-", return the error #SVN_ERR_UNSUPPORTED_FEATURE and don't 1438251881Speter * touch @a *result. 1439251881Speter * 1440251881Speter * @deprecated Provided for backwards compatibility with the 1.4 API. 1441251881Speter */ 1442251881SpeterSVN_DEPRECATED 1443251881Spetersvn_error_t * 1444251881Spetersvn_stringbuf_from_file(svn_stringbuf_t **result, 1445251881Speter const char *filename, 1446251881Speter apr_pool_t *pool); 1447251881Speter 1448251881Speter/** Sets @a *result to a string containing the contents of the already opened 1449251881Speter * @a file. Reads from the current position in file to the end. Does not 1450251881Speter * close the file or reset the cursor position. 1451251881Speter * 1452251881Speter * @note due to memory pseudo-reallocation behavior (due to pools), this 1453251881Speter * can be a memory-intensive operation for large files. 1454251881Speter */ 1455251881Spetersvn_error_t * 1456251881Spetersvn_stringbuf_from_aprfile(svn_stringbuf_t **result, 1457251881Speter apr_file_t *file, 1458251881Speter apr_pool_t *pool); 1459251881Speter 1460251881Speter/** Remove file @a path, a utf8-encoded path. This wraps apr_file_remove(), 1461251881Speter * converting any error to a Subversion error. If @a ignore_enoent is TRUE, and 1462251881Speter * the file is not present (APR_STATUS_IS_ENOENT returns TRUE), then no 1463251881Speter * error will be returned. 1464251881Speter * 1465251881Speter * The file will be removed even if it is not writable. (On Windows and 1466251881Speter * OS/2, this function first clears the file's read-only bit.) 1467251881Speter * 1468251881Speter * @since New in 1.7. 1469251881Speter */ 1470251881Spetersvn_error_t * 1471251881Spetersvn_io_remove_file2(const char *path, 1472251881Speter svn_boolean_t ignore_enoent, 1473251881Speter apr_pool_t *scratch_pool); 1474251881Speter 1475251881Speter/** Similar to svn_io_remove_file2(), except with @a ignore_enoent set to FALSE. 1476251881Speter * 1477251881Speter * @deprecated Provided for backwards compatibility with the 1.6 API. 1478251881Speter */ 1479251881SpeterSVN_DEPRECATED 1480251881Spetersvn_error_t * 1481251881Spetersvn_io_remove_file(const char *path, 1482251881Speter apr_pool_t *pool); 1483251881Speter 1484251881Speter/** Recursively remove directory @a path. @a path is utf8-encoded. 1485251881Speter * If @a ignore_enoent is @c TRUE, don't fail if the target directory 1486251881Speter * doesn't exist. Use @a pool for temporary allocations. 1487251881Speter * 1488251881Speter * Because recursive delete of a directory tree can be a lengthy operation, 1489251881Speter * provide @a cancel_func and @a cancel_baton for interruptibility. 1490251881Speter * 1491251881Speter * @since New in 1.5. 1492251881Speter */ 1493251881Spetersvn_error_t * 1494251881Spetersvn_io_remove_dir2(const char *path, 1495251881Speter svn_boolean_t ignore_enoent, 1496251881Speter svn_cancel_func_t cancel_func, 1497251881Speter void *cancel_baton, 1498251881Speter apr_pool_t *pool); 1499251881Speter 1500251881Speter/** Similar to svn_io_remove_dir2(), but with @a ignore_enoent set to 1501251881Speter * @c FALSE and @a cancel_func and @a cancel_baton set to @c NULL. 1502251881Speter * 1503251881Speter * @deprecated Provided for backward compatibility with the 1.4 API 1504251881Speter */ 1505251881SpeterSVN_DEPRECATED 1506251881Spetersvn_error_t * 1507251881Spetersvn_io_remove_dir(const char *path, 1508251881Speter apr_pool_t *pool); 1509251881Speter 1510251881Speter/** Read all of the disk entries in directory @a path, a utf8-encoded 1511251881Speter * path. Set @a *dirents to a hash mapping dirent names (<tt>char *</tt>) to 1512251881Speter * undefined non-NULL values, allocated in @a pool. 1513251881Speter * 1514251881Speter * @note The `.' and `..' directories normally returned by 1515251881Speter * apr_dir_read() are NOT returned in the hash. 1516251881Speter * 1517251881Speter * @since New in 1.4. 1518251881Speter * @deprecated Provided for backward compatibility with the 1.6 API. 1519251881Speter */ 1520251881SpeterSVN_DEPRECATED 1521251881Spetersvn_error_t * 1522251881Spetersvn_io_get_dir_filenames(apr_hash_t **dirents, 1523251881Speter const char *path, 1524251881Speter apr_pool_t *pool); 1525251881Speter 1526251881Speter/** Read all of the disk entries in directory @a path, a utf8-encoded 1527251881Speter * path. Set @a *dirents to a hash mapping dirent names (<tt>char *</tt>) to 1528251881Speter * #svn_io_dirent2_t structures, allocated in @a pool. 1529251881Speter * 1530251881Speter * If @a only_check_type is set to @c TRUE, only the kind and special 1531251881Speter * fields of the svn_io_dirent2_t are filled. 1532251881Speter * 1533251881Speter * @note The `.' and `..' directories normally returned by 1534251881Speter * apr_dir_read() are NOT returned in the hash. 1535251881Speter * 1536251881Speter * @note The kind field in the @a dirents is set according to the mapping 1537251881Speter * as documented for svn_io_check_path(). 1538251881Speter * 1539251881Speter * @since New in 1.7. 1540251881Speter */ 1541251881Spetersvn_error_t * 1542251881Spetersvn_io_get_dirents3(apr_hash_t **dirents, 1543251881Speter const char *path, 1544251881Speter svn_boolean_t only_check_type, 1545251881Speter apr_pool_t *result_pool, 1546251881Speter apr_pool_t *scratch_pool); 1547251881Speter 1548251881Speter 1549251881Speter/** Similar to svn_io_get_dirents3, but returns a mapping to svn_io_dirent_t 1550251881Speter * structures instead of svn_io_dirent2_t and with only a single pool. 1551251881Speter * 1552251881Speter * @since New in 1.3. 1553251881Speter * @deprecated Provided for backward compatibility with the 1.6 API. 1554251881Speter */ 1555251881SpeterSVN_DEPRECATED 1556251881Spetersvn_error_t * 1557251881Spetersvn_io_get_dirents2(apr_hash_t **dirents, 1558251881Speter const char *path, 1559251881Speter apr_pool_t *pool); 1560251881Speter 1561251881Speter/** Similar to svn_io_get_dirents2(), but @a *dirents is a hash table 1562251881Speter * with #svn_node_kind_t values. 1563251881Speter * 1564251881Speter * @deprecated Provided for backwards compatibility with the 1.2 API. 1565251881Speter */ 1566251881SpeterSVN_DEPRECATED 1567251881Spetersvn_error_t * 1568251881Spetersvn_io_get_dirents(apr_hash_t **dirents, 1569251881Speter const char *path, 1570251881Speter apr_pool_t *pool); 1571251881Speter 1572251881Speter/** Create a svn_io_dirent2_t instance for path. Specialized variant of 1573251881Speter * svn_io_stat() that directly translates node_kind and special. 1574251881Speter * 1575251881Speter * If @a verify_truename is @c TRUE, an additional check is performed to 1576251881Speter * verify the truename of the last path component on case insensitive 1577251881Speter * filesystems. This check is expensive compared to a just a stat, 1578251881Speter * but certainly cheaper than a full truename calculation using 1579251881Speter * apr_filepath_merge() which verifies all path components. 1580251881Speter * 1581251881Speter * If @a ignore_enoent is set to @c TRUE, set *dirent_p->kind to 1582251881Speter * svn_node_none instead of returning an error. 1583251881Speter * 1584251881Speter * @since New in 1.8. 1585251881Speter */ 1586251881Spetersvn_error_t * 1587251881Spetersvn_io_stat_dirent2(const svn_io_dirent2_t **dirent_p, 1588251881Speter const char *path, 1589251881Speter svn_boolean_t verify_truename, 1590251881Speter svn_boolean_t ignore_enoent, 1591251881Speter apr_pool_t *result_pool, 1592251881Speter apr_pool_t *scratch_pool); 1593251881Speter 1594251881Speter 1595262253Speter/** Similar to svn_io_stat_dirent2(), but always passes FALSE for 1596262253Speter * @a verify_truename. 1597251881Speter * 1598251881Speter * @since New in 1.7. 1599251881Speter * @deprecated Provided for backwards compatibility with the 1.7 API. 1600251881Speter */ 1601251881SpeterSVN_DEPRECATED 1602251881Spetersvn_error_t * 1603251881Spetersvn_io_stat_dirent(const svn_io_dirent2_t **dirent_p, 1604251881Speter const char *path, 1605251881Speter svn_boolean_t ignore_enoent, 1606251881Speter apr_pool_t *result_pool, 1607251881Speter apr_pool_t *scratch_pool); 1608251881Speter 1609251881Speter 1610251881Speter/** Callback function type for svn_io_dir_walk() */ 1611251881Spetertypedef svn_error_t * (*svn_io_walk_func_t)(void *baton, 1612251881Speter const char *path, 1613251881Speter const apr_finfo_t *finfo, 1614251881Speter apr_pool_t *pool); 1615251881Speter 1616251881Speter/** Recursively walk the directory rooted at @a dirname, a 1617251881Speter * utf8-encoded path, invoking @a walk_func (with @a walk_baton) for 1618251881Speter * each item in the tree. For a given directory, invoke @a walk_func 1619251881Speter * on the directory itself before invoking it on any children thereof. 1620251881Speter * 1621251881Speter * Deliver to @a walk_func the information specified by @a wanted, 1622251881Speter * which is a combination of @c APR_FINFO_* flags, plus the 1623251881Speter * information specified by @c APR_FINFO_TYPE and @c APR_FINFO_NAME. 1624251881Speter * 1625251881Speter * Use @a pool for all allocations. 1626251881Speter * 1627251881Speter * @note This function does not currently pass all file types to @a 1628251881Speter * walk_func -- only APR_DIR, APR_REG, and APR_LNK. We reserve the 1629251881Speter * right to pass additional file types through this interface in the 1630251881Speter * future, though, so implementations of this callback should 1631251881Speter * explicitly test FINFO->filetype. See the APR library's 1632251881Speter * apr_filetype_e enum for the various filetypes and their meanings. 1633251881Speter * 1634251881Speter * @since New in 1.7. 1635251881Speter */ 1636251881Spetersvn_error_t * 1637251881Spetersvn_io_dir_walk2(const char *dirname, 1638251881Speter apr_int32_t wanted, 1639251881Speter svn_io_walk_func_t walk_func, 1640251881Speter void *walk_baton, 1641251881Speter apr_pool_t *pool); 1642251881Speter 1643251881Speter/** Similar to svn_io_dir_walk(), but only calls @a walk_func for 1644251881Speter * files of type APR_DIR (directory) and APR_REG (regular file). 1645251881Speter * 1646251881Speter * @deprecated Provided for backwards compatibility with the 1.6 API. 1647251881Speter */ 1648251881SpeterSVN_DEPRECATED 1649251881Spetersvn_error_t * 1650251881Spetersvn_io_dir_walk(const char *dirname, 1651251881Speter apr_int32_t wanted, 1652251881Speter svn_io_walk_func_t walk_func, 1653251881Speter void *walk_baton, 1654251881Speter apr_pool_t *pool); 1655251881Speter 1656251881Speter/** 1657251881Speter * Start @a cmd with @a args, using utf8-encoded @a path as working 1658251881Speter * directory. Return the process handle for the invoked program in @a 1659251881Speter * *cmd_proc. 1660251881Speter * 1661251881Speter * If @a infile_pipe is TRUE, connect @a cmd's stdin to a pipe; 1662251881Speter * otherwise, connect it to @a infile (which may be NULL). If 1663251881Speter * @a outfile_pipe is TRUE, connect @a cmd's stdout to a pipe; otherwise, 1664251881Speter * connect it to @a outfile (which may be NULL). If @a errfile_pipe 1665251881Speter * is TRUE, connect @a cmd's stderr to a pipe; otherwise, connect it 1666251881Speter * to @a errfile (which may be NULL). (Callers must pass FALSE for 1667251881Speter * each of these boolean values for which the corresponding file 1668251881Speter * handle is non-NULL.) 1669251881Speter * 1670251881Speter * @a args is a list of utf8-encoded <tt>const char *</tt> arguments, 1671251881Speter * terminated by @c NULL. @a args[0] is the name of the program, though it 1672251881Speter * need not be the same as @a cmd. 1673251881Speter * 1674251881Speter * If @a inherit is TRUE, the invoked program inherits its environment from 1675251881Speter * the caller and @a cmd, if not absolute, is searched for in PATH. 1676251881Speter * 1677251881Speter * If @a inherit is FALSE @a cmd must be an absolute path and the invoked 1678251881Speter * program inherits the environment defined by @a env or runs with an empty 1679251881Speter * environment in @a env is NULL. 1680251881Speter * 1681251881Speter * @note On some platforms, failure to execute @a cmd in the child process 1682251881Speter * will result in error output being written to @a errfile, if non-NULL, and 1683251881Speter * a non-zero exit status being returned to the parent process. 1684251881Speter * 1685251881Speter * @note An APR bug affects Windows: passing a NULL @a env does not 1686251881Speter * guarantee the invoked program to run with an empty environment when 1687262253Speter * @a inherit is FALSE, the program may inherit its parent's environment. 1688251881Speter * Explicitly pass an empty @a env to get an empty environment. 1689251881Speter * 1690251881Speter * @since New in 1.8. 1691251881Speter */ 1692251881Spetersvn_error_t *svn_io_start_cmd3(apr_proc_t *cmd_proc, 1693251881Speter const char *path, 1694251881Speter const char *cmd, 1695251881Speter const char *const *args, 1696251881Speter const char *const *env, 1697251881Speter svn_boolean_t inherit, 1698251881Speter svn_boolean_t infile_pipe, 1699251881Speter apr_file_t *infile, 1700251881Speter svn_boolean_t outfile_pipe, 1701251881Speter apr_file_t *outfile, 1702251881Speter svn_boolean_t errfile_pipe, 1703251881Speter apr_file_t *errfile, 1704251881Speter apr_pool_t *pool); 1705251881Speter 1706251881Speter 1707251881Speter/** 1708251881Speter * Similar to svn_io_start_cmd3() but with @a env always set to NULL. 1709251881Speter * 1710251881Speter * @deprecated Provided for backward compatibility with the 1.7 API 1711251881Speter * @since New in 1.7. 1712251881Speter */ 1713251881SpeterSVN_DEPRECATED 1714251881Spetersvn_error_t *svn_io_start_cmd2(apr_proc_t *cmd_proc, 1715251881Speter const char *path, 1716251881Speter const char *cmd, 1717251881Speter const char *const *args, 1718251881Speter svn_boolean_t inherit, 1719251881Speter svn_boolean_t infile_pipe, 1720251881Speter apr_file_t *infile, 1721251881Speter svn_boolean_t outfile_pipe, 1722251881Speter apr_file_t *outfile, 1723251881Speter svn_boolean_t errfile_pipe, 1724251881Speter apr_file_t *errfile, 1725251881Speter apr_pool_t *pool); 1726251881Speter 1727251881Speter/** 1728251881Speter * Similar to svn_io_start_cmd2() but with @a infile_pipe, @a 1729251881Speter * outfile_pipe, and @a errfile_pipe always FALSE. 1730251881Speter * 1731251881Speter * @deprecated Provided for backward compatibility with the 1.6 API 1732251881Speter * @since New in 1.3. 1733251881Speter */ 1734251881SpeterSVN_DEPRECATED 1735251881Spetersvn_error_t * 1736251881Spetersvn_io_start_cmd(apr_proc_t *cmd_proc, 1737251881Speter const char *path, 1738251881Speter const char *cmd, 1739251881Speter const char *const *args, 1740251881Speter svn_boolean_t inherit, 1741251881Speter apr_file_t *infile, 1742251881Speter apr_file_t *outfile, 1743251881Speter apr_file_t *errfile, 1744251881Speter apr_pool_t *pool); 1745251881Speter 1746251881Speter/** 1747251881Speter * Wait for the process @a *cmd_proc to complete and optionally retrieve 1748251881Speter * its exit code. @a cmd is used only in error messages. 1749251881Speter * 1750251881Speter * If @a exitcode is not NULL, set @a *exitcode to the exit code of the 1751251881Speter * process and do not consider any exit code to be an error. If @a exitcode 1752251881Speter * is NULL, then if the exit code of the process is non-zero then return an 1753251881Speter * #SVN_ERR_EXTERNAL_PROGRAM error. 1754251881Speter * 1755251881Speter * If @a exitwhy is not NULL, set @a *exitwhy to indicate why the process 1756251881Speter * terminated and do not consider any reason to be an error. If @a exitwhy 1757251881Speter * is NULL, then if the termination reason is not @c APR_PROC_CHECK_EXIT() 1758251881Speter * then return an #SVN_ERR_EXTERNAL_PROGRAM error. 1759251881Speter * 1760251881Speter * @since New in 1.3. 1761251881Speter */ 1762251881Spetersvn_error_t * 1763251881Spetersvn_io_wait_for_cmd(apr_proc_t *cmd_proc, 1764251881Speter const char *cmd, 1765251881Speter int *exitcode, 1766251881Speter apr_exit_why_e *exitwhy, 1767251881Speter apr_pool_t *pool); 1768251881Speter 1769251881Speter/** Run a command to completion, by first calling svn_io_start_cmd() and 1770251881Speter * then calling svn_io_wait_for_cmd(). The parameters correspond to 1771251881Speter * the same-named parameters of those two functions. 1772251881Speter */ 1773251881Spetersvn_error_t * 1774251881Spetersvn_io_run_cmd(const char *path, 1775251881Speter const char *cmd, 1776251881Speter const char *const *args, 1777251881Speter int *exitcode, 1778251881Speter apr_exit_why_e *exitwhy, 1779251881Speter svn_boolean_t inherit, 1780251881Speter apr_file_t *infile, 1781251881Speter apr_file_t *outfile, 1782251881Speter apr_file_t *errfile, 1783251881Speter apr_pool_t *pool); 1784251881Speter 1785251881Speter/** Invoke the configured @c diff program, with @a user_args (an array 1786251881Speter * of utf8-encoded @a num_user_args arguments) if they are specified 1787251881Speter * (that is, if @a user_args is non-NULL), or "-u" if they are not. 1788251881Speter * If @a user_args is NULL, the value of @a num_user_args is ignored. 1789251881Speter * 1790251881Speter * Diff runs in utf8-encoded @a dir, and its exit status is stored in 1791251881Speter * @a exitcode, if it is not @c NULL. 1792251881Speter * 1793251881Speter * If @a label1 and/or @a label2 are not NULL they will be passed to the diff 1794251881Speter * process as the arguments of "-L" options. @a label1 and @a label2 are also 1795251881Speter * in utf8, and will be converted to native charset along with the other args. 1796251881Speter * 1797251881Speter * @a from is the first file passed to diff, and @a to is the second. The 1798251881Speter * stdout of diff will be sent to @a outfile, and the stderr to @a errfile. 1799251881Speter * 1800251881Speter * @a diff_cmd must be non-NULL. 1801251881Speter * 1802251881Speter * Do all allocation in @a pool. 1803251881Speter * @since New in 1.6.0. 1804251881Speter */ 1805251881Spetersvn_error_t * 1806251881Spetersvn_io_run_diff2(const char *dir, 1807251881Speter const char *const *user_args, 1808251881Speter int num_user_args, 1809251881Speter const char *label1, 1810251881Speter const char *label2, 1811251881Speter const char *from, 1812251881Speter const char *to, 1813251881Speter int *exitcode, 1814251881Speter apr_file_t *outfile, 1815251881Speter apr_file_t *errfile, 1816251881Speter const char *diff_cmd, 1817251881Speter apr_pool_t *pool); 1818251881Speter 1819251881Speter/** Similar to svn_io_run_diff2() but with @a diff_cmd encoded in internal 1820251881Speter * encoding used by APR. 1821251881Speter * 1822251881Speter * @deprecated Provided for backwards compatibility with the 1.5 API. */ 1823251881SpeterSVN_DEPRECATED 1824251881Spetersvn_error_t * 1825251881Spetersvn_io_run_diff(const char *dir, 1826251881Speter const char *const *user_args, 1827251881Speter int num_user_args, 1828251881Speter const char *label1, 1829251881Speter const char *label2, 1830251881Speter const char *from, 1831251881Speter const char *to, 1832251881Speter int *exitcode, 1833251881Speter apr_file_t *outfile, 1834251881Speter apr_file_t *errfile, 1835251881Speter const char *diff_cmd, 1836251881Speter apr_pool_t *pool); 1837251881Speter 1838251881Speter 1839251881Speter 1840251881Speter/** Invoke the configured @c diff3 program, in utf8-encoded @a dir 1841251881Speter * like this: 1842251881Speter * 1843251881Speter * diff3 -E -m @a mine @a older @a yours > @a merged 1844251881Speter * 1845251881Speter * (See the diff3 documentation for details.) 1846251881Speter * 1847251881Speter * If @a user_args is non-NULL, replace "-E" with the <tt>const char*</tt> 1848251881Speter * elements that @a user_args contains. 1849251881Speter * 1850251881Speter * @a mine, @a older and @a yours are utf8-encoded paths (relative to 1851251881Speter * @a dir or absolute) to three files that already exist. 1852251881Speter * 1853251881Speter * @a merged is an open file handle, and is left open after the merge 1854251881Speter * result is written to it. (@a merged should *not* be the same file 1855251881Speter * as @a mine, or nondeterministic things may happen!) 1856251881Speter * 1857251881Speter * @a mine_label, @a older_label, @a yours_label are utf8-encoded label 1858251881Speter * parameters for diff3's -L option. Any of them may be @c NULL, in 1859251881Speter * which case the corresponding @a mine, @a older, or @a yours parameter is 1860251881Speter * used instead. 1861251881Speter * 1862251881Speter * Set @a *exitcode to diff3's exit status. If @a *exitcode is anything 1863251881Speter * other than 0 or 1, then return #SVN_ERR_EXTERNAL_PROGRAM. (Note the 1864251881Speter * following from the diff3 info pages: "An exit status of 0 means 1865251881Speter * `diff3' was successful, 1 means some conflicts were found, and 2 1866251881Speter * means trouble.") 1867251881Speter * 1868251881Speter * @a diff3_cmd must be non-NULL. 1869251881Speter * 1870251881Speter * Do all allocation in @a pool. 1871251881Speter * 1872251881Speter * @since New in 1.4. 1873251881Speter */ 1874251881Spetersvn_error_t * 1875251881Spetersvn_io_run_diff3_3(int *exitcode, 1876251881Speter const char *dir, 1877251881Speter const char *mine, 1878251881Speter const char *older, 1879251881Speter const char *yours, 1880251881Speter const char *mine_label, 1881251881Speter const char *older_label, 1882251881Speter const char *yours_label, 1883251881Speter apr_file_t *merged, 1884251881Speter const char *diff3_cmd, 1885251881Speter const apr_array_header_t *user_args, 1886251881Speter apr_pool_t *pool); 1887251881Speter 1888251881Speter/** Similar to svn_io_run_diff3_3(), but with @a diff3_cmd encoded in 1889251881Speter * internal encoding used by APR. 1890251881Speter * 1891251881Speter * @deprecated Provided for backwards compatibility with the 1.5 API. 1892251881Speter * @since New in 1.4. 1893251881Speter */ 1894251881SpeterSVN_DEPRECATED 1895251881Spetersvn_error_t * 1896251881Spetersvn_io_run_diff3_2(int *exitcode, 1897251881Speter const char *dir, 1898251881Speter const char *mine, 1899251881Speter const char *older, 1900251881Speter const char *yours, 1901251881Speter const char *mine_label, 1902251881Speter const char *older_label, 1903251881Speter const char *yours_label, 1904251881Speter apr_file_t *merged, 1905251881Speter const char *diff3_cmd, 1906251881Speter const apr_array_header_t *user_args, 1907251881Speter apr_pool_t *pool); 1908251881Speter 1909251881Speter/** Similar to svn_io_run_diff3_2(), but with @a user_args set to @c NULL. 1910251881Speter * 1911251881Speter * @deprecated Provided for backwards compatibility with the 1.3 API. 1912251881Speter */ 1913251881SpeterSVN_DEPRECATED 1914251881Spetersvn_error_t * 1915251881Spetersvn_io_run_diff3(const char *dir, 1916251881Speter const char *mine, 1917251881Speter const char *older, 1918251881Speter const char *yours, 1919251881Speter const char *mine_label, 1920251881Speter const char *older_label, 1921251881Speter const char *yours_label, 1922251881Speter apr_file_t *merged, 1923251881Speter int *exitcode, 1924251881Speter const char *diff3_cmd, 1925251881Speter apr_pool_t *pool); 1926251881Speter 1927251881Speter 1928251881Speter/** Parse utf8-encoded @a mimetypes_file as a MIME types file (such as 1929251881Speter * is provided with Apache HTTP Server), and set @a *type_map to a 1930251881Speter * hash mapping <tt>const char *</tt> filename extensions to 1931251881Speter * <tt>const char *</tt> MIME types. 1932251881Speter * 1933251881Speter * @since New in 1.5. 1934251881Speter */ 1935251881Spetersvn_error_t * 1936251881Spetersvn_io_parse_mimetypes_file(apr_hash_t **type_map, 1937251881Speter const char *mimetypes_file, 1938251881Speter apr_pool_t *pool); 1939251881Speter 1940251881Speter 1941251881Speter/** Examine utf8-encoded @a file to determine if it can be described by a 1942251881Speter * known (as in, known by this function) Multipurpose Internet Mail 1943251881Speter * Extension (MIME) type. If so, set @a *mimetype to a character string 1944251881Speter * describing the MIME type, else set it to @c NULL. 1945251881Speter * 1946251881Speter * If not @c NULL, @a mimetype_map is a hash mapping <tt>const char *</tt> 1947251881Speter * filename extensions to <tt>const char *</tt> MIME types, and is the 1948251881Speter * first source consulted regarding @a file's MIME type. 1949251881Speter * 1950251881Speter * Use @a pool for any necessary allocations. 1951251881Speter * 1952251881Speter * @since New in 1.5. 1953251881Speter */ 1954251881Spetersvn_error_t * 1955251881Spetersvn_io_detect_mimetype2(const char **mimetype, 1956251881Speter const char *file, 1957251881Speter apr_hash_t *mimetype_map, 1958251881Speter apr_pool_t *pool); 1959251881Speter 1960251881Speter 1961251881Speter/** Like svn_io_detect_mimetype2, but with @a mimetypes_map set to 1962251881Speter * @c NULL. 1963251881Speter * 1964251881Speter * @deprecated Provided for backward compatibility with the 1.4 API 1965251881Speter */ 1966251881SpeterSVN_DEPRECATED 1967251881Spetersvn_error_t * 1968251881Spetersvn_io_detect_mimetype(const char **mimetype, 1969251881Speter const char *file, 1970251881Speter apr_pool_t *pool); 1971251881Speter 1972251881Speter 1973251881Speter/** Examine up to @a len bytes of data in @a buf to determine if the 1974251881Speter * can be considered binary data, in which case return TRUE. 1975251881Speter * If the data can be considered plain-text data, return FALSE. 1976251881Speter * 1977251881Speter * @since New in 1.7. 1978251881Speter */ 1979251881Spetersvn_boolean_t 1980251881Spetersvn_io_is_binary_data(const void *buf, apr_size_t len); 1981251881Speter 1982251881Speter 1983251881Speter/** Wrapper for apr_file_open(). @a fname is utf8-encoded. 1984251881Speter Always passed flag | APR_BINARY to apr. */ 1985251881Spetersvn_error_t * 1986251881Spetersvn_io_file_open(apr_file_t **new_file, 1987251881Speter const char *fname, 1988251881Speter apr_int32_t flag, 1989251881Speter apr_fileperms_t perm, 1990251881Speter apr_pool_t *pool); 1991251881Speter 1992251881Speter 1993251881Speter/** Wrapper for apr_file_close(). */ 1994251881Spetersvn_error_t * 1995251881Spetersvn_io_file_close(apr_file_t *file, 1996251881Speter apr_pool_t *pool); 1997251881Speter 1998251881Speter 1999251881Speter/** Wrapper for apr_file_getc(). */ 2000251881Spetersvn_error_t * 2001251881Spetersvn_io_file_getc(char *ch, 2002251881Speter apr_file_t *file, 2003251881Speter apr_pool_t *pool); 2004251881Speter 2005251881Speter 2006251881Speter/** Wrapper for apr_file_putc(). 2007251881Speter * @since New in 1.7 2008251881Speter */ 2009251881Spetersvn_error_t * 2010251881Spetersvn_io_file_putc(char ch, 2011251881Speter apr_file_t *file, 2012251881Speter apr_pool_t *pool); 2013251881Speter 2014251881Speter 2015251881Speter/** Wrapper for apr_file_info_get(). */ 2016251881Spetersvn_error_t * 2017251881Spetersvn_io_file_info_get(apr_finfo_t *finfo, 2018251881Speter apr_int32_t wanted, 2019251881Speter apr_file_t *file, 2020251881Speter apr_pool_t *pool); 2021251881Speter 2022251881Speter 2023251881Speter/** Wrapper for apr_file_read(). */ 2024251881Spetersvn_error_t * 2025251881Spetersvn_io_file_read(apr_file_t *file, 2026251881Speter void *buf, 2027251881Speter apr_size_t *nbytes, 2028251881Speter apr_pool_t *pool); 2029251881Speter 2030251881Speter 2031251881Speter/** Wrapper for apr_file_read_full(). 2032251881Speter * 2033251881Speter * If @a hit_eof is not NULL, EOF will be indicated there and no 2034251881Speter * svn_error_t error object will be created upon EOF. 2035251881Speter * 2036251881Speter * @since New in 1.7 2037251881Speter */ 2038251881Spetersvn_error_t * 2039251881Spetersvn_io_file_read_full2(apr_file_t *file, 2040251881Speter void *buf, 2041251881Speter apr_size_t nbytes, 2042251881Speter apr_size_t *bytes_read, 2043251881Speter svn_boolean_t *hit_eof, 2044251881Speter apr_pool_t *pool); 2045251881Speter 2046251881Speter 2047251881Speter/** Similar to svn_io_file_read_full2 with hit_eof being set 2048251881Speter * to @c NULL. 2049251881Speter * 2050251881Speter * @deprecated Provided for backward compatibility with the 1.6 API 2051251881Speter */ 2052251881SpeterSVN_DEPRECATED 2053251881Spetersvn_error_t * 2054251881Spetersvn_io_file_read_full(apr_file_t *file, 2055251881Speter void *buf, 2056251881Speter apr_size_t nbytes, 2057251881Speter apr_size_t *bytes_read, 2058251881Speter apr_pool_t *pool); 2059251881Speter 2060251881Speter 2061251881Speter/** Wrapper for apr_file_seek(). */ 2062251881Spetersvn_error_t * 2063251881Spetersvn_io_file_seek(apr_file_t *file, 2064251881Speter apr_seek_where_t where, 2065251881Speter apr_off_t *offset, 2066251881Speter apr_pool_t *pool); 2067251881Speter 2068251881Speter 2069251881Speter/** Wrapper for apr_file_write(). */ 2070251881Spetersvn_error_t * 2071251881Spetersvn_io_file_write(apr_file_t *file, 2072251881Speter const void *buf, 2073251881Speter apr_size_t *nbytes, 2074251881Speter apr_pool_t *pool); 2075251881Speter 2076251881Speter 2077251881Speter/** Wrapper for apr_file_write_full(). */ 2078251881Spetersvn_error_t * 2079251881Spetersvn_io_file_write_full(apr_file_t *file, 2080251881Speter const void *buf, 2081251881Speter apr_size_t nbytes, 2082251881Speter apr_size_t *bytes_written, 2083251881Speter apr_pool_t *pool); 2084251881Speter 2085251881Speter/** 2086251881Speter * Open a unique file in @a dirpath, and write @a nbytes from @a buf to 2087251881Speter * the file before flushing it to disk and closing it. Return the name 2088251881Speter * of the newly created file in @a *tmp_path, allocated in @a pool. 2089251881Speter * 2090251881Speter * If @a dirpath is @c NULL, use the path returned from svn_io_temp_dir(). 2091251881Speter * (Note that when using the system-provided temp directory, it may not 2092251881Speter * be possible to atomically rename the resulting file due to cross-device 2093251881Speter * issues.) 2094251881Speter * 2095251881Speter * The file will be deleted according to @a delete_when. 2096251881Speter * 2097251881Speter * @since New in 1.6. 2098251881Speter */ 2099251881Spetersvn_error_t * 2100251881Spetersvn_io_write_unique(const char **tmp_path, 2101251881Speter const char *dirpath, 2102251881Speter const void *buf, 2103251881Speter apr_size_t nbytes, 2104251881Speter svn_io_file_del_t delete_when, 2105251881Speter apr_pool_t *pool); 2106251881Speter 2107251881Speter/** Wrapper for apr_file_trunc(). 2108251881Speter * @since New in 1.6. */ 2109251881Spetersvn_error_t * 2110251881Spetersvn_io_file_trunc(apr_file_t *file, 2111251881Speter apr_off_t offset, 2112251881Speter apr_pool_t *pool); 2113251881Speter 2114251881Speter 2115251881Speter/** Wrapper for apr_stat(). @a fname is utf8-encoded. */ 2116251881Spetersvn_error_t * 2117251881Spetersvn_io_stat(apr_finfo_t *finfo, 2118251881Speter const char *fname, 2119251881Speter apr_int32_t wanted, 2120251881Speter apr_pool_t *pool); 2121251881Speter 2122251881Speter 2123251881Speter/** Rename and/or move the node (not necessarily a regular file) at 2124251881Speter * @a from_path to a new path @a to_path within the same filesystem. 2125251881Speter * In some cases, an existing node at @a to_path will be overwritten. 2126251881Speter * 2127251881Speter * A wrapper for apr_file_rename(). @a from_path and @a to_path are 2128251881Speter * utf8-encoded. 2129251881Speter */ 2130251881Spetersvn_error_t * 2131251881Spetersvn_io_file_rename(const char *from_path, 2132251881Speter const char *to_path, 2133251881Speter apr_pool_t *pool); 2134251881Speter 2135251881Speter 2136251881Speter/** Move the file from @a from_path to @a to_path, even across device 2137251881Speter * boundaries. Overwrite @a to_path if it exists. 2138251881Speter * 2139251881Speter * @note This function is different from svn_io_file_rename in that the 2140251881Speter * latter fails in the 'across device boundaries' case. 2141251881Speter * 2142251881Speter * @since New in 1.3. 2143251881Speter */ 2144251881Spetersvn_error_t * 2145251881Spetersvn_io_file_move(const char *from_path, 2146251881Speter const char *to_path, 2147251881Speter apr_pool_t *pool); 2148251881Speter 2149251881Speter 2150251881Speter/** Wrapper for apr_dir_make(). @a path is utf8-encoded. */ 2151251881Spetersvn_error_t * 2152251881Spetersvn_io_dir_make(const char *path, 2153251881Speter apr_fileperms_t perm, 2154251881Speter apr_pool_t *pool); 2155251881Speter 2156251881Speter/** Same as svn_io_dir_make(), but sets the hidden attribute on the 2157251881Speter directory on systems that support it. */ 2158251881Spetersvn_error_t * 2159251881Spetersvn_io_dir_make_hidden(const char *path, 2160251881Speter apr_fileperms_t perm, 2161251881Speter apr_pool_t *pool); 2162251881Speter 2163251881Speter/** 2164251881Speter * Same as svn_io_dir_make(), but attempts to set the sgid on the 2165251881Speter * directory on systems that support it. Does not return an error if 2166251881Speter * the attempt to set the sgid bit fails. On Unix filesystems, 2167251881Speter * setting the sgid bit on a directory ensures that files and 2168251881Speter * subdirectories created within inherit group ownership from the 2169251881Speter * parent instead of from the primary gid. 2170251881Speter * 2171251881Speter * @since New in 1.1. 2172251881Speter */ 2173251881Spetersvn_error_t * 2174251881Spetersvn_io_dir_make_sgid(const char *path, 2175251881Speter apr_fileperms_t perm, 2176251881Speter apr_pool_t *pool); 2177251881Speter 2178251881Speter/** Wrapper for apr_dir_open(). @a dirname is utf8-encoded. */ 2179251881Spetersvn_error_t * 2180251881Spetersvn_io_dir_open(apr_dir_t **new_dir, 2181251881Speter const char *dirname, 2182251881Speter apr_pool_t *pool); 2183251881Speter 2184251881Speter/** Wrapper for apr_dir_close(). 2185251881Speter * 2186251881Speter * @since New in 1.7. 2187251881Speter */ 2188251881Spetersvn_error_t * 2189251881Spetersvn_io_dir_close(apr_dir_t *thedir); 2190251881Speter 2191251881Speter/** Wrapper for apr_dir_remove(). @a dirname is utf8-encoded. 2192251881Speter * @note This function has this name to avoid confusion with 2193251881Speter * svn_io_remove_dir2(), which is recursive. 2194251881Speter */ 2195251881Spetersvn_error_t * 2196251881Spetersvn_io_dir_remove_nonrecursive(const char *dirname, 2197251881Speter apr_pool_t *pool); 2198251881Speter 2199251881Speter 2200251881Speter/** Wrapper for apr_dir_read(). Ensures that @a finfo->name is 2201251881Speter * utf8-encoded, which means allocating @a finfo->name in @a pool, 2202251881Speter * which may or may not be the same as @a finfo's pool. Use @a pool 2203251881Speter * for error allocation as well. 2204251881Speter */ 2205251881Spetersvn_error_t * 2206251881Spetersvn_io_dir_read(apr_finfo_t *finfo, 2207251881Speter apr_int32_t wanted, 2208251881Speter apr_dir_t *thedir, 2209251881Speter apr_pool_t *pool); 2210251881Speter 2211251881Speter/** Wrapper for apr_file_name_get(). @a *filename is utf8-encoded. 2212251881Speter * 2213251881Speter * @note The file name may be NULL. 2214251881Speter * 2215251881Speter * @since New in 1.7. */ 2216251881Spetersvn_error_t * 2217251881Spetersvn_io_file_name_get(const char **filename, 2218251881Speter apr_file_t *file, 2219251881Speter apr_pool_t *pool); 2220251881Speter 2221251881Speter 2222251881Speter 2223251881Speter/** Version/format files. 2224251881Speter * 2225251881Speter * @defgroup svn_io_format_files Version/format files 2226251881Speter * @{ 2227251881Speter */ 2228251881Speter 2229251881Speter/** Set @a *version to the integer that starts the file at @a path. If the 2230251881Speter * file does not begin with a series of digits followed by a newline, 2231251881Speter * return the error #SVN_ERR_BAD_VERSION_FILE_FORMAT. Use @a pool for 2232251881Speter * all allocations. 2233251881Speter */ 2234251881Spetersvn_error_t * 2235251881Spetersvn_io_read_version_file(int *version, 2236251881Speter const char *path, 2237251881Speter apr_pool_t *pool); 2238251881Speter 2239251881Speter/** Create (or overwrite) the file at @a path with new contents, 2240251881Speter * formatted as a non-negative integer @a version followed by a single 2241251881Speter * newline. On successful completion the file will be read-only. Use 2242251881Speter * @a pool for all allocations. 2243251881Speter */ 2244251881Spetersvn_error_t * 2245251881Spetersvn_io_write_version_file(const char *path, 2246251881Speter int version, 2247251881Speter apr_pool_t *pool); 2248251881Speter 2249251881Speter/** Read a line of text from a file, up to a specified length. 2250251881Speter * 2251251881Speter * Allocate @a *stringbuf in @a result_pool, and read into it one line 2252251881Speter * from @a file. Reading stops either after a line-terminator was found 2253251881Speter * or after @a max_len bytes have been read. 2254251881Speter * 2255251881Speter * If end-of-file is reached or @a max_len bytes have been read, and @a eof 2256251881Speter * is not NULL, then set @a *eof to @c TRUE. 2257251881Speter * 2258251881Speter * The line-terminator is not stored in @a *stringbuf. 2259251881Speter * The line-terminator is detected automatically and stored in @a *eol 2260251881Speter * if @a eol is not NULL. If EOF is reached and @a file does not end 2261251881Speter * with a newline character, and @a eol is not NULL, @ *eol is set to NULL. 2262251881Speter * 2263251881Speter * @a scratch_pool is used for temporary allocations. 2264251881Speter * 2265251881Speter * Hint: To read all data until a line-terminator is hit, pass APR_SIZE_MAX 2266251881Speter * for @a max_len. 2267251881Speter * 2268251881Speter * @since New in 1.8. 2269251881Speter */ 2270251881Spetersvn_error_t * 2271251881Spetersvn_io_file_readline(apr_file_t *file, 2272251881Speter svn_stringbuf_t **stringbuf, 2273251881Speter const char **eol, 2274251881Speter svn_boolean_t *eof, 2275251881Speter apr_size_t max_len, 2276251881Speter apr_pool_t *result_pool, 2277251881Speter apr_pool_t *scratch_pool); 2278251881Speter 2279251881Speter/** @} */ 2280251881Speter 2281251881Speter#ifdef __cplusplus 2282251881Speter} 2283251881Speter#endif /* __cplusplus */ 2284251881Speter 2285251881Speter#endif /* SVN_IO_H */ 2286