Fixed ZDE build - missing header file
[ZeXOS.git] / kernel / lib / stdio / close.c
blob8860b923ae70bc776b092ea4c1f50eef472e2f4e
1 /*
2 * ZeX/OS
3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
4 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * Copyright (C) 2009 Martin 'povik' Poviser (martin.povik@gmail.com)
6 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include <system.h>
24 #include <file.h>
25 #include <fd.h>
26 #include <net/socket.h>
27 #include <pipe.h>
28 #include <cache.h>
30 int close (int fd)
32 fd_t *f = fd_get (fd);
34 if (!f)
35 return 0;
37 if (f->flags & FD_SOCK) // socket close
38 sclose (fd);
40 if (f->flags & FD_PIPE) // pipe close
41 pipe_close (fd);
43 f->id = 0;
44 f->flags = 0;
45 f->e = 0;
47 if (f->s)
48 cache_closebyptr (f->s);
50 /* delete old file descriptor from fd_list */
51 f->next->prev = f->prev;
52 f->prev->next = f->next;
54 return 1;