> For the complete documentation index, see [llms.txt](https://applezulab.netdpi.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://applezulab.netdpi.net/linux-prog/copy-of-page-1-4.md).

# strncpy

這是一個 strncpy 的範例：

```c
int safe_strncpy(char *dst, char *src, int len)
{
    int count=0;
    if(len <1) return 1;

     // Null pointer is dangerous.
    if( dst==NULL || src == NULL ) return (-1);
    
    for(count=0; count<len; count++) {
        dst[count]=src[count];
        if(src[count]=='\0') break; /* String end of str */
    }

     return 0;
}
```
