@deffnx {C Function} scm_bytevector_copy_x (source, source_start, target, target_start, len)
Copy @var{len} bytes from @var{source} into @var{target}, starting
reading from @var{source-start} (a positive index within @var{source})
-and start writing at @var{target-start}.
+and start writing at @var{target-start}. It is permitted for the
+@var{source} and @var{target} regions to overlap.
@end deffn
@deffn {Scheme Procedure} bytevector-copy bv
if (SCM_UNLIKELY (c_target_start + c_len > c_target_len))
scm_out_of_range (FUNC_NAME, target_start);
- memcpy (c_target + c_target_start,
- c_source + c_source_start,
- c_len);
+ memmove (c_target + c_target_start,
+ c_source + c_source_start,
+ c_len);
return SCM_UNSPECIFIED;
}
;;;; bytevectors.test --- R6RS bytevectors. -*- mode: scheme; coding: utf-8; -*-
;;;;
-;;;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+;;;; Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
;;;; Ludovic Courtès
;;;;
;;;; This library is free software; you can redistribute it and/or
(and (bytevector=? (make-bytevector 20 7)
(make-bytevector 20 7))
(not (bytevector=? (make-bytevector 20 7)
- (make-bytevector 20 0))))))
+ (make-bytevector 20 0)))))
+
+ (pass-if "bytevector-copy! overlapping"
+ ;; See <http://debbugs.gnu.org/10070>.
+ (let ((b (u8-list->bytevector '(1 2 3 4 5 6 7 8))))
+ (bytevector-copy! b 0 b 3 4)
+ (bytevector->u8-list b)
+ (bytevector=? b #vu8(1 2 3 1 2 3 4 8)))))
\f
(with-test-prefix/c&e "2.3 Operations on Bytes and Octets"