1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

New ACC version.

committer: mfx <mfx> 1057743808 +0000
This commit is contained in:
Markus F.X.J. Oberhumer 2003-07-09 09:43:28 +00:00
parent c7224c7727
commit ad8648f668
11 changed files with 686 additions and 251 deletions

View File

@ -26,7 +26,7 @@
#ifndef __ACC_H_INCLUDED #ifndef __ACC_H_INCLUDED
#define __ACC_H_INCLUDED #define __ACC_H_INCLUDED
#define ACC_VERSION 20030527L #define ACC_VERSION 20030708L
#if !defined(ACC_CONFIG_INCLUDE) #if !defined(ACC_CONFIG_INCLUDE)
# define ACC_CONFIG_INCLUDE(file) file # define ACC_CONFIG_INCLUDE(file) file
@ -39,6 +39,9 @@
#if defined(__ICL) && !defined(__INTEL_COMPILER) #if defined(__ICL) && !defined(__INTEL_COMPILER)
# define __INTEL_COMPILER __ICL # define __INTEL_COMPILER __ICL
#endif #endif
#if defined(__IBMCPP__) && !defined(__IBMC__)
# define __IBMC__ __IBMCPP__
#endif
/* disable pedantic warnings */ /* disable pedantic warnings */
#if defined(__INTEL_COMPILER) && defined(__linux__) #if defined(__INTEL_COMPILER) && defined(__linux__)

View File

@ -34,7 +34,7 @@
#if (ACC_OS_DOS16 || ACC_OS_OS216 || ACC_OS_WIN16) #if (ACC_OS_DOS16 || ACC_OS_OS216 || ACC_OS_WIN16)
# define ACC_ARCH_IA16 1 # define ACC_ARCH_IA16 1
# define ACC_INFO_ARCH "ia16" # define ACC_INFO_ARCH "ia16"
#elif defined(__386__) || defined(__i386__) || defined(__i386) || defined(_M_IX86) #elif defined(__386__) || defined(__i386__) || defined(__i386) || defined(_M_IX86) || defined(_M_I386)
# define ACC_ARCH_IA32 1 # define ACC_ARCH_IA32 1
# define ACC_INFO_ARCH "ia32" # define ACC_INFO_ARCH "ia32"
#elif (ACC_CC_ZORTECHC && defined(__I86__)) #elif (ACC_CC_ZORTECHC && defined(__I86__))

View File

@ -128,11 +128,22 @@
# if (ACC_OS_WIN32 || ACC_OS_WIN64) # if (ACC_OS_WIN32 || ACC_OS_WIN64)
# undef HAVE_DIRENT_H /* pulls in <windows.h>; use <dir.h> instead */ # undef HAVE_DIRENT_H /* pulls in <windows.h>; use <dir.h> instead */
# endif # endif
# if (__BORLANDC__ < 0x0400)
# undef HAVE_DIRENT_H
# undef HAVE_UTIME_H
# endif
#elif (ACC_CC_DMC) #elif (ACC_CC_DMC)
# undef HAVE_DIRENT_H /* not working */ # undef HAVE_DIRENT_H /* not working */
# undef HAVE_UNISTD_H /* not working */ # undef HAVE_UNISTD_H /* not working */
# define HAVE_SYS_DIRENT_H 1 # define HAVE_SYS_DIRENT_H 1
#elif defined(__DJGPP__) #elif defined(__DJGPP__)
#elif (ACC_CC_IBMC && ACC_OS_OS2)
# undef HAVE_DOS_H
# undef HAVE_DIRENT_H
# undef HAVE_UNISTD_H
# undef HAVE_UTIME_H
# undef HAVE_SYS_TIME_H
# define HAVE_SYS_UTIME_H 1
#elif (ACC_CC_INTELC || ACC_CC_MSC) #elif (ACC_CC_INTELC || ACC_CC_MSC)
# undef HAVE_DIRENT_H # undef HAVE_DIRENT_H
# undef HAVE_UNISTD_H # undef HAVE_UNISTD_H
@ -258,6 +269,9 @@
#if (ACC_OS_POSIX) #if (ACC_OS_POSIX)
# if (ACC_CC_TINYC)
# undef HAVE_ALLOCA
# endif
#elif (ACC_OS_CYGWIN) #elif (ACC_OS_CYGWIN)
#elif (ACC_OS_EMX) #elif (ACC_OS_EMX)
# undef HAVE_CHOWN # undef HAVE_CHOWN
@ -291,15 +305,21 @@
#undef HAVE_UMASK #undef HAVE_UMASK
#if (ACC_CC_AZTECC) #if (ACC_CC_AZTECC)
# undef HAVE_ALLOCA
# undef HAVE_DIFFTIME /* difftime() is in the math library */ # undef HAVE_DIFFTIME /* difftime() is in the math library */
# undef HAVE_FSTAT # undef HAVE_FSTAT
# undef HAVE_STRDUP /* missing in 5.2a */ # undef HAVE_STRDUP /* missing in 5.2a */
# undef HAVE_SNPRINTF # undef HAVE_SNPRINTF
# undef HAVE_UTIME /* struct utimbuf is missing */
# undef HAVE_VSNPRINTF # undef HAVE_VSNPRINTF
#elif (ACC_CC_BORLANDC) #elif (ACC_CC_BORLANDC)
# if (ACC_OS_DOS16 || ACC_OS_WIN16) # if (ACC_OS_DOS16 || ACC_OS_WIN16)
# undef HAVE_DIFFTIME /* difftime() is in the math library */ # undef HAVE_DIFFTIME /* difftime() is in the math library */
# endif # endif
# if (__BORLANDC__ < 0x0400)
# undef HAVE_ALLOCA
# undef HAVE_UTIME
# endif
# if (__BORLANDC__ < 0x0550) # if (__BORLANDC__ < 0x0550)
# undef HAVE_SNPRINTF # undef HAVE_SNPRINTF
# undef HAVE_VSNPRINTF # undef HAVE_VSNPRINTF
@ -310,18 +330,27 @@
#elif defined(__DJGPP__) #elif defined(__DJGPP__)
# undef HAVE_SNPRINTF # undef HAVE_SNPRINTF
# undef HAVE_VSNPRINTF # undef HAVE_VSNPRINTF
#elif (ACC_CC_IBMC && ACC_OS_OS2)
# undef HAVE_SNPRINTF
# undef HAVE_VSNPRINTF
#elif (ACC_CC_INTELC) #elif (ACC_CC_INTELC)
# define snprintf _snprintf # define snprintf _snprintf
# define vsnprintf _vsnprintf # define vsnprintf _vsnprintf
#elif (ACC_CC_LCC) #elif (ACC_CC_LCC)
# define utime _utime # define utime _utime
#elif (ACC_CC_MSC) #elif (ACC_CC_MSC)
# if (_MSC_VER >= 700) # if (_MSC_VER < 600)
# define snprintf _snprintf # undef HAVE_STRFTIME
# define vsnprintf _vsnprintf # endif
# else # if (_MSC_VER < 700)
# undef HAVE_SNPRINTF # undef HAVE_SNPRINTF
# undef HAVE_VSNPRINTF # undef HAVE_VSNPRINTF
# else
# define snprintf _snprintf
# define vsnprintf _vsnprintf
# endif
# if (_MSC_VER < 800 && ACC_OS_WIN16)
# undef HAVE_ALLOCA
# endif # endif
#elif defined(__MINGW32__) #elif defined(__MINGW32__)
#elif (ACC_CC_PACIFICC) #elif (ACC_CC_PACIFICC)
@ -339,17 +368,17 @@
# if (ACC_OS_WIN16 && (ACC_MM_MEDIUM || ACC_MM_LARGE || ACC_MM_HUGE)) # if (ACC_OS_WIN16 && (ACC_MM_MEDIUM || ACC_MM_LARGE || ACC_MM_HUGE))
# undef HAVE_ALLOCA # undef HAVE_ALLOCA
# endif # endif
# if (__SC__ < 0x600)
# undef HAVE_SNPRINTF
# undef HAVE_VSNPRINTF
# else
# define snprintf _snprintf
# define vsnprintf _vsnprintf
# endif
# if (__SC__ < 0x700) # if (__SC__ < 0x700)
# undef HAVE_DIFFTIME /* difftime() is broken */ # undef HAVE_DIFFTIME /* difftime() is broken */
# undef HAVE_UTIME /* struct utimbuf is missing */ # undef HAVE_UTIME /* struct utimbuf is missing */
# endif # endif
# if (__SC__ >= 0x610)
# define snprintf _snprintf
# define vsnprintf _vsnprintf
# else
# undef HAVE_SNPRINTF
# undef HAVE_VSNPRINTF
# endif
#elif (ACC_CC_TOPSPEEDC) #elif (ACC_CC_TOPSPEEDC)
# undef HAVE_SNPRINTF # undef HAVE_SNPRINTF
# undef HAVE_VSNPRINTF # undef HAVE_VSNPRINTF
@ -365,12 +394,12 @@
# undef HAVE_UTIME # undef HAVE_UTIME
# endif # endif
#elif (ACC_CC_WATCOMC) #elif (ACC_CC_WATCOMC)
# if (__WATCOMC__ >= 1100) # if (__WATCOMC__ < 1100)
# define snprintf _snprintf
# define vsnprintf _vsnprintf
# else
# undef HAVE_SNPRINTF # undef HAVE_SNPRINTF
# undef HAVE_VSNPRINTF # undef HAVE_VSNPRINTF
# else
# define snprintf _snprintf
# define vsnprintf _vsnprintf
# endif # endif
#elif (ACC_CC_ZORTECHC) #elif (ACC_CC_ZORTECHC)
# if (ACC_OS_WIN16 && (ACC_MM_MEDIUM || ACC_MM_LARGE || ACC_MM_HUGE)) # if (ACC_OS_WIN16 && (ACC_MM_MEDIUM || ACC_MM_LARGE || ACC_MM_HUGE))
@ -433,6 +462,9 @@
#if (ACC_ARCH_IA32 && (ACC_CC_DMC || ACC_CC_GNUC)) #if (ACC_ARCH_IA32 && (ACC_CC_DMC || ACC_CC_GNUC))
# define SIZEOF_LONG_LONG 8 # define SIZEOF_LONG_LONG 8
# define SIZEOF_UNSIGNED_LONG_LONG 8 # define SIZEOF_UNSIGNED_LONG_LONG 8
#elif (ACC_ARCH_IA32 && (ACC_CC_SYMANTECC && __SC__ >= 0x700))
# define SIZEOF_LONG_LONG 8
# define SIZEOF_UNSIGNED_LONG_LONG 8
#elif (ACC_ARCH_IA32 && (ACC_CC_INTELC || ACC_CC_MSC)) #elif (ACC_ARCH_IA32 && (ACC_CC_INTELC || ACC_CC_MSC))
# define SIZEOF___INT64 8 # define SIZEOF___INT64 8
# define SIZEOF_UNSIGNED___INT64 8 # define SIZEOF_UNSIGNED___INT64 8
@ -443,6 +475,9 @@
#elif (ACC_ARCH_IA32 && (ACC_CC_WATCOMC && __WATCOMC__ >= 1100)) #elif (ACC_ARCH_IA32 && (ACC_CC_WATCOMC && __WATCOMC__ >= 1100))
# define SIZEOF___INT64 8 # define SIZEOF___INT64 8
# define SIZEOF_UNSIGNED___INT64 8 # define SIZEOF_UNSIGNED___INT64 8
#elif (ACC_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && (_INTEGRAL_MAX_BITS == 64))
# define SIZEOF___INT64 8
# define SIZEOF_UNSIGNED___INT64 8
#elif (ACC_ARCH_M68K && (ACC_CC_GNUC)) #elif (ACC_ARCH_M68K && (ACC_CC_GNUC))
# define SIZEOF_LONG_LONG 8 # define SIZEOF_LONG_LONG 8
# define SIZEOF_UNSIGNED_LONG_LONG 8 # define SIZEOF_UNSIGNED_LONG_LONG 8

