XINU
Functions
string.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

char * strchr (const char *, int32)
 指定された文字を文字列から探し、最初にに見つかった位置をポインタで返す。 More...
 
int strlen (char *str)
 NULL終端された文字列の長さを返す。NULL終端は長さに含まない。 More...
 
char * strncat (char *, const char *, int32)
 文字列s1の末尾に文字列s2をN文字(Byte)分、結合する。 More...
 
int32 strncmp (const char *, const char *, int32)
 
char * strncpy (char *, const char *, int32)
 文字列s1に文字列s2をN文字(Byte)分コピーする。 More...
 
int32 strnlen (const char *, uint32)
 NULL終端された文字列の長さを返す。NULL終端は長さに含まない。 More...
 
char * strrchr (const char *, int32)
 文字列の後方から指定された文字を探し、最後に見つかった位置をポインタで返す。 More...
 
char * strstr (const char *, const char *)
 検索対象の文字列Aから文字列Bを探す。 More...
 

Function Documentation

◆ strchr()

char* strchr ( const char *  s,
int  c 
)

指定された文字を文字列から探し、最初にに見つかった位置をポインタで返す。

Parameters
[in]s探索対象の文字列
[in]c検索文字
Returns
文字cが見つかった場合は文字cが最初に登場した位置を示すポインタ、
文字cが見つからなかった場合はNULLを返す。

Definition at line 13 of file strchr.c.

14 {
15  for (; *s != '\0'; s++)
16  {
17  if (*s == (const char)c)
18  {
19  return (char *)s;
20  }
21  }
22 
23  if ((const char)c == *s)
24  {
25  return (char *)s;
26  }
27 
28  return 0;
29 }

◆ strlen()

int strlen ( char *  str)

NULL終端された文字列の長さを返す。NULL終端は長さに含まない。

Parameters
[in]str長さを調べる対象の文字列
Returns
文字列の長さを返す。NULL終端は長さに含まない。

Definition at line 11 of file strlen.c.

Referenced by addton(), devisid(), devonid(), dns_bldq(), dns_geta(), getattrid(), if(), newdev(), newtype(), and xsh_ping().

12 {
13  int len;
14 
15  len = 0;
16 
17  while (*str++ != '\0')
18  {
19  len++;
20  }
21  return len;
22 }
Here is the caller graph for this function:

◆ strncat()

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

文字列s1の末尾に文字列s2をN文字(Byte)分、結合する。

処理の流れは、以下の通り。
Step1. 文字列s1のNULL終端'\0'までポインタを進める。
Step2. 文字列s1のNULL終端の位置から文字列s2を一文字ずつ連結する。
Step3. N+1回目にNULL終端を付与する。

Parameters
[in,out]s1結合先の文字列
[in]s2結合する文字列
[in]n結合する文字数(Byte)
Returns
結合後の文字列s1を返す(NULL終端済み)。

Definition at line 17 of file strncat.c.

18 {
19  char *os1;
20 
21  os1 = s1;
22  while (*s1++)
23  ;
24  --s1;
25  while ((*s1++ = *s2++))
26  if (--n < 0)
27  {
28  *--s1 = '\0';
29  break;
30  }
31  return (os1);
32 }

◆ strncmp()

int32 strncmp ( const char *  ,
const char *  ,
int32   
)

◆ 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:

◆ strnlen()

int32 strnlen ( const char *  s,
unsigned int  len 
)

NULL終端された文字列の長さを返す。NULL終端は長さに含まない。

Parameters
[in]s長さを調べる対象の文字列
[in]len読み取る長さの最大長(Byte)
Returns
文字列の長さを返す。NULL終端は長さに含まず、ユーザが指定したN Byteを最大長とする。

Definition at line 14 of file strnlen.c.

Referenced by tftpget_mb(), xsh_help(), and xsh_udpecho().

15 {
16  int n;
17 
18  n = 0;
19  while (*s++ && n < len)
20  n++;
21 
22  return (n);
23 }
Here is the caller graph for this function:

◆ strrchr()

char* strrchr ( const char *  s,
int  c 
)

文字列の後方から指定された文字を探し、最後に見つかった位置をポインタで返す。

Parameters
[in]s探索対象の文字列
[in]c検索文字
Returns
文字cが見つかった場合は文字cが最後に登場した位置を示すポインタ、
文字cが見つからなかった場合はNULLを返す。

Definition at line 13 of file strrchr.c.

14 {
15  char *r = 0;
16 
17  for (; *s != '\0'; s++)
18  {
19  if (*s == (const char)c)
20  {
21  r = (char *)s;
22  }
23  }
24 
25  if ((const char)c == *s)
26  {
27  return (char *)s;
28  }
29 
30  return r;
31 }

◆ strstr()

char* strstr ( const char *  cs,
const char *  ct 
)

検索対象の文字列Aから文字列Bを探す。

Parameters
[in]cs検索対象の文字列
[in]ct検索語句(検索キーワード)となる文字列
Returns
検索語句が見つかった場合はその位置をポインタで返し、見つからなかった場合はNULLを返す。

Definition at line 12 of file strstr.c.

13 {
14  char *cq;
15  char *cr;
16 
17  for (; *cs != '\0'; cs++)
18  {
19  if (*cs == *ct)
20  {
21  cq = (char *)cs;
22  cr = (char *)ct;
23  while ((*cq != '\0') && (*cr != '\0'))
24  {
25  if (*cq != *cr)
26  {
27  break;
28  }
29  cq++;
30  cr++;
31  }
32  if ('\0' == *cr)
33  {
34  return (char *)cs;
35  }
36  }
37  }
38  return 0;
39 }