SUMMARY:
CLIBC_16.LIB - Selected independent near model replacement functions from the standard C (Microsoft C/C++ 7.00) library. Distribution zip file includes sources, Makefile, and limited documentation.

DISTRIBUTION clibc_16.zip CONTENTS:
clibc_16.inc
clibc_16.txt
Makefile
Makefile.g
string\
 str00000.asm (strcpy.asm)
 str00001.asm
 str00002.asm
 str00010.asm
 str00011.asm
 str00012.asm
 str00100.asm (strlen.asm)
 str00101.asm
 str00110.asm
 str00111.asm
 str00200.asm (skipsp.asm)
 str00201.asm
 str00210.asm
 str00211.asm
 str00300.asm (skiptosp.asm)
 str00301.asm
 str00310.asm
 str00311.asm
 str00400.asm (strcat.asm)
 str00401.asm
 str00402.asm
 str00410.asm
 str00411.asm
 str00412.asm
 str00500.asm (strcmp.asm)
 str00501.asm
 str00502.asm
 str00510.asm
 str00511.asm
 str00512.asm
 str00600.asm (strchr.asm)
 str00601.asm
 str00610.asm
 str00611.asm
 str00700.asm (strstr.asm)
 str00701.asm
 str00702.asm
 str00710.asm
 str00711.asm
 str00712.asm
 str00800.asm (strrchr.asm)
 str00801.asm
 str00810.asm
 str00811.asm
 str00900.asm (stricmp.asm)
 str00901.asm
 str00902.asm
 str00910.asm
 str00911.asm
 str00912.asm
 str01000.asm (skipspr.asm)
 str01001.asm
 str01010.asm
 str01011.asm
 str01100.asm (skiptosr.asm)
 str01101.asm
 str01110.asm
 str01111.asm
 str01200.asm (strlwr.asm)
 str01201.asm
 str01210.asm
 str01211.asm
 str01300.asm (strupr.asm)
 str01301.asm
 str01310.asm
 str01311.asm
 str01400.asm (strncpy.asm)
 str01401.asm
 str01402.asm
 str01410.asm
 str01411.asm
 str01412.asm
 str01500.asm (strncat.asm)
 str01501.asm
 str01502.asm
 str01510.asm
 str01511.asm
 str01512.asm
 str01600.asm (memmove.asm)
 str01601.asm
 str01602.asm
 str01610.asm
 str01611.asm
 str01612.asm
 str01700.asm (memset.asm)
 str01701.asm
 str01710.asm
 str01711.asm
 str01800.asm (memcmp.asm)
 str01801.asm
 str01802.asm
 str01810.asm
 str01811.asm
 str01812.asm
 Makefile
 string.inc
 string.h
misc\
 mis00000.asm (isspace.asm)
 mis00010.asm
 mis00100.asm (isalnum.asm)
 mis00110.asm
 mis00200.asm (isalpha.asm)
 mis00210.asm
 mis00300.asm (isascii.asm)
 mis00310.asm
 mis00400.asm (iscntrl.asm)
 mis00410.asm
 mis00500.asm (iscsym.asm)
 mis00510.asm
 mis00600.asm (iscsymf.asm)
 mis00610.asm
 mis00700.asm (isdigit.asm)
 mis00710.asm
 mis00800.asm (islower.asm)
 mis00810.asm
 mis00900.asm (isupper.asm)
 mis00910.asm
 mis01000.asm (isxdigit.asm)
 mis01010.asm
 Makefile
 misc.h
 misc.inc
test\
 testmod.asm
 main.c
 Makefile

BUILD THE LIBRARY:

UNZIP DISTRIBUTION
Pkzip 2.50 zipped/ compressed the library distribution file. To unzip the library, place the clibc_16.zip file into the desired directory.
pkunzip -d clibc_16.zip
creates and places above listed files/ directories into directory clibc_16
change to directory clibc_16

EDIT MAKEFILE
After unzipping the distribution package, edit Makefile.g (NOT Makefile) as required.
Configuration options requiring attention:

