cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

strncpy.c (361B)


      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
      8char *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}