From 8e4efc36028140a7ac7fffd181040654a4931bd1 Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Wed, 16 May 2012 22:15:38 +0100 Subject: [PATCH 1/5] reimplement mingw mmap --- configure.ac | 3 +-- src/mmap.c | 74 ++++++++++++++-------------------------------------- src/mmap.h | 59 ++++++++++------------------------------- src/pread.c | 42 ----------------------------- 4 files changed, 34 insertions(+), 144 deletions(-) delete mode 100644 src/pread.c diff --git a/configure.ac b/configure.ac index 866d8bb..f7feed2 100644 --- a/configure.ac +++ b/configure.ac @@ -18,8 +18,7 @@ AM_PROG_CC_C_O AC_CHECK_HEADERS(sys/mman.h) AC_CHECK_HEADERS(sys/poll.h) -AC_CHECK_FUNCS(mmap) -AC_REPLACE_FUNCS(mmap pread) +AC_REPLACE_FUNCS(mmap) # Checks for libraries. PKG_CHECK_MODULES(USB, libusb-1.0 >= 1.0.0,, diff --git a/src/mmap.c b/src/mmap.c index 7316389..8a0a2e3 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 * -mmap (void *__addr, size_t __len, int __prot, - int __flags, int __fd, long long __offset) -{ - void *ret; - ssize_t count; + void *buf; + ssize_t count; - if (__addr || (__fd != -1 && (__prot & PROT_WRITE)) - || (__flags & MAP_SHARED)) - return MAP_FAILED; + if ( addr || fd == -1 || (prot & PROT_WRITE)) return MAP_FAILED; - ret = malloc (__len); - if (!ret) - return MAP_FAILED; + buf = malloc(len); + if ( NULL == buf ) return MAP_FAILED; - if (__fd == -1) - return ret; + if (lseek(fd,offset,SEEK_SET) != offset) return MAP_FAILED; + + count = read(fd, buf, len); + + if (count != len) { + free (buf); + return MAP_FAILED; + } - count = pread (__fd, ret, __len, __offset); - if ((size_t) count != __len) - { - free (ret); - 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; } diff --git a/src/mmap.h b/src/mmap.h index 375eafb..bff766c 100644 --- a/src/mmap.h +++ b/src/mmap.h @@ -1,62 +1,31 @@ -/* mmap.h -- mmap family functions prototypes 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. */ - -#ifndef GOLD_MMAP_H -#define GOLD_MMAP_H +#ifndef STLINK_MMAP_H +#define STLINK_MMAP_H #ifdef HAVE_SYS_MMAN_H - #include - -/* Some BSD systems still use MAP_ANON instead of MAP_ANONYMOUS. */ - -#ifndef MAP_ANONYMOUS -# define MAP_ANONYMOUS MAP_ANON -#endif - #else -#define PROT_READ 0x1 -#define PROT_WRITE 0x2 +#define PROT_READ (1<<0) +#define PROT_WRITE (1<<1) -#define MAP_SHARED 0x01 -#define MAP_PRIVATE 0x02 +#define MAP_SHARED (1<<0) +#define MAP_PRIVATE (1<<1) -#define MAP_ANONYMOUS 0x20 +#define MAP_ANONYMOUS (1<<5) -#define MAP_FAILED ((void *) -1) -#endif /* HAVE_SYS_MMAN_H */ +#define MAP_FAILED ((void *)-1) -#ifndef HAVE_MMAP #ifdef __cplusplus extern "C" { #endif -extern void *mmap (void *__addr, size_t __len, int __prot, - int __flags, int __fd, long long __offset); -extern int munmap (void *__addr, size_t __len); + +void *mmap(void *addr, size_t len, int prot, int flags, int fd, long long offset); +int munmap(void *addr, size_t len); + #ifdef __cplusplus } #endif -#endif /* HAVE_MMAP */ +#endif /* HAVE_SYS_MMAN_H */ -#endif /* GOLD_MMAP_H */ +#endif /* STLINK_MMAP_H */ diff --git a/src/pread.c b/src/pread.c deleted file mode 100644 index 4ac6115..0000000 --- a/src/pread.c +++ /dev/null @@ -1,42 +0,0 @@ -/* pread.c -- version of pread for gold. */ - -/* Copyright 2006, 2007, 2009 Free Software Foundation, Inc. - Written by Ian Lance Taylor . - - 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. */ - -/* This file implements pread for systems which don't have it. This - file is only compiled if pread is not present on the system. This - is not an exact version of pread, as it does not preserve the - current file offset. */ - -//#include "config.h" - -#include -#include -#include - -extern ssize_t pread (int, void *, size_t, off_t); - -ssize_t -pread (int fd, void *buf, size_t count, off_t offset) -{ - if (lseek(fd, offset, SEEK_SET) != offset) - return -1; - return read(fd, buf, count); -} From 5bbef2f18bd36e510dcff6aab43d65203aeb3e73 Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Wed, 16 May 2012 22:22:54 +0100 Subject: [PATCH 2/5] fix whitespace --- src/mmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mmap.c b/src/mmap.c index 8a0a2e3..9c631da 100644 --- a/src/mmap.c +++ b/src/mmap.c @@ -16,9 +16,9 @@ void *mmap (void *addr, size_t len, int prot, int flags, int fd, long long offs if ( NULL == buf ) return MAP_FAILED; if (lseek(fd,offset,SEEK_SET) != offset) return MAP_FAILED; - + count = read(fd, buf, len); - + if (count != len) { free (buf); return MAP_FAILED; From 89016d1d86de485ecb1f75312f17ee3574d07f0b Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Wed, 16 May 2012 22:44:31 +0100 Subject: [PATCH 3/5] add COPYING to repository to avoid license confusion --- .gitignore | 1 - COPYING | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 COPYING diff --git a/.gitignore b/.gitignore index 0a705b5..cf2f1a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -COPYING INSTALL Makefile.in aclocal.m4 diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..37b124e --- /dev/null +++ b/COPYING @@ -0,0 +1,27 @@ +Copyright (c) 2011 The "Capt'ns Missing Link" Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Martin Capitanio nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. From 4080a3ecbb8fcf7ac83cc53903a0b8f379cc3fc0 Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Wed, 16 May 2012 23:31:07 +0100 Subject: [PATCH 4/5] bump version --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index f7feed2..1f00f3a 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.61) -AC_INIT([stlink],[0.5.2],[davem@devkitpro.org]) +AC_INIT([stlink],[0.5.3],[davem@devkitpro.org]) AC_CONFIG_SRCDIR([src/stlink-common.c]) AC_CONFIG_LIBOBJ_DIR([src]) AM_INIT_AUTOMAKE([1.10]) From 299c5d272f58c7cb803d6a61ca16d9551c7697e5 Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Wed, 16 May 2012 23:41:42 +0100 Subject: [PATCH 5/5] use BSD timersub --- src/stlink-usb.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/stlink-usb.c b/src/stlink-usb.c index 5807227..20e5cd2 100644 --- a/src/stlink-usb.c +++ b/src/stlink-usb.c @@ -16,17 +16,18 @@ #define WLOG(format, args...) ugly_log(UWARN, LOG_TAG, format, ## args) #define fatal(format, args...) ugly_log(UFATAL, LOG_TAG, format, ## args) -#ifndef timersub -/* This is a copy from GNU C Library (GNU LGPL 2.1), sys/time.h. */ -# define timersub(a, b, result) \ - do { \ - (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ - (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ - if ((result)->tv_usec < 0) { \ - --(result)->tv_sec; \ - (result)->tv_usec += 1000000; \ - } \ - } while (0) +/* code from bsd timersub.h +http://www.gnu-darwin.org/www001/src/ports/net/libevnet/work/libevnet-0.3.8/libnostd/bsd/sys/time/timersub.h.html +*/ +#if !defined timersub +#define timersub(a, b, r) do { \ + (r)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ + (r)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ + if ((r)->tv_usec < 0) { \ + --(r)->tv_sec; \ + (r)->tv_usec += 1000000; \ + } \ +} while (0) #endif enum SCSI_Generic_Direction {SG_DXFER_TO_DEV=0, SG_DXFER_FROM_DEV=0x80};