Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
jmemname.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #define JPEG_INTERNALS
00016 #include "jinclude.h"
00017 #include "jpeglib.h"
00018 #include "jmemsys.h"
00019
00020 #ifndef HAVE_STDLIB_H
00021 extern void * malloc JPP((size_t size));
00022 extern void free JPP((void *ptr));
00023 #endif
00024
00025 #ifndef SEEK_SET
00026 #define SEEK_SET 0
00027 #endif
00028
00029 #ifdef DONT_USE_B_MODE
00030 #define READ_BINARY "r"
00031 #define RW_BINARY "w+"
00032 #else
00033 #ifdef VMS
00034 #define READ_BINARY "rb", "ctx=stm"
00035 #define RW_BINARY "w+b", "ctx=stm"
00036 #else
00037 #define READ_BINARY "rb"
00038 #define RW_BINARY "w+b"
00039 #endif
00040 #endif
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 #ifndef TEMP_DIRECTORY
00070 #define TEMP_DIRECTORY "/usr/tmp/"
00071 #endif
00072
00073 static int next_file_num;
00074
00075 #ifdef NO_MKTEMP
00076
00077 #ifndef TEMP_FILE_NAME
00078 #define TEMP_FILE_NAME "%sJPG%03d.TMP"
00079 #endif
00080
00081 #ifndef NO_ERRNO_H
00082 #include <errno.h>
00083 #endif
00084
00085
00086
00087
00088
00089 #ifndef errno
00090 extern int errno;
00091 #endif
00092
00093
00094 LOCAL(void)
00095 select_file_name (char * fname)
00096 {
00097 FILE * tfile;
00098
00099
00100 for (;;) {
00101 next_file_num++;
00102 sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num);
00103 if ((tfile = fopen(fname, READ_BINARY)) == NULL) {
00104
00105
00106
00107
00108 #ifdef ENOENT
00109 if (errno != ENOENT)
00110 continue;
00111 #endif
00112 break;
00113 }
00114 fclose(tfile);
00115 }
00116 }
00117
00118 #else
00119
00120
00121 #ifndef TEMP_FILE_NAME
00122 #define TEMP_FILE_NAME "%sJPG%dXXXXXX"
00123 #endif
00124
00125 LOCAL(void)
00126 select_file_name (char * fname)
00127 {
00128 next_file_num++;
00129 sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num);
00130 mktemp(fname);
00131
00132 }
00133
00134 #endif
00135
00136
00137
00138
00139
00140
00141
00142 GLOBAL(void *)
00143 jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
00144 {
00145 return (void *) malloc(sizeofobject);
00146 }
00147
00148 GLOBAL(void)
00149 jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
00150 {
00151 free(object);
00152 }
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162 GLOBAL(void FAR *)
00163 jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
00164 {
00165 return (void FAR *) malloc(sizeofobject);
00166 }
00167
00168 GLOBAL(void)
00169 jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
00170 {
00171 free(object);
00172 }
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 #ifndef DEFAULT_MAX_MEM
00184 #define DEFAULT_MAX_MEM 1000000L
00185 #endif
00186
00187 GLOBAL(long)
00188 jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
00189 long max_bytes_needed, long already_allocated)
00190 {
00191 return cinfo->mem->max_memory_to_use - already_allocated;
00192 }
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 METHODDEF(void)
00204 read_backing_store (j_common_ptr cinfo, backing_store_ptr info,
00205 void FAR * buffer_address,
00206 long file_offset, long byte_count)
00207 {
00208 if (fseek(info->temp_file, file_offset, SEEK_SET))
00209 ERREXIT(cinfo, JERR_TFILE_SEEK);
00210 if (JFREAD(info->temp_file, buffer_address, byte_count)
00211 != (size_t) byte_count)
00212 ERREXIT(cinfo, JERR_TFILE_READ);
00213 }
00214
00215
00216 METHODDEF(void)
00217 write_backing_store (j_common_ptr cinfo, backing_store_ptr info,
00218 void FAR * buffer_address,
00219 long file_offset, long byte_count)
00220 {
00221 if (fseek(info->temp_file, file_offset, SEEK_SET))
00222 ERREXIT(cinfo, JERR_TFILE_SEEK);
00223 if (JFWRITE(info->temp_file, buffer_address, byte_count)
00224 != (size_t) byte_count)
00225 ERREXIT(cinfo, JERR_TFILE_WRITE);
00226 }
00227
00228
00229 METHODDEF(void)
00230 close_backing_store (j_common_ptr cinfo, backing_store_ptr info)
00231 {
00232 fclose(info->temp_file);
00233 unlink(info->temp_name);
00234
00235
00236
00237
00238 TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name);
00239 }
00240
00241
00242
00243
00244
00245
00246 GLOBAL(void)
00247 jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
00248 long total_bytes_needed)
00249 {
00250 select_file_name(info->temp_name);
00251 if ((info->temp_file = fopen(info->temp_name, RW_BINARY)) == NULL)
00252 ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);
00253 info->read_backing_store = read_backing_store;
00254 info->write_backing_store = write_backing_store;
00255 info->close_backing_store = close_backing_store;
00256 TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name);
00257 }
00258
00259
00260
00261
00262
00263
00264
00265 GLOBAL(long)
00266 jpeg_mem_init (j_common_ptr cinfo)
00267 {
00268 next_file_num = 0;
00269 return DEFAULT_MAX_MEM;
00270 }
00271
00272 GLOBAL(void)
00273 jpeg_mem_term (j_common_ptr cinfo)
00274 {
00275
00276 }