1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-09 22:29:35 +00:00

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

View File

@ -142,7 +142,7 @@ void ObjWriteHeader (FILE* Obj, ObjHeader* H)
Write32 (Obj, H->StrPoolOffs);
Write32 (Obj, H->StrPoolSize);
Write32 (Obj, H->AssertOffs);
Write32 (Obj, H->AssertSize);
Write32 (Obj, H->AssertSize);
Write32 (Obj, H->ScopeOffs);
Write32 (Obj, H->ScopeSize);
}
@ -164,8 +164,15 @@ void ObjAdd (const char* Name)
Error ("Could not open `%s': %s", Name, strerror (errno));
}
/* Get the modification time of the object file */
if (fstat (fileno (Obj), &StatBuf) != 0) {
/* Get the modification time of the object file. 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.
*/
if (stat (Name, &StatBuf) != 0) {
Error ("Cannot stat object file `%s': %s", Name, strerror (errno));
}

View File

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

View File

@ -307,15 +307,12 @@ int IsIdStart (int C)
void NewInputFile (const char* Name)
/* Open a new input file */
{
InputFile* I;
FILE* F;
char* PathName = 0;
/* First try to open the file */
F = fopen (Name, "r");
FILE* F = fopen (Name, "r");
if (F == 0) {
char* PathName;
/* Error (fatal error if this is the main file) */
if (ICount == 0) {
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));
}
/* Free the allocated memory */
xfree (PathName);
/* Use the path name from now on */
Name = PathName;
}
/* check again if we do now have an open file */
if (F != 0) {
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;
if (fstat (fileno (F), &Buf) != 0) {
if (stat (Name, &Buf) != 0) {
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);
/* Create a new state variable and initialize it */
I = xmalloc (sizeof (*I));
I->F = F;
I->Pos.Line = 0;
I->Pos.Col = 0;
I->Pos.Name = FileIdx;
I->Tok = Tok;
I->C = C;
I->Line[0] = '\0';
IF = xmalloc (sizeof (*IF));
IF->F = F;
IF->Pos.Line = 0;
IF->Pos.Col = 0;
IF->Pos.Name = FileIdx;
IF->Tok = Tok;
IF->C = C;
IF->Line[0] = '\0';
/* Use the new file */
I->Next = IFile;
IFile = I;
IF->Next = IFile;
IFile = IF;
++ICount;
/* Read the first character from the new file */
@ -373,6 +377,9 @@ void NewInputFile (const char* Name)
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) {
/* 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;
if (fstat (fileno (F), &Buf) != 0) {
if (stat (IF->Name, &Buf) != 0) {
/* Error */
Fatal ("Cannot stat `%s': %s", IF->Name, strerror (errno));
}

View File

@ -17,7 +17,7 @@ COMMON = ../common
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
EBIND=emxbind
LDFLAGS=-lm

View File

@ -672,8 +672,9 @@ static void MacroCall (StrBuf* Target, Macro* M)
static void ExpandMacro (StrBuf* Target, Macro* M)
/* Expand a macro into Target */
{
/* ### printf ("Expanding %s(%u)\n", M->Name, ++V); */
/* Check if this is a function like macro */
//printf ("Expanding %s(%u)\n", M->Name, ++V);
if (M->ArgCount >= 0) {
int Whitespace = IsSpace (CurC);
@ -710,7 +711,7 @@ static void ExpandMacro (StrBuf* Target, Macro* M)
DoneMacroExp (&E);
}
//printf ("Done with %s(%u)\n", M->Name, V--);
/* ### printf ("Done with %s(%u)\n", M->Name, V--); */
}
@ -770,7 +771,7 @@ static void DefineMacro (void)
NextChar ();
NextChar ();
/* Remember that the macro is variadic and use __VA_ARGS__ as
/* Remember that the macro is variadic and use __VA_ARGS__ as
* the argument name.
*/
AddMacroArg (M, "__VA_ARGS__");
@ -827,7 +828,7 @@ static void DefineMacro (void)
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.
* Print a diagnostic if not.

View File

@ -13,7 +13,7 @@ endif
CC=gcc
CFLAGS = -O2 -g -Wall -W -I$(COMMON) -D$(SPAWN)
CFLAGS = -O2 -g -Wall -W -std=c89 -I$(COMMON) -D$(SPAWN)
EBIND = emxbind
LDFLAGS=
@ -53,7 +53,7 @@ zap: clean
.PHONY: depend dep
depend dep: $(OBJS:.o=.c)
@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
COMMON = ../common
CFLAGS = -g -O2 -Wall -W -I$(COMMON)
CFLAGS = -g -O2 -Wall -W -std=c89 -I$(COMMON)
CC = gcc
EBIND = emxbind
LDFLAGS =
@ -49,6 +49,6 @@ zap: clean
.PHONY: depend dep
depend dep: $(OBJS:.o=.c)
@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
#
CFLAGS = -g -O2 -Wall -W
CFLAGS = -g -O2 -Wall -W -std=c89
CC = gcc
LDFLAGS =
LIB = common.a
@ -72,6 +72,6 @@ zap: clean
.PHONY: depend dep
depend dep: $(OBJS:.o=.c)
@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 */
#if defined(__WATCOMC__)
#define va_copy(dest,src) memcpy((dest), (src), sizeof (va_list))
#endif
/* GNU C before version 3 has its own name */
#if defined(__GNUC__) && (__GNUC__ == 2)
/* GNU C has a builtin function */
#if defined(__GNUC__)
#define va_copy(dest,src) __va_copy(dest, src)
#endif
#endif /* #if (__STDC_VERSION__ < 199901) */
/* End of va_copy.h */
#endif

View File

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

View File

@ -28,7 +28,6 @@
#include "grc.h"
/* common stuff */
//#include "cmdline.h"
#include "fname.h"
#include "abend.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]) {
int i=0;
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, 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;
FILE *outputCFile, *outputSFile, *outputVFile;

View File

@ -4,7 +4,7 @@
COMMON = ../common
CFLAGS = -g -O2 -Wall -W -I$(COMMON)
CFLAGS = -g -O2 -Wall -W -std=c89 -I$(COMMON)
CC = gcc
LDFLAGS =
EBIND = emxbind
@ -42,6 +42,6 @@ zap: clean
.PHONY: depend dep
depend dep: $(OBJS:.o=.c)
@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/\"
#
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
EBIND=emxbind
LDFLAGS=
@ -113,7 +113,7 @@ zap: clean
.PHONY: depend dep
depend dep: $(OBJS:.o=.c)
@echo "Creating dependency information"
$(CC) -I$(COMMON) -MM -MG $^ > .depend
$(CC) $(CFLAGS) -MM -MG $^ > .depend
# -----------------------------------------------------------------------------
# Rules to make config includes

View File

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

View File

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

View File

@ -6,7 +6,7 @@
COMMON = ../../common
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
EBIND = emxbind
LDFLAGS =
@ -56,6 +56,6 @@ zap: clean
.PHONY: depend dep
depend dep: $(CHIPS:.so=.c)
@echo "Creating dependency information"
$(CC) -I$(COMMON) -I$(SIM65) -MM $^ > .depend
$(CC) $(CFLAGS) -MM $^ > .depend

View File

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