stdio.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "stdio.h"
  2. #ifdef IRON_WASM
  3. __attribute__((import_module("imports"), import_name("js_printf"))) void js_printf(const char *format);
  4. __attribute__((import_module("imports"), import_name("js_fopen"))) FILE *js_fopen(const char *filename);
  5. __attribute__((import_module("imports"), import_name("js_ftell"))) long int js_ftell(FILE *stream);
  6. __attribute__((import_module("imports"), import_name("js_fseek"))) int js_fseek(FILE *stream, long int offset, int origin);
  7. __attribute__((import_module("imports"), import_name("js_fread"))) size_t js_fread(void *ptr, size_t size, size_t count, FILE *stream);
  8. #endif
  9. FILE *stdout = NULL, *stderr = NULL;
  10. int printf(const char *format, ...) {
  11. #ifdef IRON_WASM
  12. js_printf(format);
  13. #endif
  14. return 0;
  15. }
  16. int fprintf(FILE *stream, const char *format, ...) {
  17. #ifdef IRON_WASM
  18. js_printf(format);
  19. #endif
  20. return 0;
  21. }
  22. int sprintf(char *s, const char *format, ...) {
  23. return 0;
  24. }
  25. int snprintf(char *s, size_t n, const char *format, ...) {
  26. return 0;
  27. }
  28. int vsnprintf(char *s, size_t n, const char *format, va_list arg) {
  29. return 0;
  30. }
  31. size_t fwrite(const void *ptr, size_t size, size_t count, FILE *stream) {
  32. return 0;
  33. }
  34. FILE *fopen(const char *filename, const char *mode) {
  35. #ifdef IRON_WASM
  36. return js_fopen(filename);
  37. #endif
  38. return NULL;
  39. }
  40. int fclose(FILE *stream) {
  41. return 0;
  42. }
  43. long int ftell(FILE *stream) {
  44. #ifdef IRON_WASM
  45. return js_ftell(stream);
  46. #endif
  47. return 0;
  48. }
  49. int fseek(FILE *stream, long int offset, int origin) {
  50. #ifdef IRON_WASM
  51. return js_fseek(stream, offset, origin);
  52. #endif
  53. return 0;
  54. }
  55. size_t fread(void *ptr, size_t size, size_t count, FILE *stream) {
  56. #ifdef IRON_WASM
  57. return js_fread(ptr, size, count, stream);
  58. #endif
  59. return 0;
  60. }
  61. int fputs(const char *str, FILE *stream) {
  62. return 0;
  63. }