home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / Telecomm / st52.zoo / cookie.c < prev    next >
C/C++ Source or Header  |  1991-01-21  |  2KB  |  70 lines

  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <osbind.h>
  4. #include <stdio.h>
  5. #include "st52.h"
  6.  
  7. /* Most of the cookie code here by Eric R. Smith */
  8.  
  9. /* we use a union because most cookie tags are 4 ASCII characters, so it
  10.    may be useful to sometimes think of them as strings. On the other hand,
  11.    they *are* longwords, so we may want to access them that way, too
  12.  */
  13.  
  14. union clong {
  15.     char    aschar[4];
  16.     long    aslong;
  17. };
  18.  
  19. /*
  20.  * a cookie consists of 2 longwords; a tag and a value. The tag is normally
  21.  * chosen to have some sort of significance when represented as 4 ascii
  22.  * characters (see the union definition above). What the value represents
  23.  * is dependent on the tag; it may be an address (for a TSR), or a version
  24.  * number (e.g. MiNT does this), or whatever (it may not even have a meaning).
  25.  */
  26.  
  27. struct cookie {
  28.     union clong tag;
  29.     long value;
  30. };
  31.  
  32. typedef struct cookie COOKIE;
  33.  
  34. /*
  35.  * A pointer to the cookie jar is found at 0x5a0. If there is no cookie jar
  36.  * installed, this pointer will be 0. The cookie jar itself is an array
  37.  * of cookies, with the last cookie having a "tag" of 0x00000000. (The value
  38.  * of this cookie is the number of slots left in the cookie jar.)
  39.  */
  40.  
  41. #define CJAR    ((COOKIE **) 0x5a0)
  42.  
  43. long
  44. getcookie(char *cookieid)
  45. {
  46.   char biscuit[5];
  47.   long retval = 0L;
  48.   long ssp;
  49.   char *p;
  50.   COOKIE *cookie;
  51.  
  52.   ssp = Super(0L);
  53.   cookie = *CJAR;
  54.  
  55.   if (cookie) {
  56.     while (cookie->tag.aslong != 0) {
  57.       p = cookie->tag.aschar;
  58.       sprintf(biscuit, "%c%c%c%c%c%c", p[0], p[1], p[2], p[3], '\000');
  59.       if (strncmp(cookieid, biscuit, 4) == 0) {
  60.         retval = (cookie->value);
  61.         break;
  62.       }
  63.       cookie++;
  64.     }
  65.   }
  66.   ssp = Super(ssp);
  67.   return (retval);
  68. }
  69.  
  70.