From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/CONTRIB/SNIP/addhndls.c | 104 ++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100755 reference/C/CONTRIB/SNIP/addhndls.c (limited to 'reference/C/CONTRIB/SNIP/addhndls.c') diff --git a/reference/C/CONTRIB/SNIP/addhndls.c b/reference/C/CONTRIB/SNIP/addhndls.c new file mode 100755 index 0000000..892e550 --- /dev/null +++ b/reference/C/CONTRIB/SNIP/addhndls.c @@ -0,0 +1,104 @@ +/* +** ADDHNDLS.C +** +** A compilation of public domain sources originally written by +** Doug Burger and Bob Jarvis +** +** Collected and modified for Zortech, Microsoft, and Borland by Bob Stout +** +** Demonstrates relocating the file handle table under DOS 3.x +** for having more than the usual 20 files open in a single +** program +*/ + +#include +#include +#include +#include + +#define TABLE_SIZE 255 /* NOTE: *Must* be <= FILES in CONFIG.SYS */ + +#ifdef TEST + #if !defined(__ZTC__) && !defined(__TURBOC__) /* i.e. #if MSC/QC */ + #include + #define MK_FP(seg,offset) \ + ((void far *)(((unsigned long)(seg)<<16) | (unsigned)(offset))) + + /* MSC's open() is funny - this code only works with _dos_open() */ + + int open(const char *name, int mode, ...) + { + int hdl; + + if (0 == _dos_open(name, mode, &hdl)) + return hdl; + else return -1; + } + #endif /* MSC */ +#endif /* TEST */ + +unsigned char handle_table[TABLE_SIZE]; /* table of file DOS handles */ +unsigned char far * far * handle_ptr; /* ptr to DOS's ptr to hand. */ +unsigned int far *handle_count; /* ptr to handle count */ + +int relocate(void) +{ + switch (_osmajor) + { + case 2: + return -1; + case 3: + if (3 > _osminor) + { /* by Doug Burger */ + unsigned int i; + + handle_count = MK_FP(_psp, 0x32); /* handle count at PSP:32h */ + handle_ptr = MK_FP(_psp, 0x34); /* table ptr at PSP:34h */ + for (i = 0; i < *handle_count; i++) /* relocate exiting table */ + handle_table[i] = (*handle_ptr)[i]; + for (i = *handle_count; i < TABLE_SIZE; i++) /* init. rest */ + handle_table[i] = 255; + *handle_ptr = handle_table; /* set pointer to new table */ + *handle_count = TABLE_SIZE; /* set new table size */ + return 0; + } + else + default: /* DOS 4+ */ + { /* by Bob Jarvis */ + union REGS regs; + + regs.h.ah = 0x67; + regs.x.bx = TABLE_SIZE | 1; /* has to be an odd number */ + + intdos(®s, ®s); + + if(regs.x.cflag) /* error */ + return -1; + else + return 0; + } + } +} /* relocate() */ + +/* +** Test code +*/ + +#ifdef TEST + +void main(void) +{ + int c, h; + + relocate(); + + c = 0; + while ((h = open("CON", O_RDONLY)) >= 0) /* DOS closes files */ + { + c++; /* on exit, so I */ + printf("handle = %d\n", h); /* don't bother */ + } /* saving handles */ + printf("total opened files = %d\n", c); +} /* ADDHNDLS.C */ + +#endif /* TEST */ -- cgit v1.2.3-54-g00ecf