Back to index

glibc  2.9
Defines | Functions
test-stpncpy.c File Reference
#include "test-string.h"
#include "test-strncpy.c"

Go to the source code of this file.

Defines

#define STRNCPY_RESULT(dst, len, n)   ((dst) + ((len) > (n) ? (n) : (len)))
#define TEST_MAIN

Functions

char * simple_stpncpy (char *, const char *, size_t)
char * stupid_stpncpy (char *, const char *, size_t)

Define Documentation

#define STRNCPY_RESULT (   dst,
  len,
  n 
)    ((dst) + ((len) > (n) ? (n) : (len)))

Definition at line 21 of file test-stpncpy.c.

#define TEST_MAIN

Definition at line 22 of file test-stpncpy.c.


Function Documentation

char * simple_stpncpy ( char *  dst,
const char *  src,
size_t  n 
)

Definition at line 33 of file test-stpncpy.c.

{
  while (n--)
    if ((*dst++ = *src++) == '\0')
      {
       size_t i;

       for (i = 0; i < n; ++i)
         dst[i] = '\0';
       return dst - 1;
      }
  return dst;
}
char * stupid_stpncpy ( char *  dst,
const char *  src,
size_t  n 
)

Definition at line 48 of file test-stpncpy.c.

{
  size_t nc = strnlen (src, n);
  size_t i;

  for (i = 0; i < nc; ++i)
    dst[i] = src[i];
  for (; i < n; ++i)
    dst[i] = '\0';
  return dst + nc;
}