Skip to main content

svn_io_open_uniquely_named

Function svn_io_open_uniquely_named 

Source
pub unsafe extern "C" fn svn_io_open_uniquely_named(
    file: *mut *mut apr_file_t,
    unique_name: *mut *const c_char,
    dirpath: *const c_char,
    filename: *const c_char,
    suffix: *const c_char,
    delete_when: svn_io_file_del_t,
    result_pool: *mut apr_pool_t,
    scratch_pool: *mut apr_pool_t,
) -> *mut svn_error_t
Expand description

Open a new file (for reading and writing) with a unique name based on utf-8 encoded @a filename, in the directory @a dirpath. The file handle is returned in @a *file, and the name, which ends with @a suffix, is returned in @a *unique_name, also utf8-encoded. Either @a file or @a unique_name may be @c NULL. If @a file is @c NULL, the file will be created but not open.

The file will be deleted according to @a delete_when. If that is #svn_io_file_del_on_pool_cleanup, it refers to @a result_pool.

The @c APR_BUFFERED flag will always be used when opening the file.

The first attempt will just append @a suffix. If the result is not a unique name, then subsequent attempts will append a dot, followed by an iteration number (“2”, then “3”, and so on), followed by the suffix. For example, successive calls to

svn_io_open_uniquely_named(&f, &u, “tests/t1/A/D/G”, “pi”, “.tmp”, …)

will open

tests/t1/A/D/G/pi.tmp tests/t1/A/D/G/pi.2.tmp tests/t1/A/D/G/pi.3.tmp tests/t1/A/D/G/pi.4.tmp tests/t1/A/D/G/pi.5.tmp …

Assuming @a suffix is non-empty, @a *unique_name will never be exactly the same as @a filename, even if @a filename does not exist.

If @a dirpath is NULL, then the directory returned by svn_io_temp_dir() will be used.

If @a filename is NULL, then “tempfile” will be used.

If @a suffix is NULL, then “.tmp” will be used.

Allocates @a *file and @a *unique_name in @a result_pool. All intermediate allocations will be performed in @a scratch_pool.

If no unique name can be found, #SVN_ERR_IO_UNIQUE_NAMES_EXHAUSTED is the error returned.

Claim of Historical Inevitability: this function was written because

  • tmpnam() is not thread-safe.
  • tempname() tries standard system tmp areas first.

@since New in 1.6