@@ -329,15 +329,25 @@ REBINT Mode_Syms[] = {
329
329
#endif
330
330
len += n ;
331
331
}
332
-
333
- // Auto convert string to UTF-8
334
- if (IS_STRING (data )) {
332
+
333
+ if (IS_BINARY (data )) {
334
+ file -> data = VAL_BIN_DATA (data );
335
+ }
336
+ else if (IS_STRING (data )) {
337
+ // Auto convert string to UTF-8
335
338
ser = Encode_UTF8_Value (data , len , ENCF_OS_CRLF );
336
339
file -> data = ser ? BIN_HEAD (ser ) : VAL_BIN_DATA (data ); // No encoding may be needed
337
340
len = SERIES_TAIL (ser );
338
341
}
342
+ else if (IS_CHAR (data )) {
343
+ // Auto convert char to UTF-8
344
+ REBYTE buf [8 ];
345
+ len = Encode_UTF8_Char (buf , VAL_CHAR (data ));
346
+ file -> data = & buf ;
347
+ }
339
348
else {
340
- file -> data = VAL_BIN_DATA (data );
349
+ // it should be already handled
350
+ //Trap1(PE_BAD_ARGUMENT, data);
341
351
}
342
352
file -> length = len ;
343
353
OS_DO_DEVICE (file , RDC_WRITE );
@@ -464,14 +474,16 @@ REBINT Mode_Syms[] = {
464
474
break ;
465
475
466
476
case A_APPEND :
477
+ args = Find_Refines (ds , AM_APPEND_DUP | AM_APPEND_ONLY );
478
+ if (args > 0 ) Trap0 (RE_BAD_REFINES ); // should be used some new port related error!
467
479
file -> file .index = file -> file .size ;
468
480
SET_FLAG (file -> modes , RFM_RESEEK );
469
481
470
482
case A_WRITE :
471
483
args = Find_Refines (ds , ALL_WRITE_REFS );
472
- spec = D_ARG (2 ); // data (binary, string, or block)
484
+ spec = D_ARG (2 ); // data (binary, string, char or block)
473
485
474
- if (!(IS_BINARY (spec ) || IS_STRING (spec ) || (IS_BLOCK (spec ) && (args & AM_WRITE_LINES )))) {
486
+ if (!(IS_BINARY (spec ) || IS_STRING (spec ) || IS_CHAR ( spec ) || (IS_BLOCK (spec ) && (args & AM_WRITE_LINES )))) {
475
487
//Trap1(RE_INVALID_ARG, spec);
476
488
REB_MOLD mo = {0 };
477
489
Reset_Mold (& mo );
@@ -493,14 +505,14 @@ REBINT Mode_Syms[] = {
493
505
}
494
506
495
507
// Setup for /append or /seek:
496
- if (args & AM_WRITE_APPEND ) {
508
+ if (args & AM_WRITE_APPEND || action == A_APPEND ) {
497
509
file -> file .index = -1 ; // append
498
510
SET_FLAG (file -> modes , RFM_RESEEK );
499
511
}
500
512
if (args & AM_WRITE_SEEK ) Set_Seek (file , D_ARG (ARG_WRITE_INDEX ));
501
513
514
+ len = IS_CHAR (spec ) ? 0 : VAL_LEN (spec );
502
515
// Determine length. Clip /PART to size of string if needed.
503
- len = VAL_LEN (spec );
504
516
if (args & AM_WRITE_PART ) {
505
517
REBCNT n = Int32s (D_ARG (ARG_WRITE_LENGTH ), 0 );
506
518
if (n <= len ) len = n ;
0 commit comments