Index: subversion/libsvn_subr/io.c =================================================================== --- subversion/libsvn_subr/io.c (revision 18555) +++ subversion/libsvn_subr/io.c (working copy) @@ -145,6 +145,46 @@ } +#ifdef AS400 +/* Helper function for apr_file_open() on OS400. + * + * When calling apr_file_open() with APR_BINARY and APR_CREATE on OS400 + * the new file has an ebcdic CCSID (e.g. 37). But the files created by + * Subversion have either binary or utf-8 content, never ebcdic, so the + * files are incorrectly tagged. To force these files to the proper CCSID + * call this function prior to apr_file_open(), passing the filename and a + * reference to the flag apr_file_open() will use. The function creates an + * empty file with CCSID 1208, closes it, and removes APR_EXCL from flag. + */ +apr_status_t +os400_file_create_prep(const char *fname, + apr_int32_t *flag, + apr_fileperms_t perm, + apr_pool_t *pool) +{ + apr_file_t *f; + apr_status_t apr_err; + + /* If we are not trying to create a file there is nothing to do. */ + if (~*flag & APR_CREATE) + return APR_SUCCESS; + + apr_err = apr_file_open (&f, fname, *flag & ~APR_BINARY, perm, pool); + + if (!apr_err) + apr_file_close(f); + + /* Whether or not APR_EXCL is set or not, we want to unset it before the + * call to apr_file_open() since this flag was already handled in the + * above call to open(). + */ + *flag &= ~APR_EXCL; + + return apr_err; +} +#endif + + svn_error_t * svn_io_check_resolved_path(const char *path, svn_node_kind_t *kind, @@ -264,6 +304,11 @@ SVN_ERR(svn_path_cstring_from_utf8(&unique_name_apr, unique_name, pool)); +#ifdef AS400 + apr_err = os400_file_create_prep(unique_name_apr, &flag, + APR_OS_DEFAULT, pool); + if (!apr_err) +#endif apr_err = apr_file_open(&file, unique_name_apr, flag | APR_BINARY, APR_OS_DEFAULT, pool); @@ -2237,6 +2282,10 @@ apr_status_t status; SVN_ERR(svn_path_cstring_from_utf8(&fname_apr, fname, pool)); +#ifdef AS400 + status = os400_file_create_prep(fname_apr, &flag, perm, pool); + if (!status) +#endif status = apr_file_open(new_file, fname_apr, flag | APR_BINARY, perm, pool); if (status)