home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR41 / CBASE11.ZIP / ANSI.C next >
C/C++ Source or Header  |  1993-01-01  |  2KB  |  118 lines

  1. /*
  2.  *    Copyright (c) 1989-1992 Citadel Software, Inc.
  3.  *    All Rights Reserved
  4.  */
  5.  
  6. /* #ident    "@(#)ansi.c    1.7 - 93/01/01" */
  7.  
  8. #include <port.h>
  9.  
  10. /* standard headers */
  11. #include <errno.h>
  12. #ifdef AC_STDDEF
  13. #include <stddef.h>
  14. #endif
  15. #include <stdio.h>
  16.  
  17. /* function declarations */
  18. #ifdef AC_PROTO
  19. int link(const char *path1, const char *path2);
  20. int unlink(const char *path);
  21. #else
  22. int link();
  23. int unlink();
  24. #endif
  25.  
  26. /* global data declarations */
  27. extern char *sys_errlist[];
  28. extern int sys_nerr;
  29.  
  30. /*man---------------------------------------------------------------------------
  31. NAME
  32.     ansi - ANSI functions required by cbase
  33.  
  34. DESCRIPTION
  35.     This file contains ANSI functions required by cbase which may not
  36.     be available with older compilers.  It is likely to require
  37.     editing.
  38.  
  39. ------------------------------------------------------------------------------*/
  40. #ifndef AC_STRING
  41. /* memmove:  memory move */
  42. #ifdef AC_PROTO
  43. void *memmove(void *t, const void *s, size_t n)
  44. #else
  45. void *memmove(t, s, n)
  46. void *t;
  47. const void *s;
  48. size_t n;
  49. #endif
  50. {
  51.     int i = 0;
  52.  
  53.     if (t < s) {
  54.         for (i = 0; i < n; ++i) {
  55.             *((char *)t + i) = *((char *)s + i);
  56.         }
  57.     } else {
  58.         for (i = n - 1; i >= 0; --i) {
  59.             *((char *)t + i) = *((char *)s + i);
  60.         }
  61.     }
  62.  
  63.     return t;
  64. }
  65. #endif
  66.  
  67. #ifdef AC_PROTO
  68. void perror(const char *s)
  69. #else
  70. void perror(s)
  71. const char *s;
  72. #endif
  73. {
  74.     if (s != NULL) {
  75.         fputs(s, stderr);
  76.         fputs(": ", stderr);
  77.     }
  78.     if (errno >= 0 && errno < sys_nerr) {
  79.         fprintf(stderr, "%s\n", sys_errlist[errno]);
  80.     } else {
  81.         fprintf(stderr, "Error number %d\n", errno);
  82.     }
  83.  
  84.     return;
  85. }
  86.  
  87. #ifdef AC_PROTO
  88. int remove(const char *filename)
  89. #else
  90. int remove(filename)
  91. const char *filename;
  92. #endif
  93. {
  94.     if (unlink(filename) == -1) {
  95.         return -1;
  96.     }
  97.  
  98.     return 0;
  99. }
  100.  
  101. #ifdef AC_PROTO
  102. int rename(const char *file1, const char *file2)
  103. #else
  104. int rename(file1, file2)
  105. const char *file1;
  106. const char *file2;
  107. #endif
  108. {
  109.     if (link(file1, file2) == -1) {
  110.         return -1;
  111.     }
  112.     if (unlink(file1) == -1) {
  113.         return -1;
  114.     }
  115.  
  116.     return 0;
  117. }
  118.