home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / sysutl / emsuit11.arc / EMSKILL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-22  |  4.8 KB  |  135 lines

  1. /***************************************************************************
  2.  *     EMSKILL vers 1.1, DOS                                               *
  3.  *     Releases EMS memory by handle                                       *
  4.  *     12/30/89                                                            *
  5.  *     by James W. Birdsall                                                *
  6.  *                                                                         *
  7.  *     compiles under Turbo C 2.0                                          *
  8.  *                                                                         *
  9.  *   Usage: EMSKILL handle [handle handle ...]                             *
  10.  *   Releases EMS memory associated with each handle specified on the      *
  11.  *   command line. Compatible with all versions of LIM EMS specification   *
  12.  *   3.0 and greater (specifically 3.0, 3.2, and 4.0).                     *
  13.  *                                                                         *
  14.  *   WARNING: THIS PROGRAM CAN KILL EMS MEMORY CURRENTLY IN USE BY ANOTHER *
  15.  *            PROGRAM, SUCH AS A DISK CACHE OR A RAMDISK. BE CERTAIN THAT  *
  16.  *            THE HANDLE YOU INTEND TO KILL DOES NOT BELONG TO SUCH A      *
  17.  *            PROGRAM. EMSKILL WILL NOT ALLOW HANDLE 0 (THE OS HANDLE) TO  *
  18.  *            BE KILLED.                                                   *
  19.  *                                                                         *
  20.  ***************************************************************************/
  21.  
  22.  
  23. #include <stdio.h>
  24. #include <io.h>
  25. #include <dos.h>
  26.  
  27.  
  28.  
  29. #define VERSION 1.1
  30.  
  31.  
  32.  
  33. char copyright[] = "Copyright (c) 1989 James W. Birdsall. All Rights Reserved";
  34.  
  35.  
  36.  
  37. int checkEMM(void);
  38.  
  39.  
  40.  
  41. /***************************************************************************
  42.  *     FUNCTION MAIN                                                       *
  43.  ***************************************************************************/
  44. main(int argc, char *argv[])
  45. {
  46.    int loop;
  47.    int handle;
  48.    union REGS r;
  49.  
  50.    /* if no handles or invalid handle, print usage message and exit */
  51.    for(loop = 1; loop < argc; loop++) {
  52.       if (atoi(argv[loop]) == 0) {
  53.          break;
  54.          }
  55.       }
  56.    if ((loop != argc) || (argc < 2)) {
  57.       printf("\nEMSKILL vers %.1f by James W. Birdsall\n", VERSION);
  58.       printf("   Releases EMS memory by handle.\n");
  59.       printf("   Usage: EMSKILL handle [handle handle ...]\n");
  60.       printf("     handle   number of the EMS handle to be released.\n");
  61.       printf("\n");
  62.       printf("   WARNING: THIS PROGRAM CAN KILL EMS MEMORY CURRENTLY IN\n");
  63.       printf("            USE BY ANOTHER PROGRAM, SUCH AS A DISK CACHE OR\n");
  64.       printf("            A RAMDISK. BE CERTAIN THAT THE HANDLE YOU INTEND\n");
  65.       printf("            TO KILL DOES NOT BELONG TO SUCH A PROGRAM.\n");
  66.       printf("            EMSKILL WILL NOT ALLOW HANDLE 0 (THE OS HANDLE)\n");
  67.       printf("            TO BE KILLED.\n\n");
  68.       exit(3);
  69.       }
  70.  
  71.    /* check for functioning EMM */
  72.    if (checkEMM() != 1) {
  73.       printf("EMS manager not present or malfunctioning.\n");
  74.       exit(3);
  75.       }
  76.    /* check version */
  77.    r.h.ah = 0x46;
  78.    int86(0x67, &r, &r);
  79.    if (r.h.ah != 0) {
  80.       printf("Error 0x%x talking to EMS manager.\n");
  81.       exit(3);
  82.       }
  83.    if ((r.h.al >> 4) < 3) {
  84.       printf("EMSKILL requires LIM EMS version 3.0 or greater.\n");
  85.       exit(2);
  86.       }
  87.  
  88.    /* loop through arguments */
  89.    for(loop = 1; loop < argc; loop++) {
  90.       /* get handle number, try to release */
  91.       handle = atoi(argv[loop]);
  92.       r.h.ah = 0x45;
  93.       r.x.dx = handle;
  94.       int86(0x67, &r, &r);
  95.       /* print result */
  96.       if (r.h.ah != 0) {
  97.          printf("Error 0x%x%s releasing handle %d.\n", r.h.ah,
  98.                       ((r.h.ah == 0x83) ? " (invalid handle)" : ""), handle);
  99.          }
  100.         else {
  101.          printf("Handle %d released OK.\n", handle);
  102.          }
  103.       }
  104.  
  105.    exit(0);
  106. } /* end of function main */
  107.  
  108.  
  109.  
  110. /***************************************************************************
  111.  *     FUNCTION CHECKEMM                                                   *
  112.  *   Checks for function EMM. 1 = OK, 0 = error                            *
  113.  ***************************************************************************/
  114. int checkEMM(void)
  115. {
  116.    FILE *tempfile;
  117.    int temphandle;
  118.  
  119.    /* check if EMM is present */
  120.    if ((tempfile = fopen("EMMXXXX0","rb")) == NULL)
  121.       return 0;
  122.    /* make sure we've found a device and not a file */
  123.    temphandle = fileno(tempfile);
  124.    if ((ioctl(temphandle, 0) & 0x80) != 0x80)
  125.       return 0;
  126.    /* check status of EMM */
  127.    if (ioctl(temphandle, 7) <= 0)
  128.       return 0;
  129.    /* close and return */
  130.    fclose(tempfile);
  131.    return 1;
  132. } /* end of function checkEMM */
  133.  
  134.  
  135. /* end of file EMSKILL.C */