Changeset 1207 for trunk/src


Ignore:
Timestamp:
Oct 9, 1999, 11:39:13 AM (26 years ago)
Author:
sandervl
Message:

Update by Jens Weissner

Location:
trunk/src/crtdll
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/crtdll/crtdll.cpp

    r1160 r1207  
    1 /* $Id: crtdll.cpp,v 1.8 1999-10-07 09:28:48 sandervl Exp $ */
     1/* $Id: crtdll.cpp,v 1.9 1999-10-09 09:39:12 sandervl Exp $ */
    22
    33/*
     
    66 * Implements C run-time functionality as known from UNIX.
    77 *
     8 * Partialy based on Wine and ReactOS
     9 *
    810 * Copyright 1996,1998 Marcus Meissner
    911 * Copyright 1996 Jukka Iivonen
     
    1113 * Copyright 1999 Jens Wiessner
    1214 */
    13 
    1415
    1516#include <os2win.h>
     
    4142#include <fcntl.h>
    4243#include <search.h>
     44#include <heap.h>
    4345#include <sys\utime.h>
    4446#include <sys\stat.h>
     
    4648#include <crtdll.h>
    4749#include "crtinc.h"
    48 
    4950
    5051DEFAULT_DEBUG_CHANNEL(crtdll)
     
    360361 *                  __doserrno            (CRTDLL.26)
    361362 */
    362 long * CDECL CRTDLL___doserrno()
     363int * CDECL CRTDLL___doserrno()
    363364{       
    364         dprintf(("__doserrno not implemented.\n"));
    365         SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    366         return FALSE;
    367 //      return _doserrno();
     365        dprintf(("__doserrno\n"));
     366        _doserrno = GetLastError();
     367        return &_doserrno;
    368368}
    369369
     
    385385int CDECL CRTDLL___isascii(int i)
    386386{
    387   dprintf(("CRTDLL: __isascii not implemented.\n"));
    388   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    389   return FALSE;
     387  dprintf(("CRTDLL: __isascii\n"));
     388  return  (!((i)&(~0x7f)));
    390389}
    391390
     
    394393 *           CRTDLL___iscsym   (CRTDLL.29)
    395394 */
    396 int CDECL CRTDLL___iscsym(int i)
    397 {
    398   dprintf(("CRTDLL: __iscsym not implemented.\n"));
    399   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    400   return FALSE;
     395int CDECL CRTDLL___iscsym(int c)
     396{
     397  dprintf(("CRTDLL: __iscsym\n"));
     398  return (CRTDLL_isalnum(c) || ( c == '_' )) ;
    401399}
    402400
     
    405403 *           CRTDLL___iscsymf   (CRTDLL.30)
    406404 */
    407 int CDECL CRTDLL___iscsymf(int i)
    408 {
    409   dprintf(("CRTDLL: __iscsymf not implemented.\n"));
    410   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    411   return FALSE;
     405int CDECL CRTDLL___iscsymf(int c)
     406{
     407  dprintf(("CRTDLL: __iscsymf\n"));
     408  return (isalpha(c) || ( c == '_' )) ;
    412409}
    413410
     
    429426unsigned long CDECL CRTDLL___threadhandle( void )
    430427{
    431   dprintf(("CRTDLL: __threadhandle not implemented.\n"));
    432   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    433   return FALSE;
     428  dprintf(("CRTDLL: __threadhandle\n"));
     429  return GetCurrentThread();
    434430}
    435431
     
    438434 *           CRTDLL___threadid   (CRTDLL.34)
    439435 */
    440 int * CDECL CRTDLL___threadid(void)
    441 {
    442   dprintf(("CRTDLL: __threadid  not implemented.\n"));
    443   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    444   return FALSE;
     436unsigned long CDECL CRTDLL___threadid(void)
     437{
     438  dprintf(("CRTDLL: __threadid\n"));
     439  return GetCurrentThreadId();
    445440}
    446441
     
    511506 *                  CRTDLL__beep                    (CRTDLL.45)
    512507 */
    513 void CDECL CRTDLL__beep(unsigned i1, unsigned i2)
     508void CDECL CRTDLL__beep(unsigned nFreq, unsigned nDur)
    514509{       
    515         dprintf(("_beep not implemented.\n"));
     510        dprintf(("_beep\n"));
     511        Beep(nFreq,nDur);
    516512}
    517513
     
    520516 *           CRTDLL__beginthread   (CRTDLL.46)
    521517 */
    522 unsigned long CDECL CRTDLL__beginthread(  register void (*start_address)(void *),
    523                 unsigned stack_size, void *arglist )
    524 {
    525   dprintf(("CRTDLL: _beginthread not implemented.\n"));
    526   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    527   return FALSE;
     518unsigned long CDECL CRTDLL__beginthread(void (*pfuncStart)(void *),
     519                unsigned unStackSize, void* pArgList)
     520{
     521        DWORD  ThreadId;
     522        HANDLE hThread;
     523        if (  pfuncStart == NULL )
     524                __set_errno(EINVAL);
     525
     526        hThread = CreateThread( NULL,unStackSize,(LPTHREAD_START_ROUTINE)pfuncStart,pArgList,0, &ThreadId);
     527        if (hThread == NULL ) {
     528                __set_errno(EAGAIN);
     529                return -1;
     530        }
     531        return (unsigned long)hThread;
    528532}
    529533
     
    543547 *           CRTDLL__cabs   (CRTDLL.48)
    544548 */
    545 double CDECL CRTDLL__cabs(struct complex * c)
    546 {
    547   dprintf(("CRTDLL: _cabs not implemented.\n"));
    548   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    549   return FALSE;
    550 //  return (_cabs(c));
     549double CDECL CRTDLL__cabs(struct complex * z)
     550{
     551  dprintf(("CRTDLL: _cabs not implemented\n"));
     552  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
     553  return FALSE;
    551554}
    552555
     
    554557/*********************************************************************
    555558 *                  _cexit          (CRTDLL.49)
    556  *
    557559 */
    558560void CDECL CRTDLL__cexit(INT ret)
     
    656658{
    657659  dprintf(("CRTDLL: _commit not implemented.\n"));
    658   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    659   return FALSE;
     660//  if (! FlushFileBuffers(_get_osfhandle(_fd)) ) {
     661//      __set_errno(EBADF);
     662//      return -1;
     663//  }
     664  return 0;
    660665}
    661666
     
    9951000wint_t CDECL CRTDLL__fgetwchar( void *i )
    9961001{
    997   dprintf(("CRTDLL: _fgetwchar not implemented.\n"));
    998   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    999   return FALSE;
     1002  dprintf(("CRTDLL: _fgetwchar\n"));
     1003  return CRTDLL__getch();
    10001004}
    10011005
     
    10371041int CDECL CRTDLL__findclose( long handle )
    10381042{
    1039   dprintf(("CRTDLL: _findclose not implemented.\n"));
    1040   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1041   return FALSE;
     1043  dprintf(("CRTDLL: _findclose\n"));
     1044  // check no wildcards or invalid handle
     1045  if ( handle == 0 || handle == -1)
     1046        return 0;
     1047  return FindClose(handle);
    10421048}
    10431049
     
    11151121  dprintf(("CRTDLL: _fpieee_flt not implemented.\n"));
    11161122  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1117   return FALSE;
     1123  return 0;
    11181124}
    11191125
     
    11551161 *                  _fsopen     (CRTDLL.110)
    11561162 */
    1157 FILE * CDECL CRTDLL__fsopen( const char *filename, const char *mode, int shflag )
     1163FILE * CDECL CRTDLL__fsopen( const char *file, const char *mode, int shflag )
    11581164{
    11591165  dprintf(("CRTDLL: _fsopen not implemented.\n"));
     
    12211227long CDECL CRTDLL__get_osfhandle( int posixhandle )
    12221228{
    1223   dprintf(("CRTDLL: _gcvt not implemented.\n"));
     1229  dprintf(("CRTDLL: _get_osfhandle not implemented.\n"));
    12241230  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    12251231  return FALSE;
     
    12701276 *                  _getdiskfree     (CRTDLL.122)
    12711277 */
    1272 unsigned CDECL CRTDLL__getdiskfree( unsigned drive, struct _diskfree_t *diskspace)
    1273 {
    1274   dprintf(("CRTDLL: _getdiskfree not implemented.\n"));
    1275   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1276   return FALSE;
     1278unsigned int CDECL CRTDLL__getdiskfree( unsigned int drive, struct _diskfree_t *diskspace)
     1279{
     1280  dprintf(("CRTDLL: _getdiskfree\n"));
     1281  char RootPathName[10];
     1282  RootPathName[0] = toupper(drive +'@');
     1283  RootPathName[1] = ':';
     1284  RootPathName[2] = '\\';
     1285  RootPathName[3] = 0;
     1286  if ( diskspace == NULL )
     1287        return 0;
     1288
     1289  if ( !GetDiskFreeSpaceA(RootPathName,(LPDWORD)&diskspace->sectors_per_cluster,(LPDWORD)&diskspace->bytes_per_sector,
     1290                (LPDWORD )&diskspace->avail_clusters,(LPDWORD )&diskspace->total_clusters ) )
     1291        return 0;
     1292  return diskspace->avail_clusters;
    12771293}
    12781294
     
    13071323unsigned long CDECL CRTDLL__getdrives(void)
    13081324{
    1309   dprintf(("CRTDLL: _getdrives not implemented.\n"));
    1310   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1311   return FALSE;
     1325  dprintf(("CRTDLL: _getdrives\n"));
     1326  return GetLogicalDrives();
    13121327}
    13131328
     
    13371352 *                  _getw     (CRTDLL.128)
    13381353 */
    1339 int CDECL CRTDLL__getw( FILE *fp )
    1340 {
    1341   dprintf(("CRTDLL: _getw not implemented.\n"));
    1342   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1343   return FALSE;
     1354int CDECL CRTDLL__getw( FILE *stream )
     1355{
     1356  dprintf(("CRTDLL: _getw\n"));
     1357  int w;
     1358
     1359  /* Is there a better way?  */
     1360  if (CRTDLL_fread( &w, sizeof(w), 1, stream) != 1)
     1361    return(EOF);
     1362  return(w);
    13441363}
    13451364
     
    14611480 *                  _ismbbalnum     (CRTDLL.139)
    14621481 */
    1463 int CDECL CRTDLL__ismbbalnum( unsigned int ch )
    1464 {
    1465   dprintf(("CRTDLL: _ismbbalnum not implemented.\n"));
    1466   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1467   return FALSE;
     1482int CDECL CRTDLL__ismbbalnum( unsigned int c )
     1483{
     1484  dprintf(("CRTDLL: _ismbbalnum\n"));
     1485  return (CRTDLL_isalnum(c) || CRTDLL__ismbbkalnum(c));
    14681486}
    14691487
     
    14721490 *                  _ismbbalpha     (CRTDLL.140)
    14731491 */
    1474 int CDECL CRTDLL__ismbbalpha( unsigned int ch )
    1475 {
    1476   dprintf(("CRTDLL: _ismbbalpha not implemented.\n"));
    1477   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1478   return FALSE;
     1492int CDECL CRTDLL__ismbbalpha( unsigned int c )
     1493{
     1494  dprintf(("CRTDLL: _ismbbalpha\n"));
     1495  return (isalpha(c) || CRTDLL__ismbbkalnum(c));
    14791496}
    14801497
     
    14831500 *                  _ismbbgraph     (CRTDLL.141)
    14841501 */
    1485 int CDECL CRTDLL__ismbbgraph( unsigned int ch )
    1486 {
    1487   dprintf(("CRTDLL: _ismbbgraph not implemented.\n"));
    1488   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1489   return FALSE;
     1502int CDECL CRTDLL__ismbbgraph( unsigned int c )
     1503{
     1504  dprintf(("CRTDLL: _ismbbgraph\n"));
     1505  return (CRTDLL_isgraph(c) || CRTDLL__ismbbkana(c));
    14901506}
    14911507
     
    14941510 *                  _ismbbkalnum     (CRTDLL.142)
    14951511 */
    1496 int CDECL CRTDLL__ismbbkalnum( unsigned int ch )
    1497 {
    1498   dprintf(("CRTDLL: _ismbbkalnum not implemented.\n"));
    1499   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1500   return FALSE;
     1512int CDECL CRTDLL__ismbbkalnum( unsigned int c )
     1513{
     1514  dprintf(("CRTDLL: _ismbbkalnum\n"));
     1515  return  ((_jctype+1)[(unsigned char)(c)] & (_KNJ_P));
    15011516}
    15021517
     
    15051520 *                  _ismbbkana     (CRTDLL.143)
    15061521 */
    1507 int CDECL CRTDLL__ismbbkana( unsigned int ch )
    1508 {
    1509   dprintf(("CRTDLL: _ismbbkana not implemented.\n"));
    1510   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1511   return FALSE;
     1522int CDECL CRTDLL__ismbbkana( unsigned int c )
     1523{
     1524  dprintf(("CRTDLL: _ismbbkana\n"));
     1525  return ((_jctype+1)[(unsigned char)(c)] & (_KNJ_M|_KNJ_P));
    15121526}
    15131527
     
    15161530 *                  _ismbbkpunct     (CRTDLL.144)
    15171531 */
    1518 int CDECL CRTDLL__ismbbkpunct( unsigned int ch )
    1519 {
    1520   dprintf(("CRTDLL: _ismbbkpunct not implemented.\n"));
    1521   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1522   return FALSE;
     1532int CDECL CRTDLL__ismbbkpunct( unsigned int c )
     1533{
     1534  dprintf(("CRTDLL: _ismbbkpunct\n"));
     1535  return  ((_jctype+1)[(unsigned char)(c)] & (_KNJ_P));
    15231536}
    15241537
     
    15271540 *                  _ismbblead     (CRTDLL.145)
    15281541 */
    1529 int CDECL CRTDLL__ismbblead( unsigned int ch )
    1530 {
    1531   dprintf(("CRTDLL: _ismbblead not implemented.\n"));
    1532   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1533   return FALSE;
     1542int CDECL CRTDLL__ismbblead( unsigned int c )
     1543{
     1544  dprintf(("CRTDLL: _ismbblead\n"));
     1545  return ((_jctype+1)[(unsigned char)(c)] & _KNJ_1);
    15341546}
    15351547
     
    15381550 *                  _ismbbprint     (CRTDLL.146)
    15391551 */
    1540 int CDECL CRTDLL__ismbbprint( unsigned int ch )
    1541 {
    1542   dprintf(("CRTDLL: _ismbbprint not implemented.\n"));
    1543   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1544   return FALSE;
     1552int CDECL CRTDLL__ismbbprint( unsigned int c )
     1553{
     1554  dprintf(("CRTDLL: _ismbbprint\n"));
     1555  return (isprint(c) || CRTDLL__ismbbkana(c));
    15451556}
    15461557
     
    15491560 *                  _ismbbpunct     (CRTDLL.147)
    15501561 */
    1551 int CDECL CRTDLL__ismbbpunct( unsigned int ch )
    1552 {
    1553   dprintf(("CRTDLL: _ismbbpunct not implemented.\n"));
    1554   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1555   return FALSE;
     1562int CDECL CRTDLL__ismbbpunct( unsigned int c )
     1563{
     1564  dprintf(("CRTDLL: _ismbbpunct\n"));
     1565  return (ispunct(c) ||  CRTDLL__ismbbkana(c));
    15561566}
    15571567
     
    15601570 *                  _ismbbtrail     (CRTDLL.148)
    15611571 */
    1562 int CDECL CRTDLL__ismbbtrail( unsigned int ch )
    1563 {
    1564   dprintf(("CRTDLL: _ismbbtrail not implemented.\n"));
    1565   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1566   return FALSE;
     1572int CDECL CRTDLL__ismbbtrail( unsigned int c )
     1573{
     1574  dprintf(("CRTDLL: _ismbbtrail\n"));
     1575  return ((_jctype+1)[(unsigned char)(c)] & _KNJ_2);
    15671576}
    15681577
     
    15711580 *                  _ismbcalpha     (CRTDLL.149)
    15721581 */
    1573 int CDECL CRTDLL__ismbcalpha( unsigned int ch )
    1574 {
    1575   dprintf(("CRTDLL: _ismbcalpha not implemented.\n"));
    1576   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1577   return FALSE;
     1582int CDECL CRTDLL__ismbcalpha( unsigned int c )
     1583{
     1584  dprintf(("CRTDLL: _ismbcalpha\n"));
     1585  if ((c & 0xFF00) != 0) {
     1586        // true multibyte character
     1587        return 0;
     1588  }
     1589  else
     1590        return CRTDLL__ismbbalpha(c);
     1591
     1592  return 0;
    15781593}
    15791594
     
    15821597 *                  _ismbcdigit     (CRTDLL.150)
    15831598 */
    1584 int CDECL CRTDLL__ismbcdigit( unsigned int ch )
    1585 {
    1586   dprintf(("CRTDLL: _ismbcdigit not implemented.\n"));
    1587   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1588   return FALSE;
     1599int CDECL CRTDLL__ismbcdigit( unsigned int c )
     1600{
     1601  dprintf(("CRTDLL: _ismbcdigit\n"));
     1602  if ((c & 0xFF00) != 0) {
     1603        // true multibyte character
     1604        return 0;
     1605  }
     1606  else
     1607        return 0;
     1608//              return _ismbbdigit(c);
     1609
     1610        return 0;
    15891611}
    15901612
     
    15931615 *                  _ismbchira     (CRTDLL.151)
    15941616 */
    1595 int CDECL CRTDLL__ismbchira( unsigned int ch )
    1596 {
    1597   dprintf(("CRTDLL: _ismbchira not implemented.\n"));
    1598   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1599   return FALSE;
     1617int CDECL CRTDLL__ismbchira( unsigned int c )
     1618{
     1619  dprintf(("CRTDLL: _ismbchira\n"));
     1620  return ((c>=0x829F) && (c<=0x82F1));
    16001621}
    16011622
     
    16041625 *                  _ismbckata     (CRTDLL.152)
    16051626 */
    1606 int CDECL CRTDLL__ismbckata( unsigned int ch )
    1607 {
    1608   dprintf(("CRTDLL: _ismbckata not implemented.\n"));
    1609   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1610   return FALSE;
     1627int CDECL CRTDLL__ismbckata( unsigned int c )
     1628{
     1629  dprintf(("CRTDLL: _ismbckata\n"));
     1630  return ((c>=0x8340) && (c<=0x8396));
    16111631}
    16121632
     
    16181638  dprintf(("CRTDLL: _ismbcl0 not implemented.\n"));
    16191639  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1620   return FALSE;
     1640  return 0;
    16211641}
    16221642
     
    16291649  dprintf(("CRTDLL: _ismbcl1 not implemented.\n"));
    16301650  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1631   return FALSE;
     1651  return 0;
    16321652}
    16331653
     
    16401660  dprintf(("CRTDLL: _ismbcl2 not implemented.\n"));
    16411661  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1642   return FALSE;
     1662  return 0;
    16431663}
    16441664
     
    16471667 *                  _ismbclegal     (CRTDLL.156)
    16481668 */
    1649 int CDECL CRTDLL__ismbclegal( unsigned int ch )
    1650 {
    1651   dprintf(("CRTDLL: _ismbclegal not implemented.\n"));
    1652   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1653   return FALSE;
     1669int CDECL CRTDLL__ismbclegal( unsigned int c )
     1670{
     1671  dprintf(("CRTDLL: _ismbclegal\n"));
     1672  if ((c & 0xFF00) != 0) {
     1673        return CRTDLL__ismbblead(c>>8) && CRTDLL__ismbbtrail(c&0xFF);
     1674  }
     1675  else
     1676        return CRTDLL__ismbbtrail(c&0xFF);
     1677
     1678  return 0;
    16541679}
    16551680
     
    16581683 *                  _ismbclower     (CRTDLL.157)
    16591684 */
    1660 int CDECL CRTDLL__ismbclower( unsigned int ch )
    1661 {
    1662   dprintf(("CRTDLL: _ismbclower not implemented.\n"));
    1663   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1664   return FALSE;
     1685int CDECL CRTDLL__ismbclower( unsigned int c )
     1686{
     1687  dprintf(("CRTDLL: _ismbclower\n"));
     1688  if ((c & 0xFF00) != 0) {
     1689        if ( c >= 0x829A && c<= 0x829A )
     1690                return 1;
     1691  }
     1692  else
     1693    return isupper(c);
    16651694}
    16661695
     
    16691698 *                  _ismbcprint     (CRTDLL.158)
    16701699 */
    1671 int CDECL CRTDLL__ismbcprint( unsigned int ch )
    1672 {
    1673   dprintf(("CRTDLL: _ismbcprint not implemented.\n"));
    1674   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1675   return FALSE;
     1700int CDECL CRTDLL__ismbcprint( unsigned int c )
     1701{
     1702  dprintf(("CRTDLL: _ismbcprint\n"));
     1703  if ((c & 0xFF00) != 0) {
     1704        // true multibyte character
     1705        return 0;
     1706  }
     1707  else
     1708        return 0;
     1709//      return _ismbbdigit(c);
     1710
     1711  return 0;
    16761712}
    16771713
     
    16801716 *                  _ismbcspace     (CRTDLL.159)
    16811717 */
    1682 int CDECL CRTDLL__ismbcspace( unsigned int ch )
     1718int CDECL CRTDLL__ismbcspace( unsigned int c )
    16831719{
    16841720  dprintf(("CRTDLL: _ismbcspace not implemented.\n"));
    1685   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1686   return FALSE;
     1721  if ((c & 0xFF00) != 0) {
     1722        // true multibyte character
     1723        return 0;
     1724  }
     1725  else
     1726        return 0;
     1727//      return _ismbbdigit(c);
     1728
     1729  return 0;
    16871730}
    16881731
     
    16911734 *                  _ismbcsymbol     (CRTDLL.160)
    16921735 */
    1693 int CDECL CRTDLL__ismbcsymbol( unsigned int ch )
    1694 {
    1695   dprintf(("CRTDLL: _ismbcsymbol not implemented.\n"));
    1696   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1697   return FALSE;
     1736int CDECL CRTDLL__ismbcsymbol( unsigned int c )
     1737{
     1738  dprintf(("CRTDLL: _ismbcsymbol\n"));
     1739  if ((c & 0xFF00) != 0) {
     1740        // true multibyte character
     1741        return 0;
     1742  }
     1743  else
     1744        return 0;
     1745//      return _ismbbdigit(c);
     1746
     1747  return 0;
    16981748}
    16991749
     
    17021752 *                  _ismbcupper     (CRTDLL.161)
    17031753 */
    1704 int CDECL CRTDLL__ismbcupper( unsigned int ch )
    1705 {
    1706   dprintf(("CRTDLL: _ismbcupper not implemented.\n"));
    1707   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1708   return FALSE;
     1754int CDECL CRTDLL__ismbcupper( unsigned int c )
     1755{
     1756  dprintf(("CRTDLL: _ismbcupper\n"));
     1757  if ((c & 0xFF00) != 0) {
     1758        if ( c >= 0x8260 && c<= 0x8279 )
     1759                return 1;
     1760  }
     1761  else
     1762  return isupper(c);
    17091763}
    17101764
     
    17131767 *                  _ismbslead     (CRTDLL.162)
    17141768 */
    1715 int CDECL CRTDLL__ismbslead(const unsigned char *s1, const unsigned char *s2)
    1716 {
    1717   dprintf(("CRTDLL: _ismbslead not implemented.\n"));
    1718   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1719   return FALSE;
     1769int CDECL CRTDLL__ismbslead(const unsigned char *str, const unsigned char *t)
     1770{
     1771  dprintf(("CRTDLL: _ismbslead\n"));
     1772  unsigned char *s = (unsigned char *)str;
     1773  while(*s != 0 && s != t)
     1774  { 
     1775        s+= _mbclen2(*s);
     1776  }             
     1777  return CRTDLL__ismbblead( *s);
    17201778}
    17211779
     
    17241782 *                  _ismbstrail     (CRTDLL.163)
    17251783 */
    1726 int CDECL CRTDLL__ismbstrail(const unsigned char *s1, const unsigned char *s2)
    1727 {
    1728   dprintf(("CRTDLL: _ismbstrail not implemented.\n"));
    1729   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1730   return FALSE;
     1784int CDECL CRTDLL__ismbstrail(const unsigned char *str, const unsigned char *t)
     1785{
     1786  dprintf(("CRTDLL: _ismbstrail\n"));
     1787  unsigned char *s = (unsigned char *)str;
     1788  while(*s != 0 && s != t)
     1789  {
     1790               
     1791        s+= _mbclen2(*s);
     1792  }
     1793               
     1794  return CRTDLL__ismbbtrail(*s);
    17311795}
    17321796
     
    18911955
    18921956
     1957/*********************************************************************
     1958 *                  _matherr    (CRTDLL.181)
     1959 */
    18931960#if (__IBMCPP__ > 300)
    18941961#define exception _exception
    18951962#endif
    18961963
    1897 /*********************************************************************
    1898  *                  _matherr    (CRTDLL.181)
    1899  */
    19001964double CDECL CRTDLL__matherr( struct exception * excep )
    19011965{
     
    19081972 *                  _mbbtombc        (CRTDLL.182)
    19091973 */
    1910 unsigned int CDECL CRTDLL__mbbtombc( unsigned int ch )
     1974unsigned int CDECL CRTDLL__mbbtombc( unsigned int c )
    19111975{
    19121976  dprintf(("CRTDLL: _mbbtombc\n"));
    1913   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1914   return FALSE;
     1977  if (c >= 0x20 && c <= 0x7e) {
     1978    return han_to_zen_ascii_table[c - 0x20];
     1979  } else if (ISKANA(c)) {
     1980    return han_to_zen_kana_table[c - 0xa0];
     1981  }
     1982  return c;
    19151983}
    19161984
     
    19191987 *                  _mbbtype        (CRTDLL.183)
    19201988 */
    1921 int CDECL CRTDLL__mbbtype( unsigned char s, int i )
    1922 {
    1923   dprintf(("CRTDLL: _mbbtype not implemented.\n"));
    1924   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1925   return FALSE;
     1989int CDECL CRTDLL__mbbtype( unsigned char c, int type )
     1990{
     1991  dprintf(("CRTDLL: _mbbtype\n"));
     1992        if ( type == 1 ) {
     1993                if ((c >= 0x40 && c <= 0x7e ) || (c >= 0x80 && c <= 0xfc ) )
     1994                {
     1995                        return _MBC_TRAIL;
     1996                }
     1997                else if (( c >= 0x20 && c >= 0x7E ) || ( c >= 0xA1 && c <= 0xDF ) ||
     1998                         ( c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC ) )
     1999                         return _MBC_ILLEGAL;
     2000                else
     2001                        return 0;
     2002               
     2003        }
     2004        else  {
     2005                if (( c >= 0x20 && c <= 0x7E ) || ( c >= 0xA1  && c <= 0xDF )) {
     2006                        return _MBC_SINGLE;
     2007                }
     2008                else if ( (c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC) )
     2009                        return _MBC_LEAD;
     2010                else if (( c >= 0x20 && c >= 0x7E ) || ( c >= 0xA1 && c <= 0xDF ) ||
     2011                         ( c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC ) )
     2012                         return _MBC_ILLEGAL;
     2013                else
     2014                        return 0;
     2015               
     2016        }
     2017       
     2018       
     2019        return 0;       
    19262020}
    19272021
     
    19302024 *                  _mbccpy        (CRTDLL.184)
    19312025 */
    1932 void CDECL CRTDLL__mbccpy( unsigned char *dest, const unsigned char *ch )
    1933 {
    1934   dprintf(("CRTDLL: _mbccpy not implemented.\n"));
    1935   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
     2026void CDECL CRTDLL__mbccpy( unsigned char *dst, const unsigned char *src )
     2027{
     2028  dprintf(("CRTDLL: _mbccpy\n"));
     2029
     2030  if (!CRTDLL__ismbblead(*src) )
     2031        return;
     2032               
     2033  memcpy(dst,src,_mbclen2(*src));
    19362034}
    19372035
     
    19402038 *                  _mbcjistojms     (CRTDLL.185)
    19412039 */
    1942 int CDECL CRTDLL__mbcjistojms( unsigned int ch )
    1943 {
    1944   dprintf(("CRTDLL: _mbcjistojms not implemented.\n"));
    1945   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1946   return FALSE;
     2040int CDECL CRTDLL__mbcjistojms( unsigned int c )
     2041{
     2042  dprintf(("CRTDLL: _mbcjistojms\n"));
     2043  int c1, c2;
     2044
     2045  c2 = (unsigned char)c;
     2046  c1 = c >> 8;
     2047  if (c1 >= 0x21 && c1 <= 0x7e && c2 >= 0x21 && c2 <= 0x7e) {
     2048    if (c1 & 0x01) {
     2049      c2 += 0x1f;
     2050      if (c2 >= 0x7f)
     2051        c2 ++;
     2052    } else {
     2053      c2 += 0x7e;
     2054    }
     2055    c1 += 0xe1;
     2056    c1 >>= 1;
     2057    if (c1 >= 0xa0)
     2058      c1 += 0x40;
     2059    return ((c1 << 8) | c2);
     2060  }
     2061  return 0;
    19472062}
    19482063
     
    19512066 *                  _mbcjmstojis     (CRTDLL.186)
    19522067 */
    1953 int CDECL CRTDLL__mbcjmstojis( unsigned int ch )
    1954 {
    1955   dprintf(("CRTDLL: _mbcjmstojis not implemented.\n"));
    1956   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1957   return FALSE;
     2068int CDECL CRTDLL__mbcjmstojis( unsigned int c )
     2069{
     2070  dprintf(("CRTDLL: _mbcjmstojis\n"));
     2071  int c1, c2;
     2072
     2073  c2 = (unsigned char)c;
     2074  c1 = c >> 8;
     2075  if (c1 < 0xf0 && CRTDLL__ismbblead(c1) && CRTDLL__ismbbtrail(c2)) {
     2076    if (c1 >= 0xe0)
     2077      c1 -= 0x40;
     2078    c1 -= 0x70;
     2079    c1 <<= 1;
     2080    if (c2 < 0x9f) {
     2081      c1 --;
     2082      c2 -= 0x1f;
     2083      if (c2 >= (0x80-0x1f))
     2084        c2 --;
     2085    } else {
     2086      c2 -= 0x7e;
     2087    }
     2088    return ((c1 << 8) | c2);
     2089  }
     2090  return 0;
    19582091}
    19592092
     
    19622095 *                  _mbclen    (CRTDLL.187)
    19632096 */
    1964 size_t CDECL CRTDLL__mbclen( const unsigned char *ch )
    1965 {
    1966   dprintf(("CRTDLL: _mbclen not implemented.\n"));
    1967   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1968   return FALSE;
     2097size_t CDECL CRTDLL__mbclen( const unsigned char *s )
     2098{
     2099  dprintf(("CRTDLL: _mbclen\n"));
     2100  return (CRTDLL__ismbblead(*s>>8) && CRTDLL__ismbbtrail(*s&0x00FF)) ? 2 : 1;
    19692101}
    19702102
     
    19732105 *                  _mbctohira     (CRTDLL.188)
    19742106 */
    1975 int CDECL CRTDLL__mbctohira( unsigned int ch )
    1976 {
    1977   dprintf(("CRTDLL: _mbctohira not implemented.\n"));
    1978   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1979   return FALSE;
     2107int CDECL CRTDLL__mbctohira( unsigned int c )
     2108{
     2109  dprintf(("CRTDLL: _mbctohira\n"));
     2110  return c;
    19802111}
    19812112
     
    19842115 *                  _mbctokata     (CRTDLL.189)
    19852116 */
    1986 int CDECL CRTDLL__mbctokata( unsigned int ch )
    1987 {
    1988   dprintf(("CRTDLL: _mbctokata not implemented.\n"));
    1989   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    1990   return FALSE;
     2117int CDECL CRTDLL__mbctokata( unsigned int c )
     2118{
     2119  dprintf(("CRTDLL: _mbctokata\n"));
     2120  return c;
    19912121}
    19922122
     
    19952125 *                  _mbctolower     (CRTDLL.190)
    19962126 */
    1997 unsigned int CDECL CRTDLL__mbctolower( unsigned int ch )
    1998 {
    1999   dprintf(("CRTDLL: _mbctolower not implemented.\n"));
    2000   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2001   return FALSE;
     2127unsigned int CDECL CRTDLL__mbctolower( unsigned int c )
     2128{
     2129  dprintf(("CRTDLL: _mbctolower\n"));
     2130        if ((c & 0xFF00) != 0) {
     2131// true multibyte case conversion needed
     2132                if ( CRTDLL__ismbclower(c) )
     2133                        return c + CASE_DIFF;
     2134
     2135        } else
     2136                return _mbbtolower(c);
     2137
     2138        return 0;
    20022139}
    20032140
     
    20062143 *                  _mbctombb        (CRTDLL.191)
    20072144 */
    2008 unsigned int CDECL CRTDLL__mbctombb( unsigned int ch )
    2009 {
    2010   dprintf(("CRTDLL: _mbctombb not implemented.\n"));
    2011   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2012   return FALSE;
     2145unsigned int CDECL CRTDLL__mbctombb( unsigned int c )
     2146{
     2147  dprintf(("CRTDLL: _mbctombb\n"));
     2148  int i;
     2149  unsigned short *p;
     2150
     2151  if (JISKANA(c)) {
     2152    return zen_to_han_kana_table[c - 0x8340];
     2153  } else if (JISHIRA(c)) {
     2154    c = JTOKANA(c);
     2155    return zen_to_han_kana_table[c - 0x8340];
     2156  } else if (c <= 0x8396) {
     2157    for (i = 0x20, p = han_to_zen_ascii_table; i <= 0x7e; i++, p++) {
     2158      if (*p == c) {
     2159        return i;
     2160      }
     2161    }
     2162    for (i = 0; i < ZTOH_SYMBOLS; i++) {
     2163      if (zen_to_han_symbol_table_1[i] == c) {
     2164        return zen_to_han_symbol_table_2[i];
     2165      }
     2166    }
     2167  }
     2168  return c;
    20132169}
    20142170
     
    20172173 *                  _mbctoupper     (CRTDLL.192)
    20182174 */
    2019 unsigned int CDECL CRTDLL__mbctoupper( unsigned int ch )
    2020 {
    2021   dprintf(("CRTDLL: _mbctoupper not implemented.\n"));
    2022   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2023   return FALSE;
     2175unsigned int CDECL CRTDLL__mbctoupper( unsigned int c )
     2176{
     2177  dprintf(("CRTDLL: _mbctoupper\n"));
     2178  if ((c & 0xFF00) != 0) {
     2179// true multibyte case conversion needed
     2180  if ( CRTDLL__ismbcupper(c) )
     2181        return c + CASE_DIFF;
     2182
     2183  } else
     2184        return _mbbtoupper(c);
     2185
     2186  return 0;
    20242187}
    20252188
     
    20282191 *                  _mbsbtype     (CRTDLL.194)
    20292192 */
    2030 int CDECL CRTDLL__mbsbtype( const unsigned char *s1, int ch )
    2031 {
    2032   dprintf(("CRTDLL: _mbsbtype not implemented.\n"));
    2033   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2034   return FALSE;
     2193int CDECL CRTDLL__mbsbtype( const unsigned char *str, int n )
     2194{
     2195  dprintf(("CRTDLL: _mbsbtype\n"));
     2196  if ( str == NULL )
     2197        return -1;
     2198  return CRTDLL__mbbtype(*(str+n),1);
    20352199}
    20362200
     
    20392203 *                  _mbscat       (CRTDLL.195)
    20402204 */
    2041 unsigned char * CDECL CRTDLL__mbscat( unsigned char *s1, const unsigned char *s2 )
    2042 {
    2043   dprintf(("CRTDLL: _mbscat not implemented.\n"));
     2205unsigned char * CDECL CRTDLL__mbscat( unsigned char *dst, const unsigned char *src )
     2206{
     2207  dprintf(("CRTDLL: _mbscat  not implemented.\n"));
    20442208  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    20452209  return FALSE;
     
    20502214 *                  _mbschr       (CRTDLL.196)
    20512215 */
    2052 unsigned char * CDECL CRTDLL__mbschr( const unsigned char *s, unsigned int ch )
     2216unsigned char * CDECL CRTDLL__mbschr( const unsigned char *str, unsigned int c )
    20532217{
    20542218  dprintf(("CRTDLL: _mbschr not implemented.\n"));
     
    20832247 *                  _mbscspn        (CRTDLL.199)
    20842248 */
    2085 size_t CDECL CRTDLL__mbscspn( const unsigned char *s, const unsigned char *charset )
     2249size_t CDECL CRTDLL__mbscspn( const unsigned char *s1, const unsigned char *s2 )
    20862250{
    20872251  dprintf(("CRTDLL: _mbscspn not implemented.\n"));
     
    20922256
    20932257/*********************************************************************
    2094  *           CRTDLL__mbsdec    (CRTDLL.200)
    2095  */
    2096 unsigned char * CDECL CRTDLL__mbsdec( const unsigned char *s, const unsigned char *ch )
    2097 {
    2098   dprintf(("CRTDLL: _mbsdec not implemented.\n"));
    2099   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2100   return FALSE;
    2101 }
    2102 
    2103 
    2104 /*********************************************************************
    2105  *           CRTDLL__mbsdec    (CRTDLL.201)
     2258 *           _mbsdec    (CRTDLL.200)
     2259 */
     2260unsigned char * CDECL CRTDLL__mbsdec( const unsigned char *str, const unsigned char *cur )
     2261{
     2262  dprintf(("CRTDLL: _mbsdec\n"));
     2263  unsigned char *s = (unsigned char *)cur;
     2264  if ( str >= cur )
     2265        return NULL;
     2266  s--;
     2267  if (CRTDLL__ismbblead(*(s-1)) )
     2268        s--;
     2269
     2270  return s;
     2271}
     2272
     2273
     2274/*********************************************************************
     2275 *           _mbsdup    (CRTDLL.201)
    21062276 */
    21072277unsigned char * CDECL CRTDLL__mbsdup( unsigned char *src )
     
    21622332
    21632333/*********************************************************************
    2164  *           CRTDLL__mbslwr    (CRTDLL.205)
    2165  */
    2166 unsigned char * CDECL CRTDLL__mbslwr( unsigned char *s )
    2167 {
    2168   dprintf(("CRTDLL: _mbslwr not implemented.\n"));
    2169   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2170   return FALSE;
    2171 }
    2172 
    2173 
    2174 /*********************************************************************
    2175  *           CRTDLL__mbsnbcat  (CRTDLL.206)
    2176  */
    2177 unsigned char * CDECL CRTDLL__mbsnbcat( unsigned char *s1, const unsigned char *s2, size_t n )
    2178 {
    2179   dprintf(("CRTDLL: _mbsnbcat not implemented.\n"));
    2180   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2181   return FALSE;
    2182 }
    2183 
    2184 
    2185 /*********************************************************************
    2186  *           CRTDLL__mbsnbcmp  (CRTDLL.207)
    2187  */
    2188 int CDECL CRTDLL__mbsnbcmp( const unsigned char *s1, const unsigned char *s2, size_t n )
    2189 {
    2190   dprintf(("CRTDLL: _mbsnbcmp not implemented.\n"));
    2191   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2192   return FALSE;
    2193 }
    2194 
    2195 
    2196 /*********************************************************************
    2197  *           CRTDLL__mbsnbcnt  (CRTDLL.208)
    2198  */
    2199 size_t CDECL CRTDLL__mbsnbcnt( const unsigned char *s, size_t n )
    2200 {
    2201   dprintf(("CRTDLL: _mbsnbcnt not implemented.\n"));
    2202   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2203   return FALSE;
    2204 }
    2205 
    2206 
    2207 /*********************************************************************
    2208  *           CRTDLL__mbsnbcpy  (CRTDLL.209)
    2209  */
    2210 unsigned char * CDECL CRTDLL__mbsnbcpy( unsigned char *s1, const unsigned char *s2, size_t n )
    2211 {
    2212   dprintf(("CRTDLL: _mbsnbcpy not implemented.\n"));
    2213   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2214   return FALSE;
    2215 }
    2216 
    2217 
    2218 /*********************************************************************
    2219  *           CRTDLL__mbsnbicmp (CRTDLL.210)
     2334 *           _mbslwr    (CRTDLL.205)
     2335 */
     2336unsigned char * CDECL CRTDLL__mbslwr( unsigned char *x )
     2337{
     2338  dprintf(("CRTDLL: _mbslwr\n"));
     2339  unsigned char  *y=x;
     2340
     2341  while (*y) {
     2342        if (!CRTDLL__ismbblead(*y) )
     2343                *y = tolower(*y);
     2344        else {
     2345                *y=CRTDLL__mbctolower(*(unsigned short *)y);
     2346                y++;
     2347        }
     2348  }
     2349  return x;
     2350}
     2351
     2352
     2353/*********************************************************************
     2354 *           _mbsnbcat  (CRTDLL.206)
     2355 */
     2356unsigned char * CDECL CRTDLL__mbsnbcat( unsigned char *dst, const unsigned char *src, size_t n )
     2357{
     2358  dprintf(("CRTDLL: _mbsnbcat\n"));
     2359        char *d;
     2360        char *s = (char *)src; 
     2361        if (n != 0) {
     2362                d = (char*)dst + strlen((char*)dst); // get the end of string
     2363                d += _mbclen2(*d); // move 1 or 2 up
     2364
     2365                do {
     2366                        if ((*d++ = *s++) == 0)
     2367                        {
     2368                                while (--n != 0)
     2369                                        *d++ = 0;
     2370                                break;
     2371                        }
     2372                        if ( !(n==1 && CRTDLL__ismbblead(*s)) )
     2373                                n--;
     2374                } while (n > 0);
     2375        }
     2376        return dst;
     2377}
     2378
     2379
     2380/*********************************************************************
     2381 *           _mbsnbcmp  (CRTDLL.207)
     2382 */
     2383int CDECL CRTDLL__mbsnbcmp( const unsigned char *str1, const unsigned char *str2, size_t n )
     2384{
     2385  dprintf(("CRTDLL: _mbsnbcmp\n"));
     2386        unsigned char *s1 = (unsigned char *)str1;
     2387        unsigned char *s2 = (unsigned char *)str2;
     2388
     2389        unsigned short *short_s1, *short_s2;
     2390
     2391        int l1, l2;
     2392
     2393        if (n == 0)
     2394                return 0;
     2395        do {
     2396               
     2397                if (*s1 == 0)
     2398                        break; 
     2399
     2400                l1 = CRTDLL__ismbblead(*s1);
     2401                l2 = CRTDLL__ismbblead(*s2);
     2402                if ( !l1 &&  !l2  ) {
     2403
     2404                        if (*s1 != *s2)
     2405                                return *s1 - *s2;
     2406                        else {
     2407                                s1 += 1;
     2408                                s2 += 1;
     2409                                n--;
     2410                        }
     2411                }
     2412                else if ( l1 && l2 ){
     2413                        short_s1 = (unsigned short *)s1;
     2414                        short_s2 = (unsigned short *)s2;
     2415                        if ( *short_s1 != *short_s2 )
     2416                                return *short_s1 - *short_s2;
     2417                        else {
     2418                                s1 += 2;
     2419                                s2 += 2;
     2420                                n-=2;
     2421
     2422                        }
     2423                }
     2424                else
     2425                        return *s1 - *s2;
     2426        } while (n > 0);
     2427        return 0;
     2428}
     2429
     2430
     2431/*********************************************************************
     2432 *           _mbsnbcnt  (CRTDLL.208)
     2433 */
     2434size_t CDECL CRTDLL__mbsnbcnt( const unsigned char *str, size_t n )
     2435{
     2436  dprintf(("CRTDLL: _mbsnbcnt\n"));
     2437        unsigned char *s = (unsigned char *)str;
     2438        while(*s != 0 && n > 0) {
     2439                if (!CRTDLL__ismbblead(*s) )
     2440                        n--;
     2441                s++;
     2442        }
     2443       
     2444        return (size_t)(s - str);
     2445}
     2446
     2447
     2448/*********************************************************************
     2449 *           _mbsnbcpy  (CRTDLL.209)
     2450 */
     2451unsigned char * CDECL CRTDLL__mbsnbcpy( unsigned char *str1, const unsigned char *str2, size_t n )
     2452{
     2453  dprintf(("CRTDLL: _mbsnbcpy\n"));
     2454        unsigned char *s1 = (unsigned char *)str1;
     2455        unsigned char *s2 = (unsigned char *)str2;
     2456
     2457        unsigned short *short_s1, *short_s2;
     2458
     2459        if (n == 0)
     2460                return 0;
     2461        do {
     2462               
     2463                if (*s2 == 0)
     2464                        break; 
     2465
     2466                if (  !CRTDLL__ismbblead(*s2) ) {
     2467
     2468                        *s1 = *s2;
     2469                        s1 += 1;
     2470                        s2 += 1;
     2471                        n--;
     2472                }
     2473                else {
     2474                        short_s1 = (unsigned short *)s1;
     2475                        short_s2 = (unsigned short *)s2;
     2476                        *short_s1 = *short_s2;
     2477                        s1 += 2;
     2478                        s2 += 2;
     2479                        n-=2;
     2480                }
     2481        } while (n > 0);
     2482        return str1;
     2483}
     2484
     2485
     2486/*********************************************************************
     2487 *           _mbsnbicmp (CRTDLL.210)
    22202488 */
    22212489int CDECL CRTDLL__mbsnbicmp( const unsigned char *s1, const unsigned char *s2, size_t n )
    22222490{
    2223   dprintf(("CRTDLL: _mbsnbicmp not implemented.\n"));
    2224   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2225   return FALSE;
    2226 }
    2227 
    2228 
    2229 /*********************************************************************
    2230  *           CRTDLL__mbsnbset (CRTDLL.211)
    2231  */
    2232 unsigned char * CDECL CRTDLL__mbsnbset( unsigned char *s, unsigned int ch, size_t n )
    2233 {
    2234   dprintf(("CRTDLL: _mbsnbset not implemented.\n"));
    2235   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2236   return FALSE;
    2237 }
    2238 
    2239 
    2240 /*********************************************************************
    2241  *           CRTDLL__mbsncat (CRTDLL.212)
    2242  */
    2243 unsigned char * CDECL CRTDLL__mbsncat( unsigned char *s1, const unsigned char *s2, size_t n )
    2244 {
    2245   dprintf(("CRTDLL: _mbsncat not implemented.\n"));
    2246   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2247   return FALSE;
    2248 }
    2249 
    2250 
    2251 /*********************************************************************
    2252  *           CRTDLL__mbsnccnt (CRTDLL.213)
    2253  */
    2254 size_t CDECL CRTDLL__mbsnccnt( const unsigned char *s, size_t n )
    2255 {
    2256   dprintf(("CRTDLL: _mbsnccnt not implemented.\n"));
    2257   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2258   return FALSE;
    2259 }
    2260 
    2261 
    2262 /*********************************************************************
    2263  *           CRTDLL__mbsncmp (CRTDLL.214)
    2264  */
    2265 int CDECL CRTDLL__mbsncmp( const unsigned char *s1, const unsigned char *s2, size_t n )
    2266 {
    2267   dprintf(("CRTDLL: _mbsncmp not implemented.\n"));
    2268   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2269   return FALSE;
    2270 }
    2271 
    2272 
    2273 /*********************************************************************
    2274  *           CRTDLL__mbsncpy (CRTDLL.215)
    2275  */
    2276 unsigned char * CDECL CRTDLL__mbsncpy( unsigned char *s1, const unsigned char *s2, size_t n )
    2277 {
    2278   dprintf(("CRTDLL: _mbsncpy not implemented.\n"));
    2279   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2280   return FALSE;
    2281 }
    2282 
    2283 
    2284 /*********************************************************************
    2285  *           CRTDLL__mbsnextc (CRTDLL.216)
    2286  */
    2287 unsigned int CDECL CRTDLL__mbsnextc( const unsigned char *s )
    2288 {
    2289   dprintf(("CRTDLL: _mbsnextc not implemented.\n"));
    2290   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2291   return FALSE;
    2292 }
    2293 
    2294 
    2295 /*********************************************************************
    2296  *           CRTDLL__mbsnicmp (CRTDLL.217)
     2491  dprintf(("CRTDLL: _mbsnbicmp\n"));
     2492  if (n == 0)
     2493    return 0;
     2494  do {
     2495    if (_mbbtoupper(*s1) != _mbbtoupper(*s2))
     2496      return _mbbtoupper(*(unsigned const char *)s1) - _mbbtoupper(*(unsigned const char *)s2);
     2497    s1 += _mbclen2(*s1);
     2498    s2 += _mbclen2(*s2);
     2499
     2500
     2501    if (*s1 == 0)
     2502      break;
     2503    n--;
     2504  } while (n > 0);
     2505  return 0;
     2506}
     2507
     2508
     2509/*********************************************************************
     2510 *           _mbsnbset (CRTDLL.211)
     2511 */
     2512unsigned char * CDECL CRTDLL__mbsnbset( unsigned char *src, unsigned int val, size_t count )
     2513{
     2514  dprintf(("CRTDLL: _mbsnbset\n"));
     2515        unsigned char *char_src = (unsigned char *)src;
     2516        unsigned short *short_src = (unsigned short *)src;
     2517       
     2518        if ( _mbclen2(val) == 1 ) {
     2519       
     2520                while(count > 0) {
     2521                        *char_src = val;
     2522                        char_src++;
     2523                        count--;
     2524                }
     2525                *char_src = 0;
     2526        }
     2527        else {
     2528                while(count > 0) {
     2529                        *short_src = val;
     2530                        short_src++;
     2531                        count-=2;
     2532                }       
     2533                *short_src = 0;
     2534        }
     2535       
     2536        return src;
     2537}
     2538
     2539
     2540/*********************************************************************
     2541 *           _mbsncat (CRTDLL.212)
     2542 */
     2543unsigned char * CDECL CRTDLL__mbsncat( unsigned char *dst, const unsigned char *src, size_t n )
     2544{
     2545  dprintf(("CRTDLL: _mbsncat\n"));
     2546        char *d = (char *)dst;
     2547        char *s = (char *)src; 
     2548        if (n != 0) {
     2549                d = (char*)dst + strlen((char*)dst); // get the end of string
     2550                d += _mbclen2(*d); // move 1 or 2 up
     2551
     2552                do {
     2553                        if ((*d++ = *s++) == 0)
     2554                        {
     2555                                while (--n != 0)
     2556                                        *d++ = 0;
     2557                                break;
     2558                        }
     2559                        if (!CRTDLL__ismbblead(*s) )
     2560                                n--;
     2561                } while (n > 0);
     2562        }
     2563        return dst;
     2564}
     2565
     2566
     2567/*********************************************************************
     2568 *           _mbsnccnt (CRTDLL.213)
     2569 */
     2570size_t CDECL CRTDLL__mbsnccnt( const unsigned char *str, size_t n )
     2571{
     2572  dprintf(("CRTDLL: _mbsnccnt\n"));
     2573        unsigned char *s = (unsigned char *)str;
     2574        size_t cnt = 0;
     2575        while(*s != 0 && n > 0) {
     2576                if (CRTDLL__ismbblead(*s) )
     2577                        s++;
     2578                else
     2579                        n--;
     2580                s++;
     2581                cnt++;
     2582        }
     2583       
     2584        return cnt;
     2585}
     2586
     2587
     2588/*********************************************************************
     2589 *           _mbsncmp (CRTDLL.214)
     2590 */
     2591int CDECL CRTDLL__mbsncmp( const unsigned char *str1, const unsigned char *str2, size_t n )
     2592{
     2593  dprintf(("CRTDLL: _mbsncmp\n"));
     2594        unsigned char *s1 = (unsigned char *)str1;
     2595        unsigned char *s2 = (unsigned char *)str2;
     2596
     2597        unsigned short *short_s1, *short_s2;
     2598
     2599        int l1, l2;
     2600
     2601        if (n == 0)
     2602                return 0;
     2603        do {
     2604               
     2605                if (*s1 == 0)
     2606                        break; 
     2607
     2608                l1 = CRTDLL__ismbblead(*s1);
     2609                l2 = CRTDLL__ismbblead(*s2);
     2610                if ( !l1 &&  !l2  ) {
     2611
     2612                        if (*s1 != *s2)
     2613                                return *s1 - *s2;
     2614                        else {
     2615                                s1 += 1;
     2616                                s2 += 1;
     2617                                n--;
     2618                        }
     2619                }
     2620                else if ( l1 && l2 ){
     2621                        short_s1 = (unsigned short *)s1;
     2622                        short_s2 = (unsigned short *)s2;
     2623                        if ( *short_s1 != *short_s2 )
     2624                                return *short_s1 - *short_s2;
     2625                        else {
     2626                                s1 += 2;
     2627                                s2 += 2;
     2628                                n--;
     2629
     2630                        }
     2631                }
     2632                else
     2633                        return *s1 - *s2;
     2634        } while (n > 0);
     2635        return 0;
     2636}
     2637
     2638
     2639/*********************************************************************
     2640 *           _mbsncpy (CRTDLL.215)
     2641 */
     2642unsigned char * CDECL CRTDLL__mbsncpy( unsigned char *str1, const unsigned char *str2, size_t n )
     2643{
     2644  dprintf(("CRTDLL: _mbsncpy\n"));
     2645        unsigned char *s1 = (unsigned char *)str1;
     2646        unsigned char *s2 = (unsigned char *)str2;
     2647
     2648        unsigned short *short_s1, *short_s2;
     2649
     2650        if (n == 0)
     2651                return 0;
     2652        do {
     2653               
     2654                if (*s2 == 0)
     2655                        break; 
     2656
     2657                if (  !CRTDLL__ismbblead(*s2) ) {
     2658
     2659                        *s1 = *s2;
     2660                        s1 += 1;
     2661                        s2 += 1;
     2662                        n--;
     2663                }
     2664                else {
     2665                        short_s1 = (unsigned short *)s1;
     2666                        short_s2 = (unsigned short *)s2;
     2667                        *short_s1 = *short_s2;
     2668                        s1 += 2;
     2669                        s2 += 2;
     2670                        n--;
     2671                }
     2672        } while (n > 0);
     2673        return str1;
     2674}
     2675
     2676
     2677/*********************************************************************
     2678 *           _mbsnextc (CRTDLL.216)
     2679 */
     2680unsigned int CDECL CRTDLL__mbsnextc( const unsigned char *src )
     2681{
     2682  dprintf(("CRTDLL: _mbsnextc\n"));
     2683        unsigned char *char_src = (unsigned char *)src;
     2684        unsigned short *short_src = (unsigned short *)src;
     2685
     2686        if ( src == NULL )
     2687                return 0;
     2688
     2689        if ( !CRTDLL__ismbblead(*src) )
     2690                return *char_src;
     2691        else
     2692                return *short_src;
     2693        return 0;
     2694
     2695}
     2696
     2697
     2698/*********************************************************************
     2699 *           _mbsnicmp (CRTDLL.217)
    22972700 */
    22982701int CDECL CRTDLL__mbsnicmp( const unsigned char *s1, const unsigned char *s2, size_t n )
    22992702{
    2300   dprintf(("CRTDLL: _mbsnicmp not implemented.\n"));
    2301   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2302   return FALSE;
    2303 }
    2304 
    2305 
    2306 /*********************************************************************
    2307  *           CRTDLL__mbsninc (CRTDLL.218)
    2308  */
    2309 unsigned char * CDECL CRTDLL__mbsninc( const unsigned char *s, size_t count )
    2310 {
    2311   dprintf(("CRTDLL: _mbsninc not implemented.\n"));
    2312   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2313   return FALSE;
    2314 }
    2315 
    2316 
    2317 /*********************************************************************
    2318  *           CRTDLL__mbsnset (CRTDLL.219)
    2319  */
    2320 unsigned char * CDECL CRTDLL__mbsnset( unsigned char *s, unsigned int ch, size_t n )
    2321 {
    2322   dprintf(("CRTDLL: _mbsnset not implemented.\n"));
    2323   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2324   return FALSE;
    2325 }
    2326 
    2327 
    2328 /*********************************************************************
    2329  *           CRTDLL__mbspbrk   (CRTDLL.220)
    2330  */
    2331 unsigned char * CDECL CRTDLL__mbspbrk( const unsigned char *s, const unsigned char *charset )
    2332 {
    2333   dprintf(("CRTDLL: _mbspbrk not implemented.\n"));
    2334   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2335   return FALSE;
     2703  dprintf(("CRTDLL: _mbsnicmp\n"));
     2704  if (n == 0)
     2705    return 0;
     2706  do {
     2707    if (_mbbtoupper(*s1) != _mbbtoupper(*s2))
     2708      return _mbbtoupper(*(unsigned const char *)s1) - _mbbtoupper(*(unsigned const char *)s2);
     2709
     2710// Next 2 lines won't compile
     2711//    *s1 += _mbclen2(*s1);
     2712//    *s2 += _mbclen2(*s2);
     2713
     2714
     2715    if (*s1 == 0)
     2716      break;
     2717    if (!CRTDLL__ismbblead(*s1) )
     2718        n--;
     2719  } while (n > 0);
     2720  return 0;
     2721}
     2722
     2723
     2724/*********************************************************************
     2725 *           _mbsninc (CRTDLL.218)
     2726 */
     2727unsigned char * CDECL CRTDLL__mbsninc( const unsigned char *str, size_t n )
     2728{
     2729  dprintf(("CRTDLL: _mbsninc\n"));
     2730        unsigned char *s = (unsigned char *)str;
     2731        while(*s != 0 && n > 0) {
     2732                if (!CRTDLL__ismbblead(*s) )
     2733                        n--;
     2734                s++;
     2735        }
     2736       
     2737        return s;
     2738}
     2739
     2740
     2741/*********************************************************************
     2742 *           _mbsnset (CRTDLL.219)
     2743 */
     2744unsigned char * CDECL CRTDLL__mbsnset( unsigned char *src, unsigned int val, size_t count )
     2745{
     2746  dprintf(("CRTDLL: _mbsnset\n"));
     2747        unsigned char *char_src = (unsigned char *)src;
     2748        unsigned short *short_src = (unsigned short *)src;
     2749       
     2750        if ( _mbclen2(val) == 1 ) {
     2751       
     2752                while(count > 0) {
     2753                        *char_src = val;
     2754                        char_src++;
     2755                        count--;
     2756                }
     2757                *char_src = 0;
     2758        }
     2759        else {
     2760                while(count > 0) {
     2761                        *short_src = val;
     2762                        short_src++;
     2763                        count-=2;
     2764                }       
     2765                *short_src = 0;
     2766        }
     2767       
     2768        return src;
     2769
     2770}
     2771
     2772
     2773/*********************************************************************
     2774 *           _mbspbrk   (CRTDLL.220)
     2775 */
     2776unsigned char * CDECL CRTDLL__mbspbrk( const unsigned char *s1, const unsigned char *s2 )
     2777{
     2778  dprintf(("CRTDLL: _mbspbrk\n"));
     2779  const char *scanp;
     2780  int c, sc;
     2781
     2782  while ((c = *s1++) != 0)
     2783  {
     2784    for (scanp = (char*)s2; (sc = *scanp++) != 0;)
     2785      if (sc == c)
     2786        return (unsigned char *)((char *)s1 - (char *)1);
     2787  }
     2788  return 0;
    23362789}
    23372790
     
    23492802
    23502803/*********************************************************************
    2351  *           CRTDLL__mbsrev    (CRTDLL.222)
     2804 *           _mbsrev    (CRTDLL.222)
    23522805 */
    23532806unsigned char * CDECL CRTDLL__mbsrev( unsigned char *s )
    23542807{
    2355   dprintf(("CRTDLL: _mbsrev not implemented.\n"));
    2356   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2357   return FALSE;
    2358 }
    2359 
    2360 
    2361 /*********************************************************************
    2362  *           CRTDLL__mbsset    (CRTDLL.223)
    2363  */
    2364 unsigned char * CDECL CRTDLL__mbsset( unsigned char *s, unsigned int ch )
    2365 {
    2366   dprintf(("CRTDLL: _mbsset not implemented.\n"));
    2367   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2368   return FALSE;
    2369 }
    2370 
    2371 
    2372 /*********************************************************************
    2373  *           CRTDLL__mbsspn   (CRTDLL.224)
    2374  */
    2375 size_t CDECL CRTDLL__mbsspn( const unsigned char *s, const unsigned char *charset )
    2376 {
    2377   dprintf(("CRTDLL: _mbsspn not implemented.\n"));
    2378   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2379   return FALSE;
    2380 }
    2381 
    2382 
    2383 /*********************************************************************
    2384  *           CRTDLL__mbsspnp   (CRTDLL.225)
    2385  */
    2386 unsigned char * CDECL CRTDLL__mbsspnp( const unsigned char *s, const unsigned char *charset )
    2387 {
    2388   dprintf(("CRTDLL: _mbsspnp not implemented.\n"));
    2389   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2390   return FALSE;
    2391 }
    2392 
    2393 
    2394 /*********************************************************************
    2395  *           CRTDLL__mbsstr    (CRTDLL.226)
     2808  dprintf(("CRTDLL: _mbsrev\n"));
     2809        unsigned char  *e;
     2810        unsigned char  a;
     2811        e=s;
     2812        while (*e) {
     2813                if ( CRTDLL__ismbblead(*e) ) {
     2814                        a = *e;
     2815                        *e = *++e;
     2816                        if ( *e == 0 )
     2817                                break;
     2818                        *e = a;
     2819                }
     2820                e++;
     2821        }
     2822        while (s<e) {
     2823                a=*s;
     2824                *s=*e;
     2825                *e=a;
     2826                s++;
     2827                e--;
     2828        }
     2829       
     2830
     2831        return s;
     2832}
     2833
     2834
     2835/*********************************************************************
     2836 *           _mbsset    (CRTDLL.223)
     2837 */
     2838unsigned char * CDECL CRTDLL__mbsset( unsigned char *src, unsigned int c )
     2839{
     2840  dprintf(("CRTDLL: _mbsset\n"));
     2841        unsigned char *char_src = src;
     2842        unsigned short *short_src = (unsigned short*)src;
     2843       
     2844        if ( _mbclen2(c) == 1 ) {
     2845       
     2846                while(*char_src != 0) {
     2847                        *char_src = c;
     2848                        char_src++;
     2849                }
     2850                *char_src = 0;
     2851        }
     2852        else {
     2853                while(*short_src != 0) {
     2854                        *short_src = c;
     2855                        short_src++;
     2856                }       
     2857                *short_src = 0;
     2858        }
     2859       
     2860        return src;
     2861}
     2862
     2863
     2864/*********************************************************************
     2865 *           _mbsspn   (CRTDLL.224)
     2866 */
     2867size_t CDECL CRTDLL__mbsspn( const unsigned char *s1, const unsigned char *s2 )
     2868{
     2869  dprintf(("CRTDLL: _mbsspn\n"));
     2870  const char *p = (char*)s1, *spanp;
     2871  char c, sc;
     2872
     2873 cont:
     2874  c = *p++;
     2875  for (spanp = (char*)s2; (sc = *spanp++) != 0;)
     2876    if (sc == c)
     2877      goto cont;
     2878  return (size_t)(p - 1) - (size_t)s1;
     2879}
     2880
     2881
     2882/*********************************************************************
     2883 *           _mbsspnp   (CRTDLL.225)
     2884 */
     2885unsigned char * CDECL CRTDLL__mbsspnp( const unsigned char *s1, const unsigned char *s2 )
     2886{
     2887  dprintf(("CRTDLL: _mbsspnp\n"));
     2888  const char *p = (char*)s1, *spanp;
     2889  char c, sc;
     2890
     2891 cont:
     2892  c = *p++;
     2893  for (spanp = (char*)s2; (sc = *spanp++) != 0;)
     2894    if (sc == c)
     2895      goto cont;
     2896  return (unsigned char*)p;
     2897}
     2898
     2899
     2900/*********************************************************************
     2901 *           _mbsstr    (CRTDLL.226)
    23962902 */
    23972903unsigned char * CDECL CRTDLL__mbsstr( const unsigned char *s1, const unsigned char *s2 )
     
    24042910
    24052911/*********************************************************************
    2406  *           CRTDLL__mbstok    (CRTDLL.227)
     2912 *           _mbstok    (CRTDLL.227)
    24072913 */
    24082914unsigned char * CDECL CRTDLL__mbstok( unsigned char *s, const unsigned char *delim )
    24092915{
    2410   dprintf(("CRTDLL: _mbstok not implemented.\n"));
    2411   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2412   return FALSE;
    2413 }
    2414 
    2415 
    2416 /*********************************************************************
    2417  *           CRTDLL__mbstrlen   (CRTDLL.228)
    2418  */
    2419 size_t CDECL CRTDLL__mbstrlen(const char *s)
    2420 {
    2421   dprintf(("CRTDLL: _mbstrlen not implemented.\n"));
    2422   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2423   return FALSE;
    2424 }
    2425 
    2426 
    2427 /*********************************************************************
    2428  *           CRTDLL__mbsupr    (CRTDLL.229)
    2429  */
    2430 unsigned char * CDECL CRTDLL__mbsupr( unsigned char *s )
    2431 {
    2432   dprintf(("CRTDLL: _mbsupr not implemented.\n"));
    2433   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2434   return FALSE;
     2916  dprintf(("CRTDLL: _mbstok not implemented\n"));
     2917  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
     2918  return FALSE;
     2919}
     2920
     2921
     2922/*********************************************************************
     2923 *           _mbstrlen   (CRTDLL.228)
     2924 */
     2925size_t CDECL CRTDLL__mbstrlen(const char *string)
     2926{
     2927  dprintf(("CRTDLL: _mbstrlen\n"));
     2928        char *s = (char *)string;
     2929        size_t i;
     2930        while ( *s != 0 ) {
     2931                if ( CRTDLL__ismbblead(*s) )
     2932                        s++;
     2933                s++;
     2934                i++;
     2935        }
     2936        return i;
     2937}
     2938
     2939
     2940/*********************************************************************
     2941 *           _mbsupr    (CRTDLL.229)
     2942 */
     2943unsigned char * CDECL CRTDLL__mbsupr( unsigned char *x )
     2944{
     2945  dprintf(("CRTDLL: _mbsupr\n"));
     2946        unsigned char  *y=x;
     2947        while (*y) {
     2948                if (!CRTDLL__ismbblead(*y) )
     2949                        *y = toupper(*y);
     2950                else {
     2951                        *y=CRTDLL__mbctoupper(*(unsigned short *)y);
     2952                        y++;
     2953                }
     2954        }
     2955        return x;
    24352956}
    24362957
     
    24392960 *           CRTDLL__memccpy   (CRTDLL.230)
    24402961 */
    2441 void * CDECL CRTDLL__memccpy(void *v1, const void *v2, int i, size_t s)
    2442 {
    2443   dprintf(("CRTDLL: _memccpy not implemented.\n"));
    2444   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2445   return FALSE;
     2962void * CDECL CRTDLL__memccpy(void *to, const void *from,int c,size_t count)
     2963{
     2964  dprintf(("CRTDLL: _memccpy\n"));
     2965  memcpy(to,from,count);
     2966  return memchr(to,c,count);
    24462967}
    24472968
     
    24622983 *                  _mktemp        (CRTDLL.233)
    24632984 */
    2464 char * CDECL CRTDLL__mktemp( char * templt )
    2465 {
    2466   dprintf(("CRTDLL: _mktemp not implemented.\n"));
    2467   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2468   return FALSE;
     2985char * CDECL CRTDLL__mktemp( char * _template )
     2986{
     2987  dprintf(("CRTDLL: _mktemp\n"));
     2988  static int count = 0;
     2989  char *cp, *dp;
     2990  int i, len, xcount, loopcnt;
     2991
     2992 
     2993
     2994  len = strlen (_template);
     2995  cp = _template + len;
     2996
     2997  xcount = 0;
     2998  while (xcount < 6 && cp > _template && cp[-1] == 'X')
     2999    xcount++, cp--;
     3000
     3001  if (xcount) {
     3002    dp = cp;
     3003    while (dp > _template && dp[-1] != '/' && dp[-1] != '\\' && dp[-1] != ':')
     3004      dp--;
     3005
     3006    /* Keep the first characters of the template, but turn the rest into
     3007       Xs.  */
     3008    while (cp > dp + 8 - xcount) {
     3009      *--cp = 'X';
     3010      xcount = (xcount >= 6) ? 6 : 1 + xcount;
     3011    }
     3012
     3013    /* If dots occur too early -- squash them.  */
     3014    while (dp < cp) {
     3015      if (*dp == '.') *dp = 'a';
     3016      dp++;
     3017    }
     3018
     3019    /* Try to add ".tmp" to the filename.  Truncate unused Xs.  */
     3020    if (cp + xcount + 3 < _template + len)
     3021      strcpy (cp + xcount, ".tmp");
     3022    else
     3023      cp[xcount] = 0;
     3024
     3025    for (loopcnt = 0; loopcnt < (1 << (5 * xcount)); loopcnt++) {
     3026      int c = count++;
     3027      for (i = 0; i < xcount; i++, c >>= 5)
     3028        cp[i] = "abcdefghijklmnopqrstuvwxyz012345"[c & 0x1f];
     3029      if (CRTDLL__access(_template,0) == -1)
     3030        return _template;
     3031    }
     3032  }
     3033  /* Failure:  truncate the template and return NULL.  */
     3034  *_template = 0;
     3035  return 0;
    24693036}
    24703037
     
    26413208 *                  _putw     (CRTDLL.252)
    26423209 */
    2643 INT CDECL CRTDLL__putw( int binint, FILE *fp )
    2644 {
    2645   dprintf(("CRTDLL: _putw not implemented.\n"));
    2646   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2647   return FALSE;
     3210INT CDECL CRTDLL__putw( int w, FILE *stream )
     3211{
     3212  dprintf(("CRTDLL: _putw\n"));
     3213  if (fwrite( &w, sizeof(w), 1, stream) < 1)
     3214    return(EOF);
     3215  return(0);
    26483216}
    26493217
     
    26633231 *                  _rmdir     (CRTDLL.255)
    26643232 */
    2665 INT CDECL CRTDLL__rmdir(const char *s1)
     3233INT CDECL CRTDLL__rmdir(const char *path)
    26663234{
    26673235  dprintf(("CRTDLL: _rmdir\n"));
    2668   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2669   return FALSE;
    2670 //  return (_rmdir(s1));
     3236  if (!RemoveDirectoryA(path))
     3237        return -1;
     3238  return 0;
    26713239}
    26723240
     
    27033271
    27043272/*********************************************************************
    2705  *           CRTDLL__scalb       (CRTDLL.259)
     3273 *           _scalb      (CRTDLL.259)
    27063274 */
    27073275double CDECL CRTDLL__scalb( double x, long exp )
     
    27163284 *           CRTDLL__searchenv   (CRTDLL.260)
    27173285 */
    2718 void CDECL CRTDLL__searchenv( const char *name, const char *env_var, char *buf )
    2719 {
    2720   dprintf(("CRTDLL: _searchenv not implemented.\n"));
    2721   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
     3286void CDECL CRTDLL__searchenv(const char *file,const char *var,char *path )
     3287{
     3288  dprintf(("CRTDLL: _searchenv\n"));
     3289  char *env = CRTDLL_getenv(var);
     3290
     3291  char *x;
     3292  char *y;
     3293  char *FilePart;
     3294  x = strchr(env,'=');
     3295  if ( x != NULL ) {
     3296        *x = 0;
     3297        x++;
     3298  }
     3299  y = strchr(env,';');
     3300  while ( y != NULL ) {
     3301        *y = 0;
     3302        if ( SearchPathA(x,file,NULL,MAX_PATH,path,&FilePart) > 0 ) {
     3303                        return;
     3304        }
     3305        x = y+1;
     3306        y = strchr(env,';');
     3307  }
     3308  return;
    27223309}
    27233310
     
    27283315void CDECL CRTDLL__seterrormode(int i)
    27293316{
    2730   dprintf(("CRTDLL: _seterrormode not implemented.\n"));
    2731   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
     3317  dprintf(("CRTDLL: _seterrormode\n"));
     3318  SetErrorMode(i);
     3319  return;
    27323320}
    27333321
     
    27753363
    27763364/*********************************************************************
    2777  *           CRTDLL__sopen       (CRTDLL.268)
     3365 *           _sopen      (CRTDLL.268)
    27783366 */
    27793367int CDECL CRTDLL__sopen( const char *s, int i1, int i2, ... )
     
    29193507
    29203508/*********************************************************************
    2921  *           CRTDLL__strerror    (CRTDLL.284)
     3509 *           _strerror           (CRTDLL.284)
    29223510 */
    29233511char * CDECL CRTDLL__strerror(const char *s)
     
    29353523int CDECL CRTDLL__stricoll( const char *s1, const char *s2 )
    29363524{
    2937   dprintf(("CRTDLL: _stricoll not implemented.\n"));
    2938   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2939   return FALSE;
     3525  dprintf(("CRTDLL: _stricoll\n"));
     3526  return stricmp(s1,s2);
    29403527}
    29413528
     
    29853572 *           CRTDLL__strnset     (CRTDLL.293)
    29863573 */
    2987 char * CDECL CRTDLL__strnset( char *string, int c, size_t len )
    2988 {
    2989   dprintf(("CRTDLL: _strnset not implemented.\n"));
    2990   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    2991   return FALSE;
     3574char * CDECL CRTDLL__strnset(char* szToFill, int szFill, size_t sizeMaxFill)
     3575{
     3576  dprintf(("CRTDLL: _strnset\n"));
     3577  char *t = szToFill;
     3578  int i = 0;
     3579  while( *szToFill != 0 && i < sizeMaxFill)
     3580  {
     3581        *szToFill = szFill;
     3582        szToFill++;
     3583        i++;
     3584  }
     3585  return t;
    29923586}
    29933587
     
    29963590 *           CRTDLL__strrev      (CRTDLL.294)
    29973591 */
    2998 char * CDECL CRTDLL__strrev( char *string )
    2999 {
    3000   dprintf(("CRTDLL: _strrev not implemented.\n"));
    3001   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    3002   return FALSE;
     3592char * CDECL CRTDLL__strrev( char *s )
     3593{
     3594  dprintf(("CRTDLL: _strrev\n"));
     3595  char  *e;
     3596  char   a;
     3597  e=s;
     3598  while (*e)
     3599        e++;
     3600  while (s<e) {
     3601        a=*s;
     3602        *s=*e;
     3603        *e=a;
     3604        s++;
     3605        e--;
     3606  }
     3607  return s;
    30033608}
    30043609
     
    30073612 *           CRTDLL__strset      (CRTDLL.295)
    30083613 */
    3009 char * CDECL CRTDLL__strset( char *string, int c )
    3010 {
    3011   dprintf(("CRTDLL: _strset not implemented.\n"));
    3012   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    3013   return FALSE;
     3614char * CDECL CRTDLL__strset(char* szToFill, int szFill)
     3615{
     3616  dprintf(("CRTDLL: _strset\n"));
     3617  char *t = szToFill;
     3618  while( *szToFill != 0 )
     3619  {
     3620        *szToFill = szFill;
     3621        szToFill++;
     3622  }
     3623  return t;
    30143624}
    30153625
     
    30863696
    30873697/*********************************************************************
    3088  *           CRTDLL__tzset       (CRTDLL.308)
     3698 *           _tzset      (CRTDLL.308)
    30893699 */
    30903700void CDECL CRTDLL__tzset( void )
     
    32763886{
    32773887  dprintf(("CRTDLL: _y1\n"));
    3278   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    32793888  return (_y1(x));
    32803889}
     
    33653974 *                  bsearch     (CRTDLL.346)
    33663975 */
    3367 void * CDECL CRTDLL_bsearch( const void *key, const void *base,  size_t nmemb,
    3368          size_t size, int (*compar)(const void *pkey, const void *pbase) )
    3369 {
    3370   dprintf(("CRTDLL: bsearch not implemented.\n"));
    3371   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    3372   return FALSE;
     3976void * CDECL CRTDLL_bsearch( const void *key, const void *base0,  size_t nelem,
     3977         size_t size, int (*cmp)(const void *ck, const void *ce))
     3978{
     3979  dprintf(("CRTDLL: bsearch\n"));
     3980  char *base = (char *)base0;
     3981  int lim, cmpval;
     3982  void *p;
     3983
     3984  for (lim = nelem; lim != 0; lim >>= 1)
     3985  {
     3986    p = base + (lim >> 1) * size;
     3987    cmpval = (*cmp)(key, p);
     3988    if (cmpval == 0)
     3989      return p;
     3990    if (cmpval > 0)
     3991    {                           /* key > p: move right */
     3992      base = (char *)p + size;
     3993      lim--;
     3994    } /* else move left */
     3995  }
     3996  return 0;
    33733997}
    33743998
     
    37984422/*********************************************************************
    37994423 *                  is_wctype    (CRTDLL.390)
    3800  *      FIXME - Could not find anything about it
    3801  */
    3802 INT CDECL CRTDLL_is_wctype(DWORD ret)
    3803 {
    3804         dprintf(("CRTDLL: is_wctype\n"));
     4424 */
     4425INT CDECL CRTDLL_is_wctype(wint_t wc, wctype_t wctypeFlags)
     4426{
     4427        dprintf(("CRTDLL: is_wctype not implemented.\n"));
    38054428        return 0;
    38064429}
     
    38714494 *                  iswascii    (CRTDLL.404)
    38724495 */
    3873 int CDECL CRTDLL_iswascii(wint_t i)
    3874 {
    3875   dprintf(("CRTDLL: iswascii(%08xh) not implemented.\n", i));
    3876   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    3877   return FALSE;
     4496int CDECL CRTDLL_iswascii(wint_t c)
     4497{
     4498  dprintf(("CRTDLL: iswascii\n", c));
     4499  return  (!((c)&(~0x7f)));
    38784500}
    38794501
     
    45545176  return FALSE;
    45555177}
     5178
     5179
     5180
     5181/*********************************************************************
     5182 *                  __set_errno    (INTERNAL-#1)
     5183 */
     5184int __set_errno (int error)
     5185{
     5186        errno = error;
     5187        return error;
     5188}
     5189
     5190
     5191/*********************************************************************
     5192 *                  _mbbtoupper    (INTERNAL-#2)
     5193 */
     5194unsigned int _mbbtoupper(unsigned int c)
     5195{
     5196        if (!CRTDLL__ismbblead(c) )
     5197                return toupper(c);
     5198       
     5199        return c;
     5200}
     5201
     5202
     5203/*********************************************************************
     5204 *                  _mbbtolower    (INTERNAL-#3)
     5205 */
     5206unsigned int _mbbtolower(unsigned int c)
     5207{
     5208        if (!CRTDLL__ismbblead(c) )
     5209                return tolower(c);
     5210        return c;
     5211}
     5212
     5213
     5214/*********************************************************************
     5215 *                  _mbclen2    (INTERNAL-#4)
     5216 */
     5217size_t _mbclen2(const unsigned int s)
     5218{
     5219        return (CRTDLL__ismbblead(s>>8) && CRTDLL__ismbbtrail(s&0x00FF)) ? 2 : 1;
     5220}
  • trunk/src/crtdll/crtinc.h

    r1160 r1207  
    1 /* $Id: crtinc.h,v 1.5 1999-10-07 09:28:49 sandervl Exp $ */
     1/* $Id: crtinc.h,v 1.6 1999-10-09 09:39:13 sandervl Exp $ */
    22
    33/* Definitions for the CRTDLL library (CRTDLL.DLL)
     
    66 */
    77
    8 
    98#define MB_LEN_MAX      2
    109#ifndef MAX_PATHNAME_LEN
     
    1211#endif
    1312
     13// Errno Defs
     14#define EAGAIN          11      /* Resource temporarily unavailable */
     15#define EINVAL          22      /* Invalid argument */
     16
     17
     18// MBC Defs
     19#define _MBC_SINGLE      0     
     20#define _MBC_LEAD        1     
     21#define _MBC_TRAIL       2             
     22#define _MBC_ILLEGAL    -1             
     23
     24#define _MB_CP_SBCS      0
     25#define _MB_CP_OEM      -2
     26#define _MB_CP_ANSI     -3
     27#define _MB_CP_LOCALE   -4
     28
     29#define _KNJ_M  ((char)0x01)    /* Non-punctuation of Kana-set */
     30#define _KNJ_P  ((char)0x02)    /* Punctuation of Kana-set */
     31#define _KNJ_1  ((char)0x04)    /* Legal 1st byte of double byte stream */
     32#define _KNJ_2  ((char)0x08)    /* Legal 2nd btye of double byte stream */
     33
     34#define ___     0
     35#define _1_     _KNJ_1 /* Legal 1st byte of double byte code */
     36#define __2     _KNJ_2 /* Legal 2nd byte of double byte code */
     37#define _M_     _KNJ_M /* Non-puntuation in Kana-set */
     38#define _P_     _KNJ_P /* Punctuation of Kana-set */
     39#define _12     (_1_|__2)
     40#define _M2     (_M_|__2)
     41#define _P2     (_P_|__2)
     42
     43#define CASE_DIFF (0x8281 - 0x8260)
     44
     45// Defs
    1446#define DOSFS_GetFullName(a,b,c) strcpy(c,a)
    1547
     
    3466    int   drive;
    3567} DOS_FULL_NAME;
     68
     69
     70#ifndef _DISKFREE_T_DEFINED
     71#define _DISKFREE_T_DEFINED
     72#define _DISKFREE_T_DEFINED_
     73struct _diskfree_t {
     74        unsigned total_clusters;
     75        unsigned avail_clusters;
     76        unsigned sectors_per_cluster;
     77        unsigned bytes_per_sector;
     78};
     79#define diskfree_t _diskfree_t
     80#endif
    3681
    3782
     
    89134long            CDECL CRTDLL__filelength( int i );
    90135VOID            CDECL CRTDLL__exit(DWORD ret);
     136INT             CDECL CRTDLL_isalnum(int i);
     137int             CDECL CRTDLL_isgraph(int i);
     138int             CDECL CRTDLL__access(const char *path,int mode);
     139int             CDECL CRTDLL__getch(void);
     140size_t          CDECL CRTDLL_fread( void *ptr, size_t size, size_t n, FILE *fp );
     141int             CDECL CRTDLL__mbbtype( unsigned char c, int type );
     142LPSTR           CDECL CRTDLL__mbsinc( LPCSTR str );
     143int             CDECL CRTDLL__ismbbkalnum( unsigned int c );
     144int             CDECL CRTDLL__ismbbkana( unsigned int c );
     145int             CDECL CRTDLL__ismbbalpha( unsigned int c );
     146int             CDECL CRTDLL__ismbbtrail( unsigned int c );
     147int             CDECL CRTDLL__ismbblead( unsigned int c );
     148char *          CDECL CRTDLL_getenv( const char *name );
     149
     150//
     151// Definitions for internal functions
     152//
     153int             __set_errno (int error);
     154unsigned int    _mbbtoupper(unsigned int c);
     155unsigned int    _mbbtolower(unsigned int c);
     156size_t          _mbclen2(const unsigned int s);
     157
     158
     159//
     160// MBC Includes
     161//
     162static unsigned short han_to_zen_ascii_table[0x5f] = {
     163  0x8140, 0x8149, 0x8168, 0x8194, 0x8190, 0x8193, 0x8195, 0x8166,
     164  0x8169, 0x816a, 0x8196, 0x817b, 0x8143, 0x817c, 0x8144, 0x815e,
     165  0x824f, 0x8250, 0x8251, 0x8252, 0x8253, 0x8254, 0x8255, 0x8256,
     166  0x8257, 0x8258, 0x8146, 0x8147, 0x8183, 0x8181, 0x8184, 0x8148,
     167  0x8197, 0x8260, 0x8261, 0x8262, 0x8263, 0x8264, 0x8265, 0x8266,
     168  0x8267, 0x8268, 0x8269, 0x826a, 0x826b, 0x826c, 0x826d, 0x826e,
     169  0x826f, 0x8270, 0x8271, 0x8272, 0x8273, 0x8274, 0x8275, 0x8276,
     170  0x8277, 0x8278, 0x8279, 0x816d, 0x818f, 0x816e, 0x814f, 0x8151,
     171  0x8165, 0x8281, 0x8282, 0x8283, 0x8284, 0x8285, 0x8286, 0x8287,
     172  0x8288, 0x8289, 0x828a, 0x828b, 0x828c, 0x828d, 0x828e, 0x828f,
     173  0x8290, 0x8291, 0x8292, 0x8293, 0x8294, 0x8295, 0x8296, 0x8297,
     174  0x8298, 0x8299, 0x829a, 0x816f, 0x8162, 0x8170, 0x8150
     175};
     176static unsigned short han_to_zen_kana_table[0x40] = {
     177  0x8140, 0x8142, 0x8175, 0x8176, 0x8141, 0x8145, 0x8392, 0x8340,
     178  0x8342, 0x8344, 0x8346, 0x8348, 0x8383, 0x8385, 0x8387, 0x8362,
     179  0x815b, 0x8341, 0x8343, 0x8345, 0x8347, 0x8349, 0x834a, 0x834c,
     180  0x834e, 0x8350, 0x8352, 0x8354, 0x8356, 0x8358, 0x835a, 0x835c,
     181  0x835e, 0x8360, 0x8363, 0x8365, 0x8367, 0x8369, 0x836a, 0x836b,
     182  0x836c, 0x836d, 0x836e, 0x8371, 0x8374, 0x8377, 0x837a, 0x837d,
     183  0x837e, 0x8380, 0x8381, 0x8382, 0x8384, 0x8386, 0x8388, 0x8389,
     184  0x838a, 0x838b, 0x838c, 0x838d, 0x838f, 0x8393, 0x814a, 0x814b
     185};
     186static unsigned char zen_to_han_kana_table[0x8396-0x8340+1] = {
     187  0xa7, 0xb1, 0xa8, 0xb2, 0xa9, 0xb3, 0xaa, 0xb4,
     188  0xab, 0xb5, 0xb6, 0xb6, 0xb7, 0xb7, 0xb8, 0xb8,
     189  0xb9, 0xb9, 0xba, 0xba, 0xbb, 0xbb, 0xbc, 0xbc,
     190  0xbd, 0xbd, 0xbe, 0xbe, 0xbf, 0xbf, 0xc0, 0xc0,
     191  0xc1, 0xc1, 0xaf, 0xc2, 0xc2, 0xc3, 0xc3, 0xc4,
     192  0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xca,
     193  0xca, 0xcb, 0xcb, 0xcb, 0xcc, 0xcc, 0xcc, 0xcd,
     194  0xcd, 0xcd, 0xce, 0xce, 0xce, 0xcf, 0xd0, 0,
     195  0xd1, 0xd2, 0xd3, 0xac, 0xd4, 0xad, 0xd5, 0xae,
     196  0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdc,
     197  0xb2, 0xb4, 0xa6, 0xdd, 0xb3, 0xb6, 0xb9
     198};
     199#define ZTOH_SYMBOLS 9
     200static unsigned short zen_to_han_symbol_table_1[ZTOH_SYMBOLS] = {
     201  0x8142, 0x8175, 0x8176, 0x8141, 0x8145, 0x815b, 0x814a, 0x814b
     202};
     203static unsigned char zen_to_han_symbol_table_2[ZTOH_SYMBOLS] = {
     204  0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xb0, 0xde, 0xdf
     205};
     206#define ISKANA(c) ((c) >= 0xa1 && (c) <= 0xdf)
     207#define JISHIRA(c) ((c) >= 0x829f && (c) <= 0x82f1)
     208#define JISKANA(c) ((c) >= 0x8340 && (c) <= 0x8396 && (c) != 0x837f)
     209#define JTOKANA(c) ((c) <= 0x82dd ? (c) + 0xa1 : (c) + 0xa2)
     210
     211char _jctype[257] = {
     212/*-1*/  ___,
     213/*0x*/  ___,___,___,___,___,___,___,___,___,___,___,___,___,___,___,___,
     214/*1x*/  ___,___,___,___,___,___,___,___,___,___,___,___,___,___,___,___,
     215/*2x*/  ___,___,___,___,___,___,___,___,___,___,___,___,___,___,___,___,
     216/*3x*/  ___,___,___,___,___,___,___,___,___,___,___,___,___,___,___,___,
     217/*4x*/  __2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,
     218/*5x*/  __2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,
     219/*6x*/  __2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,
     220/*7x*/  __2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,___,
     221/*8x*/  __2,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,
     222/*9x*/  _12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,
     223/*Ax*/  __2,_P2,_P2,_P2,_P2,_P2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,
     224/*Bx*/  _M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,
     225/*Cx*/  _M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,
     226/*Dx*/  _M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,
     227/*Ex*/  _12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,
     228/*Fx*/  _12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,___,___,___
     229};
Note: See TracChangeset for help on using the changeset viewer.