ftp.nice.ch/pub/next/unix/admin/msend.1.0.N.bs.tar.gz#/msend/utmp.c

This is utmp.c in view mode; [Download] [Up]

/* utmp.c:
 *
 * these routines are for manipulating the utmp file.  these were written
 * by Phil Budne (budd@bu-it.bu.edu) originally.
 */

#include "config.h"
#include "msend.h"

static FILE *uf;			/* utmp file */
static char *utmpfile = "/etc/utmp";	/* utmp file name */

/* open the utmp file if necessary and read one entry at a time
 */

struct utmp *getutent()
{ static struct utmp ubuf;
  struct stat   stb;

  /* verify that utmp file is a reasonable size
   */

  if (uf == NULL) {
    if (stat(utmpfile,&stb) == 0 ) {
      if ((stb.st_size % sizeof(struct utmp)) != 0) {
        return(NULL);
      }
    }
    else
      return(NULL);

    /* open utmp
     */

    if ((uf= fopen(utmpfile,"r")) == NULL) /* was '< 0' -20 Mar 89-composer */
      return(NULL);
  }

  /* read next utmp entry and return it if we can
   */

  if (fread(&ubuf,sizeof(ubuf),1,uf) == 0 ) {
    fseek(uf,0L,0);
    return(NULL);
  }

/* fix for problem with ut_name containing both ut_name and ut_host */
/*   when the size of ut_name = 8 .. - 20 Mar 89 - composer         */
/*   one slight side effect - kills 1st char of ut_host             */
  ubuf.ut_name[8] = '\0';
  return(&ubuf);
}

/* close utmp file
 */

void endutent()
{
  if(uf != NULL) {
    fclose(uf);
    uf= NULL;
  }
}



These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.