XINU
Functions
strncpy.c File Reference

文字列s1に文字列s2をN文字(Byte)分コピーする。 More...

Go to the source code of this file.

Functions

char * strncpy (char *s1, const char *s2, int n)
 文字列s1に文字列s2をN文字(Byte)分コピーする。 More...
 

Detailed Description

文字列s1に文字列s2をN文字(Byte)分コピーする。

Definition in file strncpy.c.

Function Documentation

◆ strncpy()

char* strncpy ( char *  s1,
const char *  s2,
int  n 
)

文字列s1に文字列s2をN文字(Byte)分コピーする。

自動でNULL終端('\0')は付与しない。
また、N Byteコピーする前にNULL終端に達した場合、残りのByte数分をNULL終端で埋める。

Parameters
[in,out]s1コピー先の文字列
[in]s2コピー元の文字列
[in]nコピーする文字数(Byte)
Returns
コピー後の文字列s1を返す。

Definition at line 15 of file strncpy.c.

Referenced by newtype(), sysinit(), and tftpget_mb().

16 {
17  register int i;
18  register char *os1;
19 
20  os1 = s1;
21  for (i = 0; i < n; i++)
22  {
23  if (((*s1++) = (*s2++)) == '\0')
24  {
25  while (++i < n)
26  {
27  *s1++ = '\0';
28  }
29  return os1;
30  }
31  }
32  return os1;
33 }
Here is the caller graph for this function: