X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fmmap.c;h=c5794da9195748e6b2cccca1cbccbc097d52a94b;hb=refs%2Fheads%2Fdebian;hp=7316389b99ec6eca4f9768d01030b86861aa582b;hpb=620a63c3ed751a136a7a26a03de2924bda01d744;p=fw%2Fstlink diff --git a/src/mmap.c b/src/mmap.c index 7316389..c5794da 100644 --- a/src/mmap.c +++ b/src/mmap.c @@ -1,69 +1,33 @@ -/* mmap.c -- version of mmap for gold. */ - -/* Copyright 2009 Free Software Foundation, Inc. - Written by Vladimir Simonov . - - This file is part of gold. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, - MA 02110-1301, USA. */ - -//#include "config.h" -//#include "ansidecl.h" - #include #include -#ifdef HAVE_STDLIB_H #include -#endif +#include #include "mmap.h" -extern ssize_t pread (int, void *, size_t, off_t); +void *mmap (void *addr, size_t len, int prot, int flags, int fd, long long offset) { + + void *buf; + ssize_t count; -void * -mmap (void *__addr, size_t __len, int __prot, - int __flags, int __fd, long long __offset) -{ - void *ret; - ssize_t count; + if ( addr || fd == -1 || (prot & PROT_WRITE)) return MAP_FAILED; - if (__addr || (__fd != -1 && (__prot & PROT_WRITE)) - || (__flags & MAP_SHARED)) - return MAP_FAILED; + buf = malloc(len); + if ( NULL == buf ) return MAP_FAILED; - ret = malloc (__len); - if (!ret) - return MAP_FAILED; + if (lseek(fd,offset,SEEK_SET) != offset) return MAP_FAILED; - if (__fd == -1) - return ret; + count = read(fd, buf, len); - count = pread (__fd, ret, __len, __offset); - if ((size_t) count != __len) - { - free (ret); - return MAP_FAILED; + if (count != len) { + free (buf); + return MAP_FAILED; } - return ret; + return buf; } -int -munmap (void *__addr, size_t __len) -{ - free (__addr); - return 0; +int munmap (void *addr, size_t len) { + free (addr); + return 0; }