+2002-07-17 Ken Raeburn <raeburn@mit.edu>
+
+ * dyn.c: New file, combining contents of old util/dyn library,
+ with unused functions omitted, and memmove assumed.
+ * dyn.h: Moved from util/dyn/dyn.h, symbol renaming macros added.
+ Changed element size to size_t. Include stdlib.h.
+ * dynP.h: Moved from util/dyn/dynP.h, symbol renaming macros
+ added.
+ * dyntest.c: Moved from util/dyn/test.c.
+ * Makefile.in (SHLIB_EXPDEPS, SHLIB_EXPLIBS): Omit libdyn
+ references.
+ (SRCS, OBJS, STLIBOBJS): Build dyn.c.
+ (dyntest, run-dyntest, clean-dyntest): New targets.
+ (check-unix): Depend on run-dyntest.
+ (clean-unix): Depend on clean-dyntest.
+ (LCLINT, LCLINTOPTS): Moved from util/dyn/Makefile.in.
+ (do-dyn-lclint): New target, untested.
+ * xdr_alloc.c: Include "dyn.h" instead of <dyn.h>.
+
2001-12-14 Ezra Peisach <epeisach@mit.edu>
* svc_auth_gssapi.c (_gssrpc_svcauth_gssapi): Local return
$(TOPLIBD)/libgssapi_krb5$(SHLIBEXT) \
$(TOPLIBD)/libkrb5$(SHLIBEXT) \
$(TOPLIBD)/libk5crypto$(SHLIBEXT) \
- $(TOPLIBD)/libcom_err$(SHLIBEXT) \
- $(TOPLIBD)/libdyn$(SHLIBEXT)
-SHLIB_EXPLIBS=-lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -ldyn
+ $(TOPLIBD)/libcom_err$(SHLIBEXT)
+SHLIB_EXPLIBS=-lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err
SHLIB_DIRS=-L$(TOPLIBD)
SHLIB_RDIRS=$(KRB5_LIBDIR)
RELDIR=rpc
$(srcdir)/clnt_simple.c \
$(srcdir)/clnt_tcp.c \
$(srcdir)/clnt_udp.c \
+ $(srcdir)/dyn.c \
$(srcdir)/rpc_dtablesize.c \
$(srcdir)/get_myaddress.c \
$(srcdir)/getrpcport.c \
clnt_simple.$(OBJEXT) \
clnt_tcp.$(OBJEXT) \
clnt_udp.$(OBJEXT) \
+ dyn.$(OBJEXT) \
rpc_dtablesize.$(OBJEXT) \
get_myaddress.$(OBJEXT) \
getrpcport.$(OBJEXT) \
clnt_simple.o \
clnt_tcp.o \
clnt_udp.o \
+ dyn.o \
rpc_dtablesize.o \
get_myaddress.o \
getrpcport.o \
clean-windows::
+# stuff picked up from old "dyn" library
+check-unix:: run-dyntest
+run-dyntest: dyntest
+ ./dyntest
+dyntest: dyntest.o dyn.o
+ $(CC) -o dyntest dyntest.o dyn.o
+clean-unix:: clean-dyntest
+clean-dyntest:
+ $(RM) dyntest dyntest.o
+
+LCLINT= lclint
+# +posixlib gets more complete errno list than ansilib
+# -usedef turns off bogus warnings from poor dataflow analysis (should be
+# redundant with gcc warnings anyways)
+# -warnposix
+# +charintliteral
+# +ignoresigns
+# -predboolint
+# -exportlocal
+# -retvalint allow ignoring of int return values (e.g., fputs)
+LCLINTOPTS=+posixlib \
+ +ignoresigns -predboolint \
+ +mod-uncon +modinternalstrict +modfilesys \
+ -expect 2
+do-dyn-lclint::
+ $(LCLINT) $(LCLINTOPTS) $(LOCALINCLUDES) $(DEFS) dyn.c dyntest.c
+
# Should only rebuild types.h here (use CONFIG_FILES=), but the weird krb5
# makefile post-processing is unconditional and would trash the makefile.
types.h: types.stamp
$(BUILDTOP)/include/gssrpc/rpc_msg.h $(BUILDTOP)/include/gssrpc/auth_unix.h \
$(BUILDTOP)/include/gssrpc/svc_auth.h $(BUILDTOP)/include/gssrpc/svc.h \
$(BUILDTOP)/include/gssrpc/pmap_clnt.h
+dyn.so dyn.po $(OUTPRE)dyn.$(OBJEXT): dyn.c dynP.h dyn.h
rpc_dtablesize.so rpc_dtablesize.po $(OUTPRE)rpc_dtablesize.$(OBJEXT): rpc_dtablesize.c \
$(BUILDTOP)/include/gssrpc/rpc.h $(BUILDTOP)/include/gssrpc/types.h \
$(BUILDTOP)/include/gssrpc/xdr.h $(BUILDTOP)/include/gssrpc/auth.h \
xdr_stdio.so xdr_stdio.po $(OUTPRE)xdr_stdio.$(OBJEXT): xdr_stdio.c $(BUILDTOP)/include/gssrpc/types.h \
$(BUILDTOP)/include/gssrpc/xdr.h
xdr_alloc.so xdr_alloc.po $(OUTPRE)xdr_alloc.$(OBJEXT): xdr_alloc.c $(BUILDTOP)/include/gssrpc/types.h \
- $(BUILDTOP)/include/gssrpc/xdr.h $(BUILDTOP)/include/dyn.h
+ $(BUILDTOP)/include/gssrpc/xdr.h dyn.h
--- /dev/null
+/*
+ * This file is the collected implementation of libdyn.a, the C
+ * Dynamic Object library. It contains everything.
+ *
+ * There are no restrictions on this code; however, if you make any
+ * changes, I request that you document them so that I do not get
+ * credit or blame for your modifications.
+ *
+ * Written by Barr3y Jaspan, Student Information Processing Board (SIPB)
+ * and MIT-Project Athena, 1989.
+ *
+ * 2002-07-17 Collected full implementation into one source file for
+ * easy inclusion into the one library still dependent on
+ * libdyn. Assume memmove. Old ChangeLog appended.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "dynP.h"
+
+#define HAVE_MEMMOVE 1
+
+
+/* old dyn_append.c */
+/*
+ * This file is part of libdyn.a, the C Dynamic Object library. It
+ * contains the source code for the function DynAppend().
+ */
+
+/*
+ * Made obsolete by DynInsert, now just a convenience function.
+ */
+int DynAppend(obj, els, num)
+ DynObjectP obj;
+ DynPtr els;
+ int num;
+{
+ return DynInsert(obj, DynSize(obj), els, num);
+}
+
+
+/* old dyn_create.c */
+/*
+ * This file is part of libdyn.a, the C Dynamic Object library. It
+ * contains the source code for the functions DynCreate() and
+ * DynDestroy().
+ */
+
+#ifndef DEFAULT_INC
+#define DEFAULT_INC 100
+#endif
+
+static int default_increment = DEFAULT_INC;
+
+DynObjectP DynCreate(el_size, inc)
+ int el_size, inc;
+{
+ DynObjectP obj;
+
+ obj = (DynObjectP) malloc(sizeof(DynObjectRecP));
+ if (obj == NULL)
+ return NULL;
+
+ obj->array = (DynPtr) malloc(1);
+ if (obj->array == NULL) {
+ free(obj);
+ return NULL;
+ }
+ obj->array[0] = '\0';
+
+ obj->el_size = el_size;
+ obj->num_el = obj->size = 0;
+ obj->debug = obj->paranoid = 0;
+ obj->inc = (inc) ? inc : default_increment;
+ obj->initzero = 0;
+
+ return obj;
+}
+
+DynObjectP DynCopy(obj)
+ DynObjectP obj;
+{
+ DynObjectP obj1;
+
+ obj1 = (DynObjectP) malloc(sizeof(DynObjectRecP));
+ if (obj1 == NULL)
+ return NULL;
+
+ obj1->el_size = obj->el_size;
+ obj1->num_el = obj->num_el;
+ obj1->size = obj->size;
+ obj1->inc = obj->inc;
+ obj1->debug = obj->debug;
+ obj1->paranoid = obj->paranoid;
+ obj1->initzero = obj->initzero;
+ obj1->array = (char *) malloc((size_t) (obj1->el_size * obj1->size));
+ if (obj1->array == NULL) {
+ free(obj1);
+ return NULL;
+ }
+ memcpy(obj1->array, obj->array,
+ (size_t) (obj1->el_size * obj1->size));
+
+ return obj1;
+}
+
+int DynDestroy(obj)
+ /*@only@*/DynObjectP obj;
+{
+ if (obj->paranoid) {
+ if (obj->debug)
+ fprintf(stderr, "dyn: destroy: zeroing %d bytes from %p.\n",
+ obj->el_size * obj->size, obj->array);
+ memset(obj->array, 0, (size_t) (obj->el_size * obj->size));
+ }
+ free(obj->array);
+ free(obj);
+ return DYN_OK;
+}
+
+int DynRelease(obj)
+ DynObjectP obj;
+{
+ if (obj->debug)
+ fprintf(stderr, "dyn: release: freeing object structure.\n");
+ free(obj);
+ return DYN_OK;
+}
+
+
+/* old dyn_debug.c */
+/*
+ * This file is part of libdyn.a, the C Dynamic Object library. It
+ * contains the source code for the function DynDebug().
+ */
+
+int DynDebug(obj, state)
+ DynObjectP obj;
+ int state;
+{
+ obj->debug = state;
+
+ fprintf(stderr, "dyn: debug: Debug state set to %d.\n", state);
+ return DYN_OK;
+}
+
+
+/* old dyn_delete.c */
+/*
+ * This file is part of libdyn.a, the C Dynamic Object library. It
+ * contains the source code for the function DynDelete().
+ */
+
+/*
+ * Checkers! Get away from that "hard disk erase" button!
+ * (Stupid dog. He almost did it to me again ...)
+ */
+int DynDelete(obj, idx)
+ DynObjectP obj;
+ int idx;
+{
+ if (idx < 0) {
+ if (obj->debug)
+ fprintf(stderr, "dyn: delete: bad index %d\n", idx);
+ return DYN_BADINDEX;
+ }
+
+ if (idx >= obj->num_el) {
+ if (obj->debug)
+ fprintf(stderr, "dyn: delete: Highest index is %d.\n",
+ obj->num_el);
+ return DYN_BADINDEX;
+ }
+
+ if (idx == obj->num_el-1) {
+ if (obj->paranoid) {
+ if (obj->debug)
+ fprintf(stderr, "dyn: delete: last element, zeroing.\n");
+ memset(obj->array + idx*obj->el_size, 0, (size_t) obj->el_size);
+ }
+ else {
+ if (obj->debug)
+ fprintf(stderr, "dyn: delete: last element, punting.\n");
+ }
+ }
+ else {
+ if (obj->debug)
+ fprintf(stderr,
+ "dyn: delete: copying %d bytes from %p + %d to + %d.\n",
+ obj->el_size*(obj->num_el - idx), obj->array,
+ (idx+1)*obj->el_size, idx*obj->el_size);
+
+#ifdef HAVE_MEMMOVE
+ memmove(obj->array + idx*obj->el_size,
+ obj->array + (idx+1)*obj->el_size,
+ (size_t) obj->el_size*(obj->num_el - idx));
+#else
+ bcopy(obj->array + (idx+1)*obj->el_size,
+ obj->array + idx*obj->el_size,
+ obj->el_size*(obj->num_el - idx));
+#endif
+ if (obj->paranoid) {
+ if (obj->debug)
+ fprintf(stderr,
+ "dyn: delete: zeroing %d bytes from %p + %d\n",
+ obj->el_size, obj->array,
+ obj->el_size*(obj->num_el - 1));
+ memset(obj->array + obj->el_size*(obj->num_el - 1), 0,
+ (size_t) obj->el_size);
+ }
+ }
+
+ --obj->num_el;
+
+ if (obj->debug)
+ fprintf(stderr, "dyn: delete: done.\n");
+
+ return DYN_OK;
+}
+
+
+/* old dyn_initzero.c */
+/*
+ * This file is part of libdyn.a, the C Dynamic Object library. It
+ * contains the source code for the function DynInitZero().
+ */
+
+int DynInitzero(obj, state)
+ DynObjectP obj;
+ int state;
+{
+ obj->initzero = state;
+
+ if (obj->debug)
+ fprintf(stderr, "dyn: initzero: initzero set to %d.\n", state);
+ return DYN_OK;
+}
+
+
+/* old dyn_insert.c */
+/*
+ * This file is part of libdyn.a, the C Dynamic Object library. It
+ * contains the source code for the function DynInsert().
+ */
+
+int DynInsert(obj, idx, els_in, num)
+ DynObjectP obj;
+ void *els_in;
+ int idx, num;
+{
+ DynPtr els = (DynPtr) els_in;
+ int ret;
+
+ if (idx < 0 || idx > obj->num_el) {
+ if (obj->debug)
+ fprintf(stderr, "dyn: insert: index %d is not in [0,%d]\n",
+ idx, obj->num_el);
+ return DYN_BADINDEX;
+ }
+
+ if (num < 1) {
+ if (obj->debug)
+ fprintf(stderr, "dyn: insert: cannot insert %d elements\n",
+ num);
+ return DYN_BADVALUE;
+ }
+
+ if (obj->debug)
+ fprintf(stderr,"dyn: insert: Moving %d bytes from %p + %d to + %d\n",
+ (obj->num_el-idx)*obj->el_size, obj->array,
+ obj->el_size*idx, obj->el_size*(idx+num));
+
+ if ((ret = _DynResize(obj, obj->num_el + num)) != DYN_OK)
+ return ret;
+#ifdef HAVE_MEMMOVE
+ memmove(obj->array + obj->el_size*(idx + num),
+ obj->array + obj->el_size*idx,
+ (size_t) ((obj->num_el-idx)*obj->el_size));
+#else
+ bcopy(obj->array + obj->el_size*idx,
+ obj->array + obj->el_size*(idx + num),
+ (obj->num_el-idx)*obj->el_size);
+#endif
+
+ if (obj->debug)
+ fprintf(stderr, "dyn: insert: Copying %d bytes from %p to %p + %d\n",
+ obj->el_size*num, els, obj->array, obj->el_size*idx);
+
+#ifdef HAVE_MEMMOVE
+ memmove(obj->array + obj->el_size*idx, els, (size_t) (obj->el_size*num));
+#else
+ bcopy(els, obj->array + obj->el_size*idx, obj->el_size*num);
+#endif
+ obj->num_el += num;
+
+ if (obj->debug)
+ fprintf(stderr, "dyn: insert: done.\n");
+
+ return DYN_OK;
+}
+
+
+/* old dyn_paranoid.c */
+/*
+ * This file is part of libdyn.a, the C Dynamic Object library. It
+ * contains the source code for the function DynDebug().
+ */
+
+int DynParanoid(obj, state)
+ DynObjectP obj;
+ int state;
+{
+ obj->paranoid = state;
+
+ if (obj->debug)
+ fprintf(stderr, "dyn: paranoid: Paranoia set to %d.\n", state);
+ return DYN_OK;
+}
+
+
+/* old dyn_put.c */
+/*
+ * This file is part of libdyn.a, the C Dynamic Object library. It
+ * contains the source code for the functions DynGet() and DynAdd().
+ */
+
+DynPtr DynArray(obj)
+ DynObjectP obj;
+{
+ if (obj->debug)
+ fprintf(stderr, "dyn: array: returning array pointer %p.\n",
+ obj->array);
+
+ return obj->array;
+}
+
+DynPtr DynGet(obj, num)
+ DynObjectP obj;
+ int num;
+{
+ if (num < 0) {
+ if (obj->debug)
+ fprintf(stderr, "dyn: get: bad index %d\n", num);
+ return NULL;
+ }
+
+ if (num >= obj->num_el) {
+ if (obj->debug)
+ fprintf(stderr, "dyn: get: highest element is %d.\n",
+ obj->num_el);
+ return NULL;
+ }
+
+ if (obj->debug)
+ fprintf(stderr, "dyn: get: Returning address %p + %d.\n",
+ obj->array, obj->el_size*num);
+
+ return (DynPtr) obj->array + obj->el_size*num;
+}
+
+int DynAdd(obj, el)
+ DynObjectP obj;
+ void *el;
+{
+ int ret;
+
+ ret = DynPut(obj, el, obj->num_el);
+ if (ret != DYN_OK)
+ return ret;
+
+ ++obj->num_el;
+ return ret;
+}
+
+/*
+ * WARNING! There is a reason this function is not documented in the
+ * man page. If DynPut used to mutate already existing elements,
+ * everything will go fine. If it is used to add new elements
+ * directly, however, the state within the object (such as
+ * obj->num_el) will not be updated properly and many other functions
+ * in the library will lose. Have a nice day.
+ */
+int DynPut(obj, el_in, idx)
+ DynObjectP obj;
+ void *el_in;
+ int idx;
+{
+ DynPtr el = (DynPtr) el_in;
+ int ret;
+
+ if (obj->debug)
+ fprintf(stderr, "dyn: put: Writing %d bytes from %p to %p + %d\n",
+ obj->el_size, el, obj->array, idx*obj->el_size);
+
+ if ((ret = _DynResize(obj, idx)) != DYN_OK)
+ return ret;
+
+#ifdef HAVE_MEMMOVE
+ memmove(obj->array + idx*obj->el_size, el, (size_t) obj->el_size);
+#else
+ bcopy(el, obj->array + idx*obj->el_size, obj->el_size);
+#endif
+
+ if (obj->debug)
+ fprintf(stderr, "dyn: put: done.\n");
+
+ return DYN_OK;
+}
+
+
+/* old dyn_realloc.c */
+/*
+ * This file is part of libdyn.a, the C Dynamic Object library. It
+ * contains the source code for the internal function _DynRealloc().
+ */
+
+/*
+ * Resize the array so that element req exists.
+ */
+int _DynResize(obj, req)
+ DynObjectP obj;
+ int req;
+{
+ int size;
+
+ if (obj->size > req)
+ return DYN_OK;
+ else if (obj->inc > 0)
+ return _DynRealloc(obj, (req - obj->size) / obj->inc + 1);
+ else {
+ if (obj->size == 0)
+ size = -obj->inc;
+ else
+ size = obj->size;
+
+ /*@-shiftsigned@*/
+ while (size <= req)
+ size <<= 1;
+ /*@=shiftsigned@*/
+
+ return _DynRealloc(obj, size);
+ }
+}
+
+/*
+ * Resize the array by num_incs units. If obj->inc is positive, this
+ * means make it obj->inc*num_incs elements larger. If obj->inc is
+ * negative, this means make the array num_incs elements long.
+ *
+ * Ideally, this function should not be called from outside the
+ * library. However, nothing will break if it is.
+ */
+int _DynRealloc(obj, num_incs)
+ DynObjectP obj;
+ int num_incs;
+{
+ DynPtr temp;
+ int new_size_in_bytes;
+
+ if (obj->inc > 0)
+ new_size_in_bytes = obj->el_size*(obj->size + obj->inc*num_incs);
+ else
+ new_size_in_bytes = obj->el_size*num_incs;
+
+ if (obj->debug)
+ fprintf(stderr,
+ "dyn: alloc: Increasing object by %d bytes (%d incs).\n",
+ new_size_in_bytes - obj->el_size*obj->size,
+ num_incs);
+
+ temp = (DynPtr) realloc(obj->array, (size_t) new_size_in_bytes);
+ if (temp == NULL) {
+ if (obj->debug)
+ fprintf(stderr, "dyn: alloc: Out of memory.\n");
+ return DYN_NOMEM;
+ }
+ else {
+ obj->array = temp;
+ if (obj->inc > 0)
+ obj->size += obj->inc*num_incs;
+ else
+ obj->size = num_incs;
+ }
+
+ if (obj->debug)
+ fprintf(stderr, "dyn: alloc: done.\n");
+
+ return DYN_OK;
+}
+
+
+/* old dyn_size.c */
+/*
+ * This file is part of libdyn.a, the C Dynamic Object library. It
+ * contains the source code for the function DynSize().
+ */
+
+int DynSize(obj)
+ DynObjectP obj;
+{
+ if (obj->debug)
+ fprintf(stderr, "dyn: size: returning size %d.\n", obj->num_el);
+
+ return obj->num_el;
+}
+
+int DynCapacity(obj)
+ DynObjectP obj;
+{
+ if (obj->debug)
+ fprintf(stderr, "dyn: capacity: returning cap of %d.\n", obj->size);
+
+ return obj->size;
+}
+
+/* Old change log, as it relates to source code; build system stuff
+ discarded.
+
+2001-10-09 Ken Raeburn <raeburn@mit.edu>
+
+ * dyn.h, dynP.h: Make prototypes unconditional. Don't define
+ P().
+
+2001-04-25 Ezra Peisach <epeisach@mit.edu>
+
+ * dyn.h: Lclint annotate functions.
+
+ * dyn_create.c (DynCreate): Do not assume that malloc(0) is valid
+ and returns a valid pointer. Fix memory leak if malloc fails.
+
+ * dyn_realloc.c (_DynResize): Turn off warning of shifting a
+ signed variable.
+
+Thu Nov 9 15:31:31 2000 Ezra Peisach <epeisach@mit.edu>
+
+ * dyn_create.c (DynCopy): Arguments to memcpy were reversed. Found
+ while playing with lclint.
+
+2000-11-09 Ezra Peisach <epeisach@mit.edu>
+
+ * dyn_create.c, dyn_delete.c, dyn_insert.c, dyn_put.c,
+ dyn_realloc.c: Cast arguments to malloc(), realloc(), memmove() to
+ size_t.
+
+ * dynP.h: Provide full prototypes for _DynRealloc() and _DynResize().
+
+ * dyn.h: Add prototype for DynAppend.
+
+2000-06-29 Ezra Peisach <epeisach@mit.edu>
+
+ * dyn_insert.c, dyn_put.c: Include string.h for memmove prototype.
+
+2000-06-28 Ezra Peisach <epeisach@mit.edu>
+
+ * dyn_create.c, dyn_delete.c, dyn_insert.c, dyn_put.c: Use %p
+ format for displaying pointers.
+
+2000-06-26 Ezra Peisach <epeisach@mit.edu>
+
+ * dyn_realloc.c: Remove unused variable.
+
+Sat Dec 6 22:50:03 1997 Ezra Peisach <epeisach@mit.edu>
+
+ * dyn_delete.c: Include <string.h>
+
+Mon Jul 22 21:37:52 1996 Ezra Peisach <epeisach@mit.edu>
+
+ * dyn.h: If __STDC__ is not defined, generate prototypes implying
+ functions and not variables.
+
+Mon Jul 22 04:20:48 1996 Marc Horowitz <marc@mit.edu>
+
+ * dyn_insert.c (DynInsert): what used to be #ifdef POSIX, should
+ be #ifdef HAVE_MEMMOVE
+*/
--- /dev/null
+/*
+ * This file is part of libdyn.a, the C Dynamic Object library. It
+ * contains the public header file.
+ *
+ * There are no restrictions on this code; however, if you make any
+ * changes, I request that you document them so that I do not get
+ * credit or blame for your modifications.
+ *
+ * Written by Barr3y Jaspan, Student Information Processing Board (SIPB)
+ * and MIT-Project Athena, 1989.
+ *
+ * 2002-07-17 Moved here from util/dyn; for old changes see dyn.c.
+ * Added macros to rename exposed symbols. For newer changes
+ * see ChangeLog in the current directory.
+ */
+
+
+/*
+ * dyn.h -- header file to be included by programs linking against
+ * libdyn.a.
+ */
+
+#ifndef _Dyn_h
+#define _Dyn_h
+
+typedef char *DynPtr;
+typedef struct _DynObject {
+ DynPtr array;
+ int el_size, num_el, size, inc;
+ int debug, paranoid, initzero;
+} DynObjectRec, *DynObject;
+
+/* Function macros */
+#define DynHigh(obj) (DynSize(obj) - 1)
+#define DynLow(obj) (0)
+
+/* Return status codes */
+#define DYN_OK -1000
+#define DYN_NOMEM -1001
+#define DYN_BADINDEX -1002
+#define DYN_BADVALUE -1003
+
+#define DynCreate gssrpcint_DynCreate
+#define DynDestroy gssrpcint_DynDestroy
+#define DynRelease gssrpcint_DynRelease
+#define DynAdd gssrpcint_DynAdd
+#define DynPut gssrpcint_DynPut
+#define DynInsert gssrpcint_DynInsert
+#define DynGet gssrpcint_DynGet
+#define DynArray gssrpcint_DynArray
+#define DynSize gssrpcint_DynSize
+#define DynCopy gssrpcint_DynCopy
+#define DynDelete gssrpcint_DynDelete
+#define DynDebug gssrpcint_DynDebug
+#define DynParanoid gssrpcint_DynParanoid
+#define DynInitzero gssrpcint_DynInitzero
+#define DynCapacity gssrpcint_DynCapacity
+#define DynAppend gssrpcint_DynAppend
+
+/*@null@*//*@only@*/ DynObject DynCreate (int el_size, int inc);
+/*@null@*//*@only@*/ DynObject DynCopy (DynObject obj);
+int DynDestroy (/*@only@*/DynObject obj), DynRelease (DynObject obj);
+int DynAdd (DynObject obj, void *el);
+int DynPut (DynObject obj, void *el, int idx);
+int DynInsert (DynObject obj, int idx, /*@observer@*/void *els, int num);
+int DynDelete (DynObject obj, int idx);
+/*@dependent@*//*@null@*/ DynPtr DynGet (DynObject obj, int num);
+/*@observer@*/ DynPtr DynArray (DynObject obj);
+int DynDebug (DynObject obj, int state);
+int DynParanoid (DynObject obj, int state);
+int DynInitzero (DynObject obj, int state);
+int DynSize (DynObject obj);
+int DynCapacity (DynObject obj);
+int DynAppend (DynObject obj, DynPtr els, int num);
+
+#undef P
+
+#endif /* _Dyn_h */
+/* DO NOT ADD ANYTHING AFTER THIS #endif */
--- /dev/null
+/*
+ * This file is part of libdyn.a, the C Dynamic Object library. It
+ * contains the private header file.
+ *
+ * There are no restrictions on this code; however, if you make any
+ * changes, I request that you document them so that I do not get
+ * credit or blame for your modifications.
+ *
+ * Written by Barr3y Jaspan, Student Information Processing Board (SIPB)
+ * and MIT-Project Athena, 1989.
+ */
+
+
+/*
+ * dynP.h -- private header file included by source files for libdyn.a.
+ */
+
+#ifndef _DynP_h
+#define _DynP_h
+
+#include "dyn.h"
+#ifdef USE_DBMALLOC
+#include <sys/stdtypes.h>
+#include <malloc.h>
+#endif
+
+/*
+ * Rep invariant:
+ * 1) el_size is the number of bytes per element in the object
+ * 2) num_el is the number of elements currently in the object. It is
+ * one higher than the highest index at which an element lives.
+ * 3) size is the number of elements the object can hold without
+ * resizing. num_el <= index.
+ * 4) inc is a multiple of the number of elements the object grows by
+ * each time it is reallocated.
+ */
+
+typedef struct _DynObject DynObjectRecP, *DynObjectP;
+
+#define _DynRealloc gssrpcint_DynRealloc
+#define _DynResize gssrpcint_DynResize
+
+/* Internal functions */
+int _DynRealloc (DynObjectP obj, int req),
+ _DynResize (DynObjectP obj, int req);
+
+#undef P
+
+#endif /* _DynP_h */
+/* DON'T ADD STUFF AFTER THIS #endif */
--- /dev/null
+/*
+ * This file is a (rather silly) demonstration of the use of the
+ * C Dynamic Object library. It is a also reasonably thorough test
+ * of the library (except that it only tests it with one data size).
+ *
+ * There are no restrictions on this code; however, if you make any
+ * changes, I request that you document them so that I do not get
+ * credit or blame for your modifications.
+ *
+ * Written by Barr3y Jaspan, Student Information Processing Board (SIPB)
+ * and MIT-Project Athena, 1989.
+ *
+ * 2002-07-17 Moved here from util/dyn/test.c. Older changes described
+ * at end of file; for newer changes see ChangeLog.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#ifdef USE_DBMALLOC
+#include <sys/stdtypes.h>
+#include <malloc.h>
+#endif
+#include <stdlib.h>
+
+#include "dyn.h"
+
+static char random_string[] = "This is a random string.";
+static char insert1[] = "This will be put at the beginning.";
+static char insert2[] = "(parenthetical remark!) ";
+static char insert3[] = " This follows the random string.";
+
+int
+main(argc, argv)
+/*@unused@*/int argc;
+/*@unused@*/char **argv;
+{
+ /*@-exitarg@*/
+ DynObject obj;
+ int i, s;
+ char d, *data;
+
+#ifdef _DEBUG_MALLOC_INC
+ union dbmalloptarg arg;
+ unsigned long hist1, hist2, o_size, c_size;
+#endif
+
+#ifdef _DEBUG_MALLOC_INC
+ arg.i = 0;
+ dbmallopt(MALLOC_ZERO, &arg);
+ dbmallopt(MALLOC_REUSE, &arg);
+
+ o_size = malloc_inuse(&hist1);
+#endif
+
+ /*@+matchanyintegral@*/
+ obj = DynCreate(sizeof(char), -8);
+ if (! obj) {
+ fprintf(stderr, "test: create failed.\n");
+ exit(1);
+ }
+
+ if(DynDebug(obj, 1) != DYN_OK) {
+ fprintf(stderr, "test: setting paranoid failed.\n");
+ exit(1);
+ }
+ if(DynParanoid(obj, 1) != DYN_OK) {
+ fprintf(stderr, "test: setting paranoid failed.\n");
+ exit(1);
+ }
+
+
+ if ((DynGet(obj, -5) != NULL) ||
+ (DynGet(obj, 0) != NULL) || (DynGet(obj, 1000) != NULL)) {
+ fprintf(stderr, "test: Get did not fail when it should have.\n");
+ exit(1);
+ }
+
+ if (DynDelete(obj, -1) != DYN_BADINDEX ||
+ DynDelete(obj, 0) != DYN_BADINDEX ||
+ DynDelete(obj, 100) != DYN_BADINDEX) {
+ fprintf(stderr, "test: Delete did not fail when it should have.\n");
+ exit(1);
+ }
+
+ printf("Size of empty object: %d\n", DynSize(obj));
+
+ for (i=0; i<14; i++) {
+ d = (char) i;
+ if (DynAdd(obj, &d) != DYN_OK) {
+ fprintf(stderr, "test: Adding %d failed.\n", i);
+ exit(1);
+ }
+ }
+
+ if (DynAppend(obj, random_string, strlen(random_string)+1) != DYN_OK) {
+ fprintf(stderr, "test: appending array failed.\n");
+ exit(1);
+ }
+
+ if (DynDelete(obj, DynHigh(obj) / 2) != DYN_OK) {
+ fprintf(stderr, "test: deleting element failed.\n");
+ exit(1);
+ }
+
+ if (DynDelete(obj, DynHigh(obj) * 2) == DYN_OK) {
+ fprintf(stderr, "test: delete should have failed here.\n");
+ exit(1);
+ }
+
+ d = '\200';
+ if (DynAdd(obj, &d) != DYN_OK) {
+ fprintf(stderr, "test: Adding %d failed.\n", i);
+ exit(1);
+ }
+
+ data = (char *) DynGet(obj, 0);
+ if(data == NULL) {
+ fprintf(stderr, "test: getting object 0 failed.\n");
+ exit(1);
+ }
+ s = DynSize(obj);
+ for (i=0; i < s; i++)
+ printf("Element %d is %d.\n", i, (int) data[i]);
+
+ data = (char *) DynGet(obj, 13);
+ if(data == NULL) {
+ fprintf(stderr, "test: getting element 13 failed.\n");
+ exit(1);
+ }
+ printf("Element 13 is %d.\n", (int) *data);
+
+ data = (char *) DynGet(obj, DynSize(obj));
+ if (data) {
+ fprintf(stderr, "DynGet did not return NULL when it should have.\n");
+ exit(1);
+ }
+
+ data = DynGet(obj, 14);
+ if(data == NULL) {
+ fprintf(stderr, "test: getting element 13 failed.\n");
+ exit(1);
+ }
+ printf("This should be the random string: \"%s\"\n", data);
+
+ if (DynInsert(obj, -1, "foo", 4) != DYN_BADINDEX ||
+ DynInsert(obj, DynSize(obj) + 1, "foo", 4) != DYN_BADINDEX ||
+ DynInsert(obj, 0, "foo", -1) != DYN_BADVALUE) {
+ fprintf(stderr, "DynInsert did not fail when it should have.\n");
+ exit(1);
+ }
+
+ if (DynInsert(obj, DynSize(obj) - 2, insert3, strlen(insert3) +
+ 1) != DYN_OK) {
+ fprintf(stderr, "DynInsert to end failed.\n");
+ exit(1);
+ }
+
+ if (DynInsert(obj, 19, insert2, strlen(insert2)) != DYN_OK) {
+ fprintf(stderr, "DynInsert to middle failed.\n");
+ exit(1);
+ }
+
+ if (DynInsert(obj, 0, insert1, strlen(insert1)+1) != DYN_OK) {
+ fprintf(stderr, "DynInsert to start failed.\n");
+ exit(1);
+ }
+
+ data = DynGet(obj, 14 + strlen(insert1) + 1);
+ if (data == NULL) {
+ fprintf(stderr, "DynGet of 14+strelen(insert1) failed.\n");
+ exit(1);
+
+ }
+ printf("A new random string: \"%s\"\n", data);
+
+ data = DynGet(obj, 0);
+ if (data == NULL) {
+ fprintf(stderr, "DynGet of 0 failed.\n");
+ exit(1);
+
+ }
+ printf("This was put at the beginning: \"%s\"\n", data);
+
+ if(DynDestroy(obj) != DYN_OK) {
+ fprintf(stderr, "test: destroy failed.\n");
+ exit(1);
+ }
+
+#ifdef _DEBUG_MALLOC_INC
+ c_size = malloc_inuse(&hist2);
+ if (o_size != c_size) {
+ printf("\n\nIgnore a single unfreed malloc segment "
+ "(stdout buffer).\n\n");
+ malloc_list(2, hist1, hist2);
+ }
+#endif
+
+ printf("All tests pass\n");
+
+ return 0;
+}
+
+/* Old change log, as it relates to source code; build system stuff
+ discarded.
+
+2001-04-25 Ezra Peisach <epeisach@mit.edu>
+
+ * test.c: Always include stdlib.h
+
+ * test.c: Check the return values of all library calls.
+
+2000-11-09 Ezra Peisach <epeisach@mit.edu>
+
+ * test.c: Include string,h, stdlib.h.
+
+*/
#include <gssrpc/types.h>
#include <gssrpc/xdr.h>
-#include <dyn.h>
+#include "dyn.h"
static bool_t xdralloc_putlong(XDR *, long *);
static bool_t xdralloc_putbytes(XDR *, caddr_t, unsigned int);