View File

@ -48,8 +48,8 @@
# define ACC_INFO_CC "DEC C" # define ACC_INFO_CC "DEC C"
# define ACC_INFO_CCVER ACC_MACRO_EXPAND(__DECC) # define ACC_INFO_CCVER ACC_MACRO_EXPAND(__DECC)
#elif defined(__IBMC__) #elif defined(__IBMC__)
# define ACC_CC_VISUALAGEC 1 # define ACC_CC_IBMC 1
# define ACC_INFO_CC "VisualAge C" # define ACC_INFO_CC "IBM C"
# define ACC_INFO_CCVER ACC_MACRO_EXPAND(__IBMC__) # define ACC_INFO_CCVER ACC_MACRO_EXPAND(__IBMC__)
#elif defined(__INTEL_COMPILER) #elif defined(__INTEL_COMPILER)
# define ACC_CC_INTELC 1 # define ACC_CC_INTELC 1

View File

@ -28,6 +28,9 @@
# if (ACC_CC_DMC || ACC_CC_PACIFICC || ACC_CC_SYMANTECC) # if (ACC_CC_DMC || ACC_CC_PACIFICC || ACC_CC_SYMANTECC)
# define ACC_COMPILE_TIME_ASSERT(expr) \ # define ACC_COMPILE_TIME_ASSERT(expr) \
switch (0) { case 1: case !(expr): break; } switch (0) { case 1: case !(expr): break; }
# elif (ACC_CC_AZTECC || ACC_CC_ZORTECHC)
# define ACC_COMPILE_TIME_ASSERT(expr) \
{ typedef int __acc_compile_time_assert_fail[1 - !(expr)]; }
# else # else
# define ACC_COMPILE_TIME_ASSERT(expr) \ # define ACC_COMPILE_TIME_ASSERT(expr) \
{ typedef int __acc_compile_time_assert_fail[1 - 2 * !(expr)]; } { typedef int __acc_compile_time_assert_fail[1 - 2 * !(expr)]; }

View File

@ -16,21 +16,30 @@
#ifndef __ACC_INCI_H_INCLUDED #ifndef __ACC_INCI_H_INCLUDED
#define __ACC_INCI_H_INCLUDED #define __ACC_INCI_H_INCLUDED
/* internal system includes */
/*************************************************************************
// internal system includes
**************************************************************************/
#if (ACC_OS_TOS && (ACC_CC_PUREC || ACC_CC_TURBOC)) #if (ACC_OS_TOS && (ACC_CC_PUREC || ACC_CC_TURBOC))
# include <tos.h> # include <tos.h>
#elif (ACC_OS_WIN32 || ACC_OS_WIN64 || ACC_OS_CYGWIN || (ACC_OS_EMX && defined(__RSXNT__))) #elif (ACC_OS_WIN32 || ACC_OS_WIN64 || ACC_OS_CYGWIN || (ACC_OS_EMX && defined(__RSXNT__)))
# if 1 && !defined(WIN32_LEAN_AND_MEAN) # if (ACC_CC_WATCOMC && __WATCOMC__ < 1000)
# define WIN32_LEAN_AND_MEAN 1 # else
# if 1 && !defined(WIN32_LEAN_AND_MEAN)
# define WIN32_LEAN_AND_MEAN 1
# endif
# include <windows.h>
# define ACC_H_WINDOWS_H 1
# endif # endif
# include <windows.h>
# define ACC_H_WINDOWS_H 1
# if (ACC_CC_BORLANDC || ACC_CC_TURBOC) # if (ACC_CC_BORLANDC || ACC_CC_TURBOC)
# include <dir.h> # include <dir.h>
# endif # endif
#elif (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_WIN16) #elif (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_WIN16)
# if (ACC_CC_BORLANDC || ACC_CC_TURBOC) # if (ACC_CC_AZTECC)
# include <model.h>
# include <stat.h>
# elif (ACC_CC_BORLANDC || ACC_CC_TURBOC)
# include <alloc.h> # include <alloc.h>
# include <dir.h> # include <dir.h>
# elif defined(__DJGPP__) # elif defined(__DJGPP__)
@ -42,8 +51,53 @@
# elif (ACC_CC_WATCOMC) # elif (ACC_CC_WATCOMC)
# include <i86.h> # include <i86.h>
# endif # endif
#elif (ACC_OS_OS216)
# if 0
# include <os2.h>
# else
unsigned short __far __pascal DosAllocHuge(unsigned short, unsigned short, unsigned short __far *, unsigned short, unsigned short);
unsigned short __far __pascal DosFreeSeg(unsigned short);
# endif
#endif #endif
/*************************************************************************
//
**************************************************************************/
#if (ACC_OS_DOS16 || ACC_OS_OS216 || ACC_OS_WIN16)
# if defined(FP_OFF)
# define ACC_FP_OFF FP_OFF
# elif defined(_FP_OFF)
# define ACC_FP_OFF _FP_OFF
# else
# define ACC_FP_OFF(x) (((const unsigned __far*)&(x))[0])
# endif
# if defined(FP_SEG)
# define ACC_FP_SEG FP_SEG
# elif defined(_FP_SEG)
# define ACC_FP_SEG _FP_SEG
# else
# define ACC_FP_SEG(x) (((const unsigned __far*)&(x))[1])
# endif
# if defined(MK_FP)
# define ACC_MK_FP MK_FP
# elif defined(_MK_FP)
# define ACC_MK_FP _MK_FP
# else
# define ACC_MK_FP(s,o) ((void __far*)(((unsigned long)(s)<<16)+(unsigned)(o)))
# endif
# if 0
# undef ACC_FP_OFF
# undef ACC_FP_SEG
# undef ACC_MK_FP
# define ACC_FP_OFF(x) (((const unsigned __far*)&(x))[0])
# define ACC_FP_SEG(x) (((const unsigned __far*)&(x))[1])
# define ACC_MK_FP(s,o) ((void __far*)(((unsigned long)(s)<<16)+(unsigned)(o)))
# endif
#endif
#endif /* already included */ #endif /* already included */

