Skip to content

Commit

Permalink
add std
Browse files Browse the repository at this point in the history
  • Loading branch information
Neutree committed May 28, 2018
1 parent 15d333f commit f2d8ff3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
8 changes: 7 additions & 1 deletion demo/std/src/demo_std.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void STD_TestTask()
Trace(1,"atox:%d",d);

float e = atof("123.456");
Trace(1,"atof:%d.%d",(int)(e),(int)(e*1000%1000));
Trace(1,"atof:%d.%d",(int)(e),((int)(e*1000)%1000));

char* string = "-12345 stop here";
char* stopString = NULL;
Expand All @@ -77,6 +77,12 @@ void STD_TestTask()
item = bsearch(&key,num,10,sizeof(int),cmp);
Trace(1,"item:%d",*item);

int read0,read1;
// sscanf("123 456","%d %d",&read0,&read1);//error!!!
sscanf("123","%d",&read0);
sscanf("456","%d",&read1);
Trace(1,"read0:%d, read1:%d",read0,read1);


OS_Sleep(3000);
}
Expand Down
8 changes: 8 additions & 0 deletions include/sdk_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ typedef struct T_INTERFACE_VTBL_TAG

//std
int (*sscanf)(const char * buf, const char * fmt, ...);
long (*atol)(const char *s);
long long (*atoll)(const char *s);
int (*atox)(const char *s, int len);
double (*atof)(const char *s);
unsigned char* (*itoa)(int value, char *str, int radix);
char* (*gcvt)(double value, int ndigit, char *buf);
int (*rand) (void);
void (*srand)(unsigned int seed);

//ssl
SSL_Error_t (*SSL_Init)(SSL_Config_t* sslConfig);
Expand Down
5 changes: 4 additions & 1 deletion include/std_inc/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ extern "C" {

#include "stddef.h"
#include <stdarg.h>
#include "sdk_init.h"

int sprintf(char * buf, const char *fmt, ...);
int snprintf(char * buf, size_t len, const char *fmt, ...);
int sscanf(const char * buf, const char * fmt, ...);

#define sscanf CSDK_FUNC(sscanf)

int vsprintf(char *buf, const char *fmt, va_list ap);
int vsnprintf(char *buf, size_t size, const char *fmt, va_list ap);
int vsscanf (const char *fp, const char *fmt0, va_list ap);
Expand Down
18 changes: 9 additions & 9 deletions include/std_inc/stdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ extern "C" {

#include "cs_types.h"
#include "stddef.h"
#include "sdk_init.h"

/* Standard atoi() function. Work as the libc one. */
int atoi(const char *s);
long atol(const char *s);
long long atoll(const char *s);
int atox(const char *s, int len);
double atof(const char *s);

unsigned char* itoa(int value, char *str, int radix);
char* gcvt(double value, int ndigit, char *buf);
#define atol CSDK_FUNC(atol)
#define atoll CSDK_FUNC(atoll)
#define atox CSDK_FUNC(atox)
#define atof CSDK_FUNC(atof)
#define itoa CSDK_FUNC(itoa)
#define gcvt CSDK_FUNC(gcvt)

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

/* Standard random functions, work as the libc ones. */
#define RAND_MAX 32767

int rand (void);
void srand(unsigned int seed);

#define rand CSDK_FUNC(rand)
#define srand CSDK_FUNC(srand)

typedef INT STD_COMPAR_FUNC_T (const VOID*, const VOID*);

Expand Down

0 comments on commit f2d8ff3

Please sign in to comment.