zipruby 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of zipruby might be problematic. Click here for more details.

@@ -22,15 +22,15 @@ static VALUE zipruby_archive_fopen(int argc, VALUE *argv, VALUE self);
22
22
  static VALUE zipruby_archive_get_stat(int argc, VALUE *argv, VALUE self);
23
23
  static VALUE zipruby_archive_add_buffer(VALUE self, VALUE name, VALUE source);
24
24
  static VALUE zipruby_archive_add_file(int argc, VALUE *argv, VALUE self);
25
- static VALUE zipruby_archive_add_filep(int argc, VALUE *argv, VALUE self);
25
+ static VALUE zipruby_archive_add_io(VALUE self, VALUE name, VALUE io);
26
26
  static VALUE zipruby_archive_add_function(int argc, VALUE *argv, VALUE self);
27
27
  static VALUE zipruby_archive_replace_buffer(int argc, VALUE *argv, VALUE self);
28
28
  static VALUE zipruby_archive_replace_file(int argc, VALUE* argv, VALUE self);
29
- static VALUE zipruby_archive_replace_filep(VALUE self, VALUE index, VALUE file);
29
+ static VALUE zipruby_archive_replace_io(int argc, VALUE* argv, VALUE self);
30
30
  static VALUE zipruby_archive_replace_function(int argc, VALUE *argv, VALUE self);
31
31
  static VALUE zipruby_archive_add_or_replace_buffer(int argc, VALUE *argv, VALUE self);
32
32
  static VALUE zipruby_archive_add_or_replace_file(int argc, VALUE *argv, VALUE self);
33
- static VALUE zipruby_archive_add_or_replace_filep(int argc, VALUE *argv, VALUE self);
33
+ static VALUE zipruby_archive_add_or_replace_io(int argc, VALUE *argv, VALUE self);
34
34
  static VALUE zipruby_archive_add_or_replace_function(int argc, VALUE *argv, VALUE self);
35
35
  static VALUE zipruby_archive_update(int argc, VALUE *argv, VALUE self);
36
36
  static VALUE zipruby_archive_get_comment(int argc, VALUE *argv, VALUE self);