View File

@ -19,17 +19,25 @@
************************************************************************/ ************************************************************************/
/* workaround for preprocessor bugs in some compilers */ /* workaround for preprocessor bugs in some compilers */
#if 0
#define ACC_0xffffL 65535ul #define ACC_0xffffL 65535ul
#define ACC_0xffffffffL 4294967295ul #define ACC_0xffffffffL 4294967295ul
#else
#define ACC_0xffffL 0xfffful
#define ACC_0xffffffffL 0xfffffffful
#endif
/* some things we cannot work around */ /* some things we cannot work around */
#if 0 #if 0
#if (32767 >= 4294967295ul) #if (ACC_0xffffL == ACC_0xffffffffL)
# error "your preprocessor is broken 1" # error "your preprocessor is broken 1"
#endif #endif
#if (65535u >= 4294967295ul) #if (32767 >= 4294967295ul)
# error "your preprocessor is broken 2" # error "your preprocessor is broken 2"
#endif #endif
#if (65535u >= 4294967295ul)
# error "your preprocessor is broken 3"
#endif
#endif #endif
@ -67,6 +75,7 @@
/* Fix old compiler versions. */ /* Fix old compiler versions. */
#if (UINT_MAX == ACC_0xffffL)
#if defined(__PACIFIC__) && defined(DOS) #if defined(__PACIFIC__) && defined(DOS)
# if !defined(__far) # if !defined(__far)
# define __far far # define __far far
@ -74,23 +83,11 @@
# if !defined(__near) # if !defined(__near)
# define __near near # define __near near
# endif # endif
#elif defined(_MSC_VER) && defined(MSDOS) #elif defined(__AZTEC_C__) && defined(__DOS__)
# if(_MSC_VER < 700) # if !defined(__huge)
# if !defined(__cdecl) # define __huge huge
# define __cdecl _cdecl
# endif
# if !defined(__far)
# define __far _far
# endif
# if !defined(__huge)
# define __huge _huge
# endif
# if !defined(__near)
# define __near _near
# endif
# endif # endif
#elif defined(__TURBOC__) && defined(__MSDOS__) #elif defined(__TSC__) && defined(__OS2__)
# if(__TURBOC__ < 0x0410)
# if !defined(__cdecl) # if !defined(__cdecl)
# define __cdecl cdecl # define __cdecl cdecl
# endif # endif
@ -103,13 +100,68 @@
# if !defined(__near) # if !defined(__near)
# define __near near # define __near near
# endif # endif
# if !defined(__pascal)
# define __pascal pascal
# endif
#elif defined(_MSC_VER) && defined(MSDOS)
# if (_MSC_VER < 600)
# if !defined(__cdecl)
# define __cdecl cdecl
# endif
# if !defined(__far)
# define __far far
# endif
# if !defined(__huge)
# define __huge huge
# endif
# if !defined(__near)
# define __near near
# endif
# if !defined(__pascal)
# define __pascal pascal
# endif
# elif (_MSC_VER < 700)
# if !defined(__cdecl)
# define __cdecl _cdecl
# endif
# if !defined(__far)
# define __far _far
# endif
# if !defined(__huge)
# define __huge _huge
# endif
# if !defined(__near)
# define __near _near
# endif
# if !defined(__pascal)
# define __pascal _pascal
# endif
# endif # endif
#elif defined(__TURBOC__) && defined(__MSDOS__)
# if (__TURBOC__ < 0x0410)
# if !defined(__cdecl)
# define __cdecl cdecl
# endif
# if !defined(__far)
# define __far far
# endif
# if !defined(__huge)
# define __huge huge
# endif
# if !defined(__near)
# define __near near
# endif
# if !defined(__pascal)
# define __pascal pascal
# endif
# endif
#endif
#endif #endif
#if defined(__MSDOS__) && defined(__TURBOC__) && (__TURBOC__ < 0x0200) #if defined(__MSDOS__) && defined(__TURBOC__) && (__TURBOC__ < 0x0200)
# define ACC_BROKEN_SIZEOF 1 # define ACC_BROKEN_SIZEOF 1
# if (__TURBOC < 0x0150) # if (__TURBOC__ < 0x0150)
# define ACC_BROKEN_INTEGRAL_PROMOTION 1 # define ACC_BROKEN_INTEGRAL_PROMOTION 1
# endif # endif
#elif defined(MSDOS) && defined(_MSC_VER) && (_MSC_VER < 700) #elif defined(MSDOS) && defined(_MSC_VER) && (_MSC_VER < 700)

View File

