/**********************************************************************
 * luc_fill_nb.c -- fill in contents of name block
 *
 * $Author: brlewis $
 * $Source: /afs/athena.mit.edu/astaff/project/lucydev/src/lib/RCS/luc_fill_nb.c,v $
 * $Header: /afs/athena.mit.edu/astaff/project/lucydev/src/lib/RCS/luc_fill_nb.c,v 1.2 91/08/01 14:30:19 brlewis Exp Locker: brlewis $
 *
 * Copyright 1991 by the Massachusetts Institute of Technology.
 *
 * For copying and distribution information, please see the file
 * <mit-copyright.h>.
 **********************************************************************/
#include <mit-copyright.h>

#ifndef lint
static char rcsid_luc_fill_nb_c[] = "$Header: /afs/athena.mit.edu/astaff/project/lucydev/src/lib/RCS/luc_fill_nb.c,v 1.2 91/08/01 14:30:19 brlewis Exp Locker: brlewis $";
#endif /* lint */

#include <stdio.h>
#include <strings.h>
#include <sys/errno.h>
#include <pwd.h>
#include "lucy/lucy.h"
#include "lucy/memory.h"

/**********************************************************************
 * luc_fill_nb(name_blk *nb, char *host, char *path)
 *	caller should allocate and zero nb
 *	caller supplies host to be filled in nb->hostname
 *	caller supplies path to be filled in nb->pathname
 *
 * - fills in all necessary fields of name_blk
 * - returns error code if out of memory
 **********************************************************************/

long
luc_fill_nb(nb, host, path)
     name_blk *nb;
     char *host, *path;
{
  struct passwd *pw;

  /* allocate fields. */
  nb->hostname = newstring(host);
  nb->pathname = newstring(path);
  nb->user_id = malloc(9);
  if (!nb->hostname || !nb->pathname || !nb->user_id) {
    luv_context[0] = '\0';	/* error context = "" */
    return((long) errno);
  }

  strcpy(nb->hostname, host);
  strcpy(nb->pathname, path);

  /* find username */
  pw = getpwuid((int) getuid());
  if (!pw) {
    strcpy(nb->user_id, "unknown");
  } else (void) strcpy(nb->user_id, pw->pw_name);
  return(0L);
}
