This is the mail archive of the
newlib@sourceware.cygnus.com
mailing list for the newlib project.
Implementation of swab()
- To: newlib at sourceware dot cygnus dot com
- Subject: Implementation of swab()
- From: Alexandre Oliva <oliva at lsd dot ic dot unicamp dot br>
- Date: 08 Mar 2000 00:45:47 -0300
I'm checking this in, approved by J. Johnston:
Index: newlib/ChangeLog
from 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.
Index: newlib/libc/string/Makefile.am
===================================================================
RCS file: /cvs/cvsfiles/devo/newlib/libc/string/Makefile.am,v
retrieving revision 1.1
diff -u -r1.1 Makefile.am
--- newlib/libc/string/Makefile.am 1998/07/17 20:21:27 1.1
+++ newlib/libc/string/Makefile.am 2000/03/04 06:54:40
@@ -39,13 +39,14 @@
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: newlib/libc/string/strings.tex
===================================================================
RCS file: /cvs/cvsfiles/devo/newlib/libc/string/strings.tex,v
retrieving revision 1.8
diff -u -r1.8 strings.tex
--- newlib/libc/string/strings.tex 1999/01/25 17:07:57 1.8
+++ newlib/libc/string/strings.tex 2000/03/04 06:54:40
@@ -37,6 +37,7 @@
* 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 @@
@page
@include string/strxfrm.def
+
+@page
+@include string/swab.def
Index: newlib/libc/include/string.h
===================================================================
RCS file: /cvs/cvsfiles/devo/newlib/libc/include/string.h,v
retrieving revision 1.20
diff -u -r1.20 string.h
--- newlib/libc/include/string.h 2000/01/11 00:20:58 1.20
+++ newlib/libc/include/string.h 2000/03/04 06:54:40
@@ -69,6 +69,7 @@
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: newlib/libc/string/swab.c
===================================================================
RCS file: swab.c
diff -N swab.c
--- newlib/libc/string/swab.c Tue May 5 13:32:27 1998
+++ newlib/libc/string/swab.c Tue Mar 7 19:33:34 2000
@@ -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. */
+}
Index: newlib/libc/string/Makefile.in
===================================================================
RCS file: /cvs/cvsfiles/devo/newlib/libc/string/Makefile.in,v
retrieving revision 1.25
diff -u -r1.25 Makefile.in
--- newlib/libc/string/Makefile.in 2000/01/11 00:21:01 1.25
+++ newlib/libc/string/Makefile.in 2000/03/04 06:30:06
@@ -121,6 +121,7 @@
strupr.c \
strxfrm.c \
strstr.c \
+ swab.c \
u_strerr.c
@@ -128,7 +129,7 @@
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 @@
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)
--
Alexandre Oliva http://www.ic.unicamp.br/~oliva/ Enjoy Guaranį
Cygnus Solutions, a Red Hat company aoliva@{redhat, cygnus}.com
Free Software Developer and Evangelist CS PhD student at IC-Unicamp
oliva@{lsd.ic.unicamp.br, gnu.org} Write to mailing lists, not to me