1 | /* |
1 | /* |
2 | * Copyright (c) 2000-2005 Marc Alexander Lehmann <schmorp@schmorp.de> |
2 | * Copyright (c) 2000-2007 Marc Alexander Lehmann <schmorp@schmorp.de> |
3 | * |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without modifica- |
4 | * Redistribution and use in source and binary forms, with or without modifica- |
5 | * tion, are permitted provided that the following conditions are met: |
5 | * tion, are permitted provided that the following conditions are met: |
6 | * |
6 | * |
7 | * 1. Redistributions of source code must retain the above copyright notice, |
7 | * 1. Redistributions of source code must retain the above copyright notice, |
8 | * this list of conditions and the following disclaimer. |
8 | * this list of conditions and the following disclaimer. |
9 | * |
9 | * |
10 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the |
11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. |
12 | * documentation and/or other materials provided with the distribution. |
13 | * |
|
|
14 | * 3. The name of the author may not be used to endorse or promote products |
|
|
15 | * derived from this software without specific prior written permission. |
|
|
16 | * |
13 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- |
15 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- |
19 | * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
16 | * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
20 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- |
17 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- |
… | |
… | |
41 | #if AVOID_ERRNO |
38 | #if AVOID_ERRNO |
42 | # define SET_ERRNO(n) |
39 | # define SET_ERRNO(n) |
43 | #else |
40 | #else |
44 | # include <errno.h> |
41 | # include <errno.h> |
45 | # define SET_ERRNO(n) errno = (n) |
42 | # define SET_ERRNO(n) errno = (n) |
|
|
43 | #endif |
|
|
44 | |
|
|
45 | #if (__i386 || __amd64) && __GNUC__ >= 3 |
|
|
46 | # define lzf_movsb(dst, src, len) \ |
|
|
47 | asm ("rep movsb" \ |
|
|
48 | : "=D" (dst), "=S" (src), "=c" (len) \ |
|
|
49 | : "0" (dst), "1" (src), "2" (len)); |
46 | #endif |
50 | #endif |
47 | |
51 | |
48 | unsigned int |
52 | unsigned int |
49 | lzf_decompress (const void *const in_data, unsigned int in_len, |
53 | lzf_decompress (const void *const in_data, unsigned int in_len, |
50 | void *out_data, unsigned int out_len) |
54 | void *out_data, unsigned int out_len) |
… | |
… | |
74 | SET_ERRNO (EINVAL); |
78 | SET_ERRNO (EINVAL); |
75 | return 0; |
79 | return 0; |
76 | } |
80 | } |
77 | #endif |
81 | #endif |
78 | |
82 | |
79 | #if USE_MEMCPY |
83 | #ifdef lzf_movsb |
80 | memcpy (op, ip, ctrl); |
84 | lzf_movsb (op, ip, ctrl); |
81 | op += ctrl; |
|
|
82 | ip += ctrl; |
|
|
83 | #else |
85 | #else |
84 | do |
86 | do |
85 | *op++ = *ip++; |
87 | *op++ = *ip++; |
86 | while (--ctrl); |
88 | while (--ctrl); |
87 | #endif |
89 | #endif |
… | |
… | |
123 | { |
125 | { |
124 | SET_ERRNO (EINVAL); |
126 | SET_ERRNO (EINVAL); |
125 | return 0; |
127 | return 0; |
126 | } |
128 | } |
127 | |
129 | |
|
|
130 | #ifdef lzf_movsb |
|
|
131 | len += 2; |
|
|
132 | lzf_movsb (op, ref, len); |
|
|
133 | #else |
128 | *op++ = *ref++; |
134 | *op++ = *ref++; |
129 | *op++ = *ref++; |
135 | *op++ = *ref++; |
130 | |
136 | |
131 | do |
137 | do |
132 | *op++ = *ref++; |
138 | *op++ = *ref++; |
133 | while (--len); |
139 | while (--len); |
|
|
140 | #endif |
134 | } |
141 | } |
135 | } |
142 | } |
136 | while (ip < in_end); |
143 | while (ip < in_end); |
137 | |
144 | |
138 | return op - (u8 *)out_data; |
145 | return op - (u8 *)out_data; |