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

Go to the source code of this file.

Macros

#define RAND_MAX   2147483646
 

Functions

int abs (int)
 整数の絶対値(int型)を返す。 More...
 
int atoi (char *)
 ASCII文字列をint型に変換する。 More...
 
long atol (char *)
 ASCII文字列をlong型に変換する。 More...
 
void bzero (void *, int)
 Byteブロック領域の先頭N bytesを数値ゼロで埋める。 More...
 
void free (void *pmem)
 
long labs (long)
 実数(long型)の絶対値を返す。 More...
 
void * malloc (unsigned int nbytes)
 
void qsort (char *, unsigned int, int, int(*)(void))
 
int rand (void)
 予め設定済みのシード値を用いて、疑似乱数を返す。 More...
 
void srand (unsigned int)
 疑似乱数のシード値を設定する。 More...
 

Detailed Description

Id
stdlib.h 2051 2009-08-27 20:55:09Z akoehler

Definition in file stdlib.h.

Macro Definition Documentation

◆ RAND_MAX

#define RAND_MAX   2147483646

Definition at line 8 of file stdlib.h.

Referenced by rand_r().

Function Documentation

◆ abs()

int abs ( int  arg)

整数の絶対値(int型)を返す。

Parameters
[in]arg絶対値に変換したい整数(int型)
Returns
引数argの絶対値(int型)

Definition at line 13 of file abs.c.

14 {
15  if (arg < 0)
16  arg = -arg;
17  return (arg);
18 }

◆ atoi()

int atoi ( char *  p)

ASCII文字列をint型に変換する。

処理の流れは、
Step1. 「不要な文字(空白、TAB)の削除」もしくは「正数/負数の判定」を行う
Step2. 0〜9の範囲の値であれば、一桁ずつ記録する。それ以外の文字は呼び飛ばす
ASCIIコードとして、0=0x30、1=0x31、2=0x32、…、9=0x39であるため、
「0x30〜0x39の範囲のASCIIコード値(0〜9の値) - '0'(=0x30)」と計算すれば、
0〜9の整数値が得られる。
Step3. Step.1で取得した符号情報(±)を反映した整数を返す。

Parameters
[in]pASCII文字列
Returns
ASCII文字列をint型に変換した整数値
Note
ASCIIコード情報は、ターミナル上で"$ man ascii"で確認できる。

Definition at line 19 of file atoi.c.

20 {
21  int n = 0, f = 0;
22 
23  for (;; p++)
24  {
25  switch (*p)
26  {
27  case ' ':
28  case '\t':
29  continue;
30  case '-':
31  f++;
32  case '+':
33  p++;
34  }
35  break;
36  }
37 
38  while (*p >= '0' && *p <= '9')
39  {
40  n = n * 10 + *p++ - '0';
41  }
42 
43  return (f ? -n : n);
44 }

◆ atol()

long atol ( char *  p)

ASCII文字列をlong型に変換する。

処理の流れは、
Step1. 「不要な文字(空白、TAB)の削除」もしくは「正数/負数の判定」を行う
Step2. 0〜9の範囲の値であれば、一桁ずつ記録する。それ以外の文字は呼び飛ばす
ASCIIコードとして、0=0x30、1=0x31、2=0x32、…、9=0x39であるため、
「0x30〜0x39の範囲のASCIIコード値(0〜9の値) - '0'(=0x30)」と計算すれば、
0〜9の整数値が得られる。
Step3. Step.1で取得した符号情報(±)を反映した整数を返す。

Parameters
[in]pASCII文字列
Returns
ASCII文字列をlong型に変換した実数
Note
ASCIIコード情報は、ターミナル上で"$ man ascii"で確認できる。

Definition at line 19 of file atol.c.

20 {
21  long n;
22  int f;
23 
24  n = 0;
25  f = 0;
26  for (;; p++)
27  {
28  switch (*p)
29  {
30  case ' ':
31  case '\t':
32  continue;
33  case '-':
34  f++;
35  case '+':
36  p++;
37  }
38  break;
39  }
40  while (*p >= '0' && *p <= '9')
41  {
42  n = n * 10 + *p++ - '0';
43  }
44  return (f ? -n : n);
45 }

◆ bzero()

void bzero ( void *  p,
int  len 
)

Byteブロック領域の先頭N bytesを数値ゼロで埋める。

Parameters
[in,out]pByteブロック(bzero()終了後にゼロで埋まった状態となる)
[in]len数値ゼロ埋めするサイズ(Byte)
Note
引数lenが0以下の場合は、何もせずreturnする。

Definition at line 12 of file bzero.c.

Referenced by newdev(), and newtype().

15 {
16  int n;
17  char *pch = (char *)p;
18 
19  if ((n = len) <= 0)
20  {
21  return;
22  }
23  do
24  {
25  *pch++ = 0;
26  } while (--n);
27 }
Here is the caller graph for this function:

◆ free()

void free ( void *  pmem)

Referenced by if().

Here is the caller graph for this function:

◆ labs()

long labs ( long  arg)

実数(long型)の絶対値を返す。

Parameters
[in]arg絶対値に変換したい実数(long型)
Returns
引数argの絶対値(long型)

Definition at line 11 of file labs.c.

12 {
13  if (arg < 0)
14  arg = -arg;
15  return (arg);
16 }

◆ malloc()

void* malloc ( unsigned int  nbytes)

Referenced by if().

Here is the caller graph for this function:

◆ qsort()

void qsort ( char *  ,
unsigned  int,
int  ,
int(*)(void)   
)

◆ rand()

int rand ( void  )

予め設定済みのシード値を用いて、疑似乱数を返す。

シード値を変えない限り、疑似乱数に再現性がある。

Returns
疑似乱数(int型の整数値。0〜RAND_MAXの範囲で表される値)

Definition at line 17 of file rand.c.

References rand_r(), and rand_seed.

18 {
19  return rand_r(&rand_seed);
20 }
int rand_r(unsigned int *)
任意のシード値を用いて、疑似乱数を返すrand_r()の宣言。
Definition: rand.c:27
static unsigned int rand_seed
疑似乱数のシード値。
Definition: rand.c:8
Here is the call graph for this function:

◆ srand()

void srand ( unsigned int  seed)

疑似乱数のシード値を設定する。

Parameters
[in]seed疑似乱数のシード(乱数を生成する際に用いる値)

Definition at line 37 of file rand.c.

References rand_seed.

39 {
40  rand_seed = seed;
41 }
static unsigned int rand_seed
疑似乱数のシード値。
Definition: rand.c:8