git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

gbdk-lib/libc/strncpy.c

      1 #include <string.h>
      2 
      3 /*
      4  * Copy s2 to s1, truncating or null-padding to always copy n bytes.
      5  * Return s1.
      6  */
      7 
      8 char *strncpy(char *s1, const char *s2, int n) {
      9     int i;
     10     char *os1 = s1;
     11     for (i = 0; i < n; i++) {
     12         if ((*s1++ = *s2++) == '\0') {
     13             while (++i < n) *s1++ = '\0';
     14             return os1;
     15         }
     16     }
     17     return os1;
     18 }

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.