From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nikita Karetnikov Subject: Re: 'substitute*' fails with "string contains #\nul character" Date: Tue, 06 Aug 2013 01:20:12 +0400 Message-ID: <87y58fkf77.fsf@karetnikov.org> References: <87zjtpi7vp.fsf@karetnikov.org> <87fvvhfe8f.fsf@gnu.org> <8738rhmb33.fsf@karetnikov.org> <87zjtneb3u.fsf@gnu.org> <87a9lml789.fsf_-_@karetnikov.org> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V6S8i-00073x-FF for guix-devel@gnu.org; Mon, 05 Aug 2013 17:16:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V6S8c-0000nt-Pc for guix-devel@gnu.org; Mon, 05 Aug 2013 17:16:28 -0400 In-Reply-To: <87a9lml789.fsf_-_@karetnikov.org> (Nikita Karetnikov's message of "Tue, 16 Jul 2013 21:55:50 +0400") List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: Ludovic =?utf-8?Q?Court=C3=A8s?= Cc: guix-devel@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable >> ice-9/boot-9.scm:106:20: string contains #\nul character: > Yes, that is expected. =E2=80=98substitute*=E2=80=99 is for textual file= s. > =E2=80=98fold-port-matches=E2=80=99 from (guix build utils) can be used f= or binary files > (see =E2=80=98remove-store-references=E2=80=99 for an example use.) Here=E2=80=99s what I=E2=80=99m trying to use: (use-modules (srfi srfi-14) (guix build utils) (rnrs bytevectors) (rnrs io ports)) (define (binary-substitute file old new) "Replace an OLD string with a NEW one in FILE." (with-atomic-file-replacement file (lambda (in out) (format #t "replacing '~a' with '~a' in '~a'...~%" old new file) (fold-port-matches (lambda (match result) (put-bytevector out (string->utf8 new)) #t) #f old in (lambda (char result) (put-u8 out (char->integer char)) result))))) If you compile this program: #include int main() { printf("Hello, world!\n"); return 0; } and try to replace =E2=80=9CHello=E2=80=9D with =E2=80=9CHallo,=E2=80=9D it= will work. If strings are not equally sized, =E2=80=98a.out=E2=80=99 will crash with a segfault. I=E2=80=99m not sure how to proceed and fail to find any howtos. Is there a tool that I could use? --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iQIcBAEBAgAGBQJSABcRAAoJEM+IQzI9IQ38UGgQAIR+Z+dLRFGUy8YqeSRzgA1Z rYFdN0u4KMJ8S/rap70Z+gOTP4U28UwTkGD0cPloPmkt7j9RiNx5WZLzhND2+rQL j9DSsPfjUJ7oXPin+xgnS2mEq8R1kBwDStmtrwtbPXqpY6wpjrZ5Ucc5c5p2aywk XEEjG3sv/5El+FWNz9Jv54VM3bPXbwOxPBmX+xePzTlfom8f5oUFxjKutVCWU9Sz 44MM1AWdygg3qVIk9LJ+FdJ7EepXjB1qDWwnXoLZ6ETBo61uDff6wjlPAkhJcNl5 Qxd2JUzzVbHi+H+H99OenG4U6ukiQiqizL68Nphd7YktaT+KPbwUfMb66ZKNhwVy 23jgf4c49OxemLGMOftsYLa2sPyZ3DmQsjvUCCMNxU3T77mUPhYDSrLR/wC0KBAn DyFG47D9ugIMLqYuXpG+5erKLJEuAyIawnHXj6ZIWoRLuYpVjvd67JdD+O4LZuGw WSOa2Nh0vEJH45hx7jxpc02f7wpczYLsLr7eRHk9Q/P8VZBY+UudrY4iwiW2nNy2 /pzrn1TyzjcqppkEAKrBicwyoeAUh+NwZrQ9IgogqFGeJHr7cE716CO8LyqsOnWZ shl/uKUenf2sP0hbLq0JAuV35jaE8tiwvNvTZJB8l5d3lMtTKD/dLUP2PqdcPdj+ KbXshzTifSXEiUtRteOA =i0cR -----END PGP SIGNATURE----- --=-=-=--