static const char *RCS ="$Id: _close.c,v 4.1 1994/09/29 23:09:02 jraja Exp $";
/*
 *	_close.c - close a file (SAS/C)
 *
 *	Copyright © 1994 AmiTCP/IP Group,
 *			 Network Solutions Development Inc.
 *			 All rights reserved.
 */
#define KERNEL
#define _INTERNAL_FILE	     /* to get a file definition */
#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/file.h>
#include <bsdsocket.h>
#include <sys/syslog.h>
#include <errno.h>
extern int errno;

int __tcpclose(struct file *ufb)
{
  if (ufb->f_type != DTYPE_SOCKET) {
    errno = EBADF;
    syslog(LOG_ERR,"__tcpclose found a nonsocket.");
    return -1;
  }

    ufb->f_count--;

    if (ufb->f_count > 0)
	return 0;

    if (SocketBase)             /* caused an enforcer hit */
				/* it seems file closing is done after destructors are called */
	return TCP_CloseSocket((int)ufb->f_so);
    else
	return 0;
}

