src/compat.c
changeset 49 59b09b0aeb96
parent 13 d3554afaa768
equal deleted inserted replaced
48:34094173351c 49:59b09b0aeb96
    17     if (buf != NULL)
    17     if (buf != NULL)
    18         strcpy (buf, s);
    18         strcpy (buf, s);
    19 
    19 
    20     return buf;
    20     return buf;
    21 }
    21 }
       
    22 
       
    23 char *safe_strncpy (char *dest, const char *src, size_t size)
       
    24 {
       
    25     size_t i;
       
    26 
       
    27     for (i = 0; i < size - 1; i++) {
       
    28         if (src[i] == '\0')
       
    29             break;
       
    30         dest[i] = src[i];
       
    31     }
       
    32 
       
    33     dest[i] = '\0';
       
    34 
       
    35     return dest;
       
    36 }