home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / uname.c < prev    next >
C/C++ Source or Header  |  1992-09-05  |  2KB  |  88 lines

  1. /*
  2.  * uname() emulation by Dave Gymer. In the public domain.
  3.  * Bugs:
  4.  *    The MiNT version stuff is in the release field. According to the GNU
  5.  *    shell utils this is the way SunOS does it, so we put the TOS
  6.  *    version number in the 'version' field (even under MiNT).
  7.  *
  8.  * (Modified slightly by ERS.)
  9.  */
  10.  
  11. #include <stdlib.h>
  12. #include <unistd.h>
  13. #include <osbind.h>
  14. #include <stdio.h>
  15. #include <string.h>
  16. #ifdef __TURBOC__
  17. #include <sys\utsname.h>
  18. #else
  19. #include <sys/utsname.h>
  20. #endif
  21.  
  22. extern int __mint;
  23. __EXTERN int gethostname __PROTO((char *buf, size_t len));
  24.  
  25. static long _mch;    /* value of the _MCH cookie, if any */
  26. static int tosvers;    /* TOS version number */
  27.  
  28. /*
  29.  * get operating system information; must execute in supervisor mode
  30.  */
  31.  
  32. static void
  33. getinfo()
  34. {
  35.     long *cookie, *sysbase;
  36.  
  37. /* get _MCH cookie value */
  38.     cookie = *((long **) 0x5a0L);
  39.     if (cookie) {
  40.         while (*cookie) {
  41.             if (*cookie == 0x5f4d4348L) {    /* _MCH */
  42.                 _mch = cookie[1];
  43.                 break;
  44.             }
  45.             cookie += 2;
  46.         }
  47.     }
  48.  
  49. /* get TOS version number */
  50.     sysbase = *((long **)(0x4f2L));
  51.     tosvers = (int)(sysbase[0] & 0x0000ffff);
  52. }
  53.  
  54. #define HILO(x) (int) ((x >> 8) & 255), (int) (x & 255)
  55.  
  56. int
  57. uname(buf)
  58.     struct utsname *buf;
  59. {
  60.     if (!tosvers)
  61.         (void)Supexec(getinfo);
  62.  
  63.     strcpy(buf->sysname, __mint ? "MiNT" : "TOS");
  64.  
  65.     if (gethostname(buf->nodename, (size_t) 15))
  66.         strcpy(buf->nodename, "??node??");
  67.  
  68.     if (__mint)
  69.         sprintf(buf->release, "%d.%d", HILO(__mint));
  70.     else
  71.         buf->release[0] = 0;
  72.  
  73.     sprintf(buf->version, "%d.%d", HILO(tosvers));
  74.  
  75.     switch((int)((_mch >> 16) & 0x0ffffL)) {
  76.     case 0:
  77.         strcpy(buf->machine, "atarist"); break;
  78.     case 1:
  79.         strcpy(buf->machine, "atariste"); break;
  80.     case 2:
  81.         strcpy(buf->machine, "ataritt"); break;
  82.     default:
  83.         strcpy(buf->machine, "atari");
  84.     }
  85.  
  86.     return 0;
  87. }
  88.