ath9k: fix antenna gain calculation
[openwrt.git] / tools / mtd-utils / patches / 120-cygwin_fixes.patch
1 --- a/Makefile
2 +++ b/Makefile
3 @@ -7,6 +7,11 @@ ifeq ($(WITHOUT_XATTR), 1)
4 CPPFLAGS += -DWITHOUT_XATTR
5 endif
6
7 +ifeq ($(shell uname -o),Cygwin)
8 +CPPFLAGS += -I./include/cygwin
9 +endif
10 +
11 +ifneq ($(shell uname -o),Cygwin)
12 SUBDIRS = lib ubi-utils mkfs.ubifs
13
14 TARGETS = ftl_format flash_erase nanddump doc_loadbios \
15 @@ -17,6 +22,10 @@ TARGETS = ftl_format flash_erase nanddum
16 rfddump rfdformat \
17 serve_image recv_image \
18 sumtool #jffs2reader
19 +else
20 +SUBDIRS =
21 +TARGETS = mkfs.jffs2
22 +endif
23 SCRIPTS = flash_eraseall
24
25 SYMLINKS =
26 --- /dev/null
27 +++ b/include/cygwin/bits-byteswap.h
28 @@ -0,0 +1,132 @@
29 +/* Macros to swap the order of bytes in integer values.
30 + Copyright (C) 1997, 1998, 2000, 2002 Free Software Foundation, Inc.
31 + This file is part of the GNU C Library.
32 +
33 + The GNU C Library is free software; you can redistribute it and/or
34 + modify it under the terms of the GNU Lesser General Public
35 + License as published by the Free Software Foundation; either
36 + version 2.1 of the License, or (at your option) any later version.
37 +
38 + The GNU C Library is distributed in the hope that it will be useful,
39 + but WITHOUT ANY WARRANTY; without even the implied warranty of
40 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41 + Lesser General Public License for more details.
42 +
43 + You should have received a copy of the GNU Lesser General Public
44 + License along with the GNU C Library; if not, write to the Free
45 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
46 + 02111-1307 USA. */
47 +
48 +#if !defined _BYTESWAP_H && !defined _NETINET_IN_H
49 +# error "Never use <bits/byteswap.h> directly; include <byteswap.h> instead."
50 +#endif
51 +
52 +#ifndef _BITS_BYTESWAP_H
53 +#define _BITS_BYTESWAP_H 1
54 +
55 +/* Swap bytes in 16 bit value. */
56 +#define __bswap_constant_16(x) \
57 + ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
58 +
59 +#ifdef __GNUC__
60 +# if __GNUC__ >= 2
61 +# define __bswap_16(x) \
62 + (__extension__ \
63 + ({ register unsigned short int __v, __x = (x); \
64 + if (__builtin_constant_p (__x)) \
65 + __v = __bswap_constant_16 (__x); \
66 + else \
67 + __asm__ ("rorw $8, %w0" \
68 + : "=r" (__v) \
69 + : "0" (__x) \
70 + : "cc"); \
71 + __v; }))
72 +# else
73 +/* This is better than nothing. */
74 +# define __bswap_16(x) \
75 + (__extension__ \
76 + ({ register unsigned short int __x = (x); __bswap_constant_16 (__x); }))
77 +# endif
78 +#else
79 +static __inline unsigned short int
80 +__bswap_16 (unsigned short int __bsx)
81 +{
82 + return __bswap_constant_16 (__bsx);
83 +}
84 +#endif
85 +
86 +/* Swap bytes in 32 bit value. */
87 +#define __bswap_constant_32(x) \
88 + ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
89 + (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
90 +
91 +#ifdef __GNUC__
92 +# if __GNUC__ >= 2
93 +/* To swap the bytes in a word the i486 processors and up provide the
94 + `bswap' opcode. On i386 we have to use three instructions. */
95 +# if !defined __i486__ && !defined __pentium__ && !defined __pentiumpro__
96 +# define __bswap_32(x) \
97 + (__extension__ \
98 + ({ register unsigned int __v, __x = (x); \
99 + if (__builtin_constant_p (__x)) \
100 + __v = __bswap_constant_32 (__x); \
101 + else \
102 + __asm__ ("rorw $8, %w0;" \
103 + "rorl $16, %0;" \
104 + "rorw $8, %w0" \
105 + : "=r" (__v) \
106 + : "0" (__x) \
107 + : "cc"); \
108 + __v; }))
109 +# else
110 +# define __bswap_32(x) \
111 + (__extension__ \
112 + ({ register unsigned int __v, __x = (x); \
113 + if (__builtin_constant_p (__x)) \
114 + __v = __bswap_constant_32 (__x); \
115 + else \
116 + __asm__ ("bswap %0" : "=r" (__v) : "0" (__x)); \
117 + __v; }))
118 +# endif
119 +# else
120 +# define __bswap_32(x) \
121 + (__extension__ \
122 + ({ register unsigned int __x = (x); __bswap_constant_32 (__x); }))
123 +# endif
124 +#else
125 +static __inline unsigned int
126 +__bswap_32 (unsigned int __bsx)
127 +{
128 + return __bswap_constant_32 (__bsx);
129 +}
130 +#endif
131 +
132 +
133 +#if defined __GNUC__ && __GNUC__ >= 2
134 +/* Swap bytes in 64 bit value. */
135 +#define __bswap_constant_64(x) \
136 + ((((x) & 0xff00000000000000ull) >> 56) \
137 + | (((x) & 0x00ff000000000000ull) >> 40) \
138 + | (((x) & 0x0000ff0000000000ull) >> 24) \
139 + | (((x) & 0x000000ff00000000ull) >> 8) \
140 + | (((x) & 0x00000000ff000000ull) << 8) \
141 + | (((x) & 0x0000000000ff0000ull) << 24) \
142 + | (((x) & 0x000000000000ff00ull) << 40) \
143 + | (((x) & 0x00000000000000ffull) << 56))
144 +
145 +# define __bswap_64(x) \
146 + (__extension__ \
147 + ({ union { __extension__ unsigned long long int __ll; \
148 + unsigned long int __l[2]; } __w, __r; \
149 + if (__builtin_constant_p (x)) \
150 + __r.__ll = __bswap_constant_64 (x); \
151 + else \
152 + { \
153 + __w.__ll = (x); \
154 + __r.__l[0] = __bswap_32 (__w.__l[1]); \
155 + __r.__l[1] = __bswap_32 (__w.__l[0]); \
156 + } \
157 + __r.__ll; }))
158 +#endif
159 +
160 +#endif /* _BITS_BYTESWAP_H */
161 --- /dev/null
162 +++ b/include/cygwin/byteswap.h
163 @@ -0,0 +1,40 @@
164 +/* Copyright (C) 1997 Free Software Foundation, Inc.
165 + This file is part of the GNU C Library.
166 +
167 + The GNU C Library is free software; you can redistribute it and/or
168 + modify it under the terms of the GNU Lesser General Public
169 + License as published by the Free Software Foundation; either
170 + version 2.1 of the License, or (at your option) any later version.
171 +
172 + The GNU C Library is distributed in the hope that it will be useful,
173 + but WITHOUT ANY WARRANTY; without even the implied warranty of
174 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
175 + Lesser General Public License for more details.
176 +
177 + You should have received a copy of the GNU Lesser General Public
178 + License along with the GNU C Library; if not, write to the Free
179 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
180 + 02111-1307 USA. */
181 +
182 +#ifndef _BYTESWAP_H
183 +#define _BYTESWAP_H 1
184 +
185 +/* Get the machine specific, optimized definitions. */
186 +#include "bits-byteswap.h"
187 +
188 +
189 +/* The following definitions must all be macros since otherwise some
190 + of the possible optimizations are not possible. */
191 +
192 +/* Return a value with all bytes in the 16 bit argument swapped. */
193 +#define bswap_16(x) __bswap_16 (x)
194 +
195 +/* Return a value with all bytes in the 32 bit argument swapped. */
196 +#define bswap_32(x) __bswap_32 (x)
197 +
198 +#if defined __GNUC__ && __GNUC__ >= 2
199 +/* Return a value with all bytes in the 64 bit argument swapped. */
200 +# define bswap_64(x) __bswap_64 (x)
201 +#endif
202 +
203 +#endif /* byteswap.h */
204 --- /dev/null
205 +++ b/include/cygwin/endian.h
206 @@ -0,0 +1,26 @@
207 +#ifndef _CYGENDIAN_H_
208 +#define _CYGENDIAN_H_
209 +
210 +#ifdef __CYGWIN__
211 +
212 +#include <sys/param.h>
213 +
214 +#ifndef __BIG_ENDIAN
215 +#define __BIG_ENDIAN 4321
216 +#endif
217 +
218 +#ifndef __LITTLE_ENDIAN
219 +#define __LITTLE_ENDIAN 1234
220 +#endif
221 +
222 +#ifndef __BYTE_ORDER
223 +#define __BYTE_ORDER __LITTLE_ENDIAN
224 +#endif
225 +
226 +#ifndef BYTE_ORDER
227 +#define BYTE_ORDER __LITTLE_ENDIAN
228 +#endif
229 +
230 +#endif /* __CYGWIN__ */
231 +
232 +#endif /* _CYGENDIAN_H_ */
233 --- /dev/null
234 +++ b/include/cygwin/ioctl.h
235 @@ -0,0 +1,38 @@
236 +#ifndef _CYGIOCTL_H_
237 +#define _CYGIOCTL_H_
238 +
239 +#ifdef __CYGWIN__
240 +
241 +#define _IOC_NRBITS 8
242 +#define _IOC_TYPEBITS 8
243 +#define _IOC_SIZEBITS 14
244 +#define _IOC_DIRBITS 2
245 +
246 +#define _IOC_NRMASK ((1 << _IOC_NRBITS)-1)
247 +#define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1)
248 +#define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1)
249 +#define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1)
250 +
251 +#define _IOC_NRSHIFT 0
252 +#define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS)
253 +#define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS)
254 +#define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS)
255 +
256 +#define _IOC_NONE 0U
257 +#define _IOC_WRITE 1U
258 +#define _IOC_READ 2U
259 +
260 +#define _IOC(dir,type,nr,size) \
261 + (((dir) << _IOC_DIRSHIFT) | \
262 + ((type) << _IOC_TYPESHIFT) | \
263 + ((nr) << _IOC_NRSHIFT) | \
264 + ((size) << _IOC_SIZESHIFT))
265 +
266 +#define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0)
267 +#define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size))
268 +#define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size))
269 +#define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
270 +
271 +#endif /* __CYGWIN__ */
272 +
273 +#endif /* _CYGIOCTL_H_ */
274 --- /dev/null
275 +++ b/include/cygwin/pread.c
276 @@ -0,0 +1,41 @@
277 +#ifdef __CYGWIN__
278 +
279 +#include <errno.h>
280 +
281 +ssize_t
282 +pread(int fd, void *p, size_t n, off_t off)
283 +{
284 + off_t ooff;
285 + int oerrno;
286 +
287 + if ((ooff = lseek(fd, off, SEEK_SET)) == -1)
288 + return -1;
289 +
290 + n = read(fd, p, n);
291 +
292 + oerrno = errno;
293 + lseek(fd, ooff, SEEK_SET);
294 + errno = oerrno;
295 +
296 + return n;
297 +}
298 +
299 +ssize_t
300 +pwrite(int fd, const void *p, size_t n, off_t off)
301 +{
302 + off_t ooff;
303 + int oerrno;
304 +
305 + if ((ooff = lseek(fd, off, SEEK_SET)) == -1)
306 + return -1;
307 +
308 + n = write(fd, p, n);
309 +
310 + oerrno = errno;
311 + lseek(fd, ooff, SEEK_SET);
312 + errno = oerrno;
313 +
314 + return n;
315 +}
316 +
317 +#endif /* __CYGWIN__ */
318 --- /dev/null
319 +++ b/lnconf.sh
320 @@ -0,0 +1,53 @@
321 +#!/bin/sh
322 +#
323 +# Generic configure replacement.
324 +#
325 +# $Id: lnconf.sh,v 1.1 2004/04/05 21:55:59 igor Exp $
326 +#
327 +# Copies all files from the script directory to the current one.
328 +# Intended to replace 'configure' for packages that don't have one, to
329 +# allow building outside of the source tree.
330 +#
331 +# Note: this does not do any fancy things with detecting shells and
332 +# supporting other platforms. But it should work on Cygwin.
333 +
334 +# find out where the script is located
335 +tdir=`echo "$0" | sed 's%[\\/][^\\/][^\\/]*$%%'`
336 +test "x$tdir" = "x$0" && tdir=.
337 +
338 +a_srcdir=`cd $tdir; pwd`
339 +a_destdir=`pwd`
340 +
341 +# sanity checks:
342 +# are we in the script directory?
343 +test "x$a_srcdir" = "x$a_destdir" && exit 0
344 +# is there any chance that this is the script directory?
345 +test "x`cd "$a_srcdir" && /bin/ls -id`" = "x`/bin/ls -id`" && exit 0
346 +
347 +# try to find lndir and use it if it's available
348 +LNDIR="`which lndir 2>/dev/null`"
349 +if [ "x$LNDIR" = "x" ]; then
350 + lndir() {
351 + test "x$1" = "x" && return 1
352 + # be careful of the current directory
353 + DINODE=`find . -maxdepth 0 -ls | sed 's/ .*$//'`
354 + case "`pwd`" in
355 + "`cd "$1" && pwd`"/*) CUR="-type d -inum $DINODE -prune -o";;
356 + esac
357 + # duplicate the directory structure
358 + (cd "$1" && find . $CUR -type d -mindepth 1 -print) | xargs -tr mkdir -p
359 + # copy all symbolic links
360 + (cd "$1" && find . $CUR -type l -mindepth 1 -print) | xargs -ri sh -c "ln -s \"\`readlink "$1/{}"\`\" \"{}\""
361 + # or simply
362 + #(cd "$1" && find . $CUR -type l -mindepth 1 -print) | xargs -ri ln -s "$1"/{} {}
363 + # link all files
364 + (cd "$1" && find . $CUR -type f -mindepth 1 -print) | xargs -ri ln -s "$1"/{} {}
365 + }
366 +else
367 + lndir() {
368 + "$LNDIR" "$@"
369 + }
370 +fi
371 +
372 +lndir "$tdir"
373 +
374 --- a/mkfs.jffs2.c
375 +++ b/mkfs.jffs2.c
376 @@ -76,6 +76,14 @@
377
378 #include "common.h"
379
380 +#ifdef __CYGWIN__
381 +#include <cygwin/ioctl.h>
382 +#include <cygwin/endian.h>
383 +#include <cygwin/pread.c>
384 +# define IFTODT(mode) (((mode) & 0170000) >> 12)
385 +# define DTTOIF(dirtype) ((dirtype) << 12)
386 +#endif /* __CYGWIN__ */
387 +
388 /* Do not use the weird XPG version of basename */
389 #undef basename
390
391 @@ -375,7 +383,7 @@ static struct filesystem_entry *recursiv
392 the following macros use it if available or use a hacky workaround...
393 */
394
395 -#ifdef __GNUC__
396 +#if defined __GNUC__ && !defined __CYGWIN__
397 #define SCANF_PREFIX "a"
398 #define SCANF_STRING(s) (&s)
399 #define GETCWD_SIZE 0
400 @@ -458,6 +466,14 @@ static int interpret_table_entry(struct
401 }
402 entry = find_filesystem_entry(root, name, mode);
403 if (entry) {
404 + /* Check the type */
405 + if ((mode & S_IFMT) != (entry->sb.st_mode & S_IFMT)) {
406 + error_msg ("skipping device_table entry '%s': type mismatch!", name);
407 + free(name);
408 + free(hostpath);
409 + return 1;
410 + }
411 +
412 /* Ok, we just need to fixup the existing entry
413 * and we will be all done... */
414 entry->sb.st_uid = uid;
415 @@ -467,11 +483,21 @@ static int interpret_table_entry(struct
416 entry->sb.st_rdev = makedev(major, minor);
417 }
418 } else {
419 + if (type == 'f' || type == 'l') {
420 + error_msg ("skipping device_table entry '%s': file does not exist!", name);
421 + free(name);
422 + free(hostpath);
423 + return 1;
424 + }
425 /* If parent is NULL (happens with device table entries),
426 * try and find our parent now) */
427 tmp = strdup(name);
428 dir = dirname(tmp);
429 - parent = find_filesystem_entry(root, dir, S_IFDIR);
430 + if (!strcmp(dir, "/")) {
431 + parent = root;
432 + } else {
433 + parent = find_filesystem_entry(root, dir, S_IFDIR);
434 + }
435 free(tmp);
436 if (parent == NULL) {
437 errmsg ("skipping device_table entry '%s': no parent directory!", name);
438 @@ -485,6 +511,7 @@ static int interpret_table_entry(struct
439 add_host_filesystem_entry(name, hostpath, uid, gid, mode, 0, parent);
440 break;
441 case 'f':
442 + case 'l':
443 add_host_filesystem_entry(name, hostpath, uid, gid, mode, 0, parent);
444 break;
445 case 'p':
446 --- a/ubi-utils/src/libubi.c
447 +++ b/ubi-utils/src/libubi.c
448 @@ -32,6 +32,9 @@
449 #include <sys/ioctl.h>
450 #include <sys/stat.h>
451 #include <sys/types.h>
452 +#ifdef __CYGWIN__
453 +#include <cygwin/ioctl.h>
454 +#endif
455 #include <libubi.h>
456 #include "libubi_int.h"
457 #include "common.h"
This page took 0.070323 seconds and 5 git commands to generate.