libowfat/io/io_close.c

32 lines
677 B
C
Raw Normal View History

2003-09-02 00:14:04 +00:00
#include <unistd.h>
#include <sys/types.h>
#ifdef __MINGW32__
#include <windows.h>
#else
2003-11-15 00:11:24 +00:00
#include <sys/mman.h>
#endif
2003-09-02 00:14:04 +00:00
#include "io_internal.h"
extern void io_dontwantread_really(int64 d,io_entry* e);
extern void io_dontwantwrite_really(int64 d,io_entry* e);
2003-09-02 00:14:04 +00:00
void io_close(int64 d) {
2003-09-06 00:03:27 +00:00
io_entry* e;
if ((e=iarray_get(&io_fds,d))) {
e->inuse=0;
2005-09-02 21:52:22 +00:00
e->cookie=0;
if (e->kernelwantread) io_dontwantread_really(d,e);
if (e->kernelwantwrite) io_dontwantwrite_really(d,e);
2003-11-15 00:11:24 +00:00
if (e->mmapped) {
#ifdef __MINGW32__
UnmapViewOfFile(e->mmapped);
CloseHandle(e->mh);
#else
2003-11-15 00:11:24 +00:00
munmap(e->mmapped,e->maplen);
#endif
2003-11-15 00:11:24 +00:00
e->mmapped=0;
}
}
2003-09-06 01:36:50 +00:00
close(d);
2003-09-02 00:14:04 +00:00
}