home *** CD-ROM | disk | FTP | other *** search
/ Nebula / nebula.bin / SourceCode / libcs / gethostattr.c < prev    next >
C/C++ Source or Header  |  1990-12-11  |  3KB  |  89 lines

  1. /*
  2.  * Copyright (c) 1990 Carnegie Mellon University
  3.  * All Rights Reserved.
  4.  * 
  5.  * Permission to use, copy, modify and distribute this software and its
  6.  * documentation is hereby granted, provided that both the copyright
  7.  * notice and this permission notice appear in all copies of the
  8.  * software, derivative works or modified versions, and any portions
  9.  * thereof, and that both notices appear in supporting documentation.
  10.  *
  11.  * THE SOFTWARE IS PROVIDED "AS IS" AND CARNEGIE MELLON UNIVERSITY
  12.  * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  13.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT
  14.  * SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE FOR ANY SPECIAL, DIRECT,
  15.  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  16.  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
  17.  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  18.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19.  *
  20.  * Users of this software agree to return to Carnegie Mellon any
  21.  * improvements or extensions that they make and grant Carnegie the
  22.  * rights to redistribute these changes.
  23.  *
  24.  * Export of this software is permitted only after complying with the
  25.  * regulations of the U.S. Deptartment of Commerce relating to the
  26.  * Export of Technical Data.
  27.  */
  28. /*
  29.  * gethostattr(ptrs, ptrcnt)
  30.  * char *ptrs[];
  31.  * int ptrcnt;
  32.  *
  33.  * This routine takes a pointer to an array of ptrcnt character pointers.
  34.  * It will place a pointer to each attribute of the current host into
  35.  * this array.  The pointers are pointing to a static buffer, so they
  36.  * should be copied if necessary.  The routine returns -1 on error, or
  37.  * the number of pointers placed in the array.  In addition, the pointer
  38.  * after the last pointer used is set to NULL if there is room in the
  39.  * array.
  40.  *
  41.  **********************************************************************
  42.  * HISTORY
  43.  * $Log:    gethostattr.c,v $
  44.  * Revision 1.4  90/12/11  17:54:30  mja
  45.  *     Add copyright/disclaimer for distribution.
  46.  * 
  47.  * 08-Nov-85  Jonathan McElravy (jm) at Carnegie-Mellon University
  48.  *      Added an fclose to close attributes file on success.
  49.  *
  50.  * 12-Oct-85  Glenn Marcy (gm0w) at Carnegie-Mellon University
  51.  *    Created.
  52.  *
  53.  **********************************************************************
  54.  */
  55.  
  56. #include <stdio.h>
  57. #include <libc.h>
  58.  
  59. static char buf[BUFSIZ];
  60.  
  61. gethostattr(ptrs, ptrcnt)
  62. char *ptrs[];
  63. int ptrcnt;
  64. {
  65.     char hname[256], *p, *q;
  66.     int count;
  67.     FILE *f;
  68.  
  69.     if (gethostname(hname, 256) < 0)
  70.     return(-1);
  71.     if ((f = fopen("/etc/attributes", "r")) == NULL)
  72.     return(-1);
  73.     while (p = fgets(buf, BUFSIZ, f)) {
  74.     if (strcasecmp(nxtarg(&p, ":"), hname)) continue;
  75.     fclose(f);
  76.     count = 0;
  77.     while (*(q = nxtarg(&p, ":\n"))) {
  78.         if (count < ptrcnt)
  79.         ptrs[count] = q;
  80.         count++;
  81.     }
  82.     if (count < ptrcnt)
  83.         ptrs[count] = NULL;
  84.     return(count);
  85.     }
  86.     fclose(f);
  87.     return(-1);
  88. }
  89.