Changeset 331 for EcnlProtoTool/trunk/mrbgems/mruby-io/src/io.c
- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/mrbgems/mruby-io/src/io.c
r321 r331 190 190 } 191 191 192 #if !defined(_WIN32) && !defined(_WIN64) && !defined(__NEWLIB__)192 #ifndef _WIN32 193 193 static int 194 194 mrb_cloexec_pipe(mrb_state *mrb, int fildes[2]) … … 265 265 #endif 266 266 267 #if !defined(_WIN32) && !defined(_WIN64) && !defined(__NEWLIB__)267 #ifndef _WIN32 268 268 static int 269 269 option_to_fd(mrb_state *mrb, mrb_value obj, const char *key) … … 390 390 391 391 mrb_iv_set(mrb, io, mrb_intern_cstr(mrb, "@buf"), mrb_str_new_cstr(mrb, "")); 392 mrb_iv_set(mrb, io, mrb_intern_cstr(mrb, "@pos"), mrb_fixnum_value(0));393 392 394 393 fptr = mrb_io_alloc(mrb); … … 444 443 445 444 mrb_iv_set(mrb, io, mrb_intern_cstr(mrb, "@buf"), mrb_str_new_cstr(mrb, "")); 446 mrb_iv_set(mrb, io, mrb_intern_cstr(mrb, "@pos"), mrb_fixnum_value(0));447 445 448 446 fptr = (struct mrb_io *)DATA_PTR(io); … … 488 486 } 489 487 490 #if !defined(_WIN32) && !defined(_WIN64) && !defined(__NEWLIB__)488 #if !defined(_WIN32) && !defined(_WIN64) 491 489 if (fptr->pid != 0) { 492 490 pid_t pid; … … 557 555 mrb_cloexec_open(mrb_state *mrb, const char *pathname, mrb_int flags, mrb_int mode) 558 556 { 557 mrb_value emsg; 559 558 int fd, retry = FALSE; 560 559 … … 577 576 } 578 577 } 579 mrb_sys_fail(mrb, "open"); 578 579 emsg = mrb_format(mrb, "open %S", mrb_str_new_cstr(mrb, pathname)); 580 mrb_str_modify(mrb, mrb_str_ptr(emsg)); 581 mrb_sys_fail(mrb, RSTRING_PTR(emsg)); 580 582 } 581 583 … … 620 622 mrb_get_args(mrb, "i|S", &maxlen, &buf); 621 623 if (maxlen < 0) { 622 return mrb_nil_value(); 624 mrb_raise(mrb, E_ARGUMENT_ERROR, "negative expanding string size"); 625 } 626 else if (maxlen == 0) { 627 return mrb_str_new(mrb, NULL, maxlen); 623 628 } 624 629 … … 626 631 buf = mrb_str_new(mrb, NULL, maxlen); 627 632 } 633 628 634 if (RSTRING_LEN(buf) != maxlen) { 629 635 buf = mrb_str_resize(mrb, buf, maxlen); 630 } 631 632 fptr = (struct mrb_io *)mrb_get_datatype(mrb, io, &mrb_io_type); 636 } else { 637 mrb_str_modify(mrb, RSTRING(buf)); 638 } 639 640 fptr = (struct mrb_io *)io_get_open_fptr(mrb, io); 641 if (!fptr->readable) { 642 mrb_raise(mrb, E_IO_ERROR, "not opened for reading"); 643 } 633 644 ret = read(fptr->fd, RSTRING_PTR(buf), maxlen); 634 645 switch (ret) { … … 702 713 } 703 714 length = write(fd, RSTRING_PTR(buf), RSTRING_LEN(buf)); 715 if (length == -1) { 716 mrb_sys_fail(mrb, 0); 717 } 704 718 705 719 return mrb_fixnum_value(length); … … 773 787 } 774 788 775 #if !defined(_WIN32) && !defined(_WIN64) && !defined(__NEWLIB__)789 #ifndef _WIN32 776 790 static mrb_value 777 791 mrb_io_s_pipe(mrb_state *mrb, mrb_value klass) … … 789 803 r = mrb_obj_value(mrb_data_object_alloc(mrb, mrb_class_ptr(klass), NULL, &mrb_io_type)); 790 804 mrb_iv_set(mrb, r, mrb_intern_cstr(mrb, "@buf"), mrb_str_new_cstr(mrb, "")); 791 mrb_iv_set(mrb, r, mrb_intern_cstr(mrb, "@pos"), mrb_fixnum_value(0));792 805 fptr_r = mrb_io_alloc(mrb); 793 806 fptr_r->fd = pipes[0]; … … 800 813 w = mrb_obj_value(mrb_data_object_alloc(mrb, mrb_class_ptr(klass), NULL, &mrb_io_type)); 801 814 mrb_iv_set(mrb, w, mrb_intern_cstr(mrb, "@buf"), mrb_str_new_cstr(mrb, "")); 802 mrb_iv_set(mrb, w, mrb_intern_cstr(mrb, "@pos"), mrb_fixnum_value(0));803 815 fptr_w = mrb_io_alloc(mrb); 804 816 fptr_w->fd = pipes[1]; … … 1072 1084 1073 1085 mrb_include_module(mrb, io, mrb_module_get(mrb, "Enumerable")); /* 15.2.20.3 */ 1074 #if !defined(_WIN32) && !defined(_WIN64) && !defined(__NEWLIB__)1086 #ifndef _WIN32 1075 1087 mrb_define_class_method(mrb, io, "_popen", mrb_io_s_popen, MRB_ARGS_ANY()); 1076 1088 mrb_define_class_method(mrb, io, "_sysclose", mrb_io_s_sysclose, MRB_ARGS_REQ(1)); … … 1079 1091 mrb_define_class_method(mrb, io, "select", mrb_io_s_select, MRB_ARGS_ANY()); 1080 1092 mrb_define_class_method(mrb, io, "sysopen", mrb_io_s_sysopen, MRB_ARGS_ANY()); 1081 #if !defined(_WIN32) && !defined(_WIN64) && !defined(__NEWLIB__)1093 #ifndef _WIN32 1082 1094 mrb_define_class_method(mrb, io, "_pipe", mrb_io_s_pipe, MRB_ARGS_NONE()); 1083 1095 #endif
Note:
See TracChangeset
for help on using the changeset viewer.