home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume05 / bsdgetut < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  3.4 KB

  1. From decwrl!purdue!mailrus!ncar!tank!nic.MR.NET!hal!ncoast!allbery Sun Nov 13 00:43:31 PST 1988
  2. Article 713 of comp.sources.misc:
  3. Path: granite!decwrl!purdue!mailrus!ncar!tank!nic.MR.NET!hal!ncoast!allbery
  4. From: jeff@tekcsc.mkt.tek.com (Jeff Beadles)
  5. Newsgroups: comp.sources.misc
  6. Subject: v05i037: Provides access to utmp file from C (For BSD)
  7. Message-ID: <8811010139.AA01510@tekcsc.MKT.TEK.COM>
  8. Date: 9 Nov 88 02:12:57 GMT
  9. Sender: allbery@ncoast.UUCP
  10. Reply-To: jeff@tekcsc.mkt.tek.com (Jeff Beadles)
  11. Lines: 103
  12. Approved: allbery@ncoast.UUCP
  13.  
  14. Posting-number: Volume 5, Issue 37
  15. Submitted-by: "Jeff Beadles" <jeff@tekcsc.mkt.tek.com>
  16. Archive-name: bsd.getut
  17.  
  18. [I take it this was redirected.  Note that it won't help you compile s5finger
  19. on a non-System-V system:  getutline() isn't here.  ++bsa]
  20.  
  21. Here's something for comp.sources.unix.  It does have a copyright message,
  22. but I think that it's more than reasonable.
  23.  
  24. Jeff Beadles  IDG Customer Support Center Tektronix, Inc.
  25. jeff@tekcsc.MKT.TEK.COM -or-              POB 1000
  26.  ..!tektronix!tekcsc.mkt.tek.com!jeff     Wilsonville, OR. 97070 MS 63-171
  27.  
  28.  
  29. #--------------------------------CUT HERE-------------------------------------
  30. #! /bin/sh
  31. #
  32. # This is a shell archive.  Save this into a file, edit it
  33. # and delete all lines above this comment.  Then give this
  34. # file to sh by executing the command "sh file".  The files
  35. # will be extracted into the current directory owned by
  36. # you with default permissions.
  37. #
  38. # The files contained herein are:
  39. #
  40. # -rw-r--r--  1 jeff         1462 Oct 31 17:36 myutmp.c
  41. #
  42. echo 'x - myutmp.c'
  43. if test -f myutmp.c; then echo 'shar: not overwriting myutmp.c'; else
  44. sed 's/^X//' << '________This_Is_The_END________' > myutmp.c
  45. X/*
  46. X *    myutmp.c  Copyright 1988, Jeff Beadles
  47. X *    Permission is granted to this program where ever you desire as long
  48. X *    as I am credited as the author.
  49. X *
  50. X *    (Does this exist somewhere?  I couldn't find a tool to do this
  51. X *    function!)
  52. X *
  53. X *    This will make-up for the lack of {get,end,set}utent.  It is not a
  54. X *    complete implimentation, but should get most people by.  I wrote it
  55. X *    so I could compile and use "party", on a BSD system here.
  56. X *
  57. X *    No makefile is needed.  Just cc -c myutmp.c  This will NOT give an
  58. X *    executable program.  It must be loaded into a program that requires
  59. X *    getutent, endutent, setutent.
  60. X *
  61. X *    Question, comments, suggestions to jeff@tekcsc.MKT.TEK.COM.
  62. X *    Flames to /dev/null.  (What do you expect for free?)
  63. X *
  64. X */
  65. X
  66. X#include <utmp.h>
  67. X#include <stdio.h>
  68. Xvoid setutent(), endutent();
  69. Xstruct utmp *getutent();
  70. Xint fp;
  71. X
  72. X/*
  73. X *    Set-up utemp file for reading
  74. X */
  75. Xvoid setutent()
  76. X    {
  77. X    fp=open("/etc/utmp",0);
  78. X    if ( fp == -1 )
  79. X        {
  80. X        perror("Error opening /etc/utmp");
  81. X        exit(-1);
  82. X        }
  83. X    }
  84. X/*
  85. X *    Get an entry from the utmp file.  Return NULL if not available.
  86. X */
  87. Xstruct utmp *getutent()
  88. X    {
  89. X    int retval;
  90. X    static struct utmp myline;
  91. X
  92. X    retval=read(fp, &myline, sizeof(struct utmp));
  93. X    if ( retval != sizeof(struct utmp))
  94. X        return( ((struct utmp *) NULL) );
  95. X        else
  96. X        if ( myline.ut_name[0] == '\0')
  97. X            getutent();    /* call again, eats blank entries */
  98. X        return(&myline);
  99. X    }
  100. X
  101. X/*
  102. X *    End use of utmp file.
  103. X */
  104. Xvoid endutent()
  105. X    {
  106. X    close(fp);
  107. X    fp=0;
  108. X    }
  109. X
  110. X
  111. ________This_Is_The_END________
  112. if test `wc -l < myutmp.c` -ne 66; then
  113.     echo 'shar: myutmp.c was damaged during transit (should have been 66 lines)'
  114. fi
  115. fi        ; : end of overwriting check
  116. exit 0
  117.  
  118.  
  119.