@ -33,70 +33,50 @@
/*********************************************************************** /***********************************************************************
// huge pointer layer - alloc // halloc
************************************************************************/ ************************************************************************/
ACC_LIBFUNC(acc_hvoid_p, acc_halloc) (acc_alloc_p ap, acc_hsize_t items, size_t size) ACC_LIBFUNC(acc_hvoid_p, acc_halloc) (acc_hsize_t size)
{ {
acc_hvoid_p p = 0; acc_hvoid_p p = 0;
#if (SIZEOF_SIZE_T > SIZEOF_LONG)
size_t s = (size_t) items * size;
#else
unsigned long s = (unsigned long) items * size;
#endif
if (!ap) if (size <= 0)
return p;
ap->ptr = p;
#if 0
ap->items = items;
ap->size = size;
ap->flags = 0;
#endif
if (items <= 0 || size <= 0 || s < items || s < size)
return p; return p;
#if defined(__palmos__) #if 0 && defined(__palmos__)
p = MemPtrNew(s); p = MemPtrNew(size);
#elif !defined(ACC_HAVE_MM_HUGE_PTR) #elif !defined(ACC_HAVE_MM_HUGE_PTR)
if (s < (size_t) -1) if (size < (size_t) -1)
p = malloc((size_t) s); p = malloc((size_t) size);
#else #else
#if (ACC_CC_MSC && _MSC_VER >= 700) #if (ACC_CC_MSC && _MSC_VER >= 700)
if (size < (size_t) -1) p = _halloc(size, 1);
p = _halloc(items, (size_t) size);
#elif (ACC_CC_MSC || ACC_CC_WATCOMC) #elif (ACC_CC_MSC || ACC_CC_WATCOMC)
if (size < (size_t) -1) p = halloc(size, 1);
p = halloc(items, (size_t) size);
#elif (ACC_CC_DMC || ACC_CC_SYMANTECC || ACC_CC_ZORTECHC) #elif (ACC_CC_DMC || ACC_CC_SYMANTECC || ACC_CC_ZORTECHC)
if (size < (size_t) -1) p = farmalloc(size);
p = _halloc(items, (size_t) size);
#elif (ACC_CC_BORLANDC || ACC_CC_TURBOC) #elif (ACC_CC_BORLANDC || ACC_CC_TURBOC)
p = farmalloc(s); p = farmalloc(size);
#elif defined(ACC_CC_AZTECC) #elif defined(ACC_CC_AZTECC)
p = lmalloc(s); p = lmalloc(size);
#else #else
if (s < (size_t) -1) if (size < (size_t) -1)
p = malloc((size_t) s); p = malloc((size_t) size);
#endif #endif
#endif #endif
ap->ptr = p;
return p; return p;
} }
ACC_LIBFUNC(int, acc_hfree) (acc_alloc_p ap) ACC_LIBFUNC(int, acc_hfree) (acc_hvoid_p p)
{ {
acc_hvoid_p p;
int r = 0; int r = 0;
if (!ap || !ap->ptr) if (!p)
return r; return r;
p = ap->ptr;
ap->ptr = 0;
#if defined(__palmos__) #if 0 && defined(__palmos__)
r = MemPtrFree(p); r = MemPtrFree(p);
#elif !defined(ACC_HAVE_MM_HUGE_PTR) #elif !defined(ACC_HAVE_MM_HUGE_PTR)
free(p); free(p);
@ -106,9 +86,9 @@ ACC_LIBFUNC(int, acc_hfree) (acc_alloc_p ap)
#elif (ACC_CC_MSC || ACC_CC_WATCOMC) #elif (ACC_CC_MSC || ACC_CC_WATCOMC)
hfree(p); hfree(p);
#elif (ACC_CC_DMC || ACC_CC_SYMANTECC || ACC_CC_ZORTECHC) #elif (ACC_CC_DMC || ACC_CC_SYMANTECC || ACC_CC_ZORTECHC)
_hfree(p); farfree((void __far*) p);
#elif (ACC_CC_BORLANDC || ACC_CC_TURBOC) #elif (ACC_CC_BORLANDC || ACC_CC_TURBOC)
farfree((void __far *) p); farfree((void __far*) p);
#elif defined(ACC_CC_AZTECC) #elif defined(ACC_CC_AZTECC)
lfree(p); lfree(p);
#else #else
@ -120,6 +100,86 @@ ACC_LIBFUNC(int, acc_hfree) (acc_alloc_p ap)
} }
/***********************************************************************
// dos_alloc
************************************************************************/
#if (ACC_OS_DOS16)
#if !defined(ACC_CC_AZTECC)
ACC_LIBFUNC(void __far*, acc_dos_alloc) (unsigned long size)
{
void __far* p = 0;
union REGS ri, ro;
if ((long)size <= 0)
return p;
size = (size + 15) >> 4;
if (size > 0xffffu)
return p;
ri.x.ax = 0x4800;
ri.x.bx = (unsigned short) size;
ro.x.cflag = 1;
int86(0x21, &ri, &ro);
if ((ro.x.cflag & 1) == 0) /* if carry flag not set */
p = (void __far*) ACC_MK_FP(ro.x.ax, 0);
return p;
}
ACC_LIBFUNC(int, acc_dos_free) (void __far* p)
{
union REGS ri, ro;
struct SREGS rs;
if (!p)
return 0;
if (ACC_FP_OFF(p) != 0)
return -1;
segread(&rs);
ri.x.ax = 0x4900;
rs.es = ACC_FP_SEG(p);
ro.x.cflag = 1;
int86x(0x21, &ri, &ro, &rs);
if (ro.x.cflag & 1) /* if carry flag set */
return -1;
return 0;
}
#endif
#endif
#if (ACC_OS_OS216)
ACC_LIBFUNC(void __far*, acc_dos_alloc) (unsigned long size)
{
void __far* p = 0;
unsigned short sel = 0;
unsigned long pmask = 0xffffu >> ACC_MM_AHSHIFT; /* 8191 */
if ((long)size <= 0)
return p;
size = (size + pmask) &~ pmask; /* align up to paragraph size */
if (DosAllocHuge((unsigned short)(size >> 16), (unsigned short)size, &sel, 0, 0) == 0)
p = (void __far*) ACC_MK_FP(sel, 0);
return p;
}
ACC_LIBFUNC(int, acc_dos_free) (void __far* p)
{
if (!p)
return 0;
if (ACC_FP_OFF(p) != 0)
return -1;
if (DosFreeSeg(ACC_FP_SEG(p)) != 0)
return -1;
return 0;
}
#endif
/*********************************************************************** /***********************************************************************
// huge pointer layer - string.h // huge pointer layer - string.h
************************************************************************/ ************************************************************************/
@ -211,7 +271,7 @@ ACC_LIBFUNC(acc_hvoid_p, acc_hmemset) (acc_hvoid_p s, int c, acc_hsize_t len)
// huge pointer layer - stdio.h // huge pointer layer - stdio.h
************************************************************************/ ************************************************************************/
ACC_LIBFUNC(acc_hsize_t, acc_hfread) (FILE *fp, acc_hvoid_p buf, acc_hsize_t size) ACC_LIBFUNC(acc_hsize_t, acc_hfread) (FILE* fp, acc_hvoid_p buf, acc_hsize_t size)
{ {
#if (ACC_HAVE_MM_HUGE_PTR) #if (ACC_HAVE_MM_HUGE_PTR)
#if (ACC_MM_COMPACT || ACC_MM_LARGE || ACC_MM_HUGE) #if (ACC_MM_COMPACT || ACC_MM_LARGE || ACC_MM_HUGE)
@ -221,7 +281,7 @@ ACC_LIBFUNC(acc_hsize_t, acc_hfread) (FILE *fp, acc_hvoid_p buf, acc_hsize_t siz
while (l < size) while (l < size)
{ {
size_t n; size_t n;
n = FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n); n = ACC_FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n);
if ((acc_hsize_t) n > size - l) if ((acc_hsize_t) n > size - l)
n = (size_t) (size - l); n = (size_t) (size - l);
n = fread((void __far*)b, 1, n, fp); n = fread((void __far*)b, 1, n, fp);
@ -240,7 +300,7 @@ ACC_LIBFUNC(acc_hsize_t, acc_hfread) (FILE *fp, acc_hvoid_p buf, acc_hsize_t siz
n = fread(tmp, 1, n, fp); n = fread(tmp, 1, n, fp);
if (n == 0) if (n == 0)
break; break;
acc_hmemcpy((acc_hbyte_p)buf + l, tmp, n); acc_hmemcpy((acc_hbyte_p)buf + l, tmp, (acc_hsize_t)n);
l += n; l += n;
} }
return l; return l;
@ -251,7 +311,7 @@ ACC_LIBFUNC(acc_hsize_t, acc_hfread) (FILE *fp, acc_hvoid_p buf, acc_hsize_t siz
} }
ACC_LIBFUNC(acc_hsize_t, acc_hfwrite) (FILE *fp, const acc_hvoid_p buf, acc_hsize_t size) ACC_LIBFUNC(acc_hsize_t, acc_hfwrite) (FILE* fp, const acc_hvoid_p buf, acc_hsize_t size)
{ {
#if (ACC_HAVE_MM_HUGE_PTR) #if (ACC_HAVE_MM_HUGE_PTR)
#if (ACC_MM_COMPACT || ACC_MM_LARGE || ACC_MM_HUGE) #if (ACC_MM_COMPACT || ACC_MM_LARGE || ACC_MM_HUGE)
@ -261,7 +321,7 @@ ACC_LIBFUNC(acc_hsize_t, acc_hfwrite) (FILE *fp, const acc_hvoid_p buf, acc_hsiz
while (l < size) while (l < size)
{ {
size_t n; size_t n;
n = FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n); n = ACC_FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n);
if ((acc_hsize_t) n > size - l) if ((acc_hsize_t) n > size - l)
n = (size_t) (size - l); n = (size_t) (size - l);
n = fwrite((void __far*)b, 1, n, fp); n = fwrite((void __far*)b, 1, n, fp);
@ -277,7 +337,7 @@ ACC_LIBFUNC(acc_hsize_t, acc_hfwrite) (FILE *fp, const acc_hvoid_p buf, acc_hsiz
while (l < size) while (l < size)
{ {
size_t n = size - l > sizeof(tmp) ? sizeof(tmp) : (size_t) (size - l); size_t n = size - l > sizeof(tmp) ? sizeof(tmp) : (size_t) (size - l);
acc_hmemcpy(tmp, (const acc_hbyte_p)buf + l, n); acc_hmemcpy(tmp, (const acc_hbyte_p)buf + l, (acc_hsize_t)n);
n = fwrite(tmp, 1, n, fp); n = fwrite(tmp, 1, n, fp);
if (n == 0) if (n == 0)
break; break;
@ -292,7 +352,7 @@ ACC_LIBFUNC(acc_hsize_t, acc_hfwrite) (FILE *fp, const acc_hvoid_p buf, acc_hsiz
/*********************************************************************** /***********************************************************************
// huge pointer layer - stdio.h // huge pointer layer - read/write
************************************************************************/ ************************************************************************/
#if (ACC_HAVE_MM_HUGE_PTR) #if (ACC_HAVE_MM_HUGE_PTR)
@ -306,7 +366,7 @@ ACC_LIBFUNC(long, acc_hread) (int fd, acc_hvoid_p buf, long size)
while (l < size) while (l < size)
{ {
unsigned n; unsigned n;
n = FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n); n = ACC_FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n);
if ((long) n > size - l) if ((long) n > size - l)
n = (unsigned) (size - l); n = (unsigned) (size - l);
n = read(fd, (void __far*)b, n); n = read(fd, (void __far*)b, n);
@ -329,7 +389,7 @@ ACC_LIBFUNC(long, acc_hread) (int fd, acc_hvoid_p buf, long size)
break; break;
if (n < 0) if (n < 0)
return -1; return -1;
acc_hmemcpy((acc_hbyte_p)buf + l, tmp, n); acc_hmemcpy((acc_hbyte_p)buf + l, tmp, (acc_hsize_t)n);
l += n; l += n;
} }
return l; return l;
@ -346,7 +406,7 @@ ACC_LIBFUNC(long, acc_hwrite) (int fd, const acc_hvoid_p buf, long size)
while (l < size) while (l < size)
{ {
unsigned n; unsigned n;
n = FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n); n = ACC_FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n);
if ((long) n > size - l) if ((long) n > size - l)
n = (unsigned) (size - l); n = (unsigned) (size - l);
n = write(fd, (void __far*)b, n); n = write(fd, (void __far*)b, n);
@ -364,7 +424,7 @@ ACC_LIBFUNC(long, acc_hwrite) (int fd, const acc_hvoid_p buf, long size)
while (l < size) while (l < size)
{ {
int n = size - l > (long)sizeof(tmp) ? (int) sizeof(tmp) : (int) (size - l); int n = size - l > (long)sizeof(tmp) ? (int) sizeof(tmp) : (int) (size - l);
acc_hmemcpy(tmp, (const acc_hbyte_p)buf + l, n); acc_hmemcpy(tmp, (const acc_hbyte_p)buf + l, (acc_hsize_t)n);
n = write(fd, tmp, n); n = write(fd, tmp, n);
if (n == 0) if (n == 0)
break; break;
@ -383,112 +443,230 @@ ACC_LIBFUNC(long, acc_hwrite) (int fd, const acc_hvoid_p buf, long size)
// wrap <dirent.h> // wrap <dirent.h>
**************************************************************************/ **************************************************************************/
#if (ACC_OS_WIN32 || ACC_OS_WIN64) #if !defined(ACCLIB_USE_OPENDIR)
#if (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_TOS || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
ACC_LIBFUNC(int, acc_findfirst) (struct acc_find_t* f, const char* path) static int acc_opendir_init(struct acc_dir_t* f, const char* path, char* buf, size_t bufsize)
{ {
WIN32_FIND_DATAA d; size_t l;
HANDLE h; char* p;
#if 1 f->f_name[0] = 0;
/* transform to backslashes, and add a '\*' to the directory name */ buf[0] = 0;
char* p = f->f_name; l = strlen(path);
p[0] = 0; if (l == 0 || l >= bufsize - 4)
if (!path[0] || strlen(path) >= sizeof(f->f_name) - 2)
return -1; return -1;
strcpy(p, path); strcpy(buf, path);
for ( ; *p; p++) p = buf + l;
if (*p == '/') if (p[-1] == ':' || p[-1] == '\\' || p[-1] == '/')
*p = '\\'; strcpy(p, "*.*");
if (p[-1] != '\\') else
*p++ = '\\'; strcpy(p, "\\*.*");
*p++ = '*'; return 0;
*p = '\0'; }
h = FindFirstFileA(f->f_name, &d);
#else #endif
h = FindFirstFileA(path, &d);
#endif #endif
f->f_name[0] = 0;
if ((f->u.h = (long) h) == -1)
return -1;
if (!d.cFileName[0] || strlen(d.cFileName) >= sizeof(f->f_name))
return -1;
strcpy(f->f_name, d.cFileName);
return 0;
}
ACC_LIBFUNC(int, acc_findnext) (struct acc_find_t* f)
#if (ACCLIB_USE_OPENDIR)
ACC_LIBFUNC(int, acc_opendir) (struct acc_dir_t* f, const char* path)
{ {
WIN32_FIND_DATAA d; f->u_dirp = opendir(path);
f->f_name[0] = 0; if (!f->u_dirp)
if (f->u.h == -1 || FindNextFileA((HANDLE) f->u.h, &d) != 0) return -2;
return -1; return acc_readdir(f);
if (!d.cFileName[0] || strlen(d.cFileName) >= sizeof(f->f_name))
return -1;
strcpy(f->f_name, d.cFileName);
return 0;
} }
ACC_LIBFUNC(int, acc_findclose) (struct acc_find_t* f) ACC_LIBFUNC(int, acc_readdir) (struct acc_dir_t* f)
{
int r = -1;
if (f->u.h != -1)
r = FindClose((HANDLE) f->u.h);
f->u.h = -1;
return r;
}
#elif (HAVE_DIRENT_H)
ACC_LIBFUNC(int, acc_findfirst) (struct acc_find_t* f, const char* path)
{
f->u.dirp = opendir(path);
return acc_findnext(f);
}
ACC_LIBFUNC(int, acc_findnext) (struct acc_find_t* f)
{ {
const struct dirent* dp; const struct dirent* dp;
f->f_name[0] = 0; f->f_name[0] = 0;
if (!f->u.dirp) if (!f->u_dirp)
return -1; return -1;
dp = readdir((DIR*) f->u.dirp); dp = readdir((DIR*) f->u_dirp);
if (!dp) if (!dp)
return -1; return -1;
if (!dp->d_name[0] || strlen(dp->d_name) >= sizeof(f->f_name)) if (!dp->d_name[0] || strlen(dp->d_name) >= sizeof(f->f_name))
return -1; return -1;
strcpy(f->f_name, dp->d_name); strcpy(f->f_name, dp->d_name);
#if (ACC_CC_WATCOMC)
ACC_COMPILE_TIME_ASSERT(sizeof(f->f_name) >= sizeof(dp->d_name))
f->f_time = dp->d_time;
f->f_date = dp->d_date;
f->f_size = dp->d_size;
#endif
return 0; return 0;
} }
ACC_LIBFUNC(int, acc_findclose) (struct acc_find_t* f) ACC_LIBFUNC(int, acc_closedir) (struct acc_dir_t* f)
{ {
int r = -1; int r = -1;
if (f->u.dirp) if (f->u_dirp)
r = closedir((DIR*) f->u.dirp); r = closedir((DIR*) f->u_dirp);
f->u.dirp = 0; f->u_dirp = 0;
return r; return r;
} }
#elif (ACC_OS_WIN32 || ACC_OS_WIN64)
ACC_LIBFUNC(int, acc_opendir) (struct acc_dir_t* f, const char* path)
{
WIN32_FIND_DATAA d;
HANDLE h;
if (acc_opendir_init(f, path, f->f_name, sizeof(f->f_name)) != 0)
return -1;
h = FindFirstFileA(f->f_name, &d);
f->f_name[0] = 0;
if ((f->u_handle = (long) h) == -1)
return -1;
if (!d.cFileName[0] || strlen(d.cFileName) >= sizeof(f->f_name))
return -1;
strcpy(f->f_name, d.cFileName);
f->f_attr = d.dwFileAttributes;
f->f_size_high = d.nFileSizeHigh;
f->f_size_low = d.nFileSizeLow;
return 0;
}
ACC_LIBFUNC(int, acc_readdir) (struct acc_dir_t* f)
{
WIN32_FIND_DATAA d;
f->f_name[0] = 0;
if (f->u_handle == -1 || FindNextFileA((HANDLE) f->u_handle, &d) == 0)
return -1;
if (!d.cFileName[0] || strlen(d.cFileName) >= sizeof(f->f_name))
return -1;
strcpy(f->f_name, d.cFileName);
f->f_attr = d.dwFileAttributes;
f->f_size_high = d.nFileSizeHigh;
f->f_size_low = d.nFileSizeLow;
return 0;
}
ACC_LIBFUNC(int, acc_closedir) (struct acc_dir_t* f)
{
int r = -1;
if (f->u_handle != -1)
r = FindClose((HANDLE) f->u_handle);
f->u_handle = -1;
return r;
}
#elif (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_WIN16)
ACC_LIBFUNC(int, acc_opendir) (struct acc_dir_t* f, const char* path)
{
char tmp[ACC_FN_PATH_MAX+1];
int r;
f->u_dirp = 0;
if (acc_opendir_init(f, path, tmp, sizeof(tmp)) != 0)
return -1;
#if (ACC_CC_AZTECC || ACC_CC_PACIFICC)
r = -1;
#elif (ACC_CC_BORLANDC || ACC_CC_TURBOC)
r = findfirst(tmp, (struct ffblk*) f->u_dta, FA_HIDDEN|FA_SYSTEM|FA_RDONLY|FA_DIREC);
#else
r = _dos_findfirst(tmp, _A_HIDDEN|_A_SYSTEM|_A_RDONLY|_A_SUBDIR, (struct find_t*) f->u_dta);
#endif
if (r != 0) f->f_name[0] = 0;
if (!f->f_name[0]) return -1;
f->u_dirp = 1;
return 0;
}
ACC_LIBFUNC(int, acc_readdir) (struct acc_dir_t* f)
{
int r;
f->f_name[0] = 0;
if (!f->u_dirp)
return -1;
#if (ACC_CC_AZTECC || ACC_CC_PACIFICC)
r = -1;
#elif (ACC_CC_BORLANDC || ACC_CC_TURBOC)
r = findnext((struct ffblk*) f->u_dta);
#else
r = _dos_findnext((struct find_t*) f->u_dta);
#endif
if (r != 0) f->f_name[0] = 0;
if (!f->f_name[0]) return -1;
return 0;
}
ACC_LIBFUNC(int, acc_closedir) (struct acc_dir_t* f)
{
ACC_COMPILE_TIME_ASSERT(sizeof(*f) == 44);
f->f_name[0] = 0;
f->u_dirp = 0;
return 0;
}
#elif (ACC_OS_TOS)
ACC_LIBFUNC(int, acc_opendir) (struct acc_dir_t* f, const char* path)
{
char tmp[ACC_FN_PATH_MAX+1];
int r;
DTA* olddta;
f->u_dirp = 0;
if (acc_opendir_init(f, path, tmp, sizeof(tmp)) != 0)
return -1;
olddta = Fgetdta();
Fsetdta((DTA*) f->u_dta);
r = Fsfirst(tmp, FA_HIDDEN|FA_SYSTEM|FA_READONLY|FA_SUBDIR);
Fsetdta(olddta);
if (r != 0) f->f_name[0] = 0;
if (!f->f_name[0]) return -1;
f->u_dirp = 1;
return 0;
}
ACC_LIBFUNC(int, acc_readdir) (struct acc_dir_t* f)
{
int r;
DTA* olddta;
f->f_name[0] = 0;
if (!f->u_dirp)
return -1;
olddta = Fgetdta();
Fsetdta((DTA*) f->u_dta);
r = Fsnext();
Fsetdta(olddta);
if (r != 0) f->f_name[0] = 0;
if (!f->f_name[0]) return -1;
return 0;
}
ACC_LIBFUNC(int, acc_closedir) (struct acc_dir_t* f)
{
ACC_COMPILE_TIME_ASSERT(sizeof(*f) == 44);
f->f_name[0] = 0;
f->u_dirp = 0;
return 0;
}
#else #else
ACC_LIBFUNC(int, acc_findfirst) (struct acc_find_t* f, const char* path) ACC_LIBFUNC(int, acc_opendir) (struct acc_dir_t* f, const char* path)
{ {
ACC_UNUSED(path); ACC_UNUSED(path);
f->f_name[0] = 0; f->f_name[0] = 0;
return -1; return -3;
} }
ACC_LIBFUNC(int, acc_findnext) (struct acc_find_t* f) ACC_LIBFUNC(int, acc_readdir) (struct acc_dir_t* f)
{ {
f->f_name[0] = 0; f->f_name[0] = 0;
return -1; return -1;
} }
ACC_LIBFUNC(int, acc_findclose) (struct acc_find_t* f) ACC_LIBFUNC(int, acc_closedir) (struct acc_dir_t* f)
{ {
f->u.dirp = 0; f->u_dirp = 0;
return -1; return -1;
} }
@ -519,7 +697,12 @@ ACC_LIBFUNC(long, acc_get_osfhandle) (int fd)
/* FIXME */ /* FIXME */
return -1; return -1;
#elif (ACC_OS_WIN32 || ACC_OS_WIN64) #elif (ACC_OS_WIN32 || ACC_OS_WIN64)
# if (ACC_CC_WATCOMC && __WATCOMC__ < 1100)
/* FIXME */
return -1;
# else
return _get_osfhandle(fd); return _get_osfhandle(fd);
# endif
#else #else
return fd; return fd;
#endif #endif
@ -580,20 +763,34 @@ ACC_LIBFUNC(int, acc_set_binmode) (int fd, int binary)
ACC_LIBFUNC(int, acc_isatty) (int fd) ACC_LIBFUNC(int, acc_isatty) (int fd)
{ {
#if (ACC_H_WINDOWS_H) /* work around library implementations that think that
/* work around naive library implementations that think that
* any character device like `nul' is a tty */ * any character device like `nul' is a tty */
long h = acc_get_osfhandle(fd);
if (h != -1)
{
DWORD d = 0;
int r = GetConsoleMode((HANDLE)h, &d);
if (!r)
return 0; /* GetConsoleMode failed -> not a tty */
}
#endif
if (fd < 0) if (fd < 0)
return 0; return 0;
#if (ACC_OS_DOS16 && !defined(ACC_CC_AZTECC))
{
union REGS ri, ro;
ri.x.ax = 0x4400;
ri.x.bx = fd;
ro.x.ax = 0;
ro.x.cflag = 1;
int86(0x21, &ri, &ro);
if ((ro.x.cflag & 1) == 0) /* if carry flag not set */
if ((ro.x.ax & 0x83) != 0x83)
return 0;
}
#elif (ACC_H_WINDOWS_H)
{
long h = acc_get_osfhandle(fd);
if (h != -1)
{
DWORD d = 0;
int r = GetConsoleMode((HANDLE)h, &d);
if (!r)
return 0; /* GetConsoleMode failed -> not a tty */
}
}
#endif
return (isatty(fd)) ? 1 : 0; return (isatty(fd)) ? 1 : 0;
} }

View File

@ -27,25 +27,27 @@
**************************************************************************/ **************************************************************************/
#if (ACC_HAVE_MM_HUGE_PTR) #if (ACC_HAVE_MM_HUGE_PTR)
# define __acc_huge __huge # define acc_hsize_t unsigned long
# define acc_hsize_t unsigned long # define acc_hvoid_p void __huge *
# define acc_hbyte_p unsigned char __huge *
# define acc_hvoid_cp const void __huge *
# define acc_hbyte_cp const unsigned char __huge *
#else #else
# define __acc_huge # define acc_hsize_t size_t
# define acc_hsize_t size_t # define acc_hvoid_p void *
# define acc_hbyte_p unsigned char *
# define acc_hvoid_cp const void *
# define acc_hbyte_cp const unsigned char *
#endif #endif
#define acc_hvoid_p void __acc_huge *
#define acc_hbyte_p unsigned char __acc_huge *
typedef struct /* halloc */
{ ACC_LIBFUNC(acc_hvoid_p, acc_halloc) (acc_hsize_t size);
acc_hvoid_p ptr; ACC_LIBFUNC(int, acc_hfree) (acc_hvoid_p p);
}
acc_alloc_t;
#define acc_alloc_p acc_alloc_t __acc_huge *
/* malloc */ #if (ACC_OS_DOS16 || ACC_OS_OS216)
ACC_LIBFUNC(acc_hvoid_p, acc_halloc) (acc_alloc_p ap, acc_hsize_t items, size_t size); ACC_LIBFUNC(void __far*, acc_dos_alloc) (unsigned long size);
ACC_LIBFUNC(int, acc_hfree) (acc_alloc_p ap); ACC_LIBFUNC(int, acc_dos_free) (void __far* p);
#endif
/* string */ /* string */
ACC_LIBFUNC(int, acc_hmemcmp) (const acc_hvoid_p s1, const acc_hvoid_p s2, acc_hsize_t len); ACC_LIBFUNC(int, acc_hmemcmp) (const acc_hvoid_p s1, const acc_hvoid_p s2, acc_hsize_t len);
@ -54,33 +56,96 @@ ACC_LIBFUNC(acc_hvoid_p, acc_hmemmove) (acc_hvoid_p dest, const acc_hvoid_p src,
ACC_LIBFUNC(acc_hvoid_p, acc_hmemset) (acc_hvoid_p s, int c, acc_hsize_t len); ACC_LIBFUNC(acc_hvoid_p, acc_hmemset) (acc_hvoid_p s, int c, acc_hsize_t len);
/* stdio */ /* stdio */
ACC_LIBFUNC(acc_hsize_t, acc_hfread) (FILE *fp, acc_hvoid_p buf, acc_hsize_t size); ACC_LIBFUNC(acc_hsize_t, acc_hfread) (FILE* fp, acc_hvoid_p buf, acc_hsize_t size);
ACC_LIBFUNC(acc_hsize_t, acc_hfwrite) (FILE *fp, const acc_hvoid_p buf, acc_hsize_t size); ACC_LIBFUNC(acc_hsize_t, acc_hfwrite) (FILE* fp, const acc_hvoid_p buf, acc_hsize_t size);
#if (ACC_HAVE_MM_HUGE_PTR) #if (ACC_HAVE_MM_HUGE_PTR)
ACC_LIBFUNC(long, acc_hread) (int fd, acc_hvoid_p buf, long size); ACC_LIBFUNC(long, acc_hread) (int fd, acc_hvoid_p buf, long size);
ACC_LIBFUNC(long, acc_hwrite) (int fd, const acc_hvoid_p buf, long size); ACC_LIBFUNC(long, acc_hwrite) (int fd, const acc_hvoid_p buf, long size);
#endif #endif
/*************************************************************************
// wrap filename limits
**************************************************************************/
/* maximum length of full pathname (excl. '\0') */
#if (ACC_OS_DOS16 || ACC_OS_WIN16)
# define ACC_FN_PATH_MAX 143
#elif (ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN32 || ACC_OS_WIN64)
# define ACC_FN_PATH_MAX 259
#elif (ACC_OS_TOS)
# define ACC_FN_PATH_MAX 259
#else
# define ACC_FN_PATH_MAX 1024
#endif
/* maximum length of a filename (a single path component) (excl. '\0') */
#if (ACC_OS_DOS16 || ACC_OS_WIN16)
# define ACC_FN_NAME_MAX 12
#elif (ACC_OS_TOS && (ACC_CC_PUREC || ACC_CC_TURBOC))
# define ACC_FN_NAME_MAX 12
#elif (ACC_OS_DOS32 && defined(__DJGPP__))
#elif (ACC_OS_DOS32)
# define ACC_FN_NAME_MAX 12
#endif
#if !defined(ACC_FN_NAME_MAX)
# define ACC_FN_NAME_MAX ACC_FN_PATH_MAX
#endif
/************************************************************************* /*************************************************************************
// wrap <dirent.h> // wrap <dirent.h>
**************************************************************************/ **************************************************************************/
struct acc_find_t #undef ACCLIB_USE_OPENDIR
#if (HAVE_DIRENT_H || ACC_CC_WATCOMC)
# define ACCLIB_USE_OPENDIR 1
# if (ACC_OS_DOS32 && defined(__BORLANDC__))
# elif (ACC_OS_DOS32 && defined(__DJGPP__))
# elif (ACC_OS_OS2 || ACC_OS_OS216)
# elif (ACC_OS_TOS && ACC_CC_GNUC)
# elif (ACC_OS_WIN32 && !defined(ACC_H_WINDOWS_H))
# elif (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_TOS || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
# undef ACCLIB_USE_OPENDIR
# endif
#endif
struct acc_dir_t
{ {
union { acc_hvoid_p dirp; long h; } u; /* private */ #if (ACCLIB_USE_OPENDIR)
#if (ACC_OS_DOS16 || ACC_OS_WIN16) void *u_dirp; /* private */
char f_name[8+1+3+1]; # if (ACC_CC_WATCOMC)
#elif (ACC_DOS32 || ACC_OS_WIN32 || ACC_OS_WIN64) unsigned short f_time;
char f_name[259+1]; unsigned short f_date;
unsigned long f_size;
# endif
char f_name[ACC_FN_NAME_MAX+1];
#elif (ACC_OS_WIN32 || ACC_OS_WIN64)
long u_handle; /* private */
unsigned f_attr;
unsigned f_size_low;
unsigned f_size_high;
char f_name[ACC_FN_NAME_MAX+1];
#elif (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_TOS || ACC_OS_WIN16)
char u_dta[21]; /* private */
unsigned char f_attr;
unsigned short f_time;
unsigned short f_date;
unsigned short f_size_low;
unsigned short f_size_high;
char f_name[ACC_FN_NAME_MAX+1];
char u_dirp; /* private */
#else #else
char f_name[1024+1]; void *u_dirp; /* private */
char f_name[ACC_FN_NAME_MAX+1];
#endif #endif
}; };
ACC_LIBFUNC(int, acc_findfirst) (struct acc_find_t* f, const char* path); ACC_LIBFUNC(int, acc_opendir) (struct acc_dir_t* d, const char* path);
ACC_LIBFUNC(int, acc_findnext) (struct acc_find_t* f); ACC_LIBFUNC(int, acc_readdir) (struct acc_dir_t* d);
ACC_LIBFUNC(int, acc_findclose) (struct acc_find_t* f); ACC_LIBFUNC(int, acc_closedir) (struct acc_dir_t* d);
/************************************************************************* /*************************************************************************
@ -105,7 +170,7 @@ ACC_LIBFUNC(int, acc_findclose) (struct acc_find_t* f);
#if defined(__CYGWIN__) || defined(__MINGW32__) #if defined(__CYGWIN__) || defined(__MINGW32__)
# define acc_alloca(x) __builtin_alloca((x)) # define acc_alloca(x) __builtin_alloca((x))
#elif defined(__BORLANDC__) && defined(__linux__) #elif defined(__BORLANDC__) && defined(__linux__)
/* FIXME: this does not work */ /* FIXME: alloca does not work */
#elif (HAVE_ALLOCA) #elif (HAVE_ALLOCA)
# define acc_alloca(x) alloca((x)) # define acc_alloca(x) alloca((x))
#endif #endif

View File

@ -32,7 +32,7 @@
#endif #endif
#if defined(__TINY__) || defined(M_I86TM) || defined(_M_I86TM) #if defined(__TINY__) || defined(M_I86TM) || defined(_M_I86TM)
# define ACC_MM_TINY 1 # define ACC_MM_TINY 1
#elif defined(__HUGE__) || defined(M_I86HM) || defined(_M_I86HM) #elif defined(__HUGE__) || defined(_HUGE_) || defined(M_I86HM) || defined(_M_I86HM)
# define ACC_MM_HUGE 1 # define ACC_MM_HUGE 1
#elif defined(__SMALL__) || defined(M_I86SM) || defined(_M_I86SM) || defined(SMALL_MODEL) #elif defined(__SMALL__) || defined(M_I86SM) || defined(_M_I86SM) || defined(SMALL_MODEL)
# define ACC_MM_SMALL 1 # define ACC_MM_SMALL 1
@ -66,9 +66,6 @@
#if (ACC_MM_TINY) #if (ACC_MM_TINY)
# undef ACC_HAVE_MM_HUGE_ARRAY # undef ACC_HAVE_MM_HUGE_ARRAY
# if (ACC_CC_MSC && _MSC_VER < 700)
# undef ACC_HAVE_MM_HUGE_PTR
# endif
#endif #endif
#if (ACC_CC_AZTECC || ACC_CC_PACIFICC || ACC_CC_ZORTECHC) #if (ACC_CC_AZTECC || ACC_CC_PACIFICC || ACC_CC_ZORTECHC)
@ -76,32 +73,38 @@
# undef ACC_HAVE_MM_HUGE_ARRAY # undef ACC_HAVE_MM_HUGE_ARRAY
#elif (ACC_CC_DMC || ACC_CC_SYMANTECC) #elif (ACC_CC_DMC || ACC_CC_SYMANTECC)
# undef ACC_HAVE_MM_HUGE_ARRAY # undef ACC_HAVE_MM_HUGE_ARRAY
#elif (ACC_CC_MSC && defined(_QC))
# undef ACC_HAVE_MM_HUGE_ARRAY
# if (_MSC_VER < 600)
# undef ACC_HAVE_MM_HUGE_PTR
# endif
#elif (ACC_CC_TURBOC && __TURBOC__ < 0x0295) #elif (ACC_CC_TURBOC && __TURBOC__ < 0x0295)
# undef ACC_HAVE_MM_HUGE_ARRAY # undef ACC_HAVE_MM_HUGE_ARRAY
#elif (ACC_CC_WATCOMC && __WATCOMC__ >= 1200) #elif (ACC_CC_WATCOMC && __WATCOMC__ >= 1200)
/* __huge pointers seem completely broken in OpenWatcom 1.0 */ /* pointer arithmetics with __huge arrays seems completely
# undef ACC_HAVE_MM_HUGE_PTR * broken in OpenWatcom 1.0 */
# undef ACC_HAVE_MM_HUGE_ARRAY # undef ACC_HAVE_MM_HUGE_ARRAY
#endif #endif
#if (ACC_HAVE_MM_HUGE_PTR) #if (ACC_CC_BORLANDC && __BORLANDC__ >= 0x0200)
# if (ACC_CC_BORLANDC && __BORLANDC__ >= 0x0400) extern void __near _AHSHIFT(void);
extern unsigned short __near _AHSHIFT; # define ACC_MM_AHSHIFT ((unsigned) _AHSHIFT)
# define ACC_MM_AHSHIFT ((unsigned) &_AHSHIFT) #elif (ACC_CC_DMC || ACC_CC_SYMANTECC || ACC_CC_ZORTECHC)
# elif (ACC_CC_DMC || ACC_CC_MSC || ACC_CC_SYMANTECC || ACC_CC_ZORTECHC) extern void __near _AHSHIFT(void);
extern unsigned short __near _AHSHIFT; # define ACC_MM_AHSHIFT ((unsigned) _AHSHIFT)
# define ACC_MM_AHSHIFT ((unsigned) &_AHSHIFT) #elif (ACC_CC_MSC || ACC_CC_TOPSPEEDC)
# elif (ACC_CC_TURBOC && __TURBOC__ >= 0x0295) extern void __near _AHSHIFT(void);
extern unsigned short __near _AHSHIFT; # define ACC_MM_AHSHIFT ((unsigned) _AHSHIFT)
# define ACC_MM_AHSHIFT ((unsigned) &_AHSHIFT) #elif (ACC_CC_TURBOC && __TURBOC__ >= 0x0295)
# elif (ACC_CC_TURBOC && ACC_OS_DOS16) extern void __near _AHSHIFT(void);
# define ACC_MM_AHSHIFT 12 # define ACC_MM_AHSHIFT ((unsigned) _AHSHIFT)
# elif (ACC_CC_WATCOMC) #elif ((ACC_CC_AZTECC || ACC_CC_PACIFICC || ACC_CC_TURBOC) && ACC_OS_DOS16)
extern unsigned char _HShift; # define ACC_MM_AHSHIFT 12
# define ACC_MM_AHSHIFT ((unsigned) _HShift) #elif (ACC_CC_WATCOMC)
# else extern unsigned char _HShift;
# error "implement ACC_MM_AHSHIFT" # define ACC_MM_AHSHIFT ((unsigned) _HShift)
# endif #else
# error "implement ACC_MM_AHSHIFT"
#endif #endif

View File

@ -17,22 +17,24 @@
* Operating System - exactly one of: * Operating System - exactly one of:
* *
* ACC_OS_POSIX [default] * ACC_OS_POSIX [default]
* ACC_OS_AMIGAOS
* ACC_OS_BEOS * ACC_OS_BEOS
* ACC_OS_CYGWIN hybrid WIN32 and POSIX * ACC_OS_CYGWIN hybrid WIN32 and POSIX
* ACC_OS_DOS16 16-bit DOS (segmented memory model) * ACC_OS_DOS16 16-bit DOS (segmented memory model)
* ACC_OS_DOS32 * ACC_OS_DOS32
* ACC_OS_EMX hybrid OS/2, DOS32, WIN32 (with RSX) and POSIX * ACC_OS_EMX hybrid OS/2, DOS32, WIN32 (with RSX) and POSIX
* ACC_OS_MAC9 Macintosh Classic * ACC_OS_MACCLASSIC Macintosh Classic
* ACC_OS_MACOSX Mac OS/X * ACC_OS_MACOSX Mac OS/X
* ACC_OS_PALMOS * ACC_OS_PALMOS
* ACC_OS_OS2 OS/2 * ACC_OS_OS2 OS/2
* ACC_OS_OS216 16-bit OS/2 1.x (segmented memory model) * ACC_OS_OS216 16-bit OS/2 1.x (segmented memory model)
* ACC_OS_QNX * ACC_OS_QNX
* ACC_OS_RISCOS
* ACC_OS_TOS Atari TOS / MiNT * ACC_OS_TOS Atari TOS / MiNT
* ACC_OS_VMS * ACC_OS_VMS
* ACC_OS_WIN16 16-bit Windows 3.x (segmented memory model) * ACC_OS_WIN16 16-bit Windows 3.x (segmented memory model)
* ACC_OS_WIN32 * ACC_OS_WIN32
* ACC_OS_WIN64 * ACC_OS_WIN64 64-bit Windows (LLP64 programming model)
*/ */
@ -42,47 +44,68 @@
#elif defined(__EMX__) && defined(__GNUC__) #elif defined(__EMX__) && defined(__GNUC__)
# define ACC_OS_EMX 1 # define ACC_OS_EMX 1
# define ACC_INFO_OS "emx" # define ACC_INFO_OS "emx"
#elif defined(__QNX__)
# define ACC_OS_QNX 1
# define ACC_INFO_OS "qnx"
#elif defined(__BORLANDC__) && defined(__DPMI32__)
# define ACC_OS_DOS32 1
# define ACC_INFO_OS "dos32"
#elif defined(__BORLANDC__) && defined(__DPMI16__)
# define ACC_OS_DOS16 1
# define ACC_INFO_OS "dos16"
#elif defined(__ZTC__) && defined(DOS386)
# define ACC_OS_DOS32 1
# define ACC_INFO_OS "dos32"
#elif defined(__OS2__) || defined(__OS2V2__)
# if (UINT_MAX == ACC_0xffffL)
# define ACC_OS_OS216 1
# define ACC_INFO_OS "os216"
# elif (UINT_MAX == ACC_0xffffffffL)
# define ACC_OS_OS2 1
# define ACC_INFO_OS "os2"
# else
# error "check your limits.h header"
# endif
#elif defined(__WIN64__) || defined(_WIN64) || defined(WIN64) #elif defined(__WIN64__) || defined(_WIN64) || defined(WIN64)
# define ACC_OS_WIN64 1 # define ACC_OS_WIN64 1
# define ACC_INFO_OS "win64" # define ACC_INFO_OS "win64"
#elif defined(__WIN32__) || defined(_WIN32) || defined(WIN32) #elif defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(__WINDOWS_386__)
# define ACC_OS_WIN32 1
# define ACC_INFO_OS "win32"
#elif defined(__NT__) || defined(__NT_DLL__) || defined(__WINDOWS_386__)
# define ACC_OS_WIN32 1 # define ACC_OS_WIN32 1
# define ACC_INFO_OS "win32" # define ACC_INFO_OS "win32"
#elif defined(__MWERKS__) && defined(__INTEL__) #elif defined(__MWERKS__) && defined(__INTEL__)
# define ACC_OS_WIN32 1 # define ACC_OS_WIN32 1
# define ACC_INFO_OS "win32" # define ACC_INFO_OS "win32"
#elif defined(__WINDOWS__) || defined(_WINDOWS) || defined(_Windows) #elif defined(__WINDOWS__) || defined(_WINDOWS) || defined(_Windows)
# if (UINT_MAX == ACC_0xffffffffL) # if (UINT_MAX == ACC_0xffffL)
# define ACC_OS_WIN32 1
# define ACC_INFO_OS "win32"
# elif (UINT_MAX == ACC_0xffffL)
# define ACC_OS_WIN16 1 # define ACC_OS_WIN16 1
# define ACC_INFO_OS "win16" # define ACC_INFO_OS "win16"
# elif (UINT_MAX == ACC_0xffffffffL)
# define ACC_OS_WIN32 1
# define ACC_INFO_OS "win32"
# else # else
# error "check your limits.h header" # error "check your limits.h header"
# endif # endif
#elif defined(__DOS__) || defined(__MSDOS__) || defined(_MSDOS) || defined(MSDOS) || (defined(__PACIFIC__) && defined(DOS)) #elif defined(__DOS__) || defined(__MSDOS__) || defined(_MSDOS) || defined(MSDOS) || (defined(__PACIFIC__) && defined(DOS))
# if (UINT_MAX == ACC_0xffffffffL) # if (UINT_MAX == ACC_0xffffL)
# define ACC_OS_DOS32 1
# define ACC_INFO_OS "dos32"
# elif (UINT_MAX == ACC_0xffffL)
# define ACC_OS_DOS16 1 # define ACC_OS_DOS16 1
# define ACC_INFO_OS "dos16" # define ACC_INFO_OS "dos16"
# elif (UINT_MAX == ACC_0xffffffffL)
# define ACC_OS_DOS32 1
# define ACC_INFO_OS "dos32"
# else # else
# error "check your limits.h header" # error "check your limits.h header"
# endif # endif
#elif defined(__OS2__) || defined(__OS2V2__) #elif defined(__WATCOMC__)
# if (UINT_MAX == ACC_0xffffffffL) # if defined(__NT__) && (UINT_MAX == ACC_0xffffL)
# define ACC_OS_OS2 1 /* wcl: NT host defaults to DOS target */
# define ACC_INFO_OS "os2" # define ACC_OS_DOS16 1
# elif (UINT_MAX == ACC_0xffffL) # define ACC_INFO_OS "dos16"
# define ACC_OS_OS216 1 # elif defined(__NT__) && (__WATCOMC__ < 1100)
# define ACC_INFO_OS "os216" /* wcl386: Watcom C 11 defines _WIN32 */
# define ACC_OS_WIN32 1
# define ACC_INFO_OS "win32"
# else # else
# error "check your limits.h header" # error "please specify a target using the -bt compiler option"
# endif # endif
#elif defined(__palmos__) #elif defined(__palmos__)
# if (UINT_MAX == ACC_0xffffL) # if (UINT_MAX == ACC_0xffffL)
@ -94,15 +117,12 @@
#elif defined(__TOS__) || defined(__atarist__) #elif defined(__TOS__) || defined(__atarist__)
# define ACC_OS_TOS 1 # define ACC_OS_TOS 1
# define ACC_INFO_OS "tos" # define ACC_INFO_OS "tos"
#elif defined(__QNX__)
# define ACC_OS_QNX 1
# define ACC_INFO_OS "qnx"
#elif defined(__MACOSX__) #elif defined(__MACOSX__)
# define ACC_OS_MACOSX 1 # define ACC_OS_MACOSX 1
# define ACC_INFO_OS "macosx" # define ACC_INFO_OS "macosx"
#elif defined(macintosh) #elif defined(macintosh)
# define ACC_OS_MACOS9 1 # define ACC_OS_MACCLASSIC 1
# define ACC_INFO_OS "macos9" # define ACC_INFO_OS "macclassic"
#elif defined(__VMS) #elif defined(__VMS)
# define ACC_OS_VMS 1 # define ACC_OS_VMS 1
# define ACC_INFO_OS "vms" # define ACC_INFO_OS "vms"
@ -159,6 +179,9 @@
# if (UINT_MAX != ACC_0xffffL) # if (UINT_MAX != ACC_0xffffL)
# error "this should not happen" # error "this should not happen"
# endif # endif
# if (ULONG_MAX != ACC_0xffffffffL)
# error "this should not happen"
# endif
#endif #endif
#if (ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_WIN32 || ACC_OS_WIN64) #if (ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_WIN32 || ACC_OS_WIN64)
# if (UINT_MAX != ACC_0xffffffffL) # if (UINT_MAX != ACC_0xffffffffL)