ReactOS  0.4.14-dev-77-gd9e7c48
jmemdos.c File Reference
#include "jinclude.h"
#include "jpeglib.h"
#include "jmemsys.h"
Include dependency graph for jmemdos.c:

Go to the source code of this file.

Classes

struct  XMScontext
 
struct  EMScontext
 
union  XMSPTR
 
struct  XMSspec
 
union  EMSspec
 

Macros

#define XMS_SUPPORTED   1
 
#define EMS_SUPPORTED   1
 
#define JPEG_INTERNALS
 
#define far_malloc(x)   malloc(x)
 
#define far_free(x)   free(x)
 
#define READ_BINARY   "rb"
 
#define DEFAULT_MAX_MEM   300000L /* for total usage about 450K */
 
#define ODD(X)   (((X) & 1L) != 0)
 
#define FIELD_AT(spec, offset, type)   (*((type *) &(spec.bytes[offset])))
 
#define SRC_TYPE(spec)   FIELD_AT(spec,4,char)
 
#define SRC_HANDLE(spec)   FIELD_AT(spec,5,EMSH)
 
#define SRC_OFFSET(spec)   FIELD_AT(spec,7,unsigned short)
 
#define SRC_PAGE(spec)   FIELD_AT(spec,9,unsigned short)
 
#define SRC_PTR(spec)   FIELD_AT(spec,7,EMSPTR)
 
#define DST_TYPE(spec)   FIELD_AT(spec,11,char)
 
#define DST_HANDLE(spec)   FIELD_AT(spec,12,EMSH)
 
#define DST_OFFSET(spec)   FIELD_AT(spec,14,unsigned short)
 
#define DST_PAGE(spec)   FIELD_AT(spec,16,unsigned short)
 
#define DST_PTR(spec)   FIELD_AT(spec,14,EMSPTR)
 
#define EMSPAGESIZE   16384L /* gospel, see the EMS specs */
 
#define HIBYTE(W)   (((W) >> 8) & 0xFF)
 
#define LOBYTE(W)   ((W) & 0xFF)
 

Typedefs

typedef void farEMSPTR
 

Functions

void *malloc JPP ((size_t size))
 
void free JPP ((void *ptr))
 
char *getenv JPP ((const char *name))
 
short far jdos_open JPP ((short far *handle, char far *filename))
 
short far jdos_close JPP ((short handle))
 
short far jdos_seek JPP ((short handle, long offset))
 
short far jdos_read JPP ((short handle, void far *buffer, unsigned short count))
 
void far jxms_getdriver JPP ((XMSDRIVER far *))
 
void far jxms_calldriver JPP ((XMSDRIVER, XMScontext far *))
 
short far jems_available JPP ((void))
 