# ============================================================================
# DIR_C_INCLUDE
#  set to location to copy *.h files into
#  will create directory clibc_16 in this directory
#  may be exactly equal to DIR_ASM_INCLUDE
#  no trailing backslash
DIR_C_INCLUDE=c:\dev\sharedide\include
# ----------------------------------------------------------------------------

# ============================================================================
# DIR_ASM_INCLUDE
#  set to location to copy *.inc files into
#  will create directory clibc_16 in this directory
#  may be exactly equal to DIR_C_INCLUDE
#  no trailing backslash
DIR_ASM_INCLUDE=c:\dev\sharedide\include
# ----------------------------------------------------------------------------

# ============================================================================
# DIR_LIB
#  the directory to copy built libraries into
#  no trailing backslash
DIR_LIB=c:\dev\sharedide\lib
# ----------------------------------------------------------------------------

# ============================================================================
# CLIBC_16_FN_CALL
#    the call type (distance) for each function in the library
#    CLIBC_16_FN_CALL_NEARCALL=0 (Default)
#	Each library member function call is NEAR16.
#	All functions are placed into a single segment, default _TEXT.
#	Do not define CLIBC_16_FN_CALL_FARCALL_SEG.
#    CLIBC_16_FN_CALL_FARCALL=1
#	Each library member function call is FAR16.
#	Must also specify/define CLIBC_16_FN_CALL_FARCALL_SEG.
#CLIBC_16_FN_CALL=0
CLIBC_16_FN_CALL=1
# ----------------------------------------------------------------------------

# ============================================================================
# CLIBC_16_FN_CALL_FARCALL_SEG
#   Determines far call functions segment.
#   Define only if CLIBC_16_FN_CALL==CLIBC_16_FN_CALL_FARCALL.
#   CLIBC_16_FN_CALL_FARCALL_SEG_SINGLE=0 (Default)
#	All the functions are placed into a single segment.
#	CLIBC_16_FUNCTION_SEG_NAME specifies the segment name.
#				   default _CLIBC_16
#   CLIBC_16_FN_CALL_FARCALL_SEG_MULTIPLE=1
#	Each group of functions are placed into their own segment.
#	CLIBC_16_FUNCTION_SEG_NAME specifies the segment base name.
#				   default _CLIBC_16
#   Note: define CLIBC_16_FUNCTION_SEG_NAME only to change default name.
#CLIBC_16_FN_CALL_FARCALL_SEG=0
CLIBC_16_FN_CALL_FARCALL_SEG=1
# ----------------------------------------------------------------------------

# ============================================================================
# CLIBC_16_EXTERN_PTRS
#   CLIBC_16_EXTERN_PTRS_NO=0 (Default)
#	Does not generate pointers to each function.
#	Do not define CLIBC_16_EXTERN_PTRS_SEG_NAME.
#   CLIBC_16_EXTERN_PTRS_YES=1
#	Generates pointers to each function.
#	Places pointers in _DATA segment.
#	Define CLIBC_16_EXTERN_PTRS_SEG_NAME only to change default name.
#   see pointers to functions in documentation
#CLIBC_16_EXTERN_PTRS=0
CLIBC_16_EXTERN_PTRS=1
# ----------------------------------------------------------------------------

# a little more tweeking, if necessary
# ============================================================================
# CLIBC_16_FUNCTION_SEG_NAME
#   Specifies the base name of the functions code segment.
#   Normally, no need to alter default value.
#   Defaults to _TEXT or _CLIBC_16.
#CLIBC_16_FUNCTION_SEG_NAME=_TEXT
#CLIBC_16_FUNCTION_SEG_NAME=_CLIBC_16
# ----------------------------------------------------------------------------

# ============================================================================
# CLIBC_16_EXTERN_PTRS_SEG_NAME
#   Specifies the name of the pointers segment.
#   Any only _DATA or CONST are directly supported.
#   Normally, no need to alter default value.
#   Defaults to _DATA.
#CLIBC_16_EXTERN_PTRS_SEG_NAME=_DATA
#CLIBC_16_EXTERN_PTRS_SEG_NAME=CONST
# ----------------------------------------------------------------------------

