File: 0001-Add-fix-to-use-with-GCC-15.patch

package info (click to toggle)
bcal 2.4-2.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 288 kB
  • sloc: ansic: 1,845; python: 170; makefile: 43; sh: 5
file content (228 lines) | stat: -rw-r--r-- 5,376 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
From 936213c00ec1d8ac086b6a722a4144413bf9c838 Mon Sep 17 00:00:00 2001
From: Robert-André Mauchin <zebob.m@gmail.com>
Date: Sat, 25 Jan 2025 16:36:43 +0100
Subject: Add fix to use with GCC 15

C23 added various new keywords, including bool, true, false, nullptr, and thread_local. Code that uses these for identifiers
need changing.

In C99 and later we can use #include <stdbool.h> which provides definitions of bool, true, and false compatible with C23.

https://gcc.gnu.org/gcc-15/porting_to.html
---
 src/bcal.c | 55 ++++++++++++++++++++++++++----------------------------
 1 file changed, 26 insertions(+), 29 deletions(-)

diff --git a/src/bcal.c b/src/bcal.c
index fd75a7c..ec11139 100644
--- a/src/bcal.c
+++ b/src/bcal.c
@@ -20,6 +20,7 @@
 
 #include <ctype.h>
 #include <errno.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
@@ -31,9 +32,6 @@
 #include "dslib.h"
 #include "log.h"
 
-#define TRUE 1
-#define FALSE !TRUE
-
 #define SECTOR_SIZE 512 /* 0x200 */
 #define MAX_HEAD 16 /* 0x10 */
 #define MAX_SECTOR 63 /* 0x3f */
@@ -44,7 +42,6 @@
 #define MAX_BITS 128
 #define ALIGNMENT_MASK_4BIT 0xF
 
-typedef unsigned char bool;
 typedef unsigned char uchar;
 typedef unsigned int uint;
 typedef unsigned long ulong;
@@ -172,8 +169,8 @@ static size_t bstrlcpy(char *dest, const char *src, size_t n)
 static bool program_exit(const char *str)
 {
 	if (!strcmp(str, "exit") || !strcmp(str, "quit"))
-		return TRUE;
-	return FALSE;
+		return true;
+	return false;
 }
 
 /*
@@ -439,31 +436,31 @@ static bool ischarvalid(char ch, uint base, uint *val)
 	{
 		if (ch == '0' || ch == '1') {
 			*val = ch - '0';
-			return TRUE;
+			return true;
 		}
 	} else if (base == 16) {
 		if (ch >= '0' && ch <= '9') {
 			*val = ch - '0';
-			return TRUE;
+			return true;
 		}
 
 		if (ch >= 'a' && ch <= 'f') {
 			*val = (ch - 'a') + 10;
-			return TRUE;
+			return true;
 		}
 
 		if (ch >= 'A' && ch <= 'F') {
 			*val = (ch - 'A') + 10;
-			return TRUE;
+			return true;
 		}
 	} else if (base == 10) {
 		if (ch >= '0' && ch <= '9') {
 			*val = ch - '0';
-			return TRUE;
+			return true;
 		}
 	}
 
-	return FALSE;
+	return false;
 }
 
 /*
@@ -1027,32 +1024,32 @@ static bool chs2lba(char *chs, maxuint_t *lba)
 	/* Fail if CHS is omitted */
 	if (token_no < 3) {
 		log(ERROR, "CHS missing\n");
-		return FALSE;
+		return false;
 	}
 
 	if (!param[3]) {
 		log(ERROR, "MAX_HEAD = 0\n");
-		return FALSE;
+		return false;
 	}
 
 	if (!param[4]) {
 		log(ERROR, "MAX_SECTOR = 0\n");
-		return FALSE;
+		return false;
 	}
 
 	if (!param[2]) {
 		log(ERROR, "S = 0\n");
-		return FALSE;
+		return false;
 	}
 
 	if (param[1] > param[3]) {
 		log(ERROR, "H > MAX_HEAD\n");
-		return FALSE;
+		return false;
 	}
 
 	if (param[2] > param[4]) {
 		log(ERROR, "S > MAX_SECTOR\n");
-		return FALSE;
+		return false;
 	}
 
 	*lba = (maxuint_t)param[3] * param[4] * param[0]; /* MH * MS * C */
