File tree Expand file tree Collapse file tree 9 files changed +186
-0
lines changed Expand file tree Collapse file tree 9 files changed +186
-0
lines changed Original file line number Diff line number Diff line change 1+ #include <assert.h>
2+ #include <errno.h>
3+ #include <stdio.h>
4+ #include <string.h>
5+
6+ int _ti_sprintf (
7+ char * __restrict buffer , const char * __restrict format , ...
8+ ) __attribute__ ((format (__printf__ , 2 , 3 )));
9+
10+ static char const * const errno_strings [] = {
11+ "no error" ,
12+ "permission error" ,
13+ "invalid argument" ,
14+ "io error" ,
15+ "math domain error" ,
16+ "math range error" ,
17+ };
18+
19+ static char * const unknown_errno_string = "unknown error -8388608" ;
20+
21+ #define unknown_errno_number_offset 14
22+ #if 0
23+ /* static_assert on a string is a Clang 16.0.0 extension */
24+ static_assert (
25+ unknown_errno_string [unknown_errno_number_offset + 0 ] == '-' &&
26+ unknown_errno_string [unknown_errno_number_offset + 8 ] == '\0' ,
27+ "the string for unknown errno numbers has been changed"
28+ );
29+ #endif
30+
31+ #define errno_strings_count (sizeof(errno_strings) / sizeof(errno_strings[0]))
32+
33+ char * strerror (int errnum ) {
34+ if ((unsigned int )errnum >= errno_strings_count ) {
35+ _ti_sprintf (& (unknown_errno_string [unknown_errno_number_offset ]), "%d" , errnum );
36+ return (char * )unknown_errno_string ;
37+ }
38+ return (char * )errno_strings [errnum ];
39+ }
40+
41+ #if 0
42+ /** disabled until the prototypes for this function are defined */
43+ size_t strerrorlen_s (errno_t errnum ) {
44+ return strlen (strerror (errnum ));
45+ }
46+ #endif
47+
48+ void perror (const char * str ) {
49+ if (str != NULL && * str != '\0' ) {
50+ fputs (str , stderr );
51+ fputc (':' , stderr );
52+ fputc (' ' , stderr );
53+ }
54+ fputs (strerror (errno ), stderr );
55+ fputc ('\n' , stderr );
56+ }
Original file line number Diff line number Diff line change @@ -104,6 +104,8 @@ int sprintf(char *__restrict buffer,
104104 const char * __restrict format , ...)
105105 __attribute__ ((format (__printf__ , 2 , 3 )));
106106
107+ void perror (const char * str );
108+
107109__END_DECLS
108110
109111#endif /* _STDIO_H */
Original file line number Diff line number Diff line change @@ -72,6 +72,7 @@ int strcasecmp(const char *s1, const char *s2)
7272int strncasecmp (const char * s1 , const char * s2 , size_t n )
7373 __attribute__((nonnull (1 , 2 )));
7474
75+ char * strerror (int errnum );
7576
7677__END_DECLS
7778
Original file line number Diff line number Diff line change 1+ assume adl=1
2+
3+ section .text
4+
5+ ; to reduce binary size (or performance in the case of sprintf), ti's routines
6+ ; can be linked instead of the toolchain's routines
7+
8+ public __ti_sprintf
9+ __ti_sprintf := 0000BCh
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ using ::vsprintf;
3535using ::snprintf;
3636using ::vsnprintf;
3737using ::sprintf;
38+ using ::perror;
3839} // namespace std
3940
4041#endif // _EZCXX_CSTDINT
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ using ::strcmp;
3333using ::strncmp;
3434using ::strcasecmp;
3535using ::strncasecmp;
36+ using ::strerror;
3637} // namespace std
3738
3839#endif // _EZCXX_CSTRING
Original file line number Diff line number Diff line change 1+ {
2+ "transfer_files" : [
3+ " bin/DEMO.8xp"
4+ ],
5+ "target" : {
6+ "name" : " DEMO" ,
7+ "isASM" : true
8+ },
9+ "sequence" : [
10+ " action|launch" ,
11+ " delay|600" ,
12+ " hashWait|1" ,
13+ " key|enter" ,
14+ " delay|600" ,
15+ " hashWait|2" ,
16+ " key|enter" ,
17+ " delay|300" ,
18+ " hashWait|3"
19+ ],
20+ "hashes" : {
21+ "1" : {
22+ "description" : " Valid errno screen" ,
23+ "start" : " vram_start" ,
24+ "size" : " vram_16_size" ,
25+ "expected_CRCs" : [
26+ " B0BE2F4E"
27+ ]
28+ },
29+ "2" : {
30+ "description" : " Invalid input screen" ,
31+ "start" : " vram_start" ,
32+ "size" : " vram_16_size" ,
33+ "expected_CRCs" : [
34+ " 29401BEE"
35+ ]
36+ },
37+ "3" : {
38+ "description" : " Exit" ,
39+ "start" : " vram_start" ,
40+ "size" : " vram_16_size" ,
41+ "expected_CRCs" : [
42+ " FFAF89BA" ,
43+ " 101734A5" ,
44+ " 9DA19F44" ,
45+ " A32840C8" ,
46+ " 349F4775"
47+ ]
48+ }
49+ }
50+ }
Original file line number Diff line number Diff line change 1+ # ----------------------------
2+ # Makefile Options
3+ # ----------------------------
4+
5+ NAME = DEMO
6+ ICON = icon.png
7+ DESCRIPTION = "CE C Toolchain Demo"
8+ COMPRESSED = NO
9+ ARCHIVED = NO
10+
11+ CFLAGS = -Wall -Wextra -Oz
12+ CXXFLAGS = -Wall -Wextra -Oz
13+
14+ PREFER_OS_LIBC = NO
15+
16+ # ----------------------------
17+
18+ include $(shell cedev-config --makefile)
Original file line number Diff line number Diff line change 1+ #include <ti/screen.h>
2+ #include <ti/getcsc.h>
3+ #include <sys/util.h>
4+ #include <stdio.h>
5+ #include <string.h>
6+ #include <errno.h>
7+ #include <limits.h>
8+
9+ /** @note assumes that the following strings are used: */
10+ #if 0
11+ static char const * const errno_str [] = {
12+ "no error" ,
13+ "permission error" ,
14+ "invalid argument" ,
15+ "io error" ,
16+ "math domain error" ,
17+ "math range error" ,
18+ };
19+
20+ static char * const unknown_errno_string = "unknown error -8388608" ;
21+ #endif
22+
23+ int main (void )
24+ {
25+ os_ClrHome ();
26+
27+ errno = 0 ; perror (NULL );
28+ errno = 1 ; perror ("" );
29+ errno = 2 ; perror ("\0" );
30+ errno = 3 ; perror (" " );
31+ errno = 4 ; perror ("%d" );
32+ errno = 5 ; perror ("perror" );
33+
34+ while (!os_GetCSC ());
35+
36+ os_ClrHome ();
37+
38+ errno = 6 ; perror (NULL );
39+ errno = -1 ; perror ("" );
40+ errno = -123456 ; perror ("%d" );
41+ errno = 123456 ; perror ("???" );
42+ errno = INT_MIN ; perror (" " );
43+ errno = INT_MAX ; perror ("#" );
44+
45+ while (!os_GetCSC ());
46+
47+ return 0 ;
48+ }
You can’t perform that action at this time.
0 commit comments