EXAMPLE 1: near function calls, no pointers, one segment
DIR_C_INCLUDE=C:\dev\sharedide\include
DIR_ASM_INCLUDE=C:\dev\sharedide\include
DIR_LIB=c:\dev\sharedide\lib
CLIBC_16_FN_CALL=0
CLIBC_16_FN_CALL_FARCALL_SEG (NODEFINITION)
CLIBC_16_FUNCTION_SEG_NAME (NODEFINITION), use default
CLIBC_16_EXTERN_PTRS=0
CLIBC_16_EXTERN_PTRS_SEG_NAME (NO DEFINITION), use default

The above values will build the library with near function calls, no function pointers, and place the resulting functions in the _TEXT segment. The include files will be placed into c:\dev\sharedide\include\clibc_16. The library clibcd16.lib and clibc_16.lib will be placed into c:\dev\sharedide\lib.

When using the library in an application, the following would be added to CL command line:
/DCLIBC_16_FN_CALL=0
/DCLIBC_16_EXTERN_PTRS=0

EXAMPLE 2: far function calls, pointers, multilple segments
DIR_C_INCLUDE=C:\dev\sharedide\include
DIR_ASM_INCLUDE=C:\dev\sharedide\include
DIR_LIB=c:\dev\sharedide\lib
CLIBC_16_FN_CALL=1
CLIBC_16_FN_CALL_FARCALL_SEG=1
CLIBC_16_FUNCTION_SEG_NAME (NODEFINITION), use default
CLIBC_16_EXTERN_PTRS=1
CLIBC_16_EXTERN_PTRS_SEG_NAME (NO DEFINITION), use default

The above values will build the library with far function calls, function pointers, and place the resulting functions into <GROUP>_CLIBC_16 segments. The include files will be placed into c:\dev\sharedide\include\clibc_16. The library clibcd16.lib and clibc_16.lib will be placed into c:\dev\sharedide\lib.

When using the library in an application, the following would be added to CL command line:
/DCLIBC_16_FN_CALL=1
/DCLIBC_16_FN_CALL_FARCALL_SEG=1
/DCLIBC_16_EXTERN_PTRS=1

RUN NMAKE
Once the files are unziped, and the Makefile.g edited, run

NMAKE
to build and install the library

CLIBC_16.LIB BUILD TOOLS
The library is built (and debugged?) with the following Microsoft development tools:
NMAKE 1.30    (MSVC 1.0 distribution)
MASM 6.14     (MASM 6.11 distribution, updated with ML614.EXE Patch)
MSC/C++ 8.0   (MSVC 1.0 distribution)
LINK 5.50     (MSVC 1.0 distribution)
PWB 2.1.49    (C/C++ 7.0 distribution)
CODEVIEW 4.10 (MSVC 1.0 distribution)
LIB 3.31      (MSVC 1.0 distribution)

Note:
Most tools run in Windows9X DOS boxes.

LIBRARY DISCUSSION

Independent means that each function included in clibc_16.lib is completely independent of any other function. Most C library functions are dependent on other library functions, computer hardware, BIOS, and may require initialization. Because each clibc_16.lib function is independent, no initialization is required, and each individual function may be included as required in an application. Programmers developing applications requiring independent functions should appreciate clibc_16.lib. Due to the independent nature of each function, only a subset of the standard C library may be implemented. As demand warrants, and/or as they are completed, and/or as they are donated, functions that may be implemented as independent will be added to clibc_16.lib. Contributions gladly accepted, especially sprintf and sscanf.

See the Run-Time Library Reference manual for each individual function. Except where noted, clibc_16.lib function parameters and return values are identical.

Some functions in clibc_16 have corresponding Microsoft intrinsic versions. To use the library, disabling automatic intrinsic substitution may be required in some cases.