@@ -1064,7 +1061,7 @@ static bool chs2lba(char *chs, maxuint_t *lba)
 	printf("  C:%lu  H:%lu  S:%lu  MAX_HEAD:%lu  MAX_SECTOR:%lu\n",
 		param[0], param[1], param[2], param[3], param[4]);
 
-	return TRUE;
+	return true;
 }
 
 static bool lba2chs(char *lba, t_chs *p_chs)
@@ -1103,17 +1100,17 @@ static bool lba2chs(char *lba, t_chs *p_chs)
 	/* Fail if LBA is omitted */
 	if (!token_no) {
 		log(ERROR, "LBA missing\n");
-		return FALSE;
+		return false;
 	}
 
 	if (!param[1]) {
 		log(ERROR, "MAX_HEAD = 0\n");
-		return FALSE;
+		return false;
 	}
 
 	if (!param[2]) {
 		log(ERROR, "MAX_SECTOR = 0\n");
-		return FALSE;
+		return false;
 	}
 
 	/* L / (MS * MH) */
@@ -1122,14 +1119,14 @@ static bool lba2chs(char *lba, t_chs *p_chs)
 	p_chs->h = (ulong)((param[0] / param[2]) % param[1]);
 	if (p_chs->h > MAX_HEAD) {
 		log(ERROR, "H > MAX_HEAD\n");
-		return FALSE;
+		return false;
 	}
 
 	/* (L % MS) + 1 */
 	p_chs->s = (ulong)((param[0] % param[2]) + 1);
 	if (p_chs->s > MAX_SECTOR) {
 		log(ERROR, "S > MAX_SECTOR\n");
-		return FALSE;
+		return false;
 	}
 
 	printf("\033[1mLBA2CHS\033[0m\n  LBA:%s  ",
@@ -1137,7 +1134,7 @@ static bool lba2chs(char *lba, t_chs *p_chs)
 	printf("MAX_HEAD:%s  ", getstr_u128(param[1], uint_buf));
 	printf("MAX_SECTOR:%s\n", getstr_u128(param[2], uint_buf));
 
-	return TRUE;
+	return true;
 }
 
 static void show_basic_sizes()
@@ -1318,7 +1315,7 @@ static int infix2postfix(char *exp, queue **resf, queue **resr)
 	char *token = strtok(exp, " ");
 	static Data tokenData, ct;
 	int balanced = 0;
-	bool tokenize = TRUE;
+	bool tokenize = true;
 
 	tokenData.p[0] = '\0';
 	tokenData.unit = 0;
@@ -1391,7 +1388,7 @@ static int infix2postfix(char *exp, queue **resf, queue **resr)
 				tokenData.unit = 1;
 				log(DEBUG, "unit found\n");
 			} else
-				tokenize = FALSE; /* We already toknized here */
+				tokenize = false; /* We already toknized here */
 
 			/* Enqueue operands */
 			log(DEBUG, "tokenData: %s %d\n", tokenData.p, tokenData.unit);
@@ -1403,7 +1400,7 @@ static int infix2postfix(char *exp, queue **resf, queue **resr)
 		if (tokenize)
 			token = strtok(NULL, " ");
 		else
-			tokenize = TRUE;
+			tokenize = true;
 
 		log(DEBUG, "token: %s\n", token);
 	}
@@ -2062,7 +2059,7 @@ int main(int argc, char **argv)
 	ulong sectorsz = SECTOR_SIZE;
 
 	if (getenv("BCAL_USE_CALC"))
-		cfg.calc = TRUE;
+		cfg.calc = true;
 
 	opterr = 0;
 	rl_bind_key('\t', rl_insert);
-- 
2.30.2