Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /****************************************************************************
  2. *
  3. *                            Open Watcom Project
  4. *
  5. *    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
  6. *
  7. *  ========================================================================
  8. *
  9. *    This file contains Original Code and/or Modifications of Original
  10. *    Code as defined in and that are subject to the Sybase Open Watcom
  11. *    Public License version 1.0 (the 'License'). You may not use this file
  12. *    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
  13. *    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
  14. *    provided with the Original Code and Modifications, and is also
  15. *    available at www.sybase.com/developer/opensource.
  16. *
  17. *    The Original Code and all software distributed under the License are
  18. *    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  19. *    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
  20. *    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
  21. *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
  22. *    NON-INFRINGEMENT. Please see the License for the specific language
  23. *    governing rights and limitations under the License.
  24. *
  25. *  ========================================================================
  26. *
  27. * Description:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
  28. *               DESCRIBE IT HERE!
  29. *
  30. ****************************************************************************/
  31.  
  32.  
  33. #include "variety.h"
  34. #include "widechar.h"
  35. #include <stdio.h>
  36. #include <string.h>
  37.  
  38. #if defined(M_I86) && !defined(__WIDECHAR__)
  39.  
  40. extern char *_fast_strncat( char _WCFAR *, const char *, size_t );
  41.  
  42. #if defined(__SMALL_DATA__)
  43.  
  44. #pragma aux _fast_strncat = \
  45.         0x57            /* push di */\
  46.         0xb9 0xff 0xff  /* mov cx,ffffh */\
  47.         0x31 0xc0       /* xor ax,ax */\
  48.         0xf2 0xae       /* repne scasb */\
  49.         0x4f            /* dec di */\
  50.         0x89 0xd1       /* mov cx,dx */\
  51.         0xac            /* L1: lodsb */\
  52.         0xaa            /* stosb */\
  53.         0x84 0xc0       /* test al,al */\
  54.         0xe0 0xfa       /* loopne L1 */\
  55.         0x74 0x03       /* je L2 */\
  56.         0x26 0x88 0x25  /* mov es:[di],ah */\
  57.         0x58            /* L2: pop ax */\
  58.         parm caller     [es di] [si] [dx]\
  59.         value           [ax] \
  60.         modify exact    [ax cx si di];
  61.  
  62. #else
  63.  
  64. #pragma aux _fast_strncat = \
  65.         0x1e            /* push ds */ \
  66.         0x8e 0xd9       /* mov ds,cx */ \
  67.         0x57            /* push di */\
  68.         0xb9 0xff 0xff  /* mov cx,ffffh */\
  69.         0x31 0xc0       /* xor ax,ax */\
  70.         0xf2 0xae       /* repne scasb */\
  71.         0x4f            /* dec di */\
  72.         0x89 0xd1       /* mov cx,dx */\
  73.         0xac            /* L1: lodsb */\
  74.         0xaa            /* stosb */\
  75.         0x84 0xc0       /* test al,al */\
  76.         0xe0 0xfa       /* loopne L1 */\
  77.         0x74 0x03       /* je L2 */\
  78.         0x26 0x88 0x25  /* mov es:[di],ah */\
  79.         0x58            /* L2: pop ax */\
  80.         0x1f            /* pop ds */ \
  81.         parm caller     [es di] [cx si] [dx]\
  82.         value           [es ax] \
  83.         modify exact    [ax cx si di];
  84. #endif
  85.  
  86. #endif
  87.  
  88.  
  89. /* concatenate t to the end of dst */
  90.  
  91. _WCRTLINK CHAR_TYPE *__F_NAME(strncat,wcsncat) ( CHAR_TYPE *dst, const CHAR_TYPE *t, size_t n )
  92.     {
  93. #if defined(M_I86) && !defined(__WIDECHAR__)
  94.         if( n ) {
  95.             return( _fast_strncat( dst, t, n ) );
  96.         }
  97.         return( dst );
  98. #else
  99.         CHAR_TYPE *s;
  100.  
  101.         #ifdef __WIDECHAR__
  102.             s = dst + wcslen( dst );
  103.         #else
  104.             s = memchr( dst, NULLCHAR, ~0u );
  105.         #endif
  106.         while( n != 0 ) {
  107.             *s = *t;
  108.             if( *s == NULLCHAR ) break;
  109.             ++s;
  110.             ++t;
  111.             --n;
  112.         }
  113.         *s = NULLCHAR;
  114.         return( dst );
  115. #endif
  116.     }
  117.