Each member function has multiple definitions. Some definitions use __cdecl call, others use __fastcall. Some definitions expect the parameter pointer offset from DS, others from SS.

Because all function parameters in clibc_16.lib use __near pointers, the assumed segment which the pointer is offset from is critical. Each function has an run time library replacement for which all pointers (source and destination) are offset from ds. Each function with a source __near pointer has a _sss version, which indicates the source pointer is offset from ss (Sss). Each function with a destination __near pointer also has a _dss version, which indicates the destination pointer is offset from ss (Dss). Each function, where applicable, preserves the es register, for additional compatibility with assembly routines.


FUNCTION NAMING CONVENTION
Each member function is referred to by a complete name, which consist of a base with an optional suffix. The base name describes the function and the optional _sss or _dss suffix describes the assumed offset for the pointer parameters. If the function uses near pointers, then the first pointer is considered the source, and, if used, the second pointer is considered the destination. If the function is described by only the base name, then both the source and destination pointers are considered offset from DS. To select the function that assumes the source is offset from SS, add the suffix _sss to the base name. To select the function that assumes the destination is offset from SS, add the suffix _dss to the base name.

FUNCTION NAMING CONVENTION EXAMPLE 1
The C library function strlen has one pointer parameter. If the function is referred to by just the base name strlen, then the pointer is assumed to be offset from DS. If the function is referred to by the base name plus the suffix _sss (complete name strlen_sss), then the parameter (source) is assumed to be offset from SS. strlen does not have a _dss version, because there is no second (destination) pointer parameter.

FUNCTION NAMING CONVENTION EXAMPLE 2
The C library function strcpy has two pointer parameters. If the function is referred to by just the base name strcpy, then both pointers are assumed to be offset from DS. If the function is referred to by the base name plus the suffix _sss (complete name strcpy_sss), then the first parameter (source) is assumed to be offset from SS. If the function is referred to by the base name plus the suffix _dss (complete name strcpy_dss), then the second parameter (destination) is assumed to be offset from SS.

FUNCTION NAMING CONVENTION EXAMPLE 3
isspace does not have any pointer parameters. There are no _sss or _dss versions.

__FASTCALL VS __CDECL
All member functions have __fastcall versions. The fastcall versions may be activated by specifying
#define FASTCALL_COMPLETENAME
prior to the .h include file. For masm, the fastcall version may be called by specifying a leading @ to the basename. If the library was built with external pointers, then both the fastcall and __cdecl version may be used by calling the appropriate function via the pointer. See POINTERS TO FUNCTIONS.

If the compiler option controlling fastcall is used, then no #define FASTCALL_ is necessary. All functions will assume the fastcall version.

#define FASTCALL_ALL will select the fastcall versions of all clibc_16 library functions, while all other functions are called with the default convention (usually __cdecl).

__FASTCALL VS __CDECL EXAMPLE
To use the fastcall version of strlen:
#define FASTCALL_STRLEN
All references to strlen will assume the fastcall version.
To use the fastcall version of strlen_sss:
#define FASTCALL_STRLEN_SSS
All references to strlen_sss will assume the fastcall version.

POINTERS TO FUNCTIONS
Pointers to functions may be built into the library by specifying CLIBC_16_EXTERN_PTRS=1. A pointer to each member function is placed into the global DGROUP(_DATA) segment.

POINTERS TO FUNCTIONS NAMING CONVENTION
The nameing convention for the pointers is as follows; That complete name is prefixed with either p_fn_ or p_fn_fc_. Function pointers prefixed with p_fn_ are pointers to the __cdecl functions, and the function pointers prefixed with p_fn_fc are pointer to the __fastcall functions.

POINTERS TO FUNCTIONS NAMING CONVENTION EXAMPLE
p_fn_strlen_sss is the __cdecl pointer to strlen_sss.
p_fn_fc_strlen_sss is the __fastcall pointer to strlen_sss.

USING THE LIBRARY

USING THE LIBRARY C
Prior to including the proper .h header file in the source, define the constants exactly as defined when building the library. They may be defined inside the source with #define or they may be defined on the command line using /D.
Most important; They must be exactly the same values as defined when building the library.

