Guest User

Untitled

a guest
Apr 20th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <sys/uio.h>
  5.  
  6. #define WASM_EXPORT __attribute__((visibility("default")))
  7.  
  8.  
  9. typedef struct Rgb {
  10. int r;
  11. int g;
  12. int b;
  13. char name[50];
  14. } RGB;
  15.  
  16. typedef struct Person {
  17. char fname[30];
  18. char name[30];
  19. } People;
  20.  
  21. WASM_EXPORT
  22. char * introduceYourself() {
  23. People Marc;
  24. strcpy(Marc.fname, "Marc");
  25. strcpy(Marc.name, "I");
  26.  
  27. printf("Hello my name is %s \n", Marc.fname);
  28.  
  29. People * Ly = malloc(sizeof(People));
  30. strcpy(Ly->fname, "Ly");
  31. return Ly->fname;
  32. }
  33.  
  34. WASM_EXPORT
  35. int main() {
  36. char lol[50] = {'l','o','l'};
  37. printf("Value of lol %s \n", lol);
  38.  
  39. RGB *sleep = malloc(sizeof(RGB));
  40.  
  41. sleep->r = 100;
  42. sleep->g = 200;
  43. sleep->b = 255;
  44. strcpy(sleep->name, "Blue rose");
  45. printf("Value of r %i \n", sleep->r);
  46. printf("Name of this beautiful color %s \n", sleep->name);
  47. }
  48.  
  49. /* External function that is implemented in JavaScript. */
  50. extern putc_js(char c);
  51.  
  52. /* Basic implementation of the writev sys call. */
  53. WASM_EXPORT
  54. size_t writev_c(int fd, const struct iovec *iov, int iovcnt) {
  55. size_t cnt = 0;
  56. for (int i = 0; i < iovcnt; i++) {
  57. for (int j = 0; j < iov[i].iov_len; j++) {
  58. putc_js(((char *)iov[i].iov_base)[j]);
  59. }
  60. cnt += iov[i].iov_len;
  61. }
  62. return cnt;
  63. }
Add Comment
Please, Sign In to add comment