Bubble android client. Fork of https://git.zx2c4.com/wireguard-android/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

78 regels
1.4 KiB

  1. /* SPDX-License-Identifier: BSD
  2. *
  3. * Copyright © 2017-2019 WireGuard LLC. All Rights Reserved.
  4. *
  5. */
  6. #define FILE_IS_EMPTY
  7. #if defined(__ANDROID_API__) && __ANDROID_API__ < 18
  8. #undef FILE_IS_EMPTY
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. ssize_t getdelim(char **buf, size_t *bufsiz, int delimiter, FILE *fp)
  12. {
  13. char *ptr, *eptr;
  14. if (*buf == NULL || *bufsiz == 0) {
  15. *bufsiz = BUFSIZ;
  16. if ((*buf = malloc(*bufsiz)) == NULL)
  17. return -1;
  18. }
  19. for (ptr = *buf, eptr = *buf + *bufsiz;;) {
  20. int c = fgetc(fp);
  21. if (c == -1) {
  22. if (feof(fp)) {
  23. ssize_t diff = (ssize_t)(ptr - *buf);
  24. if (diff != 0) {
  25. *ptr = '\0';
  26. return diff;
  27. }
  28. }
  29. return -1;
  30. }
  31. *ptr++ = c;
  32. if (c == delimiter) {
  33. *ptr = '\0';
  34. return ptr - *buf;
  35. }
  36. if (ptr + 2 >= eptr) {
  37. char *nbuf;
  38. size_t nbufsiz = *bufsiz * 2;
  39. ssize_t d = ptr - *buf;
  40. if ((nbuf = realloc(*buf, nbufsiz)) == NULL)
  41. return -1;
  42. *buf = nbuf;
  43. *bufsiz = nbufsiz;
  44. eptr = nbuf + nbufsiz;
  45. ptr = nbuf + d;
  46. }
  47. }
  48. }
  49. ssize_t getline(char **buf, size_t *bufsiz, FILE *fp)
  50. {
  51. return getdelim(buf, bufsiz, '\n', fp);
  52. }
  53. #endif
  54. #if defined(__ANDROID_API__) && __ANDROID_API__ < 24
  55. #undef FILE_IS_EMPTY
  56. #include <string.h>
  57. char *strchrnul(const char *s, int c)
  58. {
  59. char *x = strchr(s, c);
  60. if (!x)
  61. return (char *)s + strlen(s);
  62. return x;
  63. }
  64. #endif
  65. #ifdef FILE_IS_EMPTY
  66. #undef FILE_IS_EMPTY
  67. static char ____x __attribute__((unused));
  68. #endif