[Mono-dev] [PATCH]System.IO.File.Replace
Paolo Molaro
lupus at ximian.com
Mon Aug 20 04:27:38 EDT 2007
On 08/17/07 Bill Holmes wrote:
> Here is an updated version of my patch. I apologize in advance if my
> attachment is a "binary blob" again. I am not quite sure what that
> meant or what I should do about it. This time I am sending the mail
> from SUSE so maybe that will help.
It looks good now:) Binary blob means that the patch you sent was marked
as an attachment of mime-type octect-stream (octect-stream is another
name for binary blob) instead of the text file it is.
> Index: mono/mono/io-layer/io.c
> ===================================================================
> --- mono/mono/io-layer/io.c (revision 84326)
> +++ mono/mono/io-layer/io.c (working copy)
> @@ -1835,6 +1835,55 @@
> return(ret);
> }
>
> +gboolean write_file (int src_fd, int dest_fd, struct stat *st_src, gboolean report_errors)
> +{
> + int remain, n;
> + char *buf;
> + int buf_size = st_src->st_blksize;
> + gboolean ret = FALSE;
> +
> + buf_size = buf_size < 8192 ? 8192 : (buf_size > 65536 ? 65536 : buf_size);
> + buf = (char *) malloc (buf_size);
> +
> + for (;;) {
> + remain = read (src_fd, buf, buf_size);
> + if (remain < 0) {
> + if (errno == EINTR && !_wapi_thread_cur_apc_pending ())
> + continue;
> +
> + if (report_errors)
> + _wapi_set_last_error_from_errno ();
> +
> + goto write_file_cleanup;
> + }
> + if (remain == 0) {
> + break;
> + }
> +
> + while (remain > 0) {
> + if ((n = write (dest_fd, buf, remain)) < 0) {
> + if (errno == EINTR && !_wapi_thread_cur_apc_pending ())
> + continue;
> +
> + if (report_errors)
> + _wapi_set_last_error_from_errno ();
> +#ifdef DEBUG
> + g_message ("%s: write failed.", __func__);
> +#endif
> + goto write_file_cleanup;
> + }
> +
> + remain -= n;
> + }
> + }
> +
> + ret = TRUE;
> +
> +write_file_cleanup:
> + free (buf);
> + return ret ;
In this function I wouldn't use goto (I don't think I asked for this
change): the cleanup code is very simple.
Anyway, this change made me incpect the code more and there seems to be
a bug: in the case of a short write, we try to repeatedly write always
from the start of the buffer, instead of advancing into it. This causes
corruption and needs fixing.
> +gchar* convert_arg_to_utf8 (const gunichar2 *arg, const gchar *arg_name)
Here and in the other places, put the function name at the start of a
line, with the return type and storage type in their own line.
Thanks!
lupus
--
-----------------------------------------------------------------
lupus at debian.org debian/rules
lupus at ximian.com Monkeys do it better
More information about the Mono-devel-list
mailing list