OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libc/] [string/] [swab.c] - Diff between revs 148 and 158

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 148 Rev 158
/*
/*
FUNCTION
FUNCTION
        <<swab>>---swap adjacent bytes
        <<swab>>---swap adjacent bytes
 
 
ANSI_SYNOPSIS
ANSI_SYNOPSIS
        #include <unistd.h>
        #include <unistd.h>
        void swab(const void *<[in]>, void *<[out]>, ssize_t <[n]>);
        void swab(const void *<[in]>, void *<[out]>, ssize_t <[n]>);
 
 
TRAD_SYNOPSIS
TRAD_SYNOPSIS
        void swab(<[in]>, <[out]>, <[n]>
        void swab(<[in]>, <[out]>, <[n]>
        void *<[in]>;
        void *<[in]>;
        void *<[out]>;
        void *<[out]>;
        ssize_t <[n]>;
        ssize_t <[n]>;
 
 
DESCRIPTION
DESCRIPTION
        This function copies <[n]> bytes from the memory region
        This function copies <[n]> bytes from the memory region
        pointed to by <[in]> to the memory region pointed to by
        pointed to by <[in]> to the memory region pointed to by
        <[out]>, exchanging adjacent even and odd bytes.
        <[out]>, exchanging adjacent even and odd bytes.
 
 
PORTABILITY
PORTABILITY
<<swab>> requires no supporting OS subroutines.
<<swab>> requires no supporting OS subroutines.
*/
*/
 
 
#include <unistd.h>
#include <unistd.h>
 
 
void
void
_DEFUN (swab, (b1, b2, length),
_DEFUN (swab, (b1, b2, length),
        _CONST void *b1 _AND
        _CONST void *b1 _AND
        void *b2 _AND
        void *b2 _AND
        ssize_t length)
        ssize_t length)
{
{
  const char *from = b1;
  const char *from = b1;
  char *to = b2;
  char *to = b2;
  ssize_t ptr;
  ssize_t ptr;
  for (ptr = 1; ptr < length; ptr += 2)
  for (ptr = 1; ptr < length; ptr += 2)
    {
    {
      char p = from[ptr];
      char p = from[ptr];
      char q = from[ptr-1];
      char q = from[ptr-1];
      to[ptr-1] = p;
      to[ptr-1] = p;
      to[ptr  ] = q;
      to[ptr  ] = q;
    }
    }
  if (ptr == length) /* I.e., if length is odd, */
  if (ptr == length) /* I.e., if length is odd, */
    to[ptr-1] = 0;   /* then pad with a NUL. */
    to[ptr-1] = 0;   /* then pad with a NUL. */
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.