summaryrefslogtreecommitdiff
path: root/ar
diff options
context:
space:
mode:
authorRobert de Bath <rdebath@poboxes.com>2003-09-20 19:44:36 +0200
committerLubomir Rintel <lkundrak@v3.sk>2013-10-23 23:48:49 +0200
commit22950ba3df3a0b739786243679d69cd4094e8b20 (patch)
tree942907e918e556d340dcbcb8ffdc0f7d020a275e /ar
parent5613ba3c0749fa494d35c4dc36b57c5b4e6edb55 (diff)
downloaddev86-22950ba3df3a0b739786243679d69cd4094e8b20.tar.gz
Import Dev86src-0.16.13.tar.gzv0.16.13
Diffstat (limited to 'ar')
-rw-r--r--ar/Makefile8
-rw-r--r--ar/alloca.c61
-rw-r--r--ar/ar.c4
3 files changed, 67 insertions, 6 deletions
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 <stdlib.h>
+#else
+#include <memory.h>
+#include <string.h>
+#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 <time.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/errno.h>
#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 <alloca.h>
-# else
-char *alloca ();
# endif
#endif