USING THE LIBRARY C - FUNCTION POINTERS

char str[]="test string"
int i;

i = strlen(str);
i = (*p_fn_strlen)(str);
i = (*p_fn_fc_strlen)(str);

Will all call strlen. The first will call strlen directly. The second will call strlen thru the function pointer, and the third will call strlen using the fastcall method.

USING THE LIBRARY MASM
Prior to including the proper .inc header file in the source, define the constants exactly as defined when building the library. They may be defined inside the source with EQU, =, or they may be defined on the command line using /D.
Most important; They must be exactly the same values as defined when building the library.
The fastcall calling convention uses a non standard register type to pass parameters. See the description of the __fastcall calling convention to determine how the registers are used to pass parameters.

INVOKE strlen, BX
mov bx, OFFSET pointer
call @strlen

The INVOKE will call strlen thru C calling convention, and call @strlen will call it via the fastcall calling convention.

Be very careful using INVOKE. Most of the time, the proper call distance will be correct.

USING THE LIBRARY - LINKING

Linking is simply a matter of including the library in the build process. The organization of the library simulates function level linking, so only the functions directly referenced will be copied into the image file. This reduces the executable image size significantly.

CONTACT INFORMATION:

email:
bkyoung@cwnet.com

Address:
Byron Young
2351 Woodthrush Way
Pleasanton, CA 94566
United States Of America

COPYRIGHT INFORMATION:
All work, including, but not limited to, source files, make files, documentation files, project organization, name mangeling for the purpose of determining pointer offsets, included herein the distribution are copyrighted by the author. Commercial use and commercial distribution of this library, or any portion of code, documentation, or files, without the prior written permission of the author is prohibited. Library may only be distributed for personal non commercial use, in original zip format, by the simtel network. This copyright information includes all legal interpretations, but intends to specifically prohibit using this library, without negotiating a separate license agreement with the author, as part of any commercial application that results in, either direct or indirect, net or gross financial gain by the commercial user.

DISCLAIMER
No warranty, expressed or implied, is given concerning the functionality or operability of the code included in this distribution. In fact, many code portions may require debugging.

BUGS
A project of this type will never be bug free. Writing simultaneous, almost identical functions, for two different models (near, far), and two calling conventions (cdecl, fastcall), with different parameter pointer bases always generates some confusion. Bug reports gladly accepted, and are appreciated.

A consistent "bug" concerns segment registers. Some function, to determine if two pointers are equal, directly compare segment registers. Applications using these functions that switch between real and protected mode must be certain that the segment registers are synced with the hidden registers after switching modes. Future versions may correct this 'bug".

CONTRIBUTORS
Just nobody.

REVISIONS
Release_05 11/14/2002 ilibc_05.zip
Separated each member function into own module.
Simulated function level linking.
Changed the global pointer to functions naming convention, implementation.
Added, for the __far call option, individual group function segments.
Reorganized the makefiles.
Simplified build option settings, automating default values.
Adjusted copyright information.
No code fixes.
Created clibc_16.inc for internal library build use.

Release_04 10/14/2002 ilibc_04.zip
Test sources tests all clibc_16 functions.
All functions currently in library have corresponding fastcall versions.
Test sources now built with included test/Makefile
Added optional global pointers to fastcall functions.
Added __far( based) call or __near call options for function calls.
Adjusted copyright information.
Minor code fixes.

Release_03 09/24/2002 ilibc_03.zip
Major project reorganization; new source directories.
New Makefiles, added new configuration option.
Added .inc files, and separated .h files.
Created MSC7.0 RT library replacement functions.
Created functions with source (and destination) offset from ss.
Created fastcall versions of new functions.
Most new functions require debugging, focusing on segments.
Added test sources to project.

Release_02 09/14/2002 ilibc_02.zip
Fastcall functions debugged.
Numerous bug fixes in other functions.

09/04/2002 ilibc_01.zip
Initial Release.