stdio.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "stdio.h"
  2. #ifdef IRON_WASM
  3. __attribute__((import_module("imports"), import_name("js_fprintf"))) void js_fprintf(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 fprintf(FILE *stream, const char *format, ...) {
  11. #ifdef IRON_WASM
  12. js_fprintf(format);
  13. #endif
  14. return 0;
  15. }
  16. int vsnprintf(char *s, size_t n, const char *format, va_list arg) {
  17. return 0;
  18. }
  19. size_t fwrite(const void *ptr, size_t size, size_t count, FILE *stream) {
  20. return 0;
  21. }
  22. FILE *fopen(const char *filename, const char *mode) {
  23. #ifdef IRON_WASM
  24. return js_fopen(filename);
  25. #endif
  26. return NULL;
  27. }
  28. int fclose(FILE *stream) {
  29. return 0;
  30. }
  31. long int ftell(FILE *stream) {
  32. #ifdef IRON_WASM
  33. return js_ftell(stream);
  34. #endif
  35. return 0;
  36. }
  37. int fseek(FILE *stream, long int offset, int origin) {
  38. #ifdef IRON_WASM
  39. return js_fseek(stream, offset, origin);
  40. #endif
  41. return 0;
  42. }
  43. size_t fread(void *ptr, size_t size, size_t count, FILE *stream) {
  44. #ifdef IRON_WASM
  45. return js_fread(ptr, size, count, stream);
  46. #endif
  47. return 0;
  48. }
  49. int fputs(const char *str, FILE *stream) {
  50. return 0;
  51. }