logo

live-bootstrap

Mirror of <https://github.com/fosslinux/live-bootstrap>

meslibc.patch (4367B)


  1. SPDX-FileCopyrightText: 2024 Gábor Stefanik <netrolller.3d@gmail.com>
  2. SPDX-License-Identifier: GPL-3.0-or-later
  3. Remove usages of tmpfile(), rewind(), fgetpos(), fsetpos() and bsearch(),
  4. which are unsupported by meslibc, and add missing declaration for strdup.
  5. License note: Berkeley Yacc is in the public domain, but it's linked with
  6. meslibc, which is GPL-3.0-or-later, so we apply that license here too.
  7. diff -ru ../byacc-20240109.bak/main.c ./main.c
  8. --- byacc-20240109/main.c 2024-04-14 16:06:09.646465507 +0200
  9. +++ byacc-20240109/main.c 2024-04-14 20:41:56.227083399 +0200
  10. @@ -788,7 +788,7 @@
  11. (void)umask(save_umask);
  12. }
  13. #else
  14. - result = tmpfile();
  15. + result = fopen(label, "w+");
  16. #endif
  17. if (result == 0)
  18. diff -ru ../byacc-20240109.bak/output.c ./output.c
  19. --- byacc-20240109/output.c 2024-04-14 16:06:09.646465507 +0200
  20. +++ byacc-20240109/output.c 2024-04-14 16:06:24.636465897 +0200
  21. @@ -1289,7 +1289,7 @@
  22. {
  23. if (union_file != 0)
  24. {
  25. - rewind(union_file);
  26. + fseek(union_file, 0, SEEK_SET);
  27. while ((c = getc(union_file)) != EOF)
  28. putc_code(fp, c);
  29. }
  30. @@ -1314,7 +1314,7 @@
  31. if (text_file == NULL)
  32. open_error("text_file");
  33. - rewind(text_file);
  34. + fseek(text_file, 0, SEEK_SET);
  35. in = text_file;
  36. if ((c = getc(in)) == EOF)
  37. return;
  38. @@ -1684,7 +1684,7 @@
  39. int state;
  40. char line_state[20];
  41. - rewind(action_file);
  42. + fseek(action_file, 0, SEEK_SET);
  43. if ((c = getc(action_file)) == EOF)
  44. return;
  45. diff -ru ../byacc-20240109.bak/reader.c ./reader.c
  46. --- byacc-20240109/reader.c 2024-04-14 16:06:09.646465507 +0200
  47. +++ byacc-20240109/reader.c 2024-04-14 20:40:58.387082748 +0200
  48. @@ -70,7 +70,7 @@
  49. char *line_data; /* saved input-line */
  50. size_t line_used; /* position within saved input-line */
  51. size_t line_size; /* length of saved input-line */
  52. - fpos_t line_fpos; /* pointer before reading past saved input-line */
  53. + long line_fpos; /* pointer before reading past saved input-line */
  54. }
  55. SAVE_LINE;
  56. @@ -315,7 +315,7 @@
  57. line = save_area.line_data;
  58. cptr = save_area.line_used + line;
  59. linesize = save_area.line_size;
  60. - if (fsetpos(input_file, &save_area.line_fpos) != 0)
  61. + if (fseek(input_file, save_area.line_fpos, SEEK_SET) != 0)
  62. on_error();
  63. memset(&save_area, 0, sizeof(save_area));
  64. }
  65. @@ -338,7 +338,7 @@
  66. save_area.line_size = linesize;
  67. NO_SPACE(save_area.line_data);
  68. memcpy(save_area.line_data, line, linesize);
  69. - if (fgetpos(f, &save_area.line_fpos) != 0)
  70. + if ((save_area.line_fpos = ftell(f)) == -1)
  71. on_error();
  72. must_save = -must_save;
  73. }
  74. @@ -572,6 +572,36 @@
  75. return strcmp(p->name, q->name);
  76. }
  77. +/*
  78. + * Compare keyword to cached token, treating '_' and '-' the same. Some
  79. + * grammars rely upon this misfeature.
  80. + */
  81. +static int
  82. +matchec(const char *name)
  83. +{
  84. + const char *p = cache;
  85. + const char *q = name;
  86. + int code = 0; /* assume mismatch */
  87. +
  88. + while (*p != '\0' && *q != '\0')
  89. + {
  90. + char a = *p++;
  91. + char b = *q++;
  92. + if (a == '_')
  93. + a = '-';
  94. + if (b == '_')
  95. + b = '-';
  96. + if (a != b)
  97. + break;
  98. + if (*p == '\0' && *q == '\0')
  99. + {
  100. + code = 1;
  101. + break;
  102. + }
  103. + }
  104. + return code;
  105. +}
  106. +
  107. static int
  108. keyword(void)
  109. {
  110. @@ -612,10 +642,36 @@
  111. }
  112. cachec(NUL);
  113. - if ((key = bsearch(cache, keywords,
  114. - sizeof(keywords) / sizeof(*key),
  115. - sizeof(*key), compare_keys)))
  116. - return key->token;
  117. + if (matchec("token") || matchec("term"))
  118. + return (TOKEN);
  119. + if (matchec("type"))
  120. + return (TYPE);
  121. + if (matchec("left"))
  122. + return (LEFT);
  123. + if (matchec("right"))
  124. + return (RIGHT);
  125. + if (matchec("nonassoc") || matchec("binary"))
  126. + return (NONASSOC);
  127. + if (matchec("start"))
  128. + return (START);
  129. + if (matchec("union"))
  130. + return (UNION);
  131. + if (matchec("ident"))
  132. + return (IDENT);
  133. + if (matchec("expect"))
  134. + return (EXPECT);
  135. + if (matchec("expect-rr"))
  136. + return (EXPECT_RR);
  137. + if (matchec("pure-parser"))
  138. + return (PURE_PARSER);
  139. + if (matchec("parse-param"))
  140. + return (PARSE_PARAM);
  141. + if (matchec("lex-param"))
  142. + return (LEX_PARAM);
  143. + if (matchec("token-table"))
  144. + return (TOKEN_TABLE);
  145. + if (matchec("yacc"))
  146. + return (POSIX_YACC);
  147. }
  148. else
  149. {
  150. @@ -1178,6 +1234,9 @@
  151. return result;
  152. }
  153. +char *
  154. +strdup (char const *s);
  155. +
  156. static void
  157. save_param(int k, char *buffer, int name, int type2)
  158. {