main.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. int
  8. test_add(int x, int y);
  9. int
  10. test_sqrt(int x, int y);
  11. int
  12. test_hello(const char *name, char *buf, size_t buflen);
  13. int
  14. test_hello2(const char *name, char *buf, size_t buflen);
  15. int
  16. main(int argc, char **argv)
  17. {
  18. const char *name = __func__;
  19. char *buf;
  20. size_t buflen;
  21. int x = 10, y = 20, res;
  22. printf("Hello World!\n");
  23. res = test_add(x, y);
  24. printf("%d + %d = %d\n", x, y, res);
  25. res = test_sqrt(x, y);
  26. printf("sqrt(%d, %d) = %d\n", x, y, res);
  27. res = test_hello(name, NULL, 0);
  28. printf("test_hello(\"%s\", %p, %zu) = %d\n", name, NULL, (size_t)0, res);
  29. if (res == -1) {
  30. return -1;
  31. }
  32. buflen = res + 1;
  33. buf = malloc(buflen);
  34. printf("malloc(%zu) = %p\n", buflen, buf);
  35. res = test_hello(__func__, buf, buflen);
  36. if (res == -1) {
  37. return -1;
  38. }
  39. printf("test_hello(\"%s\", %p, %zu) = %d\n", name, buf, buflen, res);
  40. printf("Message from test_hello: %s", buf);
  41. free(buf);
  42. res = test_hello2(name, NULL, 0);
  43. printf("test_hello2(\"%s\", %p, %zu) = %d\n", name, NULL, (size_t)0, res);
  44. if (res == -1) {
  45. return -1;
  46. }
  47. buflen = res + 1;
  48. buf = malloc(buflen);
  49. printf("malloc(%zu) = %p\n", buflen, buf);
  50. res = test_hello2(__func__, buf, buflen);
  51. if (res == -1) {
  52. return -1;
  53. }
  54. printf("test_hello2(\"%s\", %p, %zu) = %d\n", name, buf, buflen, res);
  55. printf("Message from test_hello2: %s", buf);
  56. free(buf);
  57. return 0;
  58. }