home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume9 / siotools / part01 / kmemsio.c next >
Encoding:
C/C++ Source or Header  |  1989-12-04  |  2.5 KB  |  124 lines

  1. /* CHK=0xF436 */
  2. /*+-------------------------------------------------------------------------
  3.     kmemsio.c
  4.     ...!gatech!emory!tridom!wht
  5.  
  6.   Defined functions:
  7.     kmem_init_tty()
  8.     kmem_read_tty(ttfirst,ttcount)
  9.  
  10. --------------------------------------------------------------------------*/
  11. /*+:EDITS:*/
  12. /*:12-04-1989-16:05-wht-creation */
  13.  
  14. #include <sys/types.h>
  15. #include <sys/stat.h>
  16. #define TERMIO_HACK /* for XENIX termio.h multiple inclusion problem */
  17. #include <sys/tty.h>
  18.  
  19. #include "kmemsio.h"
  20.  
  21. #if defined(M_UNIX)
  22. #include <nlist.h>
  23. #define XLIST nlist
  24. #define XL_name n_name
  25. #define XL_value n_value
  26. #define XL_type n_type
  27. #else
  28. #include <sys/a.out.h>
  29. #define XLIST xlist
  30. #define XL_name xl_name
  31. #define XL_value xl_value
  32. #define XL_type xl_type
  33. #endif
  34.  
  35. #ifdef M_UNIX
  36. char *kernel_file = "/unix";
  37. #else
  38. char *kernel_file = "/xenix";
  39. #endif
  40. char *kmem_file = "/dev/kmem";
  41.  
  42. int kmemfd;
  43.  
  44. #if defined(M_UNIX)
  45. struct XLIST kernel_symbols[] = {
  46. #define KS_SIO_TTY    0
  47.     { "sio_tty" },
  48.     { (char *)0 }
  49. };
  50. #else
  51. struct XLIST kernel_symbols[] = {
  52. #define KS_SIO_TTY    0
  53.     {0,0,0, "_sio_tty" },
  54.     {0,0,0, (char *)0 }
  55. };
  56. #endif
  57.  
  58. #define    sio_tty_fpos kernel_symbols[KS_SIO_TTY].XL_value
  59.  
  60. struct tty sio[SIO_NTTY];
  61.  
  62. static char errmsg[80];
  63.  
  64. extern int errno;
  65. extern char *sys_errlist[];
  66.  
  67. /*+-------------------------------------------------------------------------
  68.     kmem_read_tty(ttfirst,ttcount)
  69. --------------------------------------------------------------------------*/
  70. char *
  71. kmem_read_tty(ttfirst,ttcount)
  72. int ttfirst;
  73. int ttcount;
  74. {
  75. int len = ttcount * sizeof(struct tty);
  76.  
  77.     if(((unsigned)ttfirst >= SIO_NTTY) ||
  78.         (((unsigned)ttfirst + (unsigned)ttcount) > SIO_NTTY))
  79.         return(" illegal tty ");
  80.  
  81.     if(lseek(kmemfd,sio_tty_fpos + (ttfirst * sizeof(struct tty)),0) == -1)
  82.     {
  83.         sprintf(errmsg,
  84.             " kmem lseek failure: %s ",sys_errlist[errno]);
  85.         return(errmsg);
  86.     }
  87.     errno = 0;
  88.     if(read(kmemfd,(char *)sio,len) != len)
  89.     {
  90.         sprintf(errmsg,
  91.             " kmem read failure: %s ",sys_errlist[errno]);
  92.         return(errmsg);
  93.     }
  94.  
  95.     return((char *)0);
  96.  
  97. }    /* end of kmem_read_tty */
  98.  
  99. /*+-------------------------------------------------------------------------
  100.     kmem_init_tty()
  101. --------------------------------------------------------------------------*/
  102. char *
  103. kmem_init_tty()
  104. {
  105.  
  106.     if((kmemfd = open(kmem_file,0)) < 0)
  107.     {
  108.         sprintf(errmsg," %s: %s ",kmem_file,sys_errlist[errno]);
  109.         return(errmsg);
  110.     }
  111.  
  112.     if(XLIST(kernel_file,kernel_symbols))
  113.     {
  114.         sprintf(errmsg," xlist/nlist failure: %s ",kernel_file);
  115.         return(errmsg);
  116.     }
  117.  
  118.     return((char *)0);
  119.  
  120. }    /* end of kmem_init_tty */
  121.  
  122. /* vi: set tabstop=4 shiftwidth=4: */
  123. /* end of kmemsio.c */
  124.