utils/unistd.c
/**************************************************************************
 * Name:
 *  close
 *
 * Description:
 *  Close the current opened resource identified by fd.
 *
 * Return Value:
 *  OK in case the resource was closed without issues.
 *
 *************************************************************************/
close

Close the current opened resource identified by fd.

Return Value:
OK in case the resource was closed without issues.
close Close the current opened resource identified by fd . Return Value : OK in case the resource was closed without issues .
int close(int fd)
{
  irq_state_t irq_state = cpu_disableint();
  struct opened_resource_s *res = sched_find_opened_resource(fd);
  cpu_enableint(irq_state);
  if (res == NULL) {
    return -EINVAL;
  }
  if (!res->vfs_node->ops || !res->vfs_node->ops->close) {
    return -ENOSYS;
  }
  sem_wait(&res->vfs_node->lock);
  int ret = res->vfs_node->ops->close(res);
  sched_free_resource(fd);
  res->vfs_node->open_count -= 1;
  sem_post(&res->vfs_node->lock);
  return ret;
}
int close ( int fd ) { irq_state_t irq_state = cpu_disableint ( ) ; struct opened_resource_s * res = sched_find_opened_resource ( fd ) ; cpu_enableint ( irq_state ) ; if ( res == NULL ) { return - EINVAL ; } if ( ! res -> vfs_node -> ops || ! res -> vfs_node -> ops -> close ) { return - ENOSYS ; } sem_wait ( & res -> vfs_node -> lock ) ; int ret = res -> vfs_node -> ops -> close ( res ) ; sched_free_resource ( fd ) ; res -> vfs_node -> open_count -= 1 ; sem_post ( & res -> vfs_node -> lock ) ; return ret ; }
Name:
  close
Name : close