all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Nikita Karetnikov <nikita@karetnikov.org>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: guix-devel@gnu.org
Subject: Re: 'substitute*' fails with "string contains #\nul character"
Date: Tue, 06 Aug 2013 01:20:12 +0400	[thread overview]
Message-ID: <87y58fkf77.fsf@karetnikov.org> (raw)
In-Reply-To: <87a9lml789.fsf_-_@karetnikov.org> (Nikita Karetnikov's message of "Tue, 16 Jul 2013 21:55:50 +0400")

[-- Attachment #1: Type: text/plain, Size: 1428 bytes --]

>> ice-9/boot-9.scm:106:20: string contains #\nul character:

> Yes, that is expected.  ‘substitute*’ is for textual files.

> ‘fold-port-matches’ from (guix build utils) can be used for binary files
> (see ‘remove-store-references’ for an example use.)

Here’s what I’m 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 <stdio.h>

int main()
{
  printf("Hello, world!\n");

  return 0;
}

and try to replace “Hello” with “Hallo,” it will work.  If strings are
not equally sized, ‘a.out’ will crash with a segfault.

I’m not sure how to proceed and fail to find any howtos.  Is there a
tool that I could use?

[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]

  parent reply	other threads:[~2013-08-05 21:16 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-14 13:33 'patchelf' doesn't change shared libraries Nikita Karetnikov
2013-07-14 13:44 ` Ludovic Courtès
2013-07-14 15:10   ` Nikita Karetnikov
2013-07-15 22:01     ` Ludovic Courtès
2013-07-16 17:55       ` 'substitute*' fails with "string contains #\nul character" (was: 'patchelf' doesn't change shared libraries) Nikita Karetnikov
2013-07-16 19:07         ` 'substitute*' fails with "string contains #\nul character" Ludovic Courtès
2013-08-05 21:20         ` Nikita Karetnikov [this message]
2013-08-15 10:37           ` Ludovic Courtès
2013-08-18  5:57             ` Nikita Karetnikov
2013-08-18 22:13               ` Ludovic Courtès
2013-08-18 23:53                 ` Nikita Karetnikov
2013-08-19 11:22                   ` Ludovic Courtès
2013-08-20  5:42                     ` Nikita Karetnikov
2013-08-20  7:23                       ` Ludovic Courtès
2013-08-21  5:15                         ` Nikita Karetnikov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y58fkf77.fsf@karetnikov.org \
    --to=nikita@karetnikov.org \
    --cc=guix-devel@gnu.org \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.