home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / UTNULCHK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  2.4 KB  |  85 lines

  1. /**
  2. *
  3. * Name        UTNULCHK -- Check low bytes in default data segment
  4. *                for changes.
  5. *
  6. * Synopsis    changed = utnulchk ();
  7. *
  8. *        unsigned int changed    Is nonzero if the bytes in low
  9. *                    memory have been changed since
  10. *                    UTNULCHK was called and returned
  11. *                    nonzero.
  12. *
  13. * Description    UTNULCHK checks the first BNULCHKSIZE (usually 16) bytes
  14. *        in the default data segment to see if they have been
  15. *        changed.  If they have, this usually indicates
  16. *        assignment through a NIL pointer.  If a change is
  17. *        detected, the new data is recorded, so that UTNULCHK
  18. *        will not return 1 again until the data changes again.
  19. *
  20. *        The first call to UTNULCHK sets up its data structures,
  21. *        and always returns 0.  Subsequent calls return 0 or 1 to
  22. *        indicate whether the first BNULCHKSIZE bytes in the
  23. *        default data segment have changed.
  24. *
  25. * Returns    changed     0 if low memory has not been changed,
  26. *                1 if it has.
  27. *
  28. *                0 on the first call.
  29. *
  30. * Version    6.00 (C)Copyright Blaise Computing Inc.  1987,1989
  31. *
  32. **/
  33.  
  34.  
  35. #include <dos.h>
  36.  
  37. #include <butil.h>
  38.  
  39. #define BCHKNULSIZE 0x10    /* #of bytes to save from low memory.   */
  40.  
  41.  
  42.                 /* Flag to indicate whether or not        */
  43.                 /* UTNULCHK has been called before.     */
  44. static unsigned char b_chkdid = 0;
  45.  
  46.                 /* Buffer to store low memory bytes for */
  47.                 /* later comparison.            */
  48. static char b_chkbyt [BCHKNULSIZE];
  49.  
  50.  
  51. unsigned int utnulchk()
  52. {
  53.     char far *plow;        /* Pointer to low memory.            */
  54.     unsigned int changed=0; /* Flag to indicate memory changed.     */
  55.     unsigned int i;        /* Counter/array index.            */
  56.     unsigned int seg;        /* Segment to read in low memory.        */
  57.  
  58.     seg = utseg (&_psp);
  59.  
  60.     if (b_chkdid)        /* If this is not the first call to     */
  61.     {                /* UTNULCHK...                */
  62.  
  63.                 /* Check each byte to make sure it is   */
  64.                 /* the same as it was.            */
  65.     for (plow = uttofar (seg, 0, char),  i = 0;
  66.          (i < BCHKNULSIZE) && (!changed);
  67.          plow++, i++)
  68.  
  69.         if (utpeekb (plow) != b_chkbyt [i])
  70.         changed = 1;
  71.     }
  72.  
  73.                 /* If it was changed or this is the     */
  74.                 /* first call to UTNULCHK...        */
  75.     if (changed || (!b_chkdid))
  76.     {
  77.                 /* Read current low memory into buffer. */
  78.     utpeekn (uttofar (seg, 0, char), b_chkbyt, BCHKNULSIZE);
  79.  
  80.     b_chkdid = 1;        /* Set flag to indicate we read it.     */
  81.     }
  82.  
  83.     return (changed);
  84. }
  85.