source: trunk/kernel/syscalls/sys_close.c @ 1

Last change on this file since 1 was 1, checked in by alain, 5 years ago

First import

File size: 1.5 KB
Line 
1/*
2 * sys_close.c  close a process open file
3 *
4 * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless
5 * Copyright (c) 2011,2012 UPMC Sorbonne Universites
6 *
7 * This file is part of ALMOS-kernel.
8 *
9 * ALMOS-kernel is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2.0 of the License.
12 *
13 * ALMOS-kernel is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with ALMOS-kernel; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include <cpu.h>
24#include <device.h>
25#include <driver.h>
26#include <vfs.h>
27#include <sys-vfs.h>
28#include <process.h>
29#include <thread.h>
30#include <config.h>
31
32/////////////////////////////
33int sys_close ( uint32_t fd )
34{
35        register process_t * process = current_process;
36        register thread_t  * this    = current_thread;
37        struct vfs_file_s  * file    = NULL;
38        error_t              err;
39 
40        if(( fd >= CONFIG_TASK_FILE_MAX_NR ) || (process_fd_lookup( process , fd , &file )))
41        {
42                this->info.errno = EBADFD;
43                return -1;
44        }
45
46        err = vfs_close( file , NULL );
47        if( err )
48        {
49                this->info.errno = err;
50                return -1;
51        }
52
53        process_fd_release( process , fd );
54        cpu_wbflush();
55        return 0;
56}
Note: See TracBrowser for help on using the repository browser.