diff options
Diffstat (limited to 'lib/sh')
-rw-r--r-- | lib/sh/Makefile.in | 13 | ||||
-rw-r--r-- | lib/sh/itos.c | 28 | ||||
-rw-r--r-- | lib/sh/oslib.c | 6 | ||||
-rw-r--r-- | lib/sh/rename.c | 27 | ||||
-rw-r--r-- | lib/sh/strtol.c | 1 |
5 files changed, 65 insertions, 10 deletions
diff --git a/lib/sh/Makefile.in b/lib/sh/Makefile.in index d98f9c5..439595c 100644 --- a/lib/sh/Makefile.in +++ b/lib/sh/Makefile.in @@ -16,10 +16,13 @@ INSTALL_DATA = @INSTALL_DATA@ CC = @CC@ RANLIB = @RANLIB@ AR = @AR@ +ARFLAGS = @ARFLAGS@ RM = rm -f CP = cp MV = mv +SHELL = @MAKE_SHELL@ + CFLAGS = @CFLAGS@ LOCAL_CFLAGS = @LOCAL_CFLAGS@ CPPFLAGS = @CPPFLAGS@ @@ -44,7 +47,7 @@ LIBRARY_NAME = libsh.a # The C code source files for this library. CSOURCES = clktck.c getcwd.c getenv.c oslib.c setlinebuf.c \ strcasecmp.c strerror.c strtod.c strtol.c strtoul.c \ - vprint.c itos.c + vprint.c itos.c rename.c # The header files for this library. HSOURCES = @@ -52,7 +55,7 @@ HSOURCES = # The object files contained in $(LIBRARY_NAME) OBJECTS = clktck.o getcwd.o getenv.o oslib.o setlinebuf.o \ strcasecmp.o strerror.o strtod.o strtol.o strtoul.o \ - vprint.o itos.o + vprint.o itos.o rename.o SUPPORT = Makefile @@ -60,7 +63,7 @@ all: $(LIBRARY_NAME) $(LIBRARY_NAME): $(OBJECTS) $(RM) $@ - $(AR) cr $@ $(OBJECTS) + $(AR) $(ARFLAGS) $@ $(OBJECTS) -test -n "$(RANLIB)" && $(RANLIB) $@ force: @@ -86,6 +89,7 @@ getcwd.o: getcwd.c getenv.o: getenv.c itos.o: itos.c oslib.o: oslib.c +rename.o: rename.c setlinebuf.o: setlinebuf.c strcasecmp.o: strcasecmp.c strerror.o: strerror.c @@ -100,6 +104,7 @@ getcwd.o: ${BUILD_DIR}/config.h getenv.o: ${BUILD_DIR}/config.h itos.o: ${BUILD_DIR}/config.h oslib.o: ${BUILD_DIR}/config.h +rename.o: ${BUILD_DIR}/config.h setlinebuf.o: ${BUILD_DIR}/config.h strcasecmp.o: ${BUILD_DIR}/config.h strerror.o: ${BUILD_DIR}/config.h @@ -143,6 +148,8 @@ oslib.o: ${topdir}/pathnames.h ${topdir}/externs.h oslib.o: ${POSIX_INC}/posixstat.h ${POSIX_INC}/filecntl.h oslib.o: ${POSIX_INC}/ansi_stdlib.h +rename.o: ${topdir}/bashtypes.h ${topdir}/stdc.h + strcasecmp.o: ${topdir}/stdc.h ${topdir}/bashansi.h ${topdir}/ansi_stdlib.h strerror.o: ${topdir}/bashtypes.h diff --git a/lib/sh/itos.c b/lib/sh/itos.c index 720e410..5105cb7 100644 --- a/lib/sh/itos.c +++ b/lib/sh/itos.c @@ -31,13 +31,16 @@ of an integer. 32 is larger than the string rep of 2^^31 - 1. */ #define MAX_INT_LEN 32 -/* Integer to string conversion. This conses the string; the - caller should free it. */ +/* Integer to string conversion. The caller passes the buffer and + the size. This should check for buffer underflow, but currently + does not. */ char * -itos (i) +inttostr (i, buf, len) int i; + char *buf; + int len; { - char buf[MAX_INT_LEN], *p, *ret; + char *p; int negative = 0; unsigned int ui; @@ -49,7 +52,7 @@ itos (i) ui = (unsigned int) i; - p = buf + MAX_INT_LEN - 2; + p = buf + len - 2; p[1] = '\0'; do @@ -59,6 +62,17 @@ itos (i) if (negative) *p-- = '-'; - ret = savestring (p + 1); - return (ret); + return (p + 1); +} + +/* Integer to string conversion. This conses the string; the + caller should free it. */ +char * +itos (i) + int i; +{ + char *p, lbuf[MAX_INT_LEN]; + + p = inttostr (i, lbuf, sizeof(lbuf)); + return (savestring (p)); } diff --git a/lib/sh/oslib.c b/lib/sh/oslib.c index d92c32e..3d58711 100644 --- a/lib/sh/oslib.c +++ b/lib/sh/oslib.c @@ -154,6 +154,9 @@ getdtablesize () #endif /* !HAVE_GETDTABLESIZE */ #if !defined (HAVE_BCOPY) +# if defined (bcopy) +# undef bcopy +# endif void bcopy (s,d,n) char *d, *s; @@ -164,6 +167,9 @@ bcopy (s,d,n) #endif /* !HAVE_BCOPY */ #if !defined (HAVE_BZERO) +# if defined (bzero) +# undef bzero +# endif void bzero (s, n) char *s; diff --git a/lib/sh/rename.c b/lib/sh/rename.c new file mode 100644 index 0000000..799cb69 --- /dev/null +++ b/lib/sh/rename.c @@ -0,0 +1,27 @@ +/* + * rename - rename a file + */ + +#include <config.h> + +#if !defined (HAVE_RENAME) + +#include <bashtypes.h> + +#if defined (HAVE_UNISTD_H) +# include <unistd.h> +#endif + +#include <stdc.h> + +int +rename (from, to) + const char *from, *to; +{ + unlink (to); + if (link (from, to) < 0) + return (-1); + unlink (from); + return (0); +} +#endif /* !HAVE_RENAME */ diff --git a/lib/sh/strtol.c b/lib/sh/strtol.c index aed233f..8e3aa39 100644 --- a/lib/sh/strtol.c +++ b/lib/sh/strtol.c @@ -34,6 +34,7 @@ extern int errno; # include <limits.h> #endif +#include <stdc.h> #include <bashansi.h> #ifndef NULL |