void far jems_calldriver JPP ((EMScontext far *))
 
 select_file_name (char *fname)
 
 jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
 
 jpeg_free_small (j_common_ptr cinfo, void *object, size_t sizeofobject)
 
 jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
 
 jpeg_free_large (j_common_ptr cinfo, void FAR *object, size_t sizeofobject)
 
 jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, long max_bytes_needed, long already_allocated)
 
 read_file_store (j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
 
 write_file_store (j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
 
 close_file_store (j_common_ptr cinfo, backing_store_ptr info)
 
 open_file_store (j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed)
 
 read_xms_store (j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
 
 write_xms_store (j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
 
 close_xms_store (j_common_ptr cinfo, backing_store_ptr info)
 
 open_xms_store (j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed)
 
 read_ems_store (j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
 
 write_ems_store (j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
 
 close_ems_store (j_common_ptr cinfo, backing_store_ptr info)
 
 open_ems_store (j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed)
 
 jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed)
 
 jpeg_mem_init (j_common_ptr cinfo)
 
 jpeg_mem_term (j_common_ptr cinfo)
 

Variables

You forgot to define USE_MSDOS_MEMMGR in jconfig h typedef void farXMSDRIVER
 
static int next_file_num
 
static XMSDRIVER xms_driver
 

Macro Definition Documentation

◆ DEFAULT_MAX_MEM

#define DEFAULT_MAX_MEM   300000L /* for total usage about 450K */

Definition at line 204 of file jmemdos.c.

◆ DST_HANDLE

#define DST_HANDLE (   spec)    FIELD_AT(spec,12,EMSH)

Definition at line 479 of file jmemdos.c.

◆ DST_OFFSET

#define DST_OFFSET (   spec)    FIELD_AT(spec,14,unsigned short)

Definition at line 480 of file jmemdos.c.

◆ DST_PAGE

#define DST_PAGE (   spec)    FIELD_AT(spec,16,unsigned short)

Definition at line 481 of file jmemdos.c.

◆ DST_PTR

#define DST_PTR (   spec)    FIELD_AT(spec,14,EMSPTR)

Definition at line 482 of file jmemdos.c.

◆ DST_TYPE

#define DST_TYPE (   spec)    FIELD_AT(spec,11,char)

Definition at line 478 of file jmemdos.c.

◆ EMS_SUPPORTED

#define EMS_SUPPORTED   1

Definition at line 38 of file jmemdos.c.

◆ EMSPAGESIZE

#define EMSPAGESIZE   16384L /* gospel, see the EMS specs */

Definition at line 484 of file jmemdos.c.

◆ far_free

#define far_free (   x)    free(x)

Definition at line 70 of file jmemdos.c.

◆ far_malloc

#define far_malloc (   x)    malloc(x)

Definition at line 69 of file jmemdos.c.

◆ FIELD_AT

#define FIELD_AT (   spec,
  offset,
  type 
)    (*((type *) &(spec.bytes[offset])))

Definition at line 472 of file jmemdos.c.

◆ HIBYTE

#define HIBYTE (   W)    (((W) >> 8) & 0xFF)

Definition at line 486 of file jmemdos.c.

◆ JPEG_INTERNALS

#define JPEG_INTERNALS

Definition at line 42 of file jmemdos.c.

◆ LOBYTE

#define LOBYTE (   W)    ((W) & 0xFF)

Definition at line 487 of file jmemdos.c.

◆ ODD

#define ODD (   X)    (((X) & 1L) != 0)

Definition at line 329 of file jmemdos.c.

◆ READ_BINARY

#define READ_BINARY   "rb"

Definition at line 77 of file jmemdos.c.

◆ SRC_HANDLE

#define SRC_HANDLE (   spec)    FIELD_AT(spec,5,EMSH)

Definition at line 474 of file jmemdos.c.

◆ SRC_OFFSET

#define SRC_OFFSET (   spec)    FIELD_AT(spec,7,unsigned short)

Definition at line 475 of file jmemdos.c.

◆ SRC_PAGE

#define SRC_PAGE (   spec)    FIELD_AT(spec,9,unsigned short)

Definition at line 476 of file jmemdos.c.

◆ SRC_PTR

#define SRC_PTR (   spec)    FIELD_AT(spec,7,EMSPTR)

Definition at line 477 of file jmemdos.c.

◆ SRC_TYPE

#define SRC_TYPE (   spec)    FIELD_AT(spec,4,char)

Definition at line 473 of file jmemdos.c.

◆ XMS_SUPPORTED

#define XMS_SUPPORTED   1

Definition at line 35 of file jmemdos.c.

Typedef Documentation

◆ EMSPTR

typedef void far* EMSPTR

Definition at line 464 of file jmemdos.c.

Function Documentation

◆ close_ems_store()

close_ems_store ( j_common_ptr  cinfo,
backing_store_ptr  info 
)

Definition at line 541 of file jmemdos.c.

542 {
543  EMScontext ctx;
544 
545  ctx.ax = 0x4500;
546  ctx.dx = info->handle.ems_handle;
547  jems_calldriver((EMScontext far *) & ctx);
548  TRACEMS1(cinfo, 1, JTRC_EMS_CLOSE, info->handle.ems_handle);
549  /* we ignore any error return from the driver */
550 }
unsigned short dx
Definition: jmemdos.c:103
#define far
Definition: windef.h:114
#define TRACEMS1(cinfo, lvl, code, p1)
Definition: jerror.h:268
unsigned short ax
Definition: jmemdos.c:103

Referenced by open_ems_store().

◆ close_file_store()

close_file_store ( j_common_ptr  cinfo,
backing_store_ptr  info 
)

Definition at line 275 of file jmemdos.c.

276 {
277  jdos_close(info->handle.file_handle); /* close the file */
278  remove(info->temp_name); /* delete the file */
279 /* If your system doesn't have remove(), try unlink() instead.
280  * remove() is the ANSI-standard name for this function, but
281  * unlink() was more common in pre-ANSI systems.
282  */
283  TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name);
284 }
#define TRACEMSS(cinfo, lvl, code, str)
Definition: jerror.h:299
int remove
Definition: msacm.c:1353

Referenced by open_file_store().

◆ close_xms_store()

close_xms_store ( j_common_ptr  cinfo,
backing_store_ptr  info 
)

Definition at line 401 of file jmemdos.c.

402 {
403  XMScontext ctx;
404 
405  ctx.dx = info->handle.xms_handle;
406  ctx.ax = 0x0a00;
407  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
408  TRACEMS1(cinfo, 1, JTRC_XMS_CLOSE, info->handle.xms_handle);
409  /* we ignore any error return from the driver */
410 }
unsigned short ax
Definition: jmemdos.c:99
#define far
Definition: windef.h:114
#define TRACEMS1(cinfo, lvl, code, p1)
Definition: jerror.h:268
static XMSDRIVER xms_driver
Definition: jmemdos.c:314
unsigned short dx
Definition: jmemdos.c:99

Referenced by open_xms_store().

◆ jpeg_free_large()

jpeg_free_large ( j_common_ptr  cinfo,
void FAR object,
size_t  sizeofobject 
)

Definition at line 189 of file jmemdos.c.

190 {
191  far_free(object);
192 }
#define far_free(x)
Definition: jmemdos.c:70

◆ jpeg_free_small()

jpeg_free_small ( j_common_ptr  cinfo,
void object,
size_t  sizeofobject 
)

Definition at line 172 of file jmemdos.c.

173 {
174  free(object);
175 }
#define free
Definition: debug_ros.c:5

◆ jpeg_get_large()

jpeg_get_large ( j_common_ptr  cinfo,
size_t  sizeofobject 
)

Definition at line 183 of file jmemdos.c.

184 {
185  return (void FAR *) far_malloc(sizeofobject);
186 }
#define far_malloc(x)
Definition: jmemdos.c:69
size_t sizeofobject
Definition: jmemsys.h:47
#define FAR
Definition: guiddef.h:36

◆ jpeg_get_small()

jpeg_get_small ( j_common_ptr  cinfo,
size_t  sizeofobject 
)

Definition at line 166 of file jmemdos.c.

167 {
168  return (void *) malloc(sizeofobject);
169 }
size_t sizeofobject
Definition: jmemsys.h:47
#define malloc
Definition: debug_ros.c:4

◆ jpeg_mem_available()

jpeg_mem_available ( j_common_ptr  cinfo,
long  min_bytes_needed,
long  max_bytes_needed,
long  already_allocated 
)

Definition at line 208 of file jmemdos.c.

210 {
211  return cinfo->mem->max_memory_to_use - already_allocated;
212 }
long long long already_allocated
Definition: jmemsys.h:104

◆ jpeg_mem_init()

jpeg_mem_init ( j_common_ptr  cinfo)

Definition at line 623 of file jmemdos.c.

624 {
625  next_file_num = 0; /* initialize temp file name generator */
626  return DEFAULT_MAX_MEM; /* default for max_memory_to_use */
627 }
static int next_file_num
Definition: jmemdos.c:125
#define DEFAULT_MAX_MEM
Definition: jmemdos.c:204

◆ jpeg_mem_term()

jpeg_mem_term ( j_common_ptr  cinfo)

Definition at line 630 of file jmemdos.c.

631 {
632  /* Microsoft C, at least in v6.00A, will not successfully reclaim freed
633  * blocks of size > 32Kbytes unless we give it a kick in the rear, like so:
634  */
635 #ifdef NEED_FHEAPMIN
636  _fheapmin();
637 #endif
638 }

◆ jpeg_open_backing_store()

jpeg_open_backing_store ( j_common_ptr  cinfo,
backing_store_ptr  info,
long  total_bytes_needed 
)

Definition at line 599 of file jmemdos.c.

601 {
602  /* Try extended memory, then expanded memory, then regular file. */
603 #if XMS_SUPPORTED
605  return;
606 #endif
607 #if EMS_SUPPORTED
609  return;
610 #endif
612  return;
613  ERREXITS(cinfo, JERR_TFILE_CREATE, "");
614 }
open_ems_store(j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed)
Definition: jmemdos.c:554
backing_store_ptr long total_bytes_needed
Definition: jmemsys.h:181
open_file_store(j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed)
Definition: jmemdos.c:288
open_xms_store(j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed)
Definition: jmemdos.c:414
#define ERREXITS(cinfo, code, str)
Definition: jerror.h:243

◆ JPP() [1/11]

void* malloc JPP ( (size_t size )

◆ JPP() [2/11]

void free JPP ( (void *ptr )

◆ JPP() [3/11]

char* getenv JPP ( (const char *name )

◆ JPP() [4/11]

short far jdos_open JPP ( (short far *handle, char far *filename )

◆ JPP() [5/11]

short far jdos_close JPP ( (short handle )

◆ JPP() [6/11]

short far jdos_seek JPP ( (short handle, long offset )

◆ JPP() [7/11]

short far jdos_write JPP ( (short handle, void far *buffer, unsigned short count )

◆ JPP() [8/11]

void far jxms_getdriver JPP ( (XMSDRIVER far *)  )

◆ JPP() [9/11]

void far jxms_calldriver JPP ( (XMSDRIVER, XMScontext far *)  )

◆ JPP() [10/11]

short far jems_available JPP ( (void )

◆ JPP() [11/11]

void far jems_calldriver JPP ( (EMScontext far *)  )

◆ open_ems_store()

open_ems_store ( j_common_ptr  cinfo,
backing_store_ptr  info,
long  total_bytes_needed 
)

Definition at line 554 of file jmemdos.c.

556 {
557  EMScontext ctx;
558 
559  /* Is EMS driver there? */
560  if (! jems_available())
561  return FALSE;
562 
563  /* Get status, make sure EMS is OK */
564  ctx.ax = 0x4000;
565  jems_calldriver((EMScontext far *) & ctx);
566  if (HIBYTE(ctx.ax) != 0)
567  return FALSE;
568 
569  /* Get version, must be >= 4.0 */
570  ctx.ax = 0x4600;
571  jems_calldriver((EMScontext far *) & ctx);
572  if (HIBYTE(ctx.ax) != 0 || LOBYTE(ctx.ax) < 0x40)
573  return FALSE;
574 
575  /* Try to allocate requested space */
576  ctx.ax = 0x4300;
577  ctx.bx = (unsigned short) ((total_bytes_needed + EMSPAGESIZE-1L) / EMSPAGESIZE);
578  jems_calldriver((EMScontext far *) & ctx);
579  if (HIBYTE(ctx.ax) != 0)
580  return FALSE;
581 
582  /* Succeeded, save the handle and away we go */
583  info->handle.ems_handle = ctx.dx;
584  info->read_backing_store = read_ems_store;
585  info->write_backing_store = write_ems_store;
586  info->close_backing_store = close_ems_store;
587  TRACEMS1(cinfo, 1, JTRC_EMS_OPEN, ctx.dx);
588  return TRUE; /* succeeded */
589 }
#define TRUE
Definition: types.h:120
unsigned short dx
Definition: jmemdos.c:103
unsigned short bx
Definition: jmemdos.c:103
#define LOBYTE(W)
Definition: jmemdos.c:487
#define HIBYTE(W)
Definition: jmemdos.c:486
#define far
Definition: windef.h:114
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
Definition: typeof.h:93
write_ems_store(j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
Definition: jmemdos.c:516
#define TRACEMS1(cinfo, lvl, code, p1)
Definition: jerror.h:268
read_ems_store(j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
Definition: jmemdos.c:491
backing_store_ptr long total_bytes_needed
Definition: jmemsys.h:181
close_ems_store(j_common_ptr cinfo, backing_store_ptr info)
Definition: jmemdos.c:541
#define EMSPAGESIZE
Definition: jmemdos.c:484
static const WCHAR L[]
Definition: oid.c:1250
unsigned short ax
Definition: jmemdos.c:103

Referenced by jpeg_open_backing_store().

◆ open_file_store()

open_file_store ( j_common_ptr  cinfo,
backing_store_ptr  info,
long  total_bytes_needed 
)

Definition at line 288 of file jmemdos.c.

290 {
291  short handle;
292 
293  select_file_name(info->temp_name);
294  if (jdos_open((short far *) & handle, (char far *) info->temp_name)) {
295  /* might as well exit since jpeg_open_backing_store will fail anyway */
296  ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);
297  return FALSE;
298  }
299  info->handle.file_handle = handle;
300  info->read_backing_store = read_file_store;
301  info->write_backing_store = write_file_store;
302  info->close_backing_store = close_file_store;
303  TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name);
304  return TRUE; /* succeeded */
305 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define TRUE
Definition: types.h:120
#define far
Definition: windef.h:114
read_file_store(j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
Definition: jmemdos.c:243
#define TRACEMSS(cinfo, lvl, code, str)
Definition: jerror.h:299
close_file_store(j_common_ptr cinfo, backing_store_ptr info)
Definition: jmemdos.c:275
write_file_store(j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
Definition: jmemdos.c:259
#define ERREXITS(cinfo, code, str)
Definition: jerror.h:243
select_file_name(char *fname)
Definition: jmemdos.c:128

Referenced by jpeg_open_backing_store().

◆ open_xms_store()

open_xms_store ( j_common_ptr  cinfo,
backing_store_ptr  info,
long  total_bytes_needed 
)

Definition at line 414 of file jmemdos.c.

416 {
417  XMScontext ctx;
418 
419  /* Get address of XMS driver */
420  jxms_getdriver((XMSDRIVER far *) & xms_driver);
421  if (xms_driver == NULL)
422  return FALSE; /* no driver to be had */
423 
424  /* Get version number, must be >= 2.00 */
425  ctx.ax = 0x0000;
426  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
427  if (ctx.ax < (unsigned short) 0x0200)
428  return FALSE;
429 
430  /* Try to get space (expressed in kilobytes) */
431  ctx.dx = (unsigned short) ((total_bytes_needed + 1023L) >> 10);
432  ctx.ax = 0x0900;
433  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
434  if (ctx.ax != 1)
435  return FALSE;
436 
437  /* Succeeded, save the handle and away we go */
438  info->handle.xms_handle = ctx.dx;
439  info->read_backing_store = read_xms_store;
440  info->write_backing_store = write_xms_store;
441  info->close_backing_store = close_xms_store;
442  TRACEMS1(cinfo, 1, JTRC_XMS_OPEN, ctx.dx);
443  return TRUE; /* succeeded */
444 }
#define TRUE
Definition: types.h:120
unsigned short ax
Definition: jmemdos.c:99
write_xms_store(j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
Definition: jmemdos.c:366
#define far
Definition: windef.h:114
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
Definition: typeof.h:93
#define TRACEMS1(cinfo, lvl, code, p1)
Definition: jerror.h:268
smooth NULL
Definition: ftsmooth.c:416
backing_store_ptr long total_bytes_needed
Definition: jmemsys.h:181
You forgot to define USE_MSDOS_MEMMGR in jconfig h typedef void far * XMSDRIVER
Definition: jmemdos.c:97
static XMSDRIVER xms_driver
Definition: jmemdos.c:314
unsigned short dx
Definition: jmemdos.c:99
static const WCHAR L[]
Definition: oid.c:1250
close_xms_store(j_common_ptr cinfo, backing_store_ptr info)
Definition: jmemdos.c:401
read_xms_store(j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
Definition: jmemdos.c:333

Referenced by jpeg_open_backing_store().

◆ read_ems_store()

read_ems_store ( j_common_ptr  cinfo,
backing_store_ptr  info,
void FAR buffer_address,
long  file_offset,
long  byte_count 
)

Definition at line 491 of file jmemdos.c.

494 {
495  EMScontext ctx;
496  EMSspec spec;
497 
498  spec.length = byte_count;
499  SRC_TYPE(spec) = 1;
500  SRC_HANDLE(spec) = info->handle.ems_handle;
501  SRC_PAGE(spec) = (unsigned short) (file_offset / EMSPAGESIZE);
502  SRC_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE);
503  DST_TYPE(spec) = 0;
504  DST_HANDLE(spec) = 0;
505  DST_PTR(spec) = buffer_address;
506 
507  ctx.ds_si = (void far *) & spec;
508  ctx.ax = 0x5700; /* move memory region */
509  jems_calldriver((EMScontext far *) & ctx);
510  if (HIBYTE(ctx.ax) != 0)
511  ERREXIT(cinfo, JERR_EMS_READ);
512 }
#define DST_PTR(spec)
Definition: jmemdos.c:482
#define ERREXIT(msg)
Definition: rdjpgcom.c:72
#define SRC_OFFSET(spec)
Definition: jmemdos.c:475
#define HIBYTE(W)
Definition: jmemdos.c:486
#define far
Definition: windef.h:114
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
Definition: typeof.h:93
long length
Definition: jmemdos.c:467
#define SRC_TYPE(spec)
Definition: jmemdos.c:473
#define EMSPAGESIZE
Definition: jmemdos.c:484
void far * ds_si
Definition: jmemdos.c:104
unsigned short ax
Definition: jmemdos.c:103
#define DST_TYPE(spec)
Definition: jmemdos.c:478
#define DST_HANDLE(spec)
Definition: jmemdos.c:479
#define SRC_HANDLE(spec)
Definition: jmemdos.c:474
#define SRC_PAGE(spec)
Definition: jmemdos.c:476

Referenced by open_ems_store().

◆ read_file_store()

read_file_store ( j_common_ptr  cinfo,
backing_store_ptr  info,
void FAR buffer_address,
long  file_offset,
long  byte_count 
)

Definition at line 243 of file jmemdos.c.

246 {
247  if (jdos_seek(info->handle.file_handle, file_offset))
248  ERREXIT(cinfo, JERR_TFILE_SEEK);
249  /* Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. */
250  if (byte_count > 65535L) /* safety check */
251  ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
252  if (jdos_read(info->handle.file_handle, buffer_address,
253  (unsigned short) byte_count))
254  ERREXIT(cinfo, JERR_TFILE_READ);
255 }
#define ERREXIT(msg)
Definition: rdjpgcom.c:72
static const WCHAR L[]
Definition: oid.c:1250

Referenced by open_file_store().

◆ read_xms_store()

read_xms_store ( j_common_ptr  cinfo,
backing_store_ptr  info,
void FAR buffer_address,
long  file_offset,
long  byte_count 
)

Definition at line 333 of file jmemdos.c.

336 {
337  XMScontext ctx;
338  XMSspec spec;
339  char endbuffer[2];
340 
341  /* The XMS driver can't cope with an odd length, so handle the last byte
342  * specially if byte_count is odd. We don't expect this to be common.
343  */
344 
345  spec.length = byte_count & (~ 1L);
346  spec.src_handle = info->handle.xms_handle;
347  spec.src.offset = file_offset;
348  spec.dst_handle = 0;
349  spec.dst.ptr = buffer_address;
350 
351  ctx.ds_si = (void far *) & spec;
352  ctx.ax = 0x0b00; /* EMB move */
353  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
354  if (ctx.ax != 1)
355  ERREXIT(cinfo, JERR_XMS_READ);
356 
357  if (ODD(byte_count)) {
358  read_xms_store(cinfo, info, (void FAR *) endbuffer,
359  file_offset + byte_count - 1L, 2L);
360  ((char FAR *) buffer_address)[byte_count - 1L] = endbuffer[0];
361  }
362 }
XMSPTR dst
Definition: jmemdos.c:326
#define ERREXIT(msg)
Definition: rdjpgcom.c:72
void far * ptr
Definition: jmemdos.c:318
unsigned short ax
Definition: jmemdos.c:99
XMSH dst_handle
Definition: jmemdos.c:325
#define far
Definition: windef.h:114
long length
Definition: jmemdos.c:322
long offset
Definition: jmemdos.c:317
#define FAR
Definition: guiddef.h:36
#define ODD(X)
Definition: jmemdos.c:329
static XMSDRIVER xms_driver
Definition: jmemdos.c:314
void far * ds_si
Definition: jmemdos.c:100
XMSPTR src
Definition: jmemdos.c:324
static const WCHAR L[]
Definition: oid.c:1250
XMSH src_handle
Definition: jmemdos.c:323
read_xms_store(j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
Definition: jmemdos.c:333

Referenced by open_xms_store(), and write_xms_store().

◆ select_file_name()

select_file_name ( char fname)

Definition at line 128 of file jmemdos.c.

129 {
130  const char * env;
131  char * ptr;
132  FILE * tfile;
133 
134  /* Keep generating file names till we find one that's not in use */
135  for (;;) {
136  /* Get temp directory name from environment TMP or TEMP variable;
137  * if none, use "."
138  */
139  if ((env = (const char *) getenv("TMP")) == NULL)
140  if ((env = (const char *) getenv("TEMP")) == NULL)
141  env = ".";
142  if (*env == '\0') /* null string means "." */
143  env = ".";
144  ptr = fname; /* copy name to fname */
145  while (*env != '\0')
146  *ptr++ = *env++;
147  if (ptr[-1] != '\\' && ptr[-1] != '/')
148  *ptr++ = '\\'; /* append backslash if not in env variable */
149  /* Append a suitable file name */
150  next_file_num++; /* advance counter */
151  sprintf(ptr, "JPG%03d.TMP", next_file_num);
152  /* Probe to see if file name is already in use */
153  if ((tfile = fopen(fname, READ_BINARY)) == NULL)
154  break;
155  fclose(tfile); /* oops, it's there; close tfile & try again */
156  }
157 }
#define READ_BINARY
Definition: jmemdos.c:77
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
static int next_file_num
Definition: jmemdos.c:125
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
static LPCWSTR LPCWSTR LPCWSTR env
Definition: db.cpp:168

Referenced by open_file_store().

◆ write_ems_store()

write_ems_store ( j_common_ptr  cinfo,
backing_store_ptr  info,
void FAR buffer_address,
long  file_offset,
long  byte_count 
)

Definition at line 516 of file jmemdos.c.

519 {
520  EMScontext ctx;
521  EMSspec spec;
522 
523  spec.length = byte_count;
524  SRC_TYPE(spec) = 0;
525  SRC_HANDLE(spec) = 0;
526  SRC_PTR(spec) = buffer_address;
527  DST_TYPE(spec) = 1;
528  DST_HANDLE(spec) = info->handle.ems_handle;
529  DST_PAGE(spec) = (unsigned short) (file_offset / EMSPAGESIZE);
530  DST_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE);
531 
532  ctx.ds_si = (void far *) & spec;
533  ctx.ax = 0x5700; /* move memory region */
534  jems_calldriver((EMScontext far *) & ctx);
535  if (HIBYTE(ctx.ax) != 0)
536  ERREXIT(cinfo, JERR_EMS_WRITE);
537 }
#define SRC_PTR(spec)
Definition: jmemdos.c:477
#define ERREXIT(msg)
Definition: rdjpgcom.c:72
#define HIBYTE(W)
Definition: jmemdos.c:486
#define far
Definition: windef.h:114
#define DST_OFFSET(spec)
Definition: jmemdos.c:480
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
Definition: typeof.h:93
long length
Definition: jmemdos.c:467
#define SRC_TYPE(spec)
Definition: jmemdos.c:473
#define DST_PAGE(spec)
Definition: jmemdos.c:481
#define EMSPAGESIZE
Definition: jmemdos.c:484
void far * ds_si
Definition: jmemdos.c:104
unsigned short ax
Definition: jmemdos.c:103
#define DST_TYPE(spec)
Definition: jmemdos.c:478
#define DST_HANDLE(spec)
Definition: jmemdos.c:479
#define SRC_HANDLE(spec)
Definition: jmemdos.c:474

Referenced by open_ems_store().

◆ write_file_store()

write_file_store ( j_common_ptr  cinfo,
backing_store_ptr  info,
void FAR buffer_address,
long  file_offset,
long  byte_count 
)

Definition at line 259 of file jmemdos.c.

262 {
263  if (jdos_seek(info->handle.file_handle, file_offset))
264  ERREXIT(cinfo, JERR_TFILE_SEEK);
265  /* Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. */
266  if (byte_count > 65535L) /* safety check */
267  ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
268  if (jdos_write(info->handle.file_handle, buffer_address,
269  (unsigned short) byte_count))
270  ERREXIT(cinfo, JERR_TFILE_WRITE);
271 }
#define ERREXIT(msg)
Definition: rdjpgcom.c:72
static const WCHAR L[]
Definition: oid.c:1250

Referenced by open_file_store().

◆ write_xms_store()

write_xms_store ( j_common_ptr  cinfo,
backing_store_ptr  info,
void FAR buffer_address,
long  file_offset,
long  byte_count 
)

Definition at line 366 of file jmemdos.c.

369 {
370  XMScontext ctx;
371  XMSspec spec;
372  char endbuffer[2];
373 
374  /* The XMS driver can't cope with an odd length, so handle the last byte
375  * specially if byte_count is odd. We don't expect this to be common.
376  */
377 
378  spec.length = byte_count & (~ 1L);
379  spec.src_handle = 0;
380  spec.src.ptr = buffer_address;
381  spec.dst_handle = info->handle.xms_handle;
382  spec.dst.offset = file_offset;
383 
384  ctx.ds_si = (void far *) & spec;
385  ctx.ax = 0x0b00; /* EMB move */
386  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
387  if (ctx.ax != 1)
388  ERREXIT(cinfo, JERR_XMS_WRITE);
389 
390  if (ODD(byte_count)) {
391  read_xms_store(cinfo, info, (void FAR *) endbuffer,
392  file_offset + byte_count - 1L, 2L);
393  endbuffer[0] = ((char FAR *) buffer_address)[byte_count - 1L];
394  write_xms_store(cinfo, info, (void FAR *) endbuffer,
395  file_offset + byte_count - 1L, 2L);
396  }
397 }
XMSPTR dst
Definition: jmemdos.c:326
#define ERREXIT(msg)
Definition: rdjpgcom.c:72
void far * ptr
Definition: jmemdos.c:318
unsigned short ax
Definition: jmemdos.c:99
XMSH dst_handle
Definition: jmemdos.c:325
write_xms_store(j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
Definition: jmemdos.c:366
#define far
Definition: windef.h:114
long length
Definition: jmemdos.c:322
long offset
Definition: jmemdos.c:317
#define FAR
Definition: guiddef.h:36
#define ODD(X)
Definition: jmemdos.c:329
static XMSDRIVER xms_driver
Definition: jmemdos.c:314
void far * ds_si
Definition: jmemdos.c:100
XMSPTR src
Definition: jmemdos.c:324
static const WCHAR L[]
Definition: oid.c:1250
XMSH src_handle
Definition: jmemdos.c:323
read_xms_store(j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
Definition: jmemdos.c:333

Referenced by open_xms_store().

Variable Documentation

◆ next_file_num

int next_file_num
static

Definition at line 125 of file jmemdos.c.

Referenced by jpeg_mem_init(), and select_file_name().

◆ xms_driver

XMSDRIVER xms_driver
static

Definition at line 314 of file jmemdos.c.

Referenced by close_xms_store(), open_xms_store(), read_xms_store(), and write_xms_store().

◆ XMSDRIVER

You forgot to define USE_MSDOS_MEMMGR in jconfig h typedef void far* XMSDRIVER

Definition at line 97 of file jmemdos.c.

Referenced by open_xms_store().