/**********************************************************************
 * ti library's routine for sending a file
 *
 * $Author: brlewis $
 * $Source: /afs/net.mit.edu/project/net_dev/brlewis/src/lib/RCS/sendfile.c,v $
 * $Header: /afs/net.mit.edu/project/net_dev/brlewis/src/lib/RCS/sendfile.c,v 0.2 92/04/01 16:17:09 brlewis Exp $
 *
 * 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_ti_sendfile_c[] = "$Header: /afs/net.mit.edu/project/net_dev/brlewis/src/lib/RCS/sendfile.c,v 0.2 92/04/01 16:17:09 brlewis Exp $";
#endif /* lint */

#include <stdio.h>
#include <ti/ti.h>

/**********************************************************************
 * ti_sendfile(TI_H *hti, ti_node_H hnode, FILE *fp)
 *	hnode must be a node that has been created with TI_NSYSGEN_FN set
 *
 * - sends contents of buf to server
 * - returns error code
 **********************************************************************/

/* jms 7/13/92 -- windows-izing begun */
/* i/o needs work. */

long
ti_sendfile(hti, hnode, fp)
     TI_H tp;
     ti_node_H hnode;
     FILE *fp;
{
  long code;
  char buf[BUFSIZ];
  int nbytes;

  /* tell server that file is coming */
  if (code=ti_sendfirst(hti, hnode)) return(code);

  /* send contents of file */
  do
    {
      if (nbytes = fread(buf, sizeof(char), BUFSIZ, fp))
	  if (code=ti_sendmiddle(hti, buf, nbytes)) return(code);
    } while (nbytes == BUFSIZ);

  /* send `EOF' */
  return(ti_sendlast(hti));
}
