Fixed portability problems with va_copy. In three places, calls to fstat

had to be replaced by calls to stat, because fileno is no longer available
when forcing the compiler into pure c89 (or c99) mode.


git-svn-id: svn://svn.cc65.org/cc65/trunk@3683 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2005-12-11 12:40:51 +00:00
parent 2d66b55b9d
commit 84706bd2d5
20 changed files with 87 additions and 58 deletions

View File

@@ -5,7 +5,7 @@
# Library dir # Library dir
COMMON = ../common COMMON = ../common
CFLAGS = -g -O2 -Wall -W -I$(COMMON) CFLAGS = -g -O2 -Wall -W -std=c89 -I$(COMMON)
CC = gcc CC = gcc
EBIND = emxbind EBIND = emxbind
LDFLAGS = LDFLAGS =
@@ -56,6 +56,6 @@ zap: clean
.PHONY: depend dep .PHONY: depend dep
depend dep: $(OBJS:.o=.c) depend dep: $(OBJS:.o=.c)
@echo "Creating dependency information" @echo "Creating dependency information"
$(CC) -I$(COMMON) -MM $^ > .depend $(CC) $(CFLAGS) -MM $^ > .depend

View File

@@ -164,8 +164,15 @@ void ObjAdd (const char* Name)
Error ("Could not open `%s': %s", Name, strerror (errno)); Error ("Could not open `%s': %s", Name, strerror (errno));
} }
/* Get the modification time of the object file */ /* Get the modification time of the object file. There a race condition
if (fstat (fileno (Obj), &StatBuf) != 0) { * here, since we cannot use fileno() (non standard identifier in standard
* header file), and therefore not fstat. When using stat with the
* file name, there's a risk that the file was deleted and recreated
* while it was open. Since mtime and size are only used to check
* if a file has changed in the debugger, we will ignore this problem
* here.
*/
if (stat (Name, &StatBuf) != 0) {
Error ("Cannot stat object file `%s': %s", Name, strerror (errno)); Error ("Cannot stat object file `%s': %s", Name, strerror (errno));
} }

View File

@@ -5,7 +5,7 @@
# Library dir # Library dir
COMMON = ../common COMMON = ../common
CFLAGS = -g -O2 -Wall -W -I$(COMMON) CFLAGS = -g -O2 -Wall -W -std=c89 -I$(COMMON)
CC = gcc CC = gcc
EBIND = emxbind EBIND = emxbind
LDFLAGS = LDFLAGS =
@@ -98,7 +98,7 @@ zap: clean
.PHONY: depend dep .PHONY: depend dep
depend dep: $(OBJS:.o=.c) depend dep: $(OBJS:.o=.c)
@echo "Creating dependency information" @echo "Creating dependency information"
$(CC) -I$(COMMON) -MM -MG $^ > .depend $(CC) $(CFLAGS) -MM -MG $^ > .depend
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Rules to make config includes # Rules to make config includes

View File

