shithub: rgbds

Download patch

ref: 4dfa3157e568137e71b4351f16fb7fc0927d740e
parent: f26cfa2d94171225a912ec6b8e067f960b071965
parent: d93ad2e650282ddc211aedb28fe0bc10aec2f23b
author: Eldred Habert <[email protected]>
date: Wed Jan 8 08:14:13 EST 2020

Merge pull request #454 from ISSOtm/unlocked_windows

Fix mingw build

--- a/include/extern/getopt.h
+++ b/include/extern/getopt.h
@@ -36,7 +36,7 @@
 	int val;
 };
 
-int getopt_long_only(int, char **, const char *, const struct option *, int *);
+int musl_getopt_long_only(int, char **, const char *, const struct option *, int *);
 
 #define no_argument        0
 #define required_argument  1
--- a/src/asm/main.c
+++ b/src/asm/main.c
@@ -324,8 +324,8 @@
 
 	newopt = CurrentOptions;
 
-	while ((ch = getopt_long_only(argc, argv, optstring, longopts,
-				      NULL)) != -1) {
+	while ((ch = musl_getopt_long_only(argc, argv, optstring, longopts,
+					   NULL)) != -1) {
 		switch (ch) {
 		case 'b':
 			if (strlen(optarg) == 2) {
--- a/src/extern/getopt.c
+++ b/src/extern/getopt.c
@@ -33,7 +33,7 @@
 
 int __optpos, __optreset;
 
-void __getopt_msg(const char *a, const char *b, const char *c, size_t l)
+void musl__getopt_msg(const char *a, const char *b, const char *c, size_t l)
 {
 	FILE *f = stderr;
 	(void)(fputs(a, f)>=0
@@ -52,9 +52,9 @@
 	av[dest] = tmp;
 }
 
-static int __getopt_long_core(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly);
+static int musl__getopt_long_core(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly);
 
-static int __getopt_long(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
+static int musl__getopt_long(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
 {
 	int ret, skipped, resumed;
 	if (!optind || __optreset) {
@@ -73,7 +73,7 @@
 		optind = i;
 	}
 	resumed = optind;
-	ret = __getopt_long_core(argc, argv, optstring, longopts, idx, longonly);
+	ret = musl__getopt_long_core(argc, argv, optstring, longopts, idx, longonly);
 	if (resumed > skipped) {
 		int i, cnt = optind-resumed;
 		for (i=0; i<cnt; i++)
@@ -83,7 +83,7 @@
 	return ret;
 }
 
-static int __getopt_long_core(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
+static int musl__getopt_long_core(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
 {
 	optarg = 0;
 	if (longopts && argv[optind][0] == '-' &&
@@ -128,7 +128,7 @@
 					optopt = longopts[i].val;
 					if (colon || !opterr)
 						return '?';
-					__getopt_msg(argv[0],
+					musl__getopt_msg(argv[0],
 						": option does not take an argument: ",
 						longopts[i].name,
 						strlen(longopts[i].name));
@@ -140,7 +140,7 @@
 					optopt = longopts[i].val;
 					if (colon) return ':';
 					if (!opterr) return '?';
-					__getopt_msg(argv[0],
+					musl__getopt_msg(argv[0],
 						": option requires an argument: ",
 						longopts[i].name,
 						strlen(longopts[i].name));
@@ -158,7 +158,7 @@
 		if (argv[optind][1] == '-') {
 			optopt = 0;
 			if (!colon && opterr)
-				__getopt_msg(argv[0], cnt ?
+				musl__getopt_msg(argv[0], cnt ?
 					": option is ambiguous: " :
 					": unrecognized option: ",
 					argv[optind]+2,
@@ -170,7 +170,7 @@
 	return getopt(argc, argv, optstring);
 }
 
-int getopt_long_only(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx)
+int musl_getopt_long_only(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx)
 {
-	return __getopt_long(argc, argv, optstring, longopts, idx, 1);
+	return musl__getopt_long(argc, argv, optstring, longopts, idx, 1);
 }
--- a/src/fix/main.c
+++ b/src/fix/main.c
@@ -108,8 +108,8 @@
 	int version = 0;   /* mask ROM version number */
 	int padvalue = 0;  /* to pad the rom with if it changes size */
 
-	while ((ch = getopt_long_only(argc, argv, optstring, longopts,
-				      NULL)) != -1) {
+	while ((ch = musl_getopt_long_only(argc, argv, optstring, longopts,
+					   NULL)) != -1) {
 		switch (ch) {
 		case 'C':
 			coloronly = true;
--- a/src/gfx/main.c
+++ b/src/gfx/main.c
@@ -87,8 +87,8 @@
 
 	depth = 2;
 
-	while ((ch = getopt_long_only(argc, argv, optstring, longopts,
-				      NULL)) != -1) {
+	while ((ch = musl_getopt_long_only(argc, argv, optstring, longopts,
+					   NULL)) != -1) {
 		switch (ch) {
 		case 'A':
 			opts.attrmapout = true;
--- a/src/link/main.c
+++ b/src/link/main.c
@@ -114,8 +114,8 @@
 	unsigned long value; /* For storing `strtoul`'s return value */
 
 	/* Parse options */
-	while ((optionChar = getopt_long_only(argc, argv, optstring, longopts,
-					      NULL)) != -1) {
+	while ((optionChar = musl_getopt_long_only(argc, argv, optstring,
+						   longopts, NULL)) != -1) {
 		switch (optionChar) {
 		case 'd':
 			isDmgMode = true;
--- a/src/link/output.c
+++ b/src/link/output.c
@@ -150,9 +150,8 @@
 
 		/* Output padding up to the next SECTION */
 		while (offset + baseOffset < section->org) {
-			putc_unlocked(overlayFile ? getc_unlocked(overlayFile)
-						  : padValue,
-				      outputFile);
+			putc(overlayFile ? getc(overlayFile) : padValue,
+			     outputFile);
 			offset++;
 		}
 
@@ -162,7 +161,7 @@
 		if (overlayFile) {
 			/* Skip bytes even with pipes */
 			for (uint16_t i = 0; i < section->size; i++)
-				getc_unlocked(overlayFile);
+				getc(overlayFile);
 		}
 		offset += section->size;
 
@@ -170,9 +169,7 @@
 	}
 
 	while (offset < size) {
-		putc_unlocked(overlayFile ? getc_unlocked(overlayFile)
-					  : padValue,
-			      outputFile);
+		putc(overlayFile ? getc(overlayFile) : padValue, outputFile);
 		offset++;
 	}
 }
@@ -188,10 +185,6 @@
 	checkOverlay();
 
 	if (outputFile) {
-		flockfile(outputFile);
-		if (overlayFile)
-			flockfile(overlayFile);
-
 		if (sections[SECTTYPE_ROM0].nbBanks > 0)
 			writeBank(sections[SECTTYPE_ROM0].banks[0].sections,
 				  0x0000, 0x4000);
@@ -199,10 +192,6 @@
 		for (uint32_t i = 0 ; i < sections[SECTTYPE_ROMX].nbBanks; i++)
 			writeBank(sections[SECTTYPE_ROMX].banks[i].sections,
 				  0x4000, 0x4000);
-
-		if (overlayFile)
-			funlockfile(overlayFile);
-		funlockfile(outputFile);
 	}
 
 	closeFile(outputFile);
--- a/src/link/script.c
+++ b/src/link/script.c
@@ -164,7 +164,7 @@
 
 static int readChar(FILE *file)
 {
-	int curchar = getc_unlocked(file);
+	int curchar = getc(file);
 
 	if (curchar == EOF && ferror(file))
 		err(1, "%s(%u): Unexpected error in %s", linkerScriptName,