FreeBSD/contrib/subversion/subversion/libsvn_subr/stream.c
/* Create and open a tempfile in DIRECTORY. Return its handle and path */
Create and open a tempfile in DIRECTORY. Return its handle and path
Create and open a tempfile in DIRECTORY . Return its handle and path
static svn_error_t *
create_tempfile(HANDLE *hFile,
                const char **file_path,
                const char *directory,
                apr_pool_t *result_pool,
                apr_pool_t *scratch_pool)
{
  const char *unique_name;
  apr_pool_t *iterpool = svn_pool_create(scratch_pool);
  static svn_atomic_t tempname_counter;
  int baseNr = (GetTickCount() << 11) + 13 * svn_atomic_inc(&tempname_counter)
               + GetCurrentProcessId();
  int i = 0;
  HANDLE h;
  do
    {
      apr_uint32_t unique_nr;
      WCHAR *w_name;
      unique_nr = baseNr + 7 * i++;
      svn_pool_clear(iterpool);
      unique_name = svn_dirent_join(directory,
                                    apr_psprintf(iterpool, "svn-%X",
                                                 unique_nr),
                                    iterpool);
      SVN_ERR(svn_io__utf8_to_unicode_longpath(&w_name, unique_name,
                                               iterpool));
      h = CreateFileW(w_name, GENERIC_WRITE | DELETE, 0 ,
                      NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
      if (h == INVALID_HANDLE_VALUE)
        {
          apr_status_t status = apr_get_os_error();
          if (i > 1000)
            return svn_error_createf(SVN_ERR_IO_UNIQUE_NAMES_EXHAUSTED,
                           svn_error_wrap_apr(status, NULL),
                           _("Unable to make name in '%s'"),
                           svn_dirent_local_style(directory, scratch_pool));
          if (!APR_STATUS_IS_EEXIST(status) && !APR_STATUS_IS_EACCES(status))
            return svn_error_wrap_apr(status, NULL);
        }
    }
  while (h == INVALID_HANDLE_VALUE);
  *hFile = h;
  *file_path = apr_pstrdup(result_pool, unique_name);
  svn_pool_destroy(iterpool);
  return SVN_NO_ERROR;
}
static svn_error_t * create_tempfile ( HANDLE * hFile , const char * * file_path , const char * directory , apr_pool_t * result_pool , apr_pool_t * scratch_pool ) { const char * unique_name ; apr_pool_t * iterpool = svn_pool_create ( scratch_pool ) ; static svn_atomic_t tempname_counter ; int baseNr = ( GetTickCount ( ) << 11 ) + 13 * svn_atomic_inc ( & tempname_counter ) + GetCurrentProcessId ( ) ; int i = 0 ; HANDLE h ; do { apr_uint32_t unique_nr ; WCHAR * w_name ; unique_nr = baseNr + 7 * i ++ ; svn_pool_clear ( iterpool ) ; unique_name = svn_dirent_join ( directory , apr_psprintf ( iterpool , " " , unique_nr ) , iterpool ) ; SVN_ERR ( svn_io__utf8_to_unicode_longpath ( & w_name , unique_name , iterpool ) ) ; h = CreateFileW ( w_name , GENERIC_WRITE | DELETE , 0 , NULL , CREATE_NEW , FILE_ATTRIBUTE_NORMAL , NULL ) ; if ( h == INVALID_HANDLE_VALUE ) { apr_status_t status = apr_get_os_error ( ) ; if ( i > 1000 ) return svn_error_createf ( SVN_ERR_IO_UNIQUE_NAMES_EXHAUSTED , svn_error_wrap_apr ( status , NULL ) , _ ( " " ) , svn_dirent_local_style ( directory , scratch_pool ) ) ; if ( ! APR_STATUS_IS_EEXIST ( status ) && ! APR_STATUS_IS_EACCES ( status ) ) return svn_error_wrap_apr ( status , NULL ) ; } } while ( h == INVALID_HANDLE_VALUE ) ; * hFile = h ; * file_path = apr_pstrdup ( result_pool , unique_name ) ; svn_pool_destroy ( iterpool ) ; return SVN_NO_ERROR ; }
Create and open a tempfile in DIRECTORY.
Create and open a tempfile in DIRECTORY .
/* Shares common idea with io.c's temp_file_create */ /* Generate a number that should be unique for this application and
         usually for the entire computer to reduce the number of cycles
         through this loop. (A bit of calculation is much cheaper than
         disk io) */ /* Create a completely not-sharable file to avoid indexers, and other
         filesystem watchers locking the file while we are still writing.

         We need DELETE privileges to move the file. */ /* share */