Rate This Document
Findability
Accuracy
Completeness
Readability

memcpy Interface

Interface Description

Optimized memcpy interface.

Interface Format

void *memcpy(void *dest, const void *src, size_t n);

Parameters

Parameter

Type

Description

Input/Output

dest

Pointer array

Destination array that stores the copied content.

Input/Output

src

Pointer array

Source array that stores the copied content.

Input

n

Integer

Number of bytes to be copied.

Input

Dependency

None

Example

  1. Write memcpy test code.
    1. Create a test.c file.
      vi test.c
    2. Press i to enter the insert mode and add the following test code to the file:
      #include <stdio.h>
      #include <stdint.h>
      #include <string.h>
      
      #define MAX_LENGTH 4096
      
      int main(int argc, char **argv)
      {
          uint8_t src[MAX_LENGTH] = {0};
          uint8_t dest[MAX_LENGTH] = {0};
          for (size_t i = 0; i < MAX_LENGTH; ++i) {
              src[i] = i;
          }
          memcpy(dest, src, MAX_LENGTH);
          if (memcmp(dest, src, MAX_LENGTH) == 0) {
              printf("memcpy succ!!\r\n");
          } else {
              printf("memcpy fail!!\r\n");
          }
          return 0;
      }
    3. Press Esc to exit the insert mode. Type :wq! and press Enter to save and exit the file.
  2. Compile the test.c file into an executable file test.
    gcc test.c -o test
  3. Run the test executable file.
    LD_PRELOAD=/usr/lib64/libksal_libc.so ./test
    The command output is as follows:
    memcpy succ!!