SimpleKernel 1.17.0
Loading...
Searching...
No Matches
sk_stdlib.h File Reference
#include <stddef.h>
Include dependency graph for sk_stdlib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void * malloc (size_t size)
 
void free (void *ptr)
 
void * calloc (size_t num, size_t size)
 
void * realloc (void *ptr, size_t new_size)
 
void * aligned_alloc (size_t alignment, size_t size)
 
void aligned_free (void *ptr)
 
double atof (const char *nptr)
 将字符串转换为双精度浮点数
 
int atoi (const char *nptr)
 将字符串转换为整数
 
long int atol (const char *nptr)
 将字符串转换为长整数
 
long long int atoll (const char *nptr)
 将字符串转换为长长整数
 
double strtod (const char *nptr, char **endptr)
 将字符串转换为双精度浮点数,并可以获取转换结束位置
 
long int strtol (const char *nptr, char **endptr, int base)
 将字符串按指定进制转换为长整数,并可以获取转换结束位置
 
long long int strtoll (const char *nptr, char **endptr, int base)
 将字符串按指定进制转换为长长整数,并可以获取转换结束位置
 
unsigned long int strtoul (const char *nptr, char **endptr, int base)
 将字符串按指定进制转换为无符号长整数,并可以获取转换结束位置
 
unsigned long long int strtoull (const char *nptr, char **endptr, int base)
 将字符串按指定进制转换为无符号长长整数,并可以获取转换结束位置
 

Function Documentation

◆ aligned_alloc()

void * aligned_alloc ( size_t  alignment,
size_t  size 
)

Definition at line 58 of file memory.cpp.

58 {
59 if (allocator) {
60 return allocator->aligned_alloc(alignment, size);
61 }
62 return nullptr;
63}
Here is the caller graph for this function:

◆ aligned_free()

void aligned_free ( void *  ptr)

Definition at line 65 of file memory.cpp.

65 {
66 if (allocator) {
67 allocator->aligned_free(ptr);
68 }
69}
Here is the caller graph for this function:

◆ atof()

double atof ( const char *  nptr)

将字符串转换为双精度浮点数

Parameters
nptr指向要转换的字符串的指针
Returns
转换后的双精度浮点数

◆ atoi()

int atoi ( const char *  nptr)

将字符串转换为整数

Parameters
nptr指向要转换的字符串的指针
Returns
转换后的整数值

Definition at line 153 of file sk_stdlib.c.

153{ return (int)strtol(nptr, NULL, 10); }
#define strtol

◆ atol()

long int atol ( const char *  nptr)

将字符串转换为长整数

Parameters
nptr指向要转换的字符串的指针
Returns
转换后的长整数值

Definition at line 155 of file sk_stdlib.c.

155{ return strtol(nptr, NULL, 10); }

◆ atoll()

long long int atoll ( const char *  nptr)

将字符串转换为长长整数

Parameters
nptr指向要转换的字符串的指针
Returns
转换后的长长整数值

Definition at line 157 of file sk_stdlib.c.

157{ return strtoll(nptr, NULL, 10); }
#define strtoll

◆ calloc()

void * calloc ( size_t  num,
size_t  size 
)

Definition at line 44 of file memory.cpp.

44 {
45 if (allocator) {
46 return allocator->calloc(num, size);
47 }
48 return nullptr;
49}

◆ free()

void free ( void *  ptr)

Definition at line 38 of file memory.cpp.

38 {
39 if (allocator) {
40 allocator->free(ptr);
41 }
42}
Here is the caller graph for this function:

◆ malloc()

void * malloc ( size_t  size)

Definition at line 31 of file memory.cpp.

31 {
32 if (allocator) {
33 return allocator->malloc(size);
34 }
35 return nullptr;
36}
Here is the caller graph for this function:

◆ realloc()

void * realloc ( void *  ptr,
size_t  new_size 
)

Definition at line 51 of file memory.cpp.

51 {
52 if (allocator) {
53 return allocator->realloc(ptr, new_size);
54 }
55 return nullptr;
56}

◆ strtod()

double strtod ( const char *  nptr,
char **  endptr 
)

将字符串转换为双精度浮点数,并可以获取转换结束位置

Parameters
nptr指向要转换的字符串的指针
endptr指向指针的指针,用于存储转换结束位置
Returns
转换后的双精度浮点数

◆ strtol()

long int strtol ( const char *  nptr,
char **  endptr,
int  base 
)

将字符串按指定进制转换为长整数,并可以获取转换结束位置

Parameters
nptr指向要转换的字符串的指针
endptr指向指针的指针,用于存储转换结束位置
base转换的进制(2-36,0表示自动检测)
Returns
转换后的长整数值

Definition at line 136 of file sk_stdlib.c.

136 {
137 long long int val = strtoll(nptr, endptr, base);
138#if LONG_MAX != LLONG_MAX
139 if (val > LONG_MAX) return LONG_MAX;
140 if (val < LONG_MIN) return LONG_MIN;
141#endif
142 return (long int)val;
143}

◆ strtoll()

long long int strtoll ( const char *  nptr,
char **  endptr,
int  base 
)

将字符串按指定进制转换为长长整数,并可以获取转换结束位置

Parameters
nptr指向要转换的字符串的指针
endptr指向指针的指针,用于存储转换结束位置
base转换的进制(2-36,0表示自动检测)
Returns
转换后的长长整数值

Definition at line 117 of file sk_stdlib.c.

117 {
118 int negative;
119 int overflow;
120 unsigned long long acc =
121 strtox_main(nptr, endptr, base, &negative, &overflow);
122
123 if (overflow) {
124 return negative ? LLONG_MIN : LLONG_MAX;
125 }
126
127 if (negative) {
128 if (acc > (unsigned long long)LLONG_MAX + 1) return LLONG_MIN;
129 return -(long long)acc;
130 } else {
131 if (acc > LLONG_MAX) return LLONG_MAX;
132 return (long long)acc;
133 }
134}
static unsigned long long strtox_main(const char *nptr, char **endptr, int base, int *sign_out, int *overflow)
Definition sk_stdlib.c:27
Here is the call graph for this function:

◆ strtoul()

unsigned long int strtoul ( const char *  nptr,
char **  endptr,
int  base 
)

将字符串按指定进制转换为无符号长整数,并可以获取转换结束位置

Parameters
nptr指向要转换的字符串的指针
endptr指向指针的指针,用于存储转换结束位置
base转换的进制(2-36,0表示自动检测)
Returns
转换后的无符号长整数值

Definition at line 145 of file sk_stdlib.c.

145 {
146 unsigned long long int val = strtoull(nptr, endptr, base);
147#if ULONG_MAX != ULLONG_MAX
148 if (val > ULONG_MAX) return ULONG_MAX;
149#endif
150 return (unsigned long int)val;
151}
#define strtoull

◆ strtoull()

unsigned long long int strtoull ( const char *  nptr,
char **  endptr,
int  base 
)

将字符串按指定进制转换为无符号长长整数,并可以获取转换结束位置

Parameters
nptr指向要转换的字符串的指针
endptr指向指针的指针,用于存储转换结束位置
base转换的进制(2-36,0表示自动检测)
Returns
转换后的无符号长长整数值

Definition at line 107 of file sk_stdlib.c.

107 {
108 int negative;
109 int overflow;
110 unsigned long long acc =
111 strtox_main(nptr, endptr, base, &negative, &overflow);
112
113 if (overflow) return ULLONG_MAX;
114 return negative ? -acc : acc;
115}
Here is the call graph for this function: