Project

General

Profile

Bug #7758 ยป win32-bug-7758.diff

nobu (Nobuyoshi Nakada), 02/15/2013 01:38 PM

View differences:

win32/win32.c
6041 6041
    size_t len;
6042 6042
    size_t ret;
6043 6043
    OVERLAPPED ol, *pol = NULL;
6044
#ifdef __MINGW32__
6045
    int text = 0;
6046
#endif
6044 6047

  
6045 6048
    if (is_socket(sock))
6046 6049
	return rb_w32_send(fd, buf, size, 0);
......
6065 6068
    ret = 0;
6066 6069
  retry:
6067 6070
    /* get rid of console writing bug */
6068
    len = (_osfile(fd) & FDEV) ? min(32 * 1024, size) : size;
6071
    len = size;
6072
    if (_osfile(fd) & FDEV) {
6073
	len = min(32 * 1024, size);
6074
#ifdef __MINGW32__
6075
	text = (_osfile(fd) & FTEXT);
6076
	setmode(fd, O_BINARY);
6077
#endif
6078
    }
6069 6079
    size -= len;
6070 6080

  
6071 6081
    /* if have cancel_io, use Overlapped I/O */
......
6080 6090
#endif
6081 6091
	    if (low == INVALID_SET_FILE_POINTER) {
6082 6092
		errno = map_errno(GetLastError());
6083
		MTHREAD_ONLY(LeaveCriticalSection(&_pioinfo(fd)->lock));
6084
		return -1;
6093
		ret = -1;
6094
		goto finish;
6085 6095
	    }
6086 6096
	    ol.Offset = low;
6087 6097
	    ol.OffsetHigh = high;
......
6089 6099
	ol.hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
6090 6100
	if (!ol.hEvent) {
6091 6101
	    errno = map_errno(GetLastError());
6092
	    MTHREAD_ONLY(LeaveCriticalSection(&_pioinfo(fd)->lock));
6093
	    return -1;
6102
	    ret = -1;
6103
	    goto finish;
6094 6104
	}
6095 6105

  
6096 6106
	pol = &ol;
......
6105 6115
	    else
6106 6116
		errno = map_errno(err);
6107 6117

  
6108
	    MTHREAD_ONLY(LeaveCriticalSection(&_pioinfo(fd)->lock));
6109
	    return -1;
6118
	    ret = -1;
6119
	    goto finish;
6110 6120
	}
6111 6121

  
6112 6122
	if (pol) {
......
6118 6128
		    errno = map_errno(GetLastError());
6119 6129
		CloseHandle(ol.hEvent);
6120 6130
		cancel_io((HANDLE)_osfhnd(fd));
6121
		MTHREAD_ONLY(LeaveCriticalSection(&_pioinfo(fd)->lock));
6122
		return -1;
6131
		ret = -1;
6132
		goto finish;
6123 6133
	    }
6124 6134

  
6125 6135
	    if (!GetOverlappedResult((HANDLE)_osfhnd(fd), &ol, &written,
......
6127 6137
		errno = map_errno(err);
6128 6138
		CloseHandle(ol.hEvent);
6129 6139
		cancel_io((HANDLE)_osfhnd(fd));
6130
		MTHREAD_ONLY(LeaveCriticalSection(&_pioinfo(fd)->lock));
6131
		return -1;
6140
		ret = -1;
6141
		goto finish;
6132 6142
	    }
6133 6143
	}
6134 6144
    }
......
6152 6162
	    goto retry;
6153 6163
    }
6154 6164

  
6165
  finish:
6166
#ifdef __MINGW32__
6167
    if (text) setmode(fd, O_TEXT);
6168
#endif
6169

  
6155 6170
    MTHREAD_ONLY(LeaveCriticalSection(&_pioinfo(fd)->lock));
6156 6171

  
6157 6172
    return ret;