summaryrefslogtreecommitdiff
path: root/examples/libc/printf.c
diff options
context:
space:
mode:
authorguo <[email protected]>2021-09-28 10:36:54 +0800
committerGitHub <[email protected]>2021-09-28 10:36:54 +0800
commit55a302cd092758a44b589d65470a69d9e8ae4ced (patch)
treee60fc53994c426007e9eb4877e5bd123f124ef39 /examples/libc/printf.c
parent00727d6b6db92dc1cf98f028f26fd6168594b905 (diff)
parent00d42ef73cff61ecda7ff006b077a73e1a4ff669 (diff)
Merge branch 'master' into usbh_construct
Diffstat (limited to 'examples/libc/printf.c')
-rw-r--r--examples/libc/printf.c64
1 files changed, 37 insertions, 27 deletions
diff --git a/examples/libc/printf.c b/examples/libc/printf.c
index 2d2d8a7763..c7968b9a0b 100644
--- a/examples/libc/printf.c
+++ b/examples/libc/printf.c
@@ -1,3 +1,13 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2010-11-17 Bernard first version
+ */
+
#include <stdio.h>
#include <stdlib.h>
#include <sys/fcntl.h>
@@ -142,59 +152,59 @@ int printf_test()
int i;
printf ("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n",
- snprintf (buf, sizeof (buf), "%30s", "foo"), (int) sizeof (buf),
- buf);
+ snprintf (buf, sizeof (buf), "%30s", "foo"), (int) sizeof (buf),
+ buf);
memset(buf2,0,sizeof(buf));
i=snprintf(buf2, 256, "%.9999u", 10);
printf("%i %i\n",i,strlen(buf2));
printf ("snprintf (\"%%.999999u\", 10) == %d\n",
- snprintf(buf2, sizeof(buf2), "%.999999u", 10));
+ snprintf(buf2, sizeof(buf2), "%.999999u", 10));
}
return 0;
}
void libc_printf()
{
- printf("stdout test!!\n");
- fprintf(stdout, "fprintf test!!\n");
- fprintf(stderr, "fprintf test!!\n");
- puts("puts test!!\n");
+ printf("stdout test!!\n");
+ fprintf(stdout, "fprintf test!!\n");
+ fprintf(stderr, "fprintf test!!\n");
+ puts("puts test!!\n");
- putc('1', stderr);
- putc('2', stderr);
- putc('\n', stderr);
+ putc('1', stderr);
+ putc('2', stderr);
+ putc('\n', stderr);
- printf_test();
+ printf_test();
}
FINSH_FUNCTION_EXPORT(libc_printf, printf test in libc);
void libc_dprintf()
{
- int fd;
+ int fd;
- fd = open("/dev/console", O_WRONLY, 0);
- if (fd >0)
- {
- dprintf(fd, "fd:%d printf test!!\n", fd);
- close(fd);
- }
+ fd = open("/dev/console", O_WRONLY, 0);
+ if (fd >0)
+ {
+ dprintf(fd, "fd:%d printf test!!\n", fd);
+ close(fd);
+ }
}
FINSH_FUNCTION_EXPORT(libc_dprintf, dprintf test);
void libc_fdopen()
{
- int fd;
- FILE* fp;
+ int fd;
+ FILE* fp;
- fd = open("/dev/console", O_WRONLY, 0);
- if (fd >0)
- {
- fp = fdopen(fd, "w");
- fprintf(fp, "fdopen test, fd %d!!\n", fileno(fp));
- fclose(fp);
- }
+ fd = open("/dev/console", O_WRONLY, 0);
+ if (fd >0)
+ {
+ fp = fdopen(fd, "w");
+ fprintf(fp, "fdopen test, fd %d!!\n", fileno(fp));
+ fclose(fp);
+ }
}
FINSH_FUNCTION_EXPORT(libc_fdopen, fdopen test);