ESP8266_RTOS_SDK  v1.4.0
esp_libc.h
1 /*
2  * ESPRSSIF MIT License
3  *
4  * Copyright (c) 2015 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
5  *
6  * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
7  * it is free of charge, to any person obtaining a copy of this software and associated
8  * documentation files (the "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
11  * to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies or
14  * substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  *
23  */
24 
25 #ifndef __ESP_LIBC_H__
26 #define __ESP_LIBC_H__
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 char *strcpy(char *dst, const char *src);
33 char *strncpy(char *dst, const char *src, size_t n);
34 int strcmp(const char *s1, const char *s2);
35 int strncmp(const char *s1, const char *s2, size_t n);
36 size_t strlen(const char *s);
37 char *strstr(const char *s1, const char *s2);
38 char *strcat(char *dst, const char *src);
39 char *strncat(char *dst, const char *src, size_t count);
40 size_t strspn(const char *s, const char *accept);
41 size_t strcspn(const char *s, const char *reject);
42 char *strtok_r(char *s, const char *delim, char **ptrptr);
43 char *strtok(char *s, const char *delim);
44 char *strrchr(const char *s, int c);
45 char *strdup(const char *s);
46 char *strchr(const char *s, int c);
47 long strtol(const char *str, char **endptr, int base);
48 
49 void bzero(void *s, size_t n);
50 
51 void *memcpy(void *dst, const void *src, size_t n);
52 void *memset(void *dst, int c, size_t n);
53 int memcmp(const void *m1, const void *m2, size_t n);
54 void *memmove(void *dst, const void *src, size_t n);
55 
56 int rand(void);
57 
58 int printf(const char *format, ...);
59 int sprintf(char *out, const char *format, ...);
60 int snprintf(char *buf, unsigned int count, const char *format, ...);
61 int puts(const char *str);
62 
63 void *malloc(size_t n);
64 void free(void *p);
65 void *calloc(size_t c, size_t n);
66 void *zalloc(size_t n);
67 void *realloc(void *p, size_t n);
68 
69 int atoi(const char *s);
70 long atol(const char *s);
71 
72 unsigned long os_random(void);
73 int os_get_random(unsigned char *buf, size_t len);
74 
75 /* NOTE: don't use printf_opt in irq handler, for test */
76 #define os_printf(fmt, ...) do { \
77  static const char flash_str[] ICACHE_RODATA_ATTR STORE_ATTR = fmt; \
78  printf(flash_str, ##__VA_ARGS__); \
79  } while(0)
80 
81 #ifdef __cplusplus
82 }
83 #endif
84 
85 #endif /* __LIBC_H__ */