home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / swtools / mipsABI / examples / after / index.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  1.1 KB  |  66 lines

  1. /*
  2.  * illustrate the use of memory and string routines
  3.  *
  4.  * If _ABI_SOURCE is defined, redefine all the changed routines
  5.  */
  6.  
  7. #ifdef _ABI_SOURCE
  8. #include <string.h>
  9. #define ANSI_STRING
  10. #else
  11. #include <strings.h>
  12. #endif
  13. #ifdef  _ABI_SOURCE
  14. #include <memory.h>
  15. #endif
  16. #include <stdio.h>
  17.  
  18. #ifdef  ANSI_STRING
  19.  
  20. #ifndef index
  21. #define index(s, c)     strchr((s), (c))
  22. #endif
  23. #ifndef rindex
  24. #define rindex(s, c)    strrchr((s), (c))
  25. #endif
  26.  
  27. #ifndef bcmp
  28. #define bcmp(s1, s2, n) memcmp ((s1), (s2), (n))
  29. #endif
  30. #ifndef bzero
  31. #define bzero(s, n)     memset ((s), 0, (n))
  32. #endif
  33. #ifndef bcopy
  34. #define bcopy(s, d, n)  memcpy ((d), (s), (n))
  35. #endif
  36.  
  37. #else   /* Not ANSI_STRING.  */
  38.  
  39. extern int bcmp ();
  40. extern void bzero ();
  41. extern void bcopy ();
  42.  
  43. #endif  /* ANSI_STRING.  */
  44. #undef  ANSI_STRING
  45.  
  46.  
  47. #define BUFFER 256
  48. char *string = "this is a test";
  49. char buf[BUFFER];
  50.  
  51. main ()
  52. {
  53.     int rv;
  54.     char *cp;
  55.  
  56.     bzero (buf, BUFFER);
  57.     bcopy (string, buf, strlen(string));
  58.     rv = bcmp (string, buf, strlen(string));
  59.     if ( rv == 0 )
  60.         printf ("Copied strings match\n");
  61.     cp = index (buf, 'a');
  62.     if (cp != NULL)
  63.         printf ("Found character in string\n");
  64.     
  65. }
  66.