home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / cfuncs / osf.c < prev    next >
C/C++ Source or Header  |  2000-07-29  |  2KB  |  81 lines

  1. /*
  2. ############################################################################
  3. #
  4. #    File:     osf.c
  5. #
  6. #    Subject:  Function to return OSF system table value
  7. #
  8. #    Author:   Gregg M. Townsend
  9. #
  10. #    Date:     November 17, 1997
  11. #
  12. ############################################################################
  13. #
  14. #   This file is in the public domain.
  15. #
  16. ############################################################################
  17. #
  18. #  osftable(id, index, len) returns one element from an OSF table() call.
  19. #  This function is for the OSF operating system, and fails on other systems.
  20. #  See "man table" for a detailed description of the "table" system call
  21. #  and the formats of the structures returned; see /usr/include/table.h
  22. #  for a list of allowed ID values.
  23. #  Defaults: index    0
  24. #            len    100
  25. #
  26. ############################################################################
  27. #
  28. #  Requires:  OSF or Digital UNIX, dynamic loading
  29. #
  30. ############################################################################
  31. */
  32.  
  33. #include "icall.h"
  34. #include <stdlib.h>
  35.  
  36. #define DEFLENGTH 100
  37.  
  38. #ifndef __osf__
  39. int osftable (int argc, descriptor argv[])  { Fail; }
  40. #else
  41.  
  42. int osftable (int argc, descriptor argv[])    /*: query OSF system table */
  43.    {
  44.    int id, index, len;
  45.    static void *buf;
  46.    static int bufsize;
  47.  
  48.    if (argc == 0)
  49.       Error(101);
  50.    ArgInteger(1);
  51.    id = IntegerVal(argv[1]);
  52.  
  53.    if (argc > 1)  {
  54.       ArgInteger(2);
  55.       index = IntegerVal(argv[2]);
  56.       }
  57.    else
  58.       index = 0;
  59.  
  60.    if (argc > 2)  {
  61.       ArgInteger(3);
  62.       len = IntegerVal(argv[3]);
  63.       }
  64.    else
  65.       len = DEFLENGTH;
  66.  
  67.    if (len > bufsize) {
  68.       buf = realloc(buf, bufsize = len);
  69.       if (len > 0 && !buf)
  70.          Error(305);
  71.       }
  72.  
  73.    if ((id = table(id, index, buf, 1, len)) != 1)
  74.       Fail;
  75.    RetStringN(buf, len);
  76.    }
  77.  
  78. #endif
  79.