comparison src/fileio.c @ 1142:f0dcee927c1d

updated for version 7.1a
author vimboss
date Sun, 06 May 2007 12:40:34 +0000
parents 1df41c98fc2e
children 4d2585cf5950
comparison
equal deleted inserted replaced
1141:700bffdaded3 1142:f0dcee927c1d
5011 { 5011 {
5012 /* Convert from enc_codepage to UCS-2, to the start of the 5012 /* Convert from enc_codepage to UCS-2, to the start of the
5013 * buffer. The buffer has been allocated to be big enough. */ 5013 * buffer. The buffer has been allocated to be big enough. */
5014 ip->bw_restlen = 0; 5014 ip->bw_restlen = 0;
5015 needed = MultiByteToWideChar(enc_codepage, 5015 needed = MultiByteToWideChar(enc_codepage,
5016 MB_ERR_INVALID_CHARS, (LPCSTR)from, (int)fromlen, 5016 MB_ERR_INVALID_CHARS, (LPCSTR)from, (int)fromlen,
5017 NULL, 0); 5017 NULL, 0);
5018 if (needed == 0) 5018 if (needed == 0)
5019 { 5019 {
5020 /* When conversion fails there may be a trailing byte. */ 5020 /* When conversion fails there may be a trailing byte. */
5021 needed = MultiByteToWideChar(enc_codepage, 5021 needed = MultiByteToWideChar(enc_codepage,
5022 MB_ERR_INVALID_CHARS, (LPCSTR)from, (int)fromlen - 1, 5022 MB_ERR_INVALID_CHARS, (LPCSTR)from, (int)fromlen - 1,
5023 NULL, 0); 5023 NULL, 0);
5024 if (needed == 0) 5024 if (needed == 0)
5025 { 5025 {
5026 /* Conversion doesn't work. */ 5026 /* Conversion doesn't work. */
5027 ip->bw_conv_error = TRUE; 5027 ip->bw_conv_error = TRUE;
5030 /* Save the trailing byte for the next call. */ 5030 /* Save the trailing byte for the next call. */
5031 ip->bw_rest[0] = from[fromlen - 1]; 5031 ip->bw_rest[0] = from[fromlen - 1];
5032 ip->bw_restlen = 1; 5032 ip->bw_restlen = 1;
5033 } 5033 }
5034 needed = MultiByteToWideChar(enc_codepage, MB_ERR_INVALID_CHARS, 5034 needed = MultiByteToWideChar(enc_codepage, MB_ERR_INVALID_CHARS,
5035 (LPCSTR)from, (int)(fromlen - ip->bw_restlen), 5035 (LPCSTR)from, (int)(fromlen - ip->bw_restlen),
5036 (LPWSTR)to, needed); 5036 (LPWSTR)to, needed);
5037 if (needed == 0) 5037 if (needed == 0)
5038 { 5038 {
5039 /* Safety check: Conversion doesn't work. */ 5039 /* Safety check: Conversion doesn't work. */
5040 ip->bw_conv_error = TRUE; 5040 ip->bw_conv_error = TRUE;
5070 * the conversion buffer. If the conversion uses the default 5070 * the conversion buffer. If the conversion uses the default
5071 * character "0", the data doesn't fit in this encoding, so 5071 * character "0", the data doesn't fit in this encoding, so
5072 * fail. */ 5072 * fail. */
5073 len = WideCharToMultiByte(FIO_GET_CP(flags), 0, 5073 len = WideCharToMultiByte(FIO_GET_CP(flags), 0,
5074 (LPCWSTR)ip->bw_conv_buf, (int)fromlen / sizeof(WCHAR), 5074 (LPCWSTR)ip->bw_conv_buf, (int)fromlen / sizeof(WCHAR),
5075 (LPSTR)to, (int)(ip->bw_conv_buflen - fromlen), 0, &bad); 5075 (LPSTR)to, (int)(ip->bw_conv_buflen - fromlen), 0,
5076 &bad);
5076 if (bad) 5077 if (bad)
5077 { 5078 {
5078 ip->bw_conv_error = TRUE; 5079 ip->bw_conv_error = TRUE;
5079 return FAIL; 5080 return FAIL;
5080 } 5081 }
5199 } 5200 }
5200 } 5201 }
5201 #endif 5202 #endif
5202 5203
5203 /* Repeat the write(), it may be interrupted by a signal. */ 5204 /* Repeat the write(), it may be interrupted by a signal. */
5204 while (len) 5205 while (len > 0)
5205 { 5206 {
5206 wlen = vim_write(ip->bw_fd, buf, len); 5207 wlen = vim_write(ip->bw_fd, buf, len);
5207 if (wlen <= 0) /* error! */ 5208 if (wlen <= 0) /* error! */
5208 return FAIL; 5209 return FAIL;
5209 len -= wlen; 5210 len -= wlen;