1 /*
2 * Copyright (C) 2015-2021 Alibaba Group Holding Limited
3 */
4 #include <fcntl.h>
5 #include <sys/types.h>
6 #include <unistd.h>
7 #include <stdlib.h>
8 #include <stdio.h>
9 #if AOS_COMP_CLI
10 #include "aos/cli.h"
11 #endif
12 #ifdef AOS_COMP_RAMFS
13 #include "ramfs.h"
14 #endif
15
libc_stub_example(int argc,char ** argv)16 static void libc_stub_example(int argc, char **argv)
17 {
18 (void)argc;
19 (void)argv;
20 int fd;
21 int ret;
22 char teststring = "1234";
23 char readbuf[10];
24 void *paddr = NULL;
25
26 paddr = malloc(10);
27 if(paddr == NULL){
28 printf("libc_stub: malloc fail!\r\n");
29 return;
30 }else{
31 free(paddr);
32 printf("libc_stub: malloc OK!\r\n");
33 }
34
35 #ifdef AOS_COMP_RAMFS
36 ramfs_register("/test");
37 fd = open("/test/file1", O_RDWR);
38 if(fd < 0){
39 printf("libc_stub: ramfs open fail!\r\n");
40 return;
41 }
42 ret = write(fd, teststring, 5);
43 if(ret < 0){
44 printf("libc_stub: ramfs write fail!\r\n");
45 close(fd);
46 return;
47 }
48 lseek(fd, 0, SEEK_SET);
49 ret = read(fd, readbuf, 5);
50 if(ret < 0){
51 printf("libc_stub: ramfs read fail!\r\n");
52 close(fd);
53 return;
54 }
55 if(strncmp(readbuf, teststring, 5)){
56 printf("libc_stub: ramfs test fail! readbuf:%s\r\n",readbuf);
57 }else{
58 printf("libc_stub: ramfs test success!\r\n");
59 }
60 close(fd);
61 ramfs_unregister("/test");
62 #endif
63
64 printf("libc_stub comp test success!\r\n");
65 return;
66 }
67
68 #if AOS_COMP_CLI
69 /* reg args: fun, cmd, description*/
70 ALIOS_CLI_CMD_REGISTER(libc_stub_example, libc_example, lib stub component base example)
71 #endif
72