@@ -307,15 +307,12 @@ int IsIdStart (int C)
void NewInputFile (const char* Name) void NewInputFile (const char* Name)
/* Open a new input file */ /* Open a new input file */
{ {
InputFile* I; char* PathName = 0;
FILE* F;
/* First try to open the file */ /* First try to open the file */
F = fopen (Name, "r"); FILE* F = fopen (Name, "r");
if (F == 0) { if (F == 0) {
char* PathName;
/* Error (fatal error if this is the main file) */ /* Error (fatal error if this is the main file) */
if (ICount == 0) { if (ICount == 0) {
Fatal ("Cannot open input file `%s': %s", Name, strerror (errno)); Fatal ("Cannot open input file `%s': %s", Name, strerror (errno));
@@ -330,19 +327,26 @@ void NewInputFile (const char* Name)
Error ("Cannot open include file `%s': %s", Name, strerror (errno)); Error ("Cannot open include file `%s': %s", Name, strerror (errno));
} }
/* Free the allocated memory */ /* Use the path name from now on */
xfree (PathName); Name = PathName;
} }
/* check again if we do now have an open file */ /* check again if we do now have an open file */
if (F != 0) { if (F != 0) {
unsigned FileIdx; unsigned FileIdx;
InputFile* IF;
/* Stat the file and remember the values */ /* Stat the file and remember the values. There a race condition here,
* since we cannot use fileno() (non standard identifier in standard
* header file), and therefore not fstat. When using stat with the
* file name, there's a risk that the file was deleted and recreated
* while it was open. Since mtime and size are only used to check
* if a file has changed in the debugger, we will ignore this problem
* here.
*/
struct stat Buf; struct stat Buf;
if (fstat (fileno (F), &Buf) != 0) { if (stat (Name, &Buf) != 0) {
Fatal ("Cannot stat input file `%s': %s", Name, strerror (errno)); Fatal ("Cannot stat input file `%s': %s", Name, strerror (errno));
} }
@@ -350,18 +354,18 @@ void NewInputFile (const char* Name)
FileIdx = AddFile (Name, Buf.st_size, Buf.st_mtime); FileIdx = AddFile (Name, Buf.st_size, Buf.st_mtime);
/* Create a new state variable and initialize it */ /* Create a new state variable and initialize it */
I = xmalloc (sizeof (*I)); IF = xmalloc (sizeof (*IF));
I->F = F; IF->F = F;
I->Pos.Line = 0; IF->Pos.Line = 0;
I->Pos.Col = 0; IF->Pos.Col = 0;
I->Pos.Name = FileIdx; IF->Pos.Name = FileIdx;
I->Tok = Tok; IF->Tok = Tok;
I->C = C; IF->C = C;
I->Line[0] = '\0'; IF->Line[0] = '\0';
/* Use the new file */ /* Use the new file */
I->Next = IFile; IF->Next = IFile;
IFile = I; IFile = IF;
++ICount; ++ICount;
/* Read the first character from the new file */ /* Read the first character from the new file */
@@ -373,6 +377,9 @@ void NewInputFile (const char* Name)
Tok = TOK_SEP; Tok = TOK_SEP;
} }
/* Free an allocated name buffer */
xfree (PathName);
} }

View File

