home *** CD-ROM | disk | FTP | other *** search
/ CD Shareware Magazine 1996 December / CD_shareware_12-96.iso / DOS / Programa / CCDL122.ZIP / CLIBS / IO / TEST / LOCIO.C next >
Encoding:
C/C++ Source or Header  |  1996-07-26  |  3.6 KB  |  163 lines

  1. #include <stdio.h>
  2. #include "time.h"
  3. #include "stdlib.h"
  4. #include "string.h"
  5.  
  6. /* STDINC stuff compatible with our sys */
  7.  
  8. /* CCFILE is the new definition, FILE is the BCC definition */
  9. typedef struct  {
  10.         int             level;          /* fill/empty level of buffer */
  11.         unsigned        flags;          /* File status flags          */
  12.         char            fd;             /* File descriptor            */
  13.         unsigned char   hold;           /* Ungetc char if no buffer   */
  14.                 char pad,pad1;                                    /* We need this to get BCC to define the
  15.                                                                                  * structure right */
  16.         int             bsize;          /* Buffer size                */
  17.         unsigned char   *buffer;   /* Data transfer buffer       */
  18.         unsigned char   *curp;     /* Current active pointer     */
  19.         unsigned        istemp;         /* Temporary file indicator   */
  20.         short           token;          /* Used for validity checking */
  21. }       CCFILE;                           /* This is the FILE object    */
  22.  
  23. #define _NFILE_ 100
  24.  
  25. extern FILE _streams[];
  26.  
  27. extern CCFILE *_PSTREAMS[_NFILE_];
  28. extern char *_FILENAMES[_NFILE_];
  29. extern int MAXFILES;
  30.  
  31. char inbuf[512];
  32. char outbuf[512];
  33. char errbuf[512];
  34. static int numopen = 0;
  35. static FILE *table[40];
  36.  
  37. #define FILTOK 0x444c
  38.  
  39. static CCFILE IN = {
  40.     0,_F_READ | _F_LBUF,0,0,0,0,512,&inbuf,&inbuf,0,FILTOK
  41. };
  42. static CCFILE OUT = {
  43.     0,_F_WRIT | _F_LBUF,1,0,0,0,512,&outbuf,&outbuf,0,FILTOK
  44. };
  45. static CCFILE ERR = {
  46.     0,_F_WRIT | _F_LBUF,2,0,0,0,512,&errbuf,&errbuf,0,FILTOK
  47. };
  48.  
  49. CCFILE *STDIN = &IN, *STDOUT = &OUT, *STDERR = &ERR;
  50.  
  51. /* REXIT is actually defined in the startup files and does not have to
  52.  * be written explicitly
  53.  */
  54. void _REXIT(void)
  55. {
  56.     exit(0);
  57. }
  58. void _LL_INIT(void)
  59. {
  60.     table[numopen++] = &_streams[0];    
  61.     table[numopen++] = &_streams[1];    
  62.     table[numopen++] = &_streams[2];
  63.     _PSTREAMS[MAXFILES++] = &IN;
  64.     _PSTREAMS[MAXFILES++] = &OUT;
  65.     _PSTREAMS[MAXFILES++] = &ERR;
  66. }
  67. int _LL_OPEN(char *__name, int flags)
  68. {
  69.     char buf[10],*p=buf;
  70.     if (flags & _F_READ)
  71.         *p++ = 'r';
  72.     if (flags & _F_BIN)
  73.         *p++ = 'b';
  74.     if (flags & _F_WRIT)
  75.         *p++ = '+';
  76.     *p = 0;
  77.     table[numopen] = fopen(__name,buf);
  78.     if (table[numopen])
  79.         return numopen++;
  80.     return 0;
  81. }
  82. int _LL_CREAT(char *__name, int flags)
  83. {
  84.     char buf[10],*p=buf;
  85.     if (flags & _F_WRIT)
  86.         *p++ = 'w';
  87.     if (flags & _F_BIN)
  88.         *p++ = 'b';
  89.     if (flags & _F_READ)
  90.         *p++ = '+';
  91.     *p = 0;
  92.     table[numopen] = fopen(__name,buf);
  93.     if (table[numopen])
  94.         return numopen++;
  95.     return 0;
  96. }
  97. int _LL_CLOSE(int __fd)
  98. {
  99.     int i;
  100.     fclose(table[__fd]);
  101.     for (i=__fd+1; i < numopen-1; i++)
  102.         table[i] = table[i+1];
  103.     numopen--;
  104.     return 0;
  105. }
  106. size_t _LL_GETPOS(int __fd)
  107. {
  108.     return ftell(table[__fd]);
  109. }
  110. int _LL_FLAGS(int __oldflags)
  111. {
  112.     return __oldflags;
  113. }
  114. int _LL_SEEK(int __fd, size_t __pos, int __origin)
  115. {
  116.     fseek(table[__fd],__pos,__origin);
  117.     return 0;
  118. }
  119. int _LL_RENAME(char *__old, char *__new)
  120. {
  121.     return rename(__old,__new);
  122. }
  123. int _LL_REMOVE(char *__name)
  124. {
  125.     return remove(__name);
  126. }
  127. int _LL_WRITE(int __fd,void *__buf,size_t __size)
  128. {
  129.     return !(fwrite(__buf,__size,1,table[__fd]) == __size);
  130. }
  131. int _LL_READ(int __fd,void *__buf,size_t __len)
  132. {
  133.     return fread(__buf,1,__len,table[__fd]);
  134. }
  135. void _LL_TRANSFER()
  136. {
  137. }
  138. void *_LL_MALLOC(size_t size)
  139. {
  140.     return(malloc(size));
  141. }
  142. void _LL_FREE(void *block)
  143. {
  144.     free(block);
  145. }
  146. struct tm *_LL_GETTIME(struct tm *tm2)
  147. {
  148.     time_t t = time(0);
  149.     *tm2 = *localtime(&t);
  150.     return tm2;
  151. }
  152. _LL_TICKS()
  153. {
  154.     return 0;
  155. }
  156. _LL_SYSTEM(char *name)
  157. {
  158.     return 0;
  159. }
  160. _LL_GETENV(void)
  161. {
  162.     return 0;
  163. }