memcpy_s

From RAD Studio
Jump to: navigation, search

Go Up to mem.h Index


Header File

mem.h, string.h

Category

Memory and String Manipulation Routines, Inline Routines

Prototype

void _FAR * _RESTRICT __dest, rsize_t __destmax, const void _FAR * _RESTRICT __src, rsize_t __n);

Description

Replaces memcpy, _wmemcpy adding security enhancements.

memcpy is available on UNIX System V systems.

memcpy_s copies a block of __n bytes from __src to __dest. If __src and __dest overlap, the behavior of memcpy_s is undefined.

Return Value

memcpy_s returns zero if successful, nonzero otherwise.

Example

#include <stdio.h>
#include <string.h>
int main(void)
{
   char src[] = "******************************";
   char dest[] = "abcdefghijlkmnopqrstuvwxyz0123456709";
   printf("destination before memcpy: %s\n", dest);
   if(!memcpy_s(dest, strlen(dest), src, strlen(src))){
      printf("destination after memcpy: %s\n", dest);
   }
   else{
      printf("memcpy failed\n");
   }
   return 0;
}

Portability

POSIX Win32 ANSI C ANSI C++

memcpy_s

+

+

+

+

See Also