public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* tracing: concurrency aware strncpy
@ 2010-11-04 21:37 Mathieu Desnoyers
  0 siblings, 0 replies; only message in thread
From: Mathieu Desnoyers @ 2010-11-04 21:37 UTC (permalink / raw)
  To: masami.hiramatsu.pt; +Cc: linux-kernel

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-11-04 21:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-04 21:37 tracing: concurrency aware strncpy Mathieu Desnoyers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox