OSDN Git Service

* libc/string/Makefile.am (lib_a_SOURCES): Added swab.c.
authoraoliva <aoliva>
Wed, 8 Mar 2000 03:46:00 +0000 (03:46 +0000)
committeraoliva <aoliva>
Wed, 8 Mar 2000 03:46:00 +0000 (03:46 +0000)
(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
newlib/libc/include/string.h
newlib/libc/string/Makefile.am
newlib/libc/string/Makefile.in
newlib/libc/string/strings.tex
newlib/libc/string/swab.c [new file with mode: 0644]

index 656fcbb..cf16f1d 100644 (file)
@@ -1,3 +1,12 @@
+Wed Mar  8 00:43:07 2000  Alexandre Oliva  <oliva@lsd.ic.unicamp.br>
+
+       * 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  <oliva@lsd.ic.unicamp.br>
 
        * libc/stdio/Makefile.am (lib_a_SOURCES): Added getw.c and putw.c.
index a9494f8..0707aac 100644 (file)
@@ -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
index 26d4b89..dceb4d9 100644 (file)
@@ -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
index 29a413c..8139a57 100644 (file)
@@ -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)
index 2d17d1c..f70580b 100644 (file)
@@ -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 (file)
index 0000000..710ec51
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+FUNCTION
+       <<swab>>---swap adjacent bytes
+
+ANSI_SYNOPSIS
+       #include <string.h>
+       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
+<<swab>> requires no supporting OS subroutines.
+*/
+
+#include <string.h>
+
+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. */
+}