home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name UTNULCHK -- Check low bytes in default data segment
- * for changes.
- *
- * Synopsis changed = utnulchk ();
- *
- * unsigned int changed Is nonzero if the bytes in low
- * memory have been changed since
- * UTNULCHK was called and returned
- * nonzero.
- *
- * Description UTNULCHK checks the first BNULCHKSIZE (usually 16) bytes
- * in the default data segment to see if they have been
- * changed. If they have, this usually indicates
- * assignment through a NIL pointer. If a change is
- * detected, the new data is recorded, so that UTNULCHK
- * will not return 1 again until the data changes again.
- *
- * The first call to UTNULCHK sets up its data structures,
- * and always returns 0. Subsequent calls return 0 or 1 to
- * indicate whether the first BNULCHKSIZE bytes in the
- * default data segment have changed.
- *
- * Returns changed 0 if low memory has not been changed,
- * 1 if it has.
- *
- * 0 on the first call.
- *
- * Version 6.00 (C)Copyright Blaise Computing Inc. 1987,1989
- *
- **/
-
-
- #include <dos.h>
-
- #include <butil.h>
-
- #define BCHKNULSIZE 0x10 /* #of bytes to save from low memory. */
-
-
- /* Flag to indicate whether or not */
- /* UTNULCHK has been called before. */
- static unsigned char b_chkdid = 0;
-
- /* Buffer to store low memory bytes for */
- /* later comparison. */
- static char b_chkbyt [BCHKNULSIZE];
-
-
- unsigned int utnulchk()
- {
- char far *plow; /* Pointer to low memory. */
- unsigned int changed=0; /* Flag to indicate memory changed. */
- unsigned int i; /* Counter/array index. */
- unsigned int seg; /* Segment to read in low memory. */
-
- seg = utseg (&_psp);
-
- if (b_chkdid) /* If this is not the first call to */
- { /* UTNULCHK... */
-
- /* Check each byte to make sure it is */
- /* the same as it was. */
- for (plow = uttofar (seg, 0, char), i = 0;
- (i < BCHKNULSIZE) && (!changed);
- plow++, i++)
-
- if (utpeekb (plow) != b_chkbyt [i])
- changed = 1;
- }
-
- /* If it was changed or this is the */
- /* first call to UTNULCHK... */
- if (changed || (!b_chkdid))
- {
- /* Read current low memory into buffer. */
- utpeekn (uttofar (seg, 0, char), b_chkbyt, BCHKNULSIZE);
-
- b_chkdid = 1; /* Set flag to indicate we read it. */
- }
-
- return (changed);
- }