@@ -143,9 +143,16 @@ static AFile* NewAFile (IFile* IF, FILE* F)
*/ */
if (IF->Usage++ == 0) { if (IF->Usage++ == 0) {
/* Get file size and modification time */ /* Get file size and modification time. There a race condition here,
* since we cannot use fileno() (non standard identifier in standard
* header file), and therefore not fstat. When using stat with the
* file name, there's a risk that the file was deleted and recreated
* while it was open. Since mtime and size are only used to check
* if a file has changed in the debugger, we will ignore this problem
* here.
*/
struct stat Buf; struct stat Buf;
if (fstat (fileno (F), &Buf) != 0) { if (stat (IF->Name, &Buf) != 0) {
/* Error */ /* Error */
Fatal ("Cannot stat `%s': %s", IF->Name, strerror (errno)); Fatal ("Cannot stat `%s': %s", IF->Name, strerror (errno));
} }

View File

@@ -17,7 +17,7 @@ COMMON = ../common
CC65_INC = \"/usr/lib/cc65/include/\" CC65_INC = \"/usr/lib/cc65/include/\"
# #
CFLAGS = -O2 -g -Wall -W -I$(COMMON) -DCC65_INC=$(CC65_INC) CFLAGS = -O2 -g -Wall -W -std=c89 -I$(COMMON) -DCC65_INC=$(CC65_INC)
CC=gcc CC=gcc
EBIND=emxbind EBIND=emxbind
LDFLAGS=-lm LDFLAGS=-lm

View File

@@ -672,8 +672,9 @@ static void MacroCall (StrBuf* Target, Macro* M)
static void ExpandMacro (StrBuf* Target, Macro* M) static void ExpandMacro (StrBuf* Target, Macro* M)
/* Expand a macro into Target */ /* Expand a macro into Target */
{ {
/* ### printf ("Expanding %s(%u)\n", M->Name, ++V); */
/* Check if this is a function like macro */ /* Check if this is a function like macro */
//printf ("Expanding %s(%u)\n", M->Name, ++V);
if (M->ArgCount >= 0) { if (M->ArgCount >= 0) {
int Whitespace = IsSpace (CurC); int Whitespace = IsSpace (CurC);
@@ -710,7 +711,7 @@ static void ExpandMacro (StrBuf* Target, Macro* M)
DoneMacroExp (&E); DoneMacroExp (&E);
} }
//printf ("Done with %s(%u)\n", M->Name, V--); /* ### printf ("Done with %s(%u)\n", M->Name, V--); */
} }
@@ -827,7 +828,7 @@ static void DefineMacro (void)
SB_Drop (&M->Replacement, 1); SB_Drop (&M->Replacement, 1);
} }
//printf ("%s: <%.*s>\n", M->Name, SB_GetLen (&M->Replacement), SB_GetConstBuf (&M->Replacement)); /* ### printf ("%s: <%.*s>\n", M->Name, SB_GetLen (&M->Replacement), SB_GetConstBuf (&M->Replacement)); */
/* If we have an existing macro, check if the redefinition is identical. /* If we have an existing macro, check if the redefinition is identical.
* Print a diagnostic if not. * Print a diagnostic if not.

View File

@@ -13,7 +13,7 @@ endif
CC=gcc CC=gcc
CFLAGS = -O2 -g -Wall -W -I$(COMMON) -D$(SPAWN) CFLAGS = -O2 -g -Wall -W -std=c89 -I$(COMMON) -D$(SPAWN)
EBIND = emxbind EBIND = emxbind
LDFLAGS= LDFLAGS=
@@ -53,7 +53,7 @@ zap: clean
.PHONY: depend dep .PHONY: depend dep
depend dep: $(OBJS:.o=.c) depend dep: $(OBJS:.o=.c)
@echo "Creating dependency information" @echo "Creating dependency information"
$(CC) -I$(COMMON) -D$(SPAWN) -MM $^ > .depend $(CC) $(CFLAGS) -D$(SPAWN) -MM $^ > .depend

View File

@@ -5,7 +5,7 @@
# Library dir # Library dir
COMMON = ../common COMMON = ../common
CFLAGS = -g -O2 -Wall -W -I$(COMMON) CFLAGS = -g -O2 -Wall -W -std=c89 -I$(COMMON)
CC = gcc CC = gcc
EBIND = emxbind EBIND = emxbind
LDFLAGS = LDFLAGS =
@@ -49,6 +49,6 @@ zap: clean
.PHONY: depend dep .PHONY: depend dep
depend dep: $(OBJS:.o=.c) depend dep: $(OBJS:.o=.c)
@echo "Creating dependency information" @echo "Creating dependency information"
$(CC) -I$(COMMON) -MM $^ > .depend $(CC) $(CFLAGS) -MM $^ > .depend

View File

@@ -2,7 +2,7 @@
# gcc Makefile for the binutils common stuff # gcc Makefile for the binutils common stuff
# #
CFLAGS = -g -O2 -Wall -W CFLAGS = -g -O2 -Wall -W -std=c89
CC = gcc CC = gcc
LDFLAGS = LDFLAGS =
LIB = common.a LIB = common.a
@@ -72,6 +72,6 @@ zap: clean
.PHONY: depend dep .PHONY: depend dep
depend dep: $(OBJS:.o=.c) depend dep: $(OBJS:.o=.c)
@echo "Creating dependency information" @echo "Creating dependency information"
$(CC) -MM $^ > .depend $(CC) $(CFLAGS) -MM $^ > .depend

View File

@@ -38,18 +38,27 @@
/* No action if we're using a C99 compiler */
#if (__STDC_VERSION__ < 199901)
/* The watcom compiler doesn't have va_copy and a problematic va_list definition */ /* The watcom compiler doesn't have va_copy and a problematic va_list definition */
#if defined(__WATCOMC__) #if defined(__WATCOMC__)
#define va_copy(dest,src) memcpy((dest), (src), sizeof (va_list)) #define va_copy(dest,src) memcpy((dest), (src), sizeof (va_list))
#endif #endif
/* GNU C before version 3 has its own name */ /* GNU C has a builtin function */
#if defined(__GNUC__) && (__GNUC__ == 2) #if defined(__GNUC__)
#define va_copy(dest,src) __va_copy(dest, src) #define va_copy(dest,src) __va_copy(dest, src)
#endif #endif
#endif /* #if (__STDC_VERSION__ < 199901) */
/* End of va_copy.h */ /* End of va_copy.h */
#endif #endif

