-
-
Notifications
You must be signed in to change notification settings - Fork 65
Added asprintf and fprintf along with ti_sprintf macros #558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Nice job, looks good 👍 |
|
Tests for fprintf, asprintf, ti_sprintf, ti_snprintf, and ti_asprintf have been added now. |
….h> functions since Clang can inline the functions with its own builtins
97316bb to
e25ba16
Compare
|
I have been given the go ahead from @adriweb to merge this PR |
|
I am a bit worried that the |
|
Gotta trust the tests 🫡 |
The functions I've added use this naming convention |
|
the function naming should be okay as is, and won't conflict |
|
lol wtf |
|
I'm not sure this is an issue now but if we want to change the naming convention to ce_xxx instead, we can always do that before a release anyway, no worries. Do you think it's better than ti_xxx ? |
Functions added:
fprintf/vfprintfasprintf/vasprintfti_sprintf,ti_snprintf, andti_asprintfto<ce/include/ti_sprintf.h>fprintfredirects the output ofnano_printftofputcasprintfis implemented via two calls tosnprintf#543ti_sprintfmakes explicit calls to the C89sprintffrom OS_LIBC. This can reduce binary sizes significantly compared tonano_printfti_snprintfandti_asprintfwrite to unmapped memory0xFC1000to get the size of the output. Writing to0xFB0000also works, but will output to the CEmu console. Otherwise, writing to0xFC1000should be okay unless the output exceeds ~258000 characters. Becauseti_vsprintfdoesn't exist, they are both implemented as macros, and will evaluate__VA_ARGS__twice.ti_asprintfwillmalloca buffer thatti_sprintfwill write to, returningNULLonmallocfailure. The buffer shall be deallocated withfreeti_snprintfwill return an empty string if the result ofti_sprintfwon't fit inside the buffer. This was done to make the routine more compact, as implementing the truncation behavior ofsnprintfwould require calls tomalloc. If the user wants the output to be truncated, they can useti_asprintfandstrncpy