diff options
author | David Walter Seikel | 2013-01-13 18:54:10 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 18:54:10 +1000 |
commit | 959831f4ef5a3e797f576c3de08cd65032c997ad (patch) | |
tree | e7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jmemname.c | |
parent | Add info about changes to Irrlicht. (diff) | |
download | SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2 SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz |
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to '')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jmemname.c | 552 |
1 files changed, 276 insertions, 276 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jmemname.c b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jmemname.c index e28b212..ed96dee 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jmemname.c +++ b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jmemname.c | |||
@@ -1,276 +1,276 @@ | |||
1 | /* | 1 | /* |
2 | * jmemname.c | 2 | * jmemname.c |
3 | * | 3 | * |
4 | * Copyright (C) 1992-1997, Thomas G. Lane. | 4 | * Copyright (C) 1992-1997, Thomas G. Lane. |
5 | * This file is part of the Independent JPEG Group's software. | 5 | * This file is part of the Independent JPEG Group's software. |
6 | * For conditions of distribution and use, see the accompanying README file. | 6 | * For conditions of distribution and use, see the accompanying README file. |
7 | * | 7 | * |
8 | * This file provides a generic implementation of the system-dependent | 8 | * This file provides a generic implementation of the system-dependent |
9 | * portion of the JPEG memory manager. This implementation assumes that | 9 | * portion of the JPEG memory manager. This implementation assumes that |
10 | * you must explicitly construct a name for each temp file. | 10 | * you must explicitly construct a name for each temp file. |
11 | * Also, the problem of determining the amount of memory available | 11 | * Also, the problem of determining the amount of memory available |
12 | * is shoved onto the user. | 12 | * is shoved onto the user. |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #define JPEG_INTERNALS | 15 | #define JPEG_INTERNALS |
16 | #include "jinclude.h" | 16 | #include "jinclude.h" |
17 | #include "jpeglib.h" | 17 | #include "jpeglib.h" |
18 | #include "jmemsys.h" /* import the system-dependent declarations */ | 18 | #include "jmemsys.h" /* import the system-dependent declarations */ |
19 | 19 | ||
20 | #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */ | 20 | #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */ |
21 | extern void * malloc JPP((size_t size)); | 21 | extern void * malloc JPP((size_t size)); |
22 | extern void free JPP((void *ptr)); | 22 | extern void free JPP((void *ptr)); |
23 | #endif | 23 | #endif |
24 | 24 | ||
25 | #ifndef SEEK_SET /* pre-ANSI systems may not define this; */ | 25 | #ifndef SEEK_SET /* pre-ANSI systems may not define this; */ |
26 | #define SEEK_SET 0 /* if not, assume 0 is correct */ | 26 | #define SEEK_SET 0 /* if not, assume 0 is correct */ |
27 | #endif | 27 | #endif |
28 | 28 | ||
29 | #ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ | 29 | #ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ |
30 | #define READ_BINARY "r" | 30 | #define READ_BINARY "r" |
31 | #define RW_BINARY "w+" | 31 | #define RW_BINARY "w+" |
32 | #else | 32 | #else |
33 | #ifdef VMS /* VMS is very nonstandard */ | 33 | #ifdef VMS /* VMS is very nonstandard */ |
34 | #define READ_BINARY "rb", "ctx=stm" | 34 | #define READ_BINARY "rb", "ctx=stm" |
35 | #define RW_BINARY "w+b", "ctx=stm" | 35 | #define RW_BINARY "w+b", "ctx=stm" |
36 | #else /* standard ANSI-compliant case */ | 36 | #else /* standard ANSI-compliant case */ |
37 | #define READ_BINARY "rb" | 37 | #define READ_BINARY "rb" |
38 | #define RW_BINARY "w+b" | 38 | #define RW_BINARY "w+b" |
39 | #endif | 39 | #endif |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | 42 | ||
43 | /* | 43 | /* |
44 | * Selection of a file name for a temporary file. | 44 | * Selection of a file name for a temporary file. |
45 | * This is system-dependent! | 45 | * This is system-dependent! |
46 | * | 46 | * |
47 | * The code as given is suitable for most Unix systems, and it is easily | 47 | * The code as given is suitable for most Unix systems, and it is easily |
48 | * modified for most non-Unix systems. Some notes: | 48 | * modified for most non-Unix systems. Some notes: |
49 | * 1. The temp file is created in the directory named by TEMP_DIRECTORY. | 49 | * 1. The temp file is created in the directory named by TEMP_DIRECTORY. |
50 | * The default value is /usr/tmp, which is the conventional place for | 50 | * The default value is /usr/tmp, which is the conventional place for |
51 | * creating large temp files on Unix. On other systems you'll probably | 51 | * creating large temp files on Unix. On other systems you'll probably |
52 | * want to change the file location. You can do this by editing the | 52 | * want to change the file location. You can do this by editing the |
53 | * #define, or (preferred) by defining TEMP_DIRECTORY in jconfig.h. | 53 | * #define, or (preferred) by defining TEMP_DIRECTORY in jconfig.h. |
54 | * | 54 | * |
55 | * 2. If you need to change the file name as well as its location, | 55 | * 2. If you need to change the file name as well as its location, |
56 | * you can override the TEMP_FILE_NAME macro. (Note that this is | 56 | * you can override the TEMP_FILE_NAME macro. (Note that this is |
57 | * actually a printf format string; it must contain %s and %d.) | 57 | * actually a printf format string; it must contain %s and %d.) |
58 | * Few people should need to do this. | 58 | * Few people should need to do this. |
59 | * | 59 | * |
60 | * 3. mktemp() is used to ensure that multiple processes running | 60 | * 3. mktemp() is used to ensure that multiple processes running |
61 | * simultaneously won't select the same file names. If your system | 61 | * simultaneously won't select the same file names. If your system |
62 | * doesn't have mktemp(), define NO_MKTEMP to do it the hard way. | 62 | * doesn't have mktemp(), define NO_MKTEMP to do it the hard way. |
63 | * (If you don't have <errno.h>, also define NO_ERRNO_H.) | 63 | * (If you don't have <errno.h>, also define NO_ERRNO_H.) |
64 | * | 64 | * |
65 | * 4. You probably want to define NEED_SIGNAL_CATCHER so that cjpeg.c/djpeg.c | 65 | * 4. You probably want to define NEED_SIGNAL_CATCHER so that cjpeg.c/djpeg.c |
66 | * will cause the temp files to be removed if you stop the program early. | 66 | * will cause the temp files to be removed if you stop the program early. |
67 | */ | 67 | */ |
68 | 68 | ||
69 | #ifndef TEMP_DIRECTORY /* can override from jconfig.h or Makefile */ | 69 | #ifndef TEMP_DIRECTORY /* can override from jconfig.h or Makefile */ |
70 | #define TEMP_DIRECTORY "/usr/tmp/" /* recommended setting for Unix */ | 70 | #define TEMP_DIRECTORY "/usr/tmp/" /* recommended setting for Unix */ |
71 | #endif | 71 | #endif |
72 | 72 | ||
73 | static int next_file_num; /* to distinguish among several temp files */ | 73 | static int next_file_num; /* to distinguish among several temp files */ |
74 | 74 | ||
75 | #ifdef NO_MKTEMP | 75 | #ifdef NO_MKTEMP |
76 | 76 | ||
77 | #ifndef TEMP_FILE_NAME /* can override from jconfig.h or Makefile */ | 77 | #ifndef TEMP_FILE_NAME /* can override from jconfig.h or Makefile */ |
78 | #define TEMP_FILE_NAME "%sJPG%03d.TMP" | 78 | #define TEMP_FILE_NAME "%sJPG%03d.TMP" |
79 | #endif | 79 | #endif |
80 | 80 | ||
81 | #ifndef NO_ERRNO_H | 81 | #ifndef NO_ERRNO_H |
82 | #include <errno.h> /* to define ENOENT */ | 82 | #include <errno.h> /* to define ENOENT */ |
83 | #endif | 83 | #endif |
84 | 84 | ||
85 | /* ANSI C specifies that errno is a macro, but on older systems it's more | 85 | /* ANSI C specifies that errno is a macro, but on older systems it's more |
86 | * likely to be a plain int variable. And not all versions of errno.h | 86 | * likely to be a plain int variable. And not all versions of errno.h |
87 | * bother to declare it, so we have to in order to be most portable. Thus: | 87 | * bother to declare it, so we have to in order to be most portable. Thus: |
88 | */ | 88 | */ |
89 | #ifndef errno | 89 | #ifndef errno |
90 | extern int errno; | 90 | extern int errno; |
91 | #endif | 91 | #endif |
92 | 92 | ||
93 | 93 | ||
94 | LOCAL(void) | 94 | LOCAL(void) |
95 | select_file_name (char * fname) | 95 | select_file_name (char * fname) |
96 | { | 96 | { |
97 | FILE * tfile; | 97 | FILE * tfile; |
98 | 98 | ||
99 | /* Keep generating file names till we find one that's not in use */ | 99 | /* Keep generating file names till we find one that's not in use */ |
100 | for (;;) { | 100 | for (;;) { |
101 | next_file_num++; /* advance counter */ | 101 | next_file_num++; /* advance counter */ |
102 | sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num); | 102 | sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num); |
103 | if ((tfile = fopen(fname, READ_BINARY)) == NULL) { | 103 | if ((tfile = fopen(fname, READ_BINARY)) == NULL) { |
104 | /* fopen could have failed for a reason other than the file not | 104 | /* fopen could have failed for a reason other than the file not |
105 | * being there; for example, file there but unreadable. | 105 | * being there; for example, file there but unreadable. |
106 | * If <errno.h> isn't available, then we cannot test the cause. | 106 | * If <errno.h> isn't available, then we cannot test the cause. |
107 | */ | 107 | */ |
108 | #ifdef ENOENT | 108 | #ifdef ENOENT |
109 | if (errno != ENOENT) | 109 | if (errno != ENOENT) |
110 | continue; | 110 | continue; |
111 | #endif | 111 | #endif |
112 | break; | 112 | break; |
113 | } | 113 | } |
114 | fclose(tfile); /* oops, it's there; close tfile & try again */ | 114 | fclose(tfile); /* oops, it's there; close tfile & try again */ |
115 | } | 115 | } |
116 | } | 116 | } |
117 | 117 | ||
118 | #else /* ! NO_MKTEMP */ | 118 | #else /* ! NO_MKTEMP */ |
119 | 119 | ||
120 | /* Note that mktemp() requires the initial filename to end in six X's */ | 120 | /* Note that mktemp() requires the initial filename to end in six X's */ |
121 | #ifndef TEMP_FILE_NAME /* can override from jconfig.h or Makefile */ | 121 | #ifndef TEMP_FILE_NAME /* can override from jconfig.h or Makefile */ |
122 | #define TEMP_FILE_NAME "%sJPG%dXXXXXX" | 122 | #define TEMP_FILE_NAME "%sJPG%dXXXXXX" |
123 | #endif | 123 | #endif |
124 | 124 | ||
125 | LOCAL(void) | 125 | LOCAL(void) |
126 | select_file_name (char * fname) | 126 | select_file_name (char * fname) |
127 | { | 127 | { |
128 | next_file_num++; /* advance counter */ | 128 | next_file_num++; /* advance counter */ |
129 | sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num); | 129 | sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num); |
130 | mktemp(fname); /* make sure file name is unique */ | 130 | mktemp(fname); /* make sure file name is unique */ |
131 | /* mktemp replaces the trailing XXXXXX with a unique string of characters */ | 131 | /* mktemp replaces the trailing XXXXXX with a unique string of characters */ |
132 | } | 132 | } |
133 | 133 | ||
134 | #endif /* NO_MKTEMP */ | 134 | #endif /* NO_MKTEMP */ |
135 | 135 | ||
136 | 136 | ||
137 | /* | 137 | /* |
138 | * Memory allocation and freeing are controlled by the regular library | 138 | * Memory allocation and freeing are controlled by the regular library |
139 | * routines malloc() and free(). | 139 | * routines malloc() and free(). |
140 | */ | 140 | */ |
141 | 141 | ||
142 | GLOBAL(void *) | 142 | GLOBAL(void *) |
143 | jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject) | 143 | jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject) |
144 | { | 144 | { |
145 | return (void *) malloc(sizeofobject); | 145 | return (void *) malloc(sizeofobject); |
146 | } | 146 | } |
147 | 147 | ||
148 | GLOBAL(void) | 148 | GLOBAL(void) |
149 | jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject) | 149 | jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject) |
150 | { | 150 | { |
151 | free(object); | 151 | free(object); |
152 | } | 152 | } |
153 | 153 | ||
154 | 154 | ||
155 | /* | 155 | /* |
156 | * "Large" objects are treated the same as "small" ones. | 156 | * "Large" objects are treated the same as "small" ones. |
157 | * NB: although we include FAR keywords in the routine declarations, | 157 | * NB: although we include FAR keywords in the routine declarations, |
158 | * this file won't actually work in 80x86 small/medium model; at least, | 158 | * this file won't actually work in 80x86 small/medium model; at least, |
159 | * you probably won't be able to process useful-size images in only 64KB. | 159 | * you probably won't be able to process useful-size images in only 64KB. |
160 | */ | 160 | */ |
161 | 161 | ||
162 | GLOBAL(void FAR *) | 162 | GLOBAL(void FAR *) |
163 | jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject) | 163 | jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject) |
164 | { | 164 | { |
165 | return (void FAR *) malloc(sizeofobject); | 165 | return (void FAR *) malloc(sizeofobject); |
166 | } | 166 | } |
167 | 167 | ||
168 | GLOBAL(void) | 168 | GLOBAL(void) |
169 | jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject) | 169 | jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject) |
170 | { | 170 | { |
171 | free(object); | 171 | free(object); |
172 | } | 172 | } |
173 | 173 | ||
174 | 174 | ||
175 | /* | 175 | /* |
176 | * This routine computes the total memory space available for allocation. | 176 | * This routine computes the total memory space available for allocation. |
177 | * It's impossible to do this in a portable way; our current solution is | 177 | * It's impossible to do this in a portable way; our current solution is |
178 | * to make the user tell us (with a default value set at compile time). | 178 | * to make the user tell us (with a default value set at compile time). |
179 | * If you can actually get the available space, it's a good idea to subtract | 179 | * If you can actually get the available space, it's a good idea to subtract |
180 | * a slop factor of 5% or so. | 180 | * a slop factor of 5% or so. |
181 | */ | 181 | */ |
182 | 182 | ||
183 | #ifndef DEFAULT_MAX_MEM /* so can override from makefile */ | 183 | #ifndef DEFAULT_MAX_MEM /* so can override from makefile */ |
184 | #define DEFAULT_MAX_MEM 1000000L /* default: one megabyte */ | 184 | #define DEFAULT_MAX_MEM 1000000L /* default: one megabyte */ |
185 | #endif | 185 | #endif |
186 | 186 | ||
187 | GLOBAL(long) | 187 | GLOBAL(long) |
188 | jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, | 188 | jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, |
189 | long max_bytes_needed, long already_allocated) | 189 | long max_bytes_needed, long already_allocated) |
190 | { | 190 | { |
191 | return cinfo->mem->max_memory_to_use - already_allocated; | 191 | return cinfo->mem->max_memory_to_use - already_allocated; |
192 | } | 192 | } |
193 | 193 | ||
194 | 194 | ||
195 | /* | 195 | /* |
196 | * Backing store (temporary file) management. | 196 | * Backing store (temporary file) management. |
197 | * Backing store objects are only used when the value returned by | 197 | * Backing store objects are only used when the value returned by |
198 | * jpeg_mem_available is less than the total space needed. You can dispense | 198 | * jpeg_mem_available is less than the total space needed. You can dispense |
199 | * with these routines if you have plenty of virtual memory; see jmemnobs.c. | 199 | * with these routines if you have plenty of virtual memory; see jmemnobs.c. |
200 | */ | 200 | */ |
201 | 201 | ||
202 | 202 | ||
203 | METHODDEF(void) | 203 | METHODDEF(void) |
204 | read_backing_store (j_common_ptr cinfo, backing_store_ptr info, | 204 | read_backing_store (j_common_ptr cinfo, backing_store_ptr info, |
205 | void FAR * buffer_address, | 205 | void FAR * buffer_address, |
206 | long file_offset, long byte_count) | 206 | long file_offset, long byte_count) |
207 | { | 207 | { |
208 | if (fseek(info->temp_file, file_offset, SEEK_SET)) | 208 | if (fseek(info->temp_file, file_offset, SEEK_SET)) |
209 | ERREXIT(cinfo, JERR_TFILE_SEEK); | 209 | ERREXIT(cinfo, JERR_TFILE_SEEK); |
210 | if (JFREAD(info->temp_file, buffer_address, byte_count) | 210 | if (JFREAD(info->temp_file, buffer_address, byte_count) |
211 | != (size_t) byte_count) | 211 | != (size_t) byte_count) |
212 | ERREXIT(cinfo, JERR_TFILE_READ); | 212 | ERREXIT(cinfo, JERR_TFILE_READ); |
213 | } | 213 | } |
214 | 214 | ||
215 | 215 | ||
216 | METHODDEF(void) | 216 | METHODDEF(void) |
217 | write_backing_store (j_common_ptr cinfo, backing_store_ptr info, | 217 | write_backing_store (j_common_ptr cinfo, backing_store_ptr info, |
218 | void FAR * buffer_address, | 218 | void FAR * buffer_address, |
219 | long file_offset, long byte_count) | 219 | long file_offset, long byte_count) |
220 | { | 220 | { |
221 | if (fseek(info->temp_file, file_offset, SEEK_SET)) | 221 | if (fseek(info->temp_file, file_offset, SEEK_SET)) |
222 | ERREXIT(cinfo, JERR_TFILE_SEEK); | 222 | ERREXIT(cinfo, JERR_TFILE_SEEK); |
223 | if (JFWRITE(info->temp_file, buffer_address, byte_count) | 223 | if (JFWRITE(info->temp_file, buffer_address, byte_count) |
224 | != (size_t) byte_count) | 224 | != (size_t) byte_count) |
225 | ERREXIT(cinfo, JERR_TFILE_WRITE); | 225 | ERREXIT(cinfo, JERR_TFILE_WRITE); |
226 | } | 226 | } |
227 | 227 | ||
228 | 228 | ||
229 | METHODDEF(void) | 229 | METHODDEF(void) |
230 | close_backing_store (j_common_ptr cinfo, backing_store_ptr info) | 230 | close_backing_store (j_common_ptr cinfo, backing_store_ptr info) |
231 | { | 231 | { |
232 | fclose(info->temp_file); /* close the file */ | 232 | fclose(info->temp_file); /* close the file */ |
233 | unlink(info->temp_name); /* delete the file */ | 233 | unlink(info->temp_name); /* delete the file */ |
234 | /* If your system doesn't have unlink(), use remove() instead. | 234 | /* If your system doesn't have unlink(), use remove() instead. |
235 | * remove() is the ANSI-standard name for this function, but if | 235 | * remove() is the ANSI-standard name for this function, but if |
236 | * your system was ANSI you'd be using jmemansi.c, right? | 236 | * your system was ANSI you'd be using jmemansi.c, right? |
237 | */ | 237 | */ |
238 | TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name); | 238 | TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name); |
239 | } | 239 | } |
240 | 240 | ||
241 | 241 | ||
242 | /* | 242 | /* |
243 | * Initial opening of a backing-store object. | 243 | * Initial opening of a backing-store object. |
244 | */ | 244 | */ |
245 | 245 | ||
246 | GLOBAL(void) | 246 | GLOBAL(void) |
247 | jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, | 247 | jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, |
248 | long total_bytes_needed) | 248 | long total_bytes_needed) |
249 | { | 249 | { |
250 | select_file_name(info->temp_name); | 250 | select_file_name(info->temp_name); |
251 | if ((info->temp_file = fopen(info->temp_name, RW_BINARY)) == NULL) | 251 | if ((info->temp_file = fopen(info->temp_name, RW_BINARY)) == NULL) |
252 | ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name); | 252 | ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name); |
253 | info->read_backing_store = read_backing_store; | 253 | info->read_backing_store = read_backing_store; |
254 | info->write_backing_store = write_backing_store; | 254 | info->write_backing_store = write_backing_store; |
255 | info->close_backing_store = close_backing_store; | 255 | info->close_backing_store = close_backing_store; |
256 | TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name); | 256 | TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name); |
257 | } | 257 | } |
258 | 258 | ||
259 | 259 | ||
260 | /* | 260 | /* |
261 | * These routines take care of any system-dependent initialization and | 261 | * These routines take care of any system-dependent initialization and |
262 | * cleanup required. | 262 | * cleanup required. |
263 | */ | 263 | */ |
264 | 264 | ||
265 | GLOBAL(long) | 265 | GLOBAL(long) |
266 | jpeg_mem_init (j_common_ptr cinfo) | 266 | jpeg_mem_init (j_common_ptr cinfo) |
267 | { | 267 | { |
268 | next_file_num = 0; /* initialize temp file name generator */ | 268 | next_file_num = 0; /* initialize temp file name generator */ |
269 | return DEFAULT_MAX_MEM; /* default for max_memory_to_use */ | 269 | return DEFAULT_MAX_MEM; /* default for max_memory_to_use */ |
270 | } | 270 | } |
271 | 271 | ||
272 | GLOBAL(void) | 272 | GLOBAL(void) |
273 | jpeg_mem_term (j_common_ptr cinfo) | 273 | jpeg_mem_term (j_common_ptr cinfo) |
274 | { | 274 | { |
275 | /* no work */ | 275 | /* no work */ |
276 | } | 276 | } |