View File

@@ -5,7 +5,7 @@
# Library dir # Library dir
COMMON = ../common COMMON = ../common
CFLAGS = -g -O2 -Wall -W -I$(COMMON) CFLAGS = -g -O2 -Wall -W -std=c89 -I$(COMMON)
CC=gcc CC=gcc
EBIND=emxbind EBIND=emxbind
LDFLAGS= LDFLAGS=
@@ -60,6 +60,6 @@ zap: clean
.PHONY: depend dep .PHONY: depend dep
depend dep: $(OBJS:.o=.c) depend dep: $(OBJS:.o=.c)
@echo "Creating dependency information" @echo "Creating dependency information"
$(CC) -I$(COMMON) -MM $^ > .depend $(CC) $(CFLAGS) -MM $^ > .depend

View File

@@ -28,7 +28,6 @@
#include "grc.h" #include "grc.h"
/* common stuff */ /* common stuff */
//#include "cmdline.h"
#include "fname.h" #include "fname.h"
#include "abend.h" #include "abend.h"
#include "chartype.h" #include "chartype.h"
@@ -261,7 +260,6 @@ int a;
} }
} }
//char *bintos(unsigned char a, char *out) {
char *bintos(unsigned char a, char out[7]) { char *bintos(unsigned char a, char out[7]) {
int i=0; int i=0;
for (;i<8;i++) { for (;i<8;i++) {

View File

@@ -66,7 +66,7 @@ const unsigned char icon1[] = {
128, 0, 1, 128, 0, 1, 128, 0, 1, 128, 0, 1, 128, 0, 1, 128, 0, 1, 128, 0, 1, 128, 0, 1, 128, 0, 1, 128, 0, 1,
128, 0, 1, 128, 0, 1, 128, 0, 1, 128, 0, 1, 255, 255, 255 }; 128, 0, 1, 128, 0, 1, 128, 0, 1, 128, 0, 1, 255, 255, 255 };
char *ProgName; // for AbEnd, later remove and use common/cmdline.h char *ProgName; /* for AbEnd, later remove and use common/cmdline.h */
char *outputCName=NULL, *outputSName=NULL, *outputVName=NULL; char *outputCName=NULL, *outputSName=NULL, *outputVName=NULL;
FILE *outputCFile, *outputSFile, *outputVFile; FILE *outputCFile, *outputSFile, *outputVFile;

View File

@@ -4,7 +4,7 @@
COMMON = ../common COMMON = ../common
CFLAGS = -g -O2 -Wall -W -I$(COMMON) CFLAGS = -g -O2 -Wall -W -std=c89 -I$(COMMON)
CC = gcc CC = gcc
LDFLAGS = LDFLAGS =
EBIND = emxbind EBIND = emxbind
@@ -42,6 +42,6 @@ zap: clean
.PHONY: depend dep .PHONY: depend dep
depend dep: $(OBJS:.o=.c) depend dep: $(OBJS:.o=.c)
@echo "Creating dependency information" @echo "Creating dependency information"
$(CC) -I$(COMMON) -MM $^ > .depend $(CC) $(CFLAGS) -MM $^ > .depend

View File

@@ -10,7 +10,7 @@ COMMON = ../common
CC65_LIB = \"/usr/lib/cc65/lib/\" CC65_LIB = \"/usr/lib/cc65/lib/\"
# #
CFLAGS = -g -O2 -Wall -W -I$(COMMON) -DCC65_LIB=$(CC65_LIB) CFLAGS = -g -O2 -Wall -W -std=c89 -I$(COMMON) -DCC65_LIB=$(CC65_LIB)
CC=gcc CC=gcc
EBIND=emxbind EBIND=emxbind
LDFLAGS= LDFLAGS=
@@ -113,7 +113,7 @@ zap: clean
.PHONY: depend dep .PHONY: depend dep
depend dep: $(OBJS:.o=.c) depend dep: $(OBJS:.o=.c)
@echo "Creating dependency information" @echo "Creating dependency information"
$(CC) -I$(COMMON) -MM -MG $^ > .depend $(CC) $(CFLAGS) -MM -MG $^ > .depend
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Rules to make config includes # Rules to make config includes

View File

@@ -2,7 +2,7 @@
# gcc Makefile for the program sources # gcc Makefile for the program sources
# #
CFLAGS = -g -O2 -Wall CFLAGS = -g -O2 -Wall -std=c89
CC = gcc CC = gcc
LDFLAGS = LDFLAGS =

View File

@@ -6,7 +6,7 @@
# Library dir # Library dir
COMMON = ../common COMMON = ../common
CFLAGS = -O2 -g -Wall -W -I$(COMMON) CFLAGS = -O2 -g -Wall -W -std=c89 -I$(COMMON)
CC=gcc CC=gcc
EBIND=emxbind EBIND=emxbind
LDFLAGS= LDFLAGS=
@@ -48,7 +48,7 @@ zap: clean
.PHONY: depend dep .PHONY: depend dep
depend dep: $(OBJS:.o=.c) depend dep: $(OBJS:.o=.c)
@echo "Creating dependency information" @echo "Creating dependency information"
$(CC) -I$(COMMON) -MM $^ > .depend $(CC) $(CFLAGS) -MM $^ > .depend

View File

@@ -6,7 +6,7 @@
COMMON = ../../common COMMON = ../../common
SIM65 = .. SIM65 = ..
CFLAGS = -g -O2 -Wall -W -I$(COMMON) -I$(SIM65) -fpic CFLAGS = -g -O2 -Wall -W -std=c89 -I$(COMMON) -I$(SIM65) -fpic
CC = gcc CC = gcc
EBIND = emxbind EBIND = emxbind
LDFLAGS = LDFLAGS =
@@ -56,6 +56,6 @@ zap: clean
.PHONY: depend dep .PHONY: depend dep
depend dep: $(CHIPS:.so=.c) depend dep: $(CHIPS:.so=.c)
@echo "Creating dependency information" @echo "Creating dependency information"
$(CC) -I$(COMMON) -I$(SIM65) -MM $^ > .depend $(CC) $(CFLAGS) -MM $^ > .depend

View File

@@ -5,7 +5,7 @@
# Library dir # Library dir
COMMON = ../common COMMON = ../common
CFLAGS = -g -O2 -Wall -W -I$(COMMON) CFLAGS = -g -O2 -Wall -W -std=c89 -I$(COMMON)
CC = gcc CC = gcc
EBIND = emxbind EBIND = emxbind
LDFLAGS = LDFLAGS =
@@ -63,6 +63,6 @@ zap: clean
.PHONY: depend dep .PHONY: depend dep
depend dep: $(OBJS:.o=.c) depend dep: $(OBJS:.o=.c)
@echo "Creating dependency information" @echo "Creating dependency information"
$(CC) -I$(COMMON) -MM $^ > .depend $(CC) $(CFLAGS) -MM $^ > .depend