home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / utilities / utilst / virtual / !Virtual / c / lib < prev    next >
Text File  |  1992-07-26  |  1KB  |  74 lines

  1. #include "swis.h"
  2. #include "swiv.h"
  3.  
  4. #include "lib.h"
  5.  
  6. void strcpy(char *p,char *q)
  7. {
  8. while ((*p++=*q++)!=0)
  9.   ;
  10. }
  11.  
  12. void memcpy(char *p, char *q, int n)
  13. {
  14. while (n-->0)
  15.   *p++=*q++;
  16. }
  17.  
  18. int strlen( char *p )
  19. {
  20.   int n=0;
  21.   while (*p++)
  22.     n++;
  23.   return n;
  24. }
  25.  
  26. int xtoi( char *p )
  27. {
  28.   int v=0;
  29.   if (swix(OS_ReadUnsigned,IN(R0|R1)|OUT(R2),16,p,&v))
  30.     return 0;
  31.   return v;
  32. }
  33.  
  34. int sizetoi( char *p )
  35. {
  36.   int v=0;
  37.   if (swix(OS_ReadUnsigned,IN(R0|R1)|OUT(R1|R2),10,p,&p,&v))
  38.     return 0;
  39.   if (*p=='K' || *p=='k')
  40.     v*=1024;
  41.   if (*p=='M' || *p=='m')
  42.     v*=1024*1024;
  43.   return v;
  44. }
  45.  
  46. void *alloc(int size)
  47.   void *addr;
  48.   swi(OS_Module, IN(R0|R3)|OUT(R2), 6, size, &addr);
  49.   return addr;
  50. }
  51.  
  52. void free(void *addr)
  53. {
  54.   if (addr)
  55.     swi(OS_Module, IN(R0|R2), 7, addr);
  56. }
  57.  
  58. #ifndef print_f
  59. #define print_f 0xBe00
  60. #endif
  61.  
  62. void printf(char *format,...)
  63. {
  64.   int *a=(int *)&format+1;
  65.   swi(print_f,IN(R0|R1|R2|R3|R4|R5|R6|R7|R8),format,a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]);
  66. }
  67.  
  68. void _printf(char *format,...)
  69. {
  70.   int *a=(int *)&format+1;
  71.   swi(print_f,IN(R0|R1|R2|R3|R4|R5|R6|R7|R8),format,a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]);
  72. }
  73.