home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / FILES.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  2KB  |  75 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. ** FILES.C:  A program to determine the number of file handles
  5. **
  6. ** Released in to the Public Domain by Matthew Hunt @ 1:129/135, in the
  7. ** hopes that no "programmer" will be so lazy that he|she simple reads
  8. ** the CONFIG.SYS file ever again.
  9. **
  10. ** Any improvements and modifications are welcome, but I ask that all
  11. ** modified versions also be placed into the Public Domain.
  12. **
  13. ** Information on the List of Lists and SFT format was provided by
  14. ** PC Magazine November 26, 1991, and PC Interrupts by Ralf Brown
  15. ** and Jim Kyle.  FILES.C was originally written for Power C.
  16. **
  17. ** Modifications for other compiler support by Bob Stout @ 1:106/2000.6
  18. */
  19.  
  20. #include <dos.h>
  21. #include "dosfiles.h"
  22. #include "mk_fp.h"
  23.  
  24. /*
  25. ** Walk the SFT linked list, counting file handles as we go
  26. */
  27.  
  28. int files(void)
  29. {
  30.       struct SFT_HEADER (FAR *sft);
  31.       unsigned int segment, offset;
  32.       int count=0;
  33.       union REGS regs;
  34.       struct SREGS sregs;
  35.  
  36.       /* Get ptr to List of Lists in ES:DX */
  37.  
  38.       regs.x.ax = 0x5200;
  39.       segread(&sregs);
  40.       intdosx(®s, ®s, &sregs);
  41.  
  42.       /* Get ssss:oooo to first SFT  */
  43.  
  44.       segment = *((unsigned FAR *)(MK_FP(sregs.es, regs.x.bx + 6)));
  45.       offset  = *((unsigned FAR *)(MK_FP(sregs.es, regs.x.bx + 4)));
  46.  
  47.       /* Point our structure to it.  */
  48.  
  49.       sft = MK_FP(segment, offset);
  50.  
  51.       do
  52.       {
  53.             count += sft->number;               /* Add the number of FILES */
  54.             sft = sft->next;                    /* Point to next one       */
  55.       } while(FP_OFF(sft->next) != 0x0FFFF);    /* Last one in the chain   */
  56.  
  57.       /* Add the FILES for the last entry */
  58.  
  59.       count += sft->number;
  60.       return count;
  61. }
  62.  
  63. #ifdef TEST
  64.  
  65. #include <stdio.h>
  66. #include <stdlib.h>
  67.  
  68. int main(void)
  69. {
  70.     printf("Number of FILES entries: %d", files());
  71.     return EXIT_SUCCESS;
  72. }
  73.  
  74. #endif /* TEST */
  75.