/**********************************************************************
 * luc_add_csp.c -- add email address to list of correspondents
 *
 * $Author: brlewis $
 * $Source: /afs/athena.mit.edu/astaff/project/lucydev/src/lib/RCS/luc_add_csp.c,v $
 * $Header: /afs/athena.mit.edu/astaff/project/lucydev/src/lib/RCS/luc_add_csp.c,v 1.1 91/08/01 14:27:56 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_add_csp_c[] = "$Header: /afs/athena.mit.edu/astaff/project/lucydev/src/lib/RCS/luc_add_csp.c,v 1.1 91/08/01 14:27:56 brlewis Exp Locker: brlewis $";
#endif /* lint */

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

/**********************************************************************
 * luc_add_csp(char *s)
 *
 * - adds s to correspondent list
 * - returns error code
 **********************************************************************/

long
luc_add_csp(s)
     char *s;
{
  char filename[127];
  FILE *fp;

  /* Get correspondents directory */
  sprintf(filename, "%s/Private", getenv("HOME"));
  if (access(filename, W_OK)) {
    if (mkdir(filename, 0700)) {
      strcpy(luv_context, filename);
      return((long) errno);
    }
  }

  /* Get correspondents file */
  strcat(filename, "/correspondents");
  fp = fopen(filename, "a");
  if (!fp) {
    strcpy(luv_context, filename);
    return((long) errno);
  }

  fprintf(fp, "%s\n", s);
  if (fclose(fp) == EOF) {
    strcpy(luv_context, filename);
    return((long) errno);
  }
  return(0L);
}
