From 85dd2e5b73ef28bac042360f93733d9b4728c4ac Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Wed, 8 Mar 2000 03:46:01 +0000 Subject: [PATCH] * libc/string/Makefile.am (lib_a_SOURCES): Added swab.c. (CHEWOUT_FILES): Added swab.def. * libc/string/Makefile.in: Rebuilt. * libc/string/string.tex: Include swab.def. * libc/include/string.h (swab): Declare. * libc/string/swab.c: New file. --- newlib/ChangeLog | 9 +++++++ newlib/libc/include/string.h | 1 + newlib/libc/string/Makefile.am | 3 ++- newlib/libc/string/Makefile.in | 5 ++-- newlib/libc/string/strings.tex | 4 ++++ newlib/libc/string/swab.c | 44 ++++++++++++++++++++++++++++++++++ 6 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 newlib/libc/string/swab.c diff --git a/newlib/ChangeLog b/newlib/ChangeLog index 656fcbbd2..cf16f1d77 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,12 @@ +Wed Mar 8 00:43:07 2000 Alexandre Oliva + + * libc/string/Makefile.am (lib_a_SOURCES): Added swab.c. + (CHEWOUT_FILES): Added swab.def. + * libc/string/Makefile.in: Rebuilt. + * libc/string/string.tex: Include swab.def. + * libc/include/string.h (swab): Declare. + * libc/string/swab.c: New file. + Wed Mar 8 00:38:35 2000 Alexandre Oliva * libc/stdio/Makefile.am (lib_a_SOURCES): Added getw.c and putw.c. diff --git a/newlib/libc/include/string.h b/newlib/libc/include/string.h index a9494f826..0707aac16 100644 --- a/newlib/libc/include/string.h +++ b/newlib/libc/include/string.h @@ -69,6 +69,7 @@ char *_EXFUN(strupr,(char *)); char *_EXFUN(strsignal, (int __signo)); int _EXFUN(strtosigno, (const char *__name)); #endif +void _EXFUN(swab,(const void *, void *, ssize_t)); /* These function names are used on Windows and perhaps other systems. */ #ifndef strcmpi diff --git a/newlib/libc/string/Makefile.am b/newlib/libc/string/Makefile.am index 26d4b8952..dceb4d909 100644 --- a/newlib/libc/string/Makefile.am +++ b/newlib/libc/string/Makefile.am @@ -39,13 +39,14 @@ lib_a_SOURCES = \ strupr.c \ strxfrm.c \ strstr.c \ + swab.c \ u_strerr.c CHEWOUT_FILES=\ bcmp.def memcpy.def strcmp.def strncat.def strstr.def \ bcopy.def memmove.def strcoll.def strncmp.def strtok.def \ bzero.def memset.def strcpy.def strncpy.def strxfrm.def \ -index.def rindex.def strcspn.def strpbrk.def \ +index.def rindex.def strcspn.def strpbrk.def swab.def \ memchr.def strcat.def strerror.def strrchr.def \ memcmp.def strchr.def strlen.def strspn.def \ strcasecmp.def strncasecmp.def strlwr.def strupr.def diff --git a/newlib/libc/string/Makefile.in b/newlib/libc/string/Makefile.in index 29a413c0d..8139a578d 100644 --- a/newlib/libc/string/Makefile.in +++ b/newlib/libc/string/Makefile.in @@ -121,6 +121,7 @@ lib_a_SOURCES = \ strupr.c \ strxfrm.c \ strstr.c \ + swab.c \ u_strerr.c @@ -128,7 +129,7 @@ CHEWOUT_FILES = \ bcmp.def memcpy.def strcmp.def strncat.def strstr.def \ bcopy.def memmove.def strcoll.def strncmp.def strtok.def \ bzero.def memset.def strcpy.def strncpy.def strxfrm.def \ -index.def rindex.def strcspn.def strpbrk.def \ +index.def rindex.def strcspn.def strpbrk.def swab.def \ memchr.def strcat.def strerror.def strrchr.def \ memcmp.def strchr.def strlen.def strspn.def \ strcasecmp.def strncasecmp.def strlwr.def strupr.def @@ -155,7 +156,7 @@ lib_a_OBJECTS = bcmp.o bcopy.o bzero.o index.o memchr.o memcmp.o \ memcpy.o memmove.o memset.o rindex.o strcat.o strchr.o strcmp.o \ strcasecmp.o strcoll.o strcpy.o strcspn.o strerror.o strlen.o strlwr.o \ strncat.o strncmp.o strncasecmp.o strncpy.o strpbrk.o strrchr.o \ -strspn.o strtok.o strtok_r.o strupr.o strxfrm.o strstr.o u_strerr.o +strspn.o strtok.o strtok_r.o strupr.o strxfrm.o strstr.o swab.o u_strerr.o CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) CCLD = $(CC) diff --git a/newlib/libc/string/strings.tex b/newlib/libc/string/strings.tex index 2d17d1c6f..f70580b2c 100644 --- a/newlib/libc/string/strings.tex +++ b/newlib/libc/string/strings.tex @@ -37,6 +37,7 @@ managing areas of memory. The corresponding declarations are in * strtok:: Get next token from a string * strupr:: Convert string to upper case * strxfrm:: Transform string +* swab:: Swap adjacent bytes @end menu @page @@ -131,3 +132,6 @@ managing areas of memory. The corresponding declarations are in @page @include string/strxfrm.def + +@page +@include string/swab.def diff --git a/newlib/libc/string/swab.c b/newlib/libc/string/swab.c new file mode 100644 index 000000000..710ec5161 --- /dev/null +++ b/newlib/libc/string/swab.c @@ -0,0 +1,44 @@ +/* +FUNCTION + <>---swap adjacent bytes + +ANSI_SYNOPSIS + #include + void swab(const void *<[in]>, void *<[out]>, size_t <[n]>); + +TRAD_SYNOPSIS + void swab(<[in]>, <[out]>, <[n]> + void *<[in]>; + void *<[out]>; + size_t <[n]>; + +DESCRIPTION + This function copies <[n]> bytes from the memory region + pointed to by <[in]> to the memory region pointed to by + <[out]>, exchanging adjacent even and odd bytes. + +PORTABILITY +<> requires no supporting OS subroutines. +*/ + +#include + +void +_DEFUN (swab, (b1, b2, length), + _CONST void *b1 _AND + void *b2 _AND + ssize_t length) +{ + const char *from = b1; + char *to = b2; + ssize_t ptr; + for (ptr = 1; ptr < length; ptr += 2) + { + char p = from[ptr]; + char q = from[ptr-1]; + to[ptr-1] = p; + to[ptr ] = q; + } + if (ptr == length) /* I.e., if length is odd, */ + to[ptr-1] = 0; /* then pad with a NUL. */ +} -- 2.43.5