public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: masami.hiramatsu.pt@hitachi.com
Cc: linux-kernel@vger.kernel.org
Subject: tracing: concurrency aware strncpy
Date: Thu, 4 Nov 2010 17:37:05 -0400	[thread overview]
Message-ID: <20101104213705.GA17485@Krystal> (raw)

Hi Masami,
This might help you out...

/*
 * ltt_relay_do_strncpy - copy a string up to a certain number of bytes
 * @dest: destination
 * @src: source
 * @len: max. length to copy
 * @terminated: output string ends with \0 (output)
 *
 * returns the number of bytes copied. Does not finalize with \0 if len is
 * reached.
 */
static __inline__
size_t ltt_relay_do_strncpy(void *dest, const void *src, size_t len,
                            int *terminated)
{
        size_t orig_len = len;

        *terminated = 0;
        /*
         * What we really want here is an __inline__ strncpy, but we
         * don't have constants, so gcc generally uses a function call.
         */
        for (; len > 0; len--) {
                *(u8 *)dest = ACCESS_ONCE(*(const u8 *)src);
                /* Check with dest, because src may be modified concurrently */
                if (*(const u8 *)dest == '\0') {
                        len--;
                        *terminated = 1;
                        break;
                }
                dest++;
                src++;
        }
        return orig_len - len;
}


-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com

                 reply	other threads:[~2010-11-04 21:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20101104213705.GA17485@Krystal \
    --to=mathieu.desnoyers@efficios.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox