aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fileio.c88
1 files changed, 51 insertions, 37 deletions
diff --git a/src/fileio.c b/src/fileio.c
index ad8bb93284f..722370ea5ce 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -5354,52 +5354,66 @@ e_write (desc, string, start, end, coding)
5354 5354
5355 /* We used to have a code for handling selective display here. But, 5355 /* We used to have a code for handling selective display here. But,
5356 now it is handled within encode_coding. */ 5356 now it is handled within encode_coding. */
5357 if (STRINGP (string)) 5357
5358 while (start < end)
5358 { 5359 {
5359 coding->src_multibyte = SCHARS (string) < SBYTES (string); 5360 if (STRINGP (string))
5360 if (CODING_REQUIRE_ENCODING (coding))
5361 { 5361 {
5362 encode_coding_object (coding, string, 5362 coding->src_multibyte = SCHARS (string) < SBYTES (string);
5363 start, string_char_to_byte (string, start), 5363 if (CODING_REQUIRE_ENCODING (coding))
5364 end, string_char_to_byte (string, end), Qt); 5364 {
5365 encode_coding_object (coding, string,
5366 start, string_char_to_byte (string, start),
5367 end, string_char_to_byte (string, end), Qt);
5368 }
5369 else
5370 {
5371 coding->dst_object = string;
5372 coding->consumed_char = SCHARS (string);
5373 coding->produced = SBYTES (string);
5374 }
5365 } 5375 }
5366 else 5376 else
5367 { 5377 {
5368 coding->dst_object = string; 5378 int start_byte = CHAR_TO_BYTE (start);
5369 coding->produced = SBYTES (string); 5379 int end_byte = CHAR_TO_BYTE (end);
5370 }
5371 }
5372 else
5373 {
5374 int start_byte = CHAR_TO_BYTE (start);
5375 int end_byte = CHAR_TO_BYTE (end);
5376 5380
5377 coding->src_multibyte = (end - start) < (end_byte - start_byte); 5381 coding->src_multibyte = (end - start) < (end_byte - start_byte);
5378 if (CODING_REQUIRE_ENCODING (coding)) 5382 if (CODING_REQUIRE_ENCODING (coding))
5379 { 5383 {
5380 encode_coding_object (coding, Fcurrent_buffer (), 5384 encode_coding_object (coding, Fcurrent_buffer (),
5381 start, CHAR_TO_BYTE (start), 5385 start, start_byte, end, end_byte, Qt);
5382 end, CHAR_TO_BYTE (end), Qt); 5386 }
5387 else
5388 {
5389 coding->dst_object = Qnil;
5390 coding->dst_pos_byte = start_byte;
5391 if (start >= GPT || end <= GPT)
5392 {
5393 coding->consumed_char = end - start;
5394 coding->produced = end_byte - start_byte;
5395 }
5396 else
5397 {
5398 coding->consumed_char = GPT - start;
5399 coding->produced = GPT_BYTE - start_byte;
5400 }
5401 }
5383 } 5402 }
5384 else 5403
5404 if (coding->produced > 0)
5385 { 5405 {
5386 coding->dst_object = Qnil; 5406 coding->produced -=
5387 coding->produced = end - start; 5407 emacs_write (desc,
5388 coding->dst_pos_byte = start_byte; 5408 STRINGP (coding->dst_object)
5409 ? SDATA (coding->dst_object)
5410 : BYTE_POS_ADDR (coding->dst_pos_byte),
5411 coding->produced);
5412
5413 if (coding->produced)
5414 return -1;
5389 } 5415 }
5390 } 5416 start += coding->consumed_char;
5391
5392 if (coding->produced > 0)
5393 {
5394 coding->produced -=
5395 emacs_write (desc,
5396 STRINGP (coding->dst_object)
5397 ? SDATA (coding->dst_object)
5398 : BYTE_POS_ADDR (coding->dst_pos_byte),
5399 coding->produced);
5400
5401 if (coding->produced)
5402 return -1;
5403 } 5417 }
5404 5418
5405 return 0; 5419 return 0;