From 22950ba3df3a0b739786243679d69cd4094e8b20 Mon Sep 17 00:00:00 2001 From: Robert de Bath Date: Sat, 20 Sep 2003 19:44:36 +0200 Subject: Import Dev86src-0.16.13.tar.gz --- ar/Makefile | 8 ++++---- ar/alloca.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ar/ar.c | 4 ++-- 3 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 ar/alloca.c (limited to 'ar') diff --git a/ar/Makefile b/ar/Makefile index 792a77a..490a1f6 100644 --- a/ar/Makefile +++ b/ar/Makefile @@ -6,12 +6,12 @@ LIBDIR =/usr/bin CFLAGS =-O LDFLAGS = DEFS = -OBJS= ar.o +OBJS= ar.o alloca.o all: ar86 ar86: $(OBJS) - $(CC) $(LDFLAGS) $^ -o $@ + $(CC) $(LDFLAGS) $(OBJS) -o $@ install: ar86 install -d $(LIBDIR) @@ -23,12 +23,12 @@ clean realclean clobber: $(OBJS): ar.h rel_aout.h ar.h: - [ -f ar.h ] || \ + test -f ar.h || \ { rm -f ar.h ; ln -s ../libc/include/ar.h . ; } || \ ln ../libc/include/ar.h . rel_aout.h: - [ -f rel_aout.h ] || \ + test -f rel_aout.h || \ { rm -f rel_aout.h ; ln -s ../ld/rel_aout.h . ; } || \ ln ../ld/rel_aout.h . diff --git a/ar/alloca.c b/ar/alloca.c new file mode 100644 index 0000000..880c100 --- /dev/null +++ b/ar/alloca.c @@ -0,0 +1,61 @@ + +#ifdef __STDC__ +#include +#else +#include +#include +#endif + +#ifdef __TINYC__ +typedef union mem_cell +{ + union mem_cell *next; /* A pointer to the next mem */ + unsigned int size; /* An int >= sizeof pointer */ + char *depth; /* For the alloca hack */ +} +mem; + +#define m_size(p) ((p) [0].size) /* For malloc */ +#define m_next(p) ((p) [1].next) /* For malloc and alloca */ +#define m_deep(p) ((p) [0].depth) /* For alloca */ + +static mem *alloca_stack = 0; + +void * +alloca(size) +size_t size; +{ + auto char probe; /* Probes stack depth: */ + register mem *hp; + + /* + * Reclaim garbage, defined as all alloca'd storage that was allocated + * from deeper in the stack than currently. + */ + + for (hp = alloca_stack; hp != 0;) + if (m_deep(hp) < &probe) + { + register mem *np = m_next(hp); + free((void *) hp); /* Collect garbage. */ + hp = np; /* -> next header. */ + } + else + break; /* Rest are not deeper. */ + + alloca_stack = hp; /* -> last valid storage. */ + if (size == 0) + return 0; /* No allocation required. */ + + hp = (mem *) malloc(sizeof(mem)*2 + size); + if (hp == 0) + return hp; + + m_next(hp) = alloca_stack; + m_deep(hp) = &probe; + alloca_stack = hp; + + /* User storage begins just after header. */ + return (void *) (hp + 2); +} +#endif diff --git a/ar/ar.c b/ar/ar.c index 28cf6e4..1753293 100644 --- a/ar/ar.c +++ b/ar/ar.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "ar.h" #include "rel_aout.h" @@ -43,6 +44,7 @@ extern int sys_nerr; #define HAVE_RENAME #undef HAVE_FSYNC #endif +#define HAVE_TRAILING_SLASH_IN_NAME extern int errno; @@ -53,8 +55,6 @@ extern int errno; #else # if defined(sparc) || defined(HAVE_ALLOCA_H) # include -# else -char *alloca (); # endif #endif -- cgit v1.2.1