Changeset 5c13d64 in buchla-68k for libsm


Ignore:
Timestamp:
07/09/2017 01:36:31 PM (7 years ago)
Author:
Thomas Lopatic <thomas@…>
Branches:
master
Children:
0292fbb
Parents:
002f873
Message:

Use void pointers for mem*() functions.

Location:
libsm
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • libsm/memccpy.c

    r002f873 r5c13d64  
    44        Version 1 -- 1987-06-12
    55
    6         Copy s2 to s1, stopping if character c is copied.
     6        Copy vp2 to vp1, stopping if character c is copied.
    77        Copy no more than n bytes.
    88        Return a pointer to the byte after character c in the copy,
     
    1111*/
    1212
    13 char *memccpy(char *s1, char *s2, char c, int n)
     13void *memccpy(void *vp1, void *vp2, char c, int n)
    1414{
    15         while (--n >= 0)
    16                 if ((*s1++ = *s2++) == c)
    17                         return(s1);
    18         return((char *)0);
     15        char *cp1 = vp1;
     16        char *cp2 = vp2;
     17
     18        while (--n >= 0)
     19                if ((*cp1++ = *cp2++) == c)
     20                        return(cp1);
     21
     22        return((void *)0);
    1923}
  • libsm/memchr.c

    r002f873 r5c13d64  
    44        Version 1 -- 1987-06-12
    55
    6         Return the ptr in sp at which the character c appears;
     6        Return the ptr in vp at which the character c appears;
    77        NULL if not found in n chars; don't stop at \0.
    88   =============================================================================
    99*/
    1010
    11 char *memchr(char *sp, char c, int n)
     11void *memchr(void *vp, char c, int n)
    1212{
    13         while (--n >= 0)
    14                 if (*sp++ == c)
    15                         return(--sp);
    16         return((char *)0);
     13        char *cp = vp;
     14
     15        while (--n >= 0)
     16                if (*cp++ == c)
     17                        return(--cp);
     18
     19        return((void *)0);
    1720}
  • libsm/memcmp.c

    r002f873 r5c13d64  
    44        Version 2 -- 1987-06-15
    55
    6         Compare n bytes:  s1>s2: >0  s1==s2: 0  s1<s2: <0
     6        Compare n bytes:  vp1>vp2: >0  vp1==vp2: 0  vp1<vp2: <0
    77   =============================================================================
    88*/
    99
    10 int memcmp(char *s1, char *s2, int n)
     10int memcmp(void *vp1, void *vp2, int n)
    1111{
     12        char *cp1 = vp1;
     13        char *cp2 = vp2;
    1214        register int    diff;
    1315
    14         if (s1 != s2)
    15                 while (--n >= 0)
    16                         if (diff = *s1++ - *s2++)
    17                                 return(diff);
    18         return(0);
     16        if (cp1 != cp2)
     17                while (--n >= 0)
     18                        if (diff = *cp1++ - *cp2++)
     19                                return(diff);
     20
     21        return(0);
    1922}
  • libsm/memcmpu.c

    r002f873 r5c13d64  
    88#include "ctype.h"
    99
    10 int memcmpu(char *s1, char *s2, int n)
     10int memcmpu(void *vp1, void *vp2, int n)
    1111{
     12        char *cp1 = vp1;
     13        char *cp2 = vp2;
    1214        register char c1, c2;
    1315
    1416        while (n) {
    1517
    16                 c1 = *s1++;
    17                 c2 = *s2++;
     18                c1 = *cp1++;
     19                c2 = *cp2++;
    1820
    1921                if (isascii(c1) && islower(c1))
  • libsm/memcpy.c

    r002f873 r5c13d64  
    44        Version 1 -- 1987-06-12
    55
    6         Copy s2 to s1, always copy n bytes.
    7         Return s1.
     6        Copy vp2 to vp1, always copy n bytes.
     7        Return vp1.
    88   =============================================================================
    99 */
    1010
    11 char *memcpy(char *s1, char *s2, int n)
     11void *memcpy(void *vp1, void *vp2, int n)
    1212{
    13         register char *os1 = s1;
     13        char *cp1 = vp1;
     14        char *cp2 = vp2;
    1415
    15         while (--n >= 0)
    16                 *s1++ = *s2++;
    17         return (os1);
     16        while (--n >= 0)
     17                *cp1++ = *cp2++;
     18
     19        return(vp1);
    1820}
  • libsm/memcpyw.c

    r002f873 r5c13d64  
    44        Version 2 -- 1987-06-15 -- D.N. Lynx Crowe
    55
    6         Copy s2 to s1, always copy n words.
    7         Return pointer to s1.
     6        Copy vp2 to vp1, always copy n words.
     7        Return pointer to vp1.
    88   =============================================================================
    99*/
    1010
    11 short *memcpyw(short *s1, short *s2, int n)
     11void *memcpyw(void *vp1, void *vp2, int n)
    1212{
    13         register short *os1 = s1;
     13        short *sp1 = vp1;
     14        short *sp2 = vp2;
    1415
    15         while (--n >= 0)
    16                 *s1++ = *s2++;
    17         return (os1);
     16        while (--n >= 0)
     17                *sp1++ = *sp2++;
     18
     19        return(vp1);
    1820}
  • libsm/memset.c

    r002f873 r5c13d64  
    44        Version 1 -- 1987-06-12
    55
    6         Set an array of n chars starting at sp to the character c.
    7         Return sp.
     6        Set an array of n chars starting at vp to the character c.
     7        Return vp.
    88   =============================================================================
    99*/
    1010
    11 char *memset(char *sp, char c, int n)
     11void *memset(void *vp, char c, int n)
    1212{
    13         register char *sp0 = sp;
     13        char *cp = vp;
    1414
    15         while (--n >= 0)
    16                 *sp++ = c;
     15        while (--n >= 0)
     16                *cp++ = c;
    1717               
    18         return(sp0);
     18        return(vp);
    1919}
  • libsm/memsetw.c

    r002f873 r5c13d64  
    44        Version 1 -- 1987-03-18 -- D.N. Lynx Crowe
    55
    6         Set an array of n shorts starting at sp to the short w.
    7         Return pointer to sp.
     6        Set an array of n shorts starting at vp to the short s.
     7        Return pointer to vp.
    88   =============================================================================
    99*/
    1010
    11 short *memsetw(short *sp, short w, short n)
     11void *memsetw(void *vp, short s, short n)
    1212{
    13         register short *sp0 = sp;
     13        short *sp = vp;
    1414
    15         while (--n >= 0)
    16                 *sp++ = w;
     15        while (--n >= 0)
     16                *sp++ = s;
    1717
    18         return(sp0);
     18        return(vp);
    1919}
Note: See TracChangeset for help on using the changeset viewer.