@@ -72,18 +72,18 @@ void Init_zipruby_archive() {
72
72
  rb_define_method(Archive, "get_stat", zipruby_archive_get_stat, -1);
73
73
  rb_define_method(Archive, "add_buffer", zipruby_archive_add_buffer, 2);
74
74
  rb_define_method(Archive, "add_file", zipruby_archive_add_file, -1);
75
- rb_define_method(Archive, "add_filep", zipruby_archive_add_filep, -1);
75
+ rb_define_method(Archive, "add_io", zipruby_archive_add_io, 2);
76
76
  rb_define_method(Archive, "add", zipruby_archive_add_function, -1);
77
77
  rb_define_method(Archive, "replace_buffer", zipruby_archive_replace_buffer, -1);
78
78
  rb_define_method(Archive, "replace_file", zipruby_archive_replace_file, -1);
79
- rb_define_method(Archive, "replace_filep", zipruby_archive_replace_filep, 2);
79
+ rb_define_method(Archive, "replace_io", zipruby_archive_replace_io, -1);
80
80
  rb_define_method(Archive, "replace", zipruby_archive_replace_function, -1);
81
81
  rb_define_method(Archive, "add_or_replace_buffer", zipruby_archive_add_or_replace_buffer, -1);
82
82
  rb_define_method(Archive, "add_or_replace_file", zipruby_archive_add_or_replace_file, -1);
83
- rb_define_method(Archive, "add_or_replace_filep", zipruby_archive_add_or_replace_filep, -1);
83
+ rb_define_method(Archive, "add_or_replace_io", zipruby_archive_add_or_replace_io, -1);
84
84
  rb_define_method(Archive, "add_or_replace", zipruby_archive_add_or_replace_function, -1);
85
85
  rb_define_method(Archive, "update", zipruby_archive_update, -1);
86
- rb_define_method(Archive, "<<", zipruby_archive_add_filep, -1);
86
+ rb_define_method(Archive, "<<", zipruby_archive_add_io, 2);
87
87
  rb_define_method(Archive, "get_comment", zipruby_archive_get_comment, -1);
88
88
  rb_define_method(Archive, "comment", zipruby_archive_get_comment, -1);
89
89
  rb_define_method(Archive, "comment=", zipruby_archive_set_comment, 1);
@@ -149,10 +149,10 @@ static VALUE zipruby_archive_s_open(int argc, VALUE *argv, VALUE self) {
149
149
  archive = rb_funcall(Archive, rb_intern("new"), 0);
150
150
  Data_Get_Struct(archive, struct zipruby_archive, p_archive);
151
151
 
152
- if ((p_archive->archive = zip_open(StringValuePtr(path), i_flags, &errorp)) == NULL) {
152
+ if ((p_archive->archive = zip_open(RSTRING_PTR(path), i_flags, &errorp)) == NULL) {
153
153
  char errstr[ERRSTR_BUFSIZE];
154
154
  zip_error_to_str(errstr, ERRSTR_BUFSIZE, errorp, errno);
155
- rb_raise(Error, "Open archive failed - %s: %s", StringValuePtr(path), errstr);
155
+ rb_raise(Error, "Open archive failed - %s: %s", RSTRING_PTR(path), errstr);
156
156
  }
157
157
 
158
158
  p_archive->path = path;
@@ -182,7 +182,7 @@ static VALUE zipruby_archive_s_open_buffer(int argc, VALUE *argv, VALUE self) {
182
182
  struct zipruby_archive *p_archive;
183
183
  void *data = NULL;
184
184
  int len = 0, i_flags = 0;
185
- int errorp;
185
+ int errorp;
186
186
 
187
187
  rb_scan_args(argc, argv, "02", &buffer, &flags);
188
188
 
@@ -202,8 +202,8 @@ static VALUE zipruby_archive_s_open_buffer(int argc, VALUE *argv, VALUE self) {
202
202
 
203
203
  i_flags = (i_flags | ZIP_TRUNC);
204
204
  } else if (TYPE(buffer) == T_STRING) {
205
- data = StringValuePtr(buffer);
206
- len = RSTRING(buffer)->len;
205
+ data = RSTRING_PTR(buffer);
206
+ len = RSTRING_LEN(buffer);
207
207
  } else if (rb_obj_is_instance_of(buffer, rb_cProc)) {
208
208
  data = (void *) buffer;
209
209
  len = -1;
@@ -247,60 +247,66 @@ static VALUE zipruby_archive_s_open_buffer(int argc, VALUE *argv, VALUE self) {
247
247
 
248
248
  /* */
249
249
  static VALUE zipruby_archive_s_decrypt(VALUE self, VALUE path, VALUE password) {
250
+ int res;
250
251
  int errorp, wrongpwd;
251
252
  long pwdlen;
252
253
 
253
254
  Check_Type(path, T_STRING);
254
255
  Check_Type(password, T_STRING);
255
- pwdlen = RSTRING(password)->len;
256
+ pwdlen = RSTRING_LEN(password);
256
257
 
257
258
  if (pwdlen < 1) {
258
- rb_raise(Error, "Decrypt archive failed - %s: Password is empty", StringValuePtr(path));
259
+ rb_raise(Error, "Decrypt archive failed - %s: Password is empty", RSTRING_PTR(path));
259
260
  } else if (pwdlen > 0xff) {
260
- rb_raise(Error, "Decrypt archive failed - %s: Password is too long", StringValuePtr(path));
261
+ rb_raise(Error, "Decrypt archive failed - %s: Password is too long", RSTRING_PTR(path));
261
262
  }
262
263
 
263
- if (zip_decrypt(StringValuePtr(path), StringValuePtr(password), pwdlen, &errorp, &wrongpwd) == -1) {
264
+ res = zip_decrypt(RSTRING_PTR(path), RSTRING_PTR(password), pwdlen, &errorp, &wrongpwd);
265
+
266
+ if (res == -1) {
264
267
  if (wrongpwd) {
265
- rb_raise(Error, "Decrypt archive failed - %s: Wrong password", StringValuePtr(path));
268
+ rb_raise(Error, "Decrypt archive failed - %s: Wrong password", RSTRING_PTR(path));
266
269
  } else {
267
270
  char errstr[ERRSTR_BUFSIZE];
268
271
  zip_error_to_str(errstr, ERRSTR_BUFSIZE, errorp, errno);
269
- rb_raise(Error, "Decrypt archive failed - %s: %s", StringValuePtr(path), errstr);
272
+ rb_raise(Error, "Decrypt archive failed - %s: %s", RSTRING_PTR(path), errstr);
270
273
  }
271
274
  }
272
275
 
273
- return Qnil;
276
+ return (res > 0) ? Qtrue : Qfalse;
274
277
  }
275
278
 
276
279
  /* */
277
280
  static VALUE zipruby_archive_s_encrypt(VALUE self, VALUE path, VALUE password) {
281
+ int res;
278
282
  int errorp;
279
283
  long pwdlen;
280
284
 
281
285
  Check_Type(path, T_STRING);
282
286
  Check_Type(password, T_STRING);
283
- pwdlen = RSTRING(password)->len;
287
+ pwdlen = RSTRING_LEN(password);
284
288
 
285
289
  if (pwdlen < 1) {
286
- rb_raise(Error, "Encrypt archive failed - %s: Password is empty", StringValuePtr(path));
290
+ rb_raise(Error, "Encrypt archive failed - %s: Password is empty", RSTRING_PTR(path));
287
291
  } else if (pwdlen > 0xff) {
288
- rb_raise(Error, "Encrypt archive failed - %s: Password is too long", StringValuePtr(path));
292
+ rb_raise(Error, "Encrypt archive failed - %s: Password is too long", RSTRING_PTR(path));
289
293
  }
290
294
 
291
- if (zip_encrypt(StringValuePtr(path), StringValuePtr(password), pwdlen, &errorp) == -1) {
295
+ res = zip_encrypt(RSTRING_PTR(path), RSTRING_PTR(password), pwdlen, &errorp);
296
+
297
+ if (res == -1) {
292
298
  char errstr[ERRSTR_BUFSIZE];
293
299
  zip_error_to_str(errstr, ERRSTR_BUFSIZE, errorp, errno);
294
- rb_raise(Error, "Encrypt archive failed - %s: %s", StringValuePtr(path), errstr);
300
+ rb_raise(Error, "Encrypt archive failed - %s: %s", RSTRING_PTR(path), errstr);
295
301
  }
296
302
 
297
- return Qnil;
303
+ return (res > 0) ? Qtrue : Qfalse;
298
304
  }
299
305
 
300
306
  /* */
301
307
  static VALUE zipruby_archive_close(VALUE self) {
302
308
  struct zipruby_archive *p_archive;
303
- int changed, survivors;
309
+ int changed, survivors;
304
310
 
305
311
  if (!zipruby_archive_is_open(self)) {
306
312
  return Qfalse;
@@ -409,25 +415,25 @@ static VALUE zipruby_archive_add_buffer(VALUE self, VALUE name, VALUE source) {
409
415
  Data_Get_Struct(self, struct zipruby_archive, p_archive);
410
416
  Check_Archive(p_archive);
411
417
 
412
- len = RSTRING(source)->len;
418
+ len = RSTRING_LEN(source);
413
419
 
414
420
  if ((data = malloc(len)) == NULL) {
415
421
  rb_raise(rb_eRuntimeError, "Add file failed: Cannot allocate memory");
416
422
  }
417
423
 
418
424
  memset(data, 0, len);
419
- memcpy(data, StringValuePtr(source), len);
425
+ memcpy(data, RSTRING_PTR(source), len);
420
426
 
421
427
  if ((zsource = zip_source_buffer(p_archive->archive, data, len, 1)) == NULL) {
422
428
  free(data);
423
- rb_raise(Error, "Add file failed - %s: %s", StringValuePtr(name), zip_strerror(p_archive->archive));
429
+ rb_raise(Error, "Add file failed - %s: %s", RSTRING_PTR(name), zip_strerror(p_archive->archive));
424
430
  }
425
431
 
426
- if (zip_add(p_archive->archive, StringValuePtr(name), zsource) == -1) {
432
+ if (zip_add(p_archive->archive, RSTRING_PTR(name), zsource) == -1) {
427
433
  zip_source_free(zsource);
428
434
  zip_unchange_all(p_archive->archive);
429
435
  zip_unchange_archive(p_archive->archive);
430
- rb_raise(Error, "Add file failed - %s: %s", StringValuePtr(name), zip_strerror(p_archive->archive));
436
+ rb_raise(Error, "Add file failed - %s: %s", RSTRING_PTR(name), zip_strerror(p_archive->archive));
431
437
  }
432
438
 
433
439
  return Qnil;
@@ -444,7 +450,7 @@ static VALUE zipruby_archive_replace_buffer(int argc, VALUE *argv, VALUE self) {
444
450
 
445
451
  rb_scan_args(argc, argv, "21", &index, &source, &flags);
446
452
 
447
- if (!rb_obj_is_instance_of(index, rb_cString) && !rb_obj_is_instance_of(index, rb_cFixnum)) {
453
+ if (TYPE(index) != T_STRING && !FIXNUM_P(index)) {
448
454
  rb_raise(rb_eTypeError, "wrong argument type %s (expected Fixnum or String)", rb_class2name(CLASS_OF(index)));
449
455
  }
450
456
 
@@ -456,19 +462,19 @@ static VALUE zipruby_archive_replace_buffer(int argc, VALUE *argv, VALUE self) {
456
462
  Data_Get_Struct(self, struct zipruby_archive, p_archive);
457
463
  Check_Archive(p_archive);
458
464
 
459
- if (rb_obj_is_instance_of(index, rb_cFixnum)) {
465
+ if (FIXNUM_P(index)) {
460
466
  i_index = NUM2INT(index);
461
- } else if ((i_index = zip_name_locate(p_archive->archive, StringValuePtr(index), i_flags)) == -1) {
462
- rb_raise(Error, "Replace file failed - %s: Archive does not contain a file", StringValuePtr(index));
467
+ } else if ((i_index = zip_name_locate(p_archive->archive, RSTRING_PTR(index), i_flags)) == -1) {
468
+ rb_raise(Error, "Replace file failed - %s: Archive does not contain a file", RSTRING_PTR(index));
463
469
  }
464
470
 
465
- len = RSTRING(source)->len;
471
+ len = RSTRING_LEN(source);
466
472
 
467
473
  if ((data = malloc(len)) == NULL) {
468
474
  rb_raise(rb_eRuntimeError, "Replace file failed: Cannot allocate memory");
469
475
  }
470
476
 
471
- memcpy(data, StringValuePtr(source), len);
477
+ memcpy(data, RSTRING_PTR(source), len);
472
478
 
473
479
  if ((zsource = zip_source_buffer(p_archive->archive, data, len, 1)) == NULL) {
474
480
  free(data);
@@ -501,7 +507,7 @@ static VALUE zipruby_archive_add_or_replace_buffer(int argc, VALUE *argv, VALUE
501
507
  Data_Get_Struct(self, struct zipruby_archive, p_archive);
502
508
  Check_Archive(p_archive);
503
509
 
504
- index = zip_name_locate(p_archive->archive, StringValuePtr(name), i_flags);
510
+ index = zip_name_locate(p_archive->archive, RSTRING_PTR(name), i_flags);
505
511
 
506
512
  if (index >= 0) {
507
513
  VALUE _args[] = { INT2NUM(index), source };
@@ -534,15 +540,15 @@ static VALUE zipruby_archive_add_file(int argc, VALUE *argv, VALUE self) {
534
540
  Data_Get_Struct(self, struct zipruby_archive, p_archive);
535
541
  Check_Archive(p_archive);
536
542
 
537
- if ((zsource = zip_source_file(p_archive->archive, StringValuePtr(fname), 0, -1)) == NULL) {
538
- rb_raise(Error, "Add file failed - %s: %s", StringValuePtr(name), zip_strerror(p_archive->archive));
543
+ if ((zsource = zip_source_file(p_archive->archive, RSTRING_PTR(fname), 0, -1)) == NULL) {
544
+ rb_raise(Error, "Add file failed - %s: %s", RSTRING_PTR(name), zip_strerror(p_archive->archive));
539
545
  }
540
546
 
541
- if (zip_add(p_archive->archive, StringValuePtr(name), zsource) == -1) {
547
+ if (zip_add(p_archive->archive, RSTRING_PTR(name), zsource) == -1) {
542
548
  zip_source_free(zsource);
543
549
  zip_unchange_all(p_archive->archive);
544
550
  zip_unchange_archive(p_archive->archive);
545
- rb_raise(Error, "Add file failed - %s: %s", StringValuePtr(name), zip_strerror(p_archive->archive));
551
+ rb_raise(Error, "Add file failed - %s: %s", RSTRING_PTR(name), zip_strerror(p_archive->archive));
546
552
  }
547
553
 
548
554
  return Qnil;
@@ -557,7 +563,7 @@ static VALUE zipruby_archive_replace_file(int argc, VALUE* argv, VALUE self) {
557
563
 
558
564
  rb_scan_args(argc, argv, "21", &index, &fname, &flags);
559
565
 
560
- if (!rb_obj_is_instance_of(index, rb_cString) && !rb_obj_is_instance_of(index, rb_cFixnum)) {
566
+ if (TYPE(index) != T_STRING && !FIXNUM_P(index)) {
561
567
  rb_raise(rb_eTypeError, "wrong argument type %s (expected Fixnum or String)", rb_class2name(CLASS_OF(index)));
562
568
  }
563
569
 
@@ -569,13 +575,13 @@ static VALUE zipruby_archive_replace_file(int argc, VALUE* argv, VALUE self) {
569
575
  Data_Get_Struct(self, struct zipruby_archive, p_archive);
570
576
  Check_Archive(p_archive);
571
577
 
572
- if (rb_obj_is_instance_of(index, rb_cFixnum)) {
578
+ if (FIXNUM_P(index)) {
573
579
  i_index = NUM2INT(index);
574
- } else if ((i_index = zip_name_locate(p_archive->archive, StringValuePtr(index), i_flags)) == -1) {
575
- rb_raise(Error, "Replace file failed - %s: Archive does not contain a file", StringValuePtr(index));
580
+ } else if ((i_index = zip_name_locate(p_archive->archive, RSTRING_PTR(index), i_flags)) == -1) {
581
+ rb_raise(Error, "Replace file failed - %s: Archive does not contain a file", RSTRING_PTR(index));
576
582
  }
577
583
 
578
- if ((zsource = zip_source_file(p_archive->archive, StringValuePtr(fname), 0, -1)) == NULL) {
584
+ if ((zsource = zip_source_file(p_archive->archive, RSTRING_PTR(fname), 0, -1)) == NULL) {
579
585
  rb_raise(Error, "Replace file failed at %d: %s", i_index, zip_strerror(p_archive->archive));
580
586
  }
581
587
 
@@ -621,7 +627,7 @@ static VALUE zipruby_archive_add_or_replace_file(int argc, VALUE *argv, VALUE se
621
627
  Data_Get_Struct(self, struct zipruby_archive, p_archive);
622
628
  Check_Archive(p_archive);
623
629
 
624
- index = zip_name_locate(p_archive->archive, StringValuePtr(name), i_flags);
630
+ index = zip_name_locate(p_archive->archive, RSTRING_PTR(name), i_flags);
625
631
 
626
632
  if (index >= 0) {
627
633
  VALUE _args[] = { INT2NUM(index), fname };
@@ -633,63 +639,38 @@ static VALUE zipruby_archive_add_or_replace_file(int argc, VALUE *argv, VALUE se
633
639
  }
634
640
 
635
641
  /* */
636
- static VALUE zipruby_archive_add_filep(int argc, VALUE *argv, VALUE self) {
637
- VALUE name, file, source;
638
-
639
- rb_scan_args(argc, argv, "11", &name, &file);
640
-
641
- if (NIL_P(file)) {
642
- file = name;
643
- name = Qnil;
644
- }
645
-
646
- Check_Type(file, T_FILE);
647
-
648
- if (NIL_P(name)) {
649
- name = rb_funcall(rb_cFile, rb_intern("basename"), 1, rb_funcall(file, rb_intern("path"), 0));
650
- }
642
+ static VALUE zipruby_archive_add_io(VALUE self, VALUE name, VALUE io) {
643
+ VALUE source;
651
644
 
652
- source = rb_funcall(file, rb_intern("read"), 0);
645
+ Check_IO(io);
646
+ source = rb_funcall(io, rb_intern("read"), 0);
653
647
 
654
648
  return zipruby_archive_add_buffer(self, name, source);
655
649
  }
656
650
 
657
651
  /* */
658
- static VALUE zipruby_archive_replace_filep(VALUE self, VALUE index, VALUE file) {
659
- VALUE source;
660
- VALUE _args[2];
652
+ static VALUE zipruby_archive_replace_io(int argc, VALUE *argv, VALUE self) {
653
+ VALUE source, io, index, flags;
654
+ VALUE _args[3];
661
655
 
662
- Check_Type(file, T_FILE);
663
- source = rb_funcall(file, rb_intern("read"), 0);
656
+ rb_scan_args(argc, argv, "21", &index, &io, &flags);
657
+ Check_IO(io);
658
+ source = rb_funcall(io, rb_intern("read"), 0);
664
659
 
665
660
  _args[0] = index;
666
661
  _args[1] = source;
667
- return zipruby_archive_replace_buffer(2, _args, self);
662
+ _args[2] = flags;
663
+ return zipruby_archive_replace_file(2, _args, self);
668
664
  }
669
665
 
670
666
  /* */
671
- static VALUE zipruby_archive_add_or_replace_filep(int argc, VALUE *argv, VALUE self) {
672
- VALUE name, file, flags;
667
+ static VALUE zipruby_archive_add_or_replace_io(int argc, VALUE *argv, VALUE self) {
668
+ VALUE name, io, flags;
673
669
  struct zipruby_archive *p_archive;
674
670
  int index, i_flags = 0;
675
671
 
676
- rb_scan_args(argc, argv, "12", &name, &file, &flags);
677
-
678
- if (NIL_P(flags) && FIXNUM_P(file)) {
679
- flags = file;
680
- file = Qnil;
681
- }
682
-
683
- if (NIL_P(file)) {
684
- file = name;
685
- name = Qnil;
686
- }
687
-
688
- Check_Type(file, T_FILE);
689
-
690
- if (NIL_P(name)) {
691
- name = rb_funcall(rb_cFile, rb_intern("basename"), 1, rb_funcall(file, rb_intern("path"), 0));
692
- }
672
+ rb_scan_args(argc, argv, "21", &name, &io, &flags);
673
+ Check_IO(io);
693
674
 
694
675
  if (!NIL_P(flags)) {
695
676
  i_flags = NUM2INT(flags);
@@ -699,13 +680,13 @@ static VALUE zipruby_archive_add_or_replace_filep(int argc, VALUE *argv, VALUE s
699
680
  Data_Get_Struct(self, struct zipruby_archive, p_archive);
700
681
  Check_Archive(p_archive);
701
682
 
702
- index = zip_name_locate(p_archive->archive, StringValuePtr(name), i_flags);
683
+ index = zip_name_locate(p_archive->archive, RSTRING_PTR(name), i_flags);
703
684
 
704
685
  if (index >= 0) {
705
- return zipruby_archive_replace_filep(self, INT2NUM(index), file);
686
+ VALUE _args[] = {INT2NUM(index), io, flags};
687
+ return zipruby_archive_replace_io(2, _args, self);
706
688
  } else {
707
- VALUE _args[] = { name, file };
708
- return zipruby_archive_add_filep(2, _args, self);
689
+ return zipruby_archive_add_io(self ,name, io);
709
690
  }
710
691
  }
711
692
 
@@ -718,6 +699,7 @@ static VALUE zipruby_archive_add_function(int argc, VALUE *argv, VALUE self) {
718
699
 
719
700
  rb_scan_args(argc, argv, "11", &name, &mtime);
720
701
  rb_need_block();
702
+ Check_Type(name, T_STRING);
721
703
 
722
704
  if (NIL_P(mtime)) {
723
705
  mtime = rb_funcall(rb_cTime, rb_intern("now"), 0);
@@ -731,7 +713,7 @@ static VALUE zipruby_archive_add_function(int argc, VALUE *argv, VALUE self) {
731
713
  if ((z = malloc(sizeof(struct read_proc))) == NULL) {
732
714
  zip_unchange_all(p_archive->archive);
733
715
  zip_unchange_archive(p_archive->archive);
734
- rb_raise(rb_eRuntimeError, "Add failed - %s: Cannot allocate memory", StringValuePtr(name));
716
+ rb_raise(rb_eRuntimeError, "Add failed - %s: Cannot allocate memory", RSTRING_PTR(name));
735
717
  }
736
718
 
737
719
  z->proc = rb_block_proc();
@@ -739,14 +721,14 @@ static VALUE zipruby_archive_add_function(int argc, VALUE *argv, VALUE self) {
739
721
 
740
722
  if ((zsource = zip_source_proc(p_archive->archive, z)) == NULL) {
741
723
  free(z);
742
- rb_raise(Error, "Add failed - %s: %s", StringValuePtr(name), zip_strerror(p_archive->archive));
724
+ rb_raise(Error, "Add failed - %s: %s", RSTRING_PTR(name), zip_strerror(p_archive->archive));
743
725
  }
744
726
 
745
- if (zip_add(p_archive->archive, StringValuePtr(name), zsource) == -1) {
727
+ if (zip_add(p_archive->archive, RSTRING_PTR(name), zsource) == -1) {
746
728
  zip_source_free(zsource);
747
729
  zip_unchange_all(p_archive->archive);
748
730
  zip_unchange_archive(p_archive->archive);
749
- rb_raise(Error, "Add file failed - %s: %s", StringValuePtr(name), zip_strerror(p_archive->archive));
731
+ rb_raise(Error, "Add file failed - %s: %s", RSTRING_PTR(name), zip_strerror(p_archive->archive));
750
732
  }
751
733
 
752
734
  return Qnil;
@@ -817,7 +799,7 @@ static VALUE zipruby_archive_add_or_replace_function(int argc, VALUE *argv, VALU
817
799
  Data_Get_Struct(self, struct zipruby_archive, p_archive);
818
800
  Check_Archive(p_archive);
819
801
 
820
- index = zip_name_locate(p_archive->archive, StringValuePtr(name), i_flags);
802
+ index = zip_name_locate(p_archive->archive, RSTRING_PTR(name), i_flags);
821
803
 
822
804
  if (index >= 0) {
823
805
  VALUE _args[] = { INT2NUM(index), mtime };
@@ -965,8 +947,8 @@ static VALUE zipruby_archive_set_comment(VALUE self, VALUE comment) {
965
947
 
966
948
  if (!NIL_P(comment)) {
967
949
  Check_Type(comment, T_STRING);
968
- s_comment = StringValuePtr(comment);
969
- len = RSTRING(comment)->len;
950
+ s_comment = RSTRING_PTR(comment);
951
+ len = RSTRING_LEN(comment);
970
952
  }
971
953
 
972
954
  Data_Get_Struct(self, struct zipruby_archive, p_archive);
@@ -997,7 +979,7 @@ static VALUE zipruby_archive_locate_name(int argc, VALUE *argv, VALUE self) {
997
979
  Data_Get_Struct(self, struct zipruby_archive, p_archive);
998
980
  Check_Archive(p_archive);
999
981
 
1000
- return INT2NUM(zip_name_locate(p_archive->archive, StringValuePtr(fname), i_flags));
982
+ return INT2NUM(zip_name_locate(p_archive->archive, RSTRING_PTR(fname), i_flags));
1001
983
  }
1002
984
 
1003
985
  /* */
@@ -1030,8 +1012,8 @@ static VALUE zipruby_archive_set_fcomment(VALUE self, VALUE index, VALUE comment
1030
1012
 
1031
1013
  if (!NIL_P(comment)) {
1032
1014
  Check_Type(comment, T_STRING);
1033
- s_comment = StringValuePtr(comment);
1034
- len = RSTRING(comment)->len;
1015
+ s_comment = RSTRING_PTR(comment);
1016
+ len = RSTRING_LEN(comment);
1035
1017
  }
1036
1018
 
1037
1019
  Data_Get_Struct(self, struct zipruby_archive, p_archive);
@@ -1066,10 +1048,11 @@ static VALUE zipruby_archive_fdelete(VALUE self, VALUE index) {
1066
1048
  static VALUE zipruby_archive_frename(VALUE self, VALUE index, VALUE name) {
1067
1049
  struct zipruby_archive *p_archive;
1068
1050
 
1051
+ Check_Type(name, T_STRING);
1069
1052
  Data_Get_Struct(self, struct zipruby_archive, p_archive);
1070
1053
  Check_Archive(p_archive);
1071
1054
 
1072
- if (zip_rename(p_archive->archive, NUM2INT(index), StringValuePtr(name)) == -1) {
1055
+ if (zip_rename(p_archive->archive, NUM2INT(index), RSTRING_PTR(name)) == -1) {
1073
1056
  zip_unchange_all(p_archive->archive);
1074
1057
  zip_unchange_archive(p_archive->archive);
1075
1058
  rb_raise(Error, "Rename file failed at %d: %s", NUM2INT(index), zip_strerror(p_archive->archive));
@@ -1158,7 +1141,7 @@ static VALUE zipruby_archive_each(VALUE self) {
1158
1141
  /* */
1159
1142
  static VALUE zipruby_archive_commit(VALUE self) {
1160
1143
  struct zipruby_archive *p_archive;
1161
- int changed, survivors;
1144
+ int changed, survivors;
1162
1145
  int errorp;
1163
1146
 
1164
1147
  Data_Get_Struct(self, struct zipruby_archive, p_archive);
@@ -1179,7 +1162,7 @@ static VALUE zipruby_archive_commit(VALUE self) {
1179
1162
  p_archive->archive = NULL;
1180
1163
  p_archive->flags = (p_archive->flags & ~(ZIP_CREATE | ZIP_EXCL));
1181
1164
 
1182
- if ((p_archive->archive = zip_open(StringValuePtr(p_archive->path), p_archive->flags, &errorp)) == NULL) {
1165
+ if ((p_archive->archive = zip_open(RSTRING_PTR(p_archive->path), p_archive->flags, &errorp)) == NULL) {
1183
1166
  char errstr[ERRSTR_BUFSIZE];
1184
1167
  zip_error_to_str(errstr, ERRSTR_BUFSIZE, errorp, errno);
1185
1168
  rb_raise(Error, "Commit archive failed: %s", errstr);
@@ -1198,13 +1181,14 @@ static VALUE zipruby_archive_is_open(VALUE self) {
1198
1181
 
1199
1182
  /* */
1200
1183
  static VALUE zipruby_archive_decrypt(VALUE self, VALUE password) {
1184
+ VALUE retval;
1201
1185
  struct zipruby_archive *p_archive;
1202
1186
  long pwdlen;
1203
- int changed, survivors;
1187
+ int changed, survivors;
1204
1188
  int errorp;
1205
1189
 
1206
1190
  Check_Type(password, T_STRING);
1207
- pwdlen = RSTRING(password)->len;
1191
+ pwdlen = RSTRING_LEN(password);
1208
1192
 
1209
1193
  if (pwdlen < 1) {
1210
1194
  rb_raise(Error, "Decrypt archive failed: Password is empty");
@@ -1230,26 +1214,27 @@ static VALUE zipruby_archive_decrypt(VALUE self, VALUE password) {
1230
1214
  p_archive->archive = NULL;
1231
1215
  p_archive->flags = (p_archive->flags & ~(ZIP_CREATE | ZIP_EXCL));
1232
1216
 
1233
- zipruby_archive_s_decrypt(Archive, p_archive->path, password);
1217
+ retval = zipruby_archive_s_decrypt(Archive, p_archive->path, password);
1234
1218
 
1235
- if ((p_archive->archive = zip_open(StringValuePtr(p_archive->path), p_archive->flags, &errorp)) == NULL) {
1219
+ if ((p_archive->archive = zip_open(RSTRING_PTR(p_archive->path), p_archive->flags, &errorp)) == NULL) {
1236
1220
  char errstr[ERRSTR_BUFSIZE];
1237
1221
  zip_error_to_str(errstr, ERRSTR_BUFSIZE, errorp, errno);
1238
1222
  rb_raise(Error, "Decrypt archive failed: %s", errstr);
1239
1223
  }
1240
1224
 
1241
- return Qnil;
1225
+ return retval;
1242
1226
  }
1243
1227
 
1244
1228
  /* */
1245
1229
  static VALUE zipruby_archive_encrypt(VALUE self, VALUE password) {
1230
+ VALUE retval;
1246
1231
  struct zipruby_archive *p_archive;
1247
1232
  long pwdlen;
1248
- int changed, survivors;
1233
+ int changed, survivors;
1249
1234
  int errorp;
1250
1235
 
1251
1236
  Check_Type(password, T_STRING);
1252
- pwdlen = RSTRING(password)->len;
1237
+ pwdlen = RSTRING_LEN(password);
1253
1238
 
1254
1239
  if (pwdlen < 1) {
1255
1240
  rb_raise(Error, "Encrypt archive failed: Password is empty");
@@ -1275,17 +1260,18 @@ static VALUE zipruby_archive_encrypt(VALUE self, VALUE password) {
1275
1260
  p_archive->archive = NULL;
1276
1261
  p_archive->flags = (p_archive->flags & ~(ZIP_CREATE | ZIP_EXCL));
1277
1262
 
1278
- zipruby_archive_s_encrypt(Archive, p_archive->path, password);
1263
+ retval = zipruby_archive_s_encrypt(Archive, p_archive->path, password);
1279
1264
 
1280
- if ((p_archive->archive = zip_open(StringValuePtr(p_archive->path), p_archive->flags, &errorp)) == NULL) {
1265
+ if ((p_archive->archive = zip_open(RSTRING_PTR(p_archive->path), p_archive->flags, &errorp)) == NULL) {
1281
1266
  char errstr[ERRSTR_BUFSIZE];
1282
1267
  zip_error_to_str(errstr, ERRSTR_BUFSIZE, errorp, errno);
1283
1268
  rb_raise(Error, "Encrypt archive failed: %s", errstr);
1284
1269
  }
1285
1270
 
1286
- return Qnil;
1271
+ return retval;
1287
1272
  }
1288
1273
 
1274
+ /* */
1289
1275
  static VALUE zipruby_archive_read(VALUE self) {
1290
1276
  VALUE retval = Qnil;
1291
1277
  struct zipruby_archive *p_archive;
@@ -1299,17 +1285,17 @@ static VALUE zipruby_archive_read(VALUE self) {
1299
1285
  if (NIL_P(p_archive->path)) {
1300
1286
  rb_raise(rb_eRuntimeError, "invalid Zip::Archive");
1301
1287
  }
1302
-
1303
- #ifdef _WIN32
1304
- if (fopen_s(&fzip ,StringValuePtr(p_archive->path), "rb") != 0) {
1288
+
1289
+ #ifdef _WIN32
1290
+ if (fopen_s(&fzip, RSTRING_PTR(p_archive->path), "rb") != 0) {
1305
1291
  rb_raise(Error, "Read archive failed: Cannot open archive");
1306
- }
1307
- #else
1308
- if ((fzip = fopen(StringValuePtr(p_archive->path), "rb")) == NULL) {
1292
+ }
1293
+ #else
1294
+ if ((fzip = fopen(RSTRING_PTR(p_archive->path), "rb")) == NULL) {
1309
1295
  rb_raise(Error, "Read archive failed: Cannot open archive");
1310
- }
1311
- #endif
1312
-
1296
+ }
1297
+ #endif
1298
+
1313
1299
  block_given = rb_block_given_p();
1314
1300
 
1315
1301
  while ((n = fread(buf, 1, sizeof(buf), fzip)) > 0) {
@@ -1327,10 +1313,10 @@ static VALUE zipruby_archive_read(VALUE self) {
1327
1313
  #ifdef RUBY_WIN32_H
1328
1314
  #undef fclose
1329
1315
  fclose(fzip);
1330
- #define fclose(f) rb_w32_fclose(f)
1331
- #else
1316
+ #define fclose(f) rb_w32_fclose(f)
1317
+ #else
1332
1318
  fclose(fzip);
1333
- #endif
1319
+ #endif
1334
1320
 
1335
1321
  if (n == -1) {
1336
1322
  rb_raise(Error, "Read archive failed");
data/ext/zipruby_file.c CHANGED
@@ -104,7 +104,7 @@ static VALUE zipruby_file_initialize(int argc, VALUE *argv, VALUE self) {
104
104
  }
105
105
 
106
106
  switch (TYPE(index)) {
107
- case T_STRING: fname = StringValuePtr(index); break;
107
+ case T_STRING: fname = RSTRING_PTR(index); break;
108
108
  case T_FIXNUM: i_index = NUM2INT(index); break;
109
109
  default:
110
110
  rb_raise(rb_eTypeError, "wrong argument type %s (expected String or Fixnum)", rb_class2name(CLASS_OF(index)));
@@ -260,8 +260,8 @@ static VALUE zipruby_file_set_comment(VALUE self, VALUE comment) {
260
260
 
261
261
  if (!NIL_P(comment)) {
262
262
  Check_Type(comment, T_STRING);
263
- s_comment = StringValuePtr(comment);
264
- len = RSTRING(comment)->len;
263
+ s_comment = RSTRING_PTR(comment);
264
+ len = RSTRING_LEN(comment);
265
265
  }
266
266
 
267
267
  Data_Get_Struct(self, struct zipruby_file, p_file);
@@ -296,10 +296,11 @@ static VALUE zipruby_file_delete(VALUE self) {
296
296
  static VALUE zipruby_file_rename(VALUE self, VALUE name) {
297
297
  struct zipruby_file *p_file;
298
298
 
299
+ Check_Type(name, T_STRING);
299
300
  Data_Get_Struct(self, struct zipruby_file, p_file);
300
301
  Check_File(p_file);
301
302
 
302
- if (zip_rename(p_file->archive, p_file->sb->index, StringValuePtr(name)) == -1) {
303
+ if (zip_rename(p_file->archive, p_file->sb->index, RSTRING_PTR(name)) == -1) {
303
304
  zip_unchange_all(p_file->archive);
304
305
  zip_unchange_archive(p_file->archive);
305
306
  rb_raise(Error, "Rename file failed - %s: %s", p_file->sb->name, zip_strerror(p_file->archive));
data/ext/zipruby_stat.c CHANGED
@@ -64,7 +64,7 @@ static VALUE zipruby_stat_initialize(int argc, VALUE *argv, VALUE self) {
64
64
  }
65
65
 
66
66
  switch (TYPE(index)) {
67
- case T_STRING: fname = StringValuePtr(index); break;
67
+ case T_STRING: fname = RSTRING_PTR(index); break;
68
68
  case T_FIXNUM: i_index = NUM2INT(index); break;
69
69
  default:
70
70
  rb_raise(rb_eTypeError, "wrong argument type %s (expected String or Fixnum)", rb_class2name(CLASS_OF(index)));
@@ -29,11 +29,11 @@ static ssize_t read_proc(void *state, void *data, size_t len, enum zip_source_cm
29
29
  return 0;
30
30
  }
31
31
 
32
- n = RSTRING(src)->len;
32
+ n = RSTRING_LEN(src);
33
33
 
34
34
  if (n > 0) {
35
35
  n = (n > len) ? len : n;
36
- memcpy(buf, StringValuePtr(src), n);
36
+ memcpy(buf, RSTRING_PTR(src), n);
37
37
  }
38
38
 
39
39
  return n;