1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22/* 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27#pragma ident "%Z%%M% %I% %E% SMI" 28 29 .file "%M%" 30 31/ 32/ Wide character wcsncpy() implementation 33/ 34/ Algorithm based on Solaris 2.6 gen/strncpy.s implementation 35/ 36 37#include "SYS.h" 38 39 ANSI_PRAGMA_WEAK(wcsncmp,function) 40 ANSI_PRAGMA_WEAK(wsncmp,function) 41 42 ENTRY(wcsncmp) 43 pushl %esi / save register variables 44 movl 8(%esp),%esi / %esi = first string 45 movl %edi,%edx 46 movl 12(%esp),%edi / %edi = second string 47 cmpl %esi,%edi / same string? 48 je .equal 49 movl 16(%esp),%ecx / %ecx = length 50 incl %ecx / will later predecrement this uint 51.loop: 52 decl %ecx 53 je .equal / Used all n chars? 54 movl (%esi),%eax / slodb ; scab 55 cmpl (%edi),%eax 56 jne .notequal_0 / Are the bytes equal? 57 testl %eax,%eax 58 je .equal / End of string? 59 60 decl %ecx 61 je .equal / Used all n chars? 62 movl 4(%esi),%eax / slodb ; scab 63 cmpl 4(%edi),%eax 64 jne .notequal_1 / Are the bytes equal? 65 testl %eax,%eax 66 je .equal / End of string? 67 68 decl %ecx 69 je .equal / Used all n chars? 70 movl 8(%esi),%eax / slodb ; scab 71 cmpl 8(%edi),%eax 72 jne .notequal_2 / Are the bytes equal? 73 testl %eax,%eax 74 je .equal / End of string? 75 76 decl %ecx 77 je .equal / Used all n chars? 78 movl 12(%esi),%eax / slodb ; scab 79 cmpl 12(%edi),%eax 80 jne .notequal_3 / Are the bytes equal? 81 addl $16,%esi 82 addl $16,%edi 83 testl %eax,%eax 84 jne .loop / End of string? 85 86.equal: 87 popl %esi / restore registers 88 xorl %eax,%eax / return 0 89 movl %edx,%edi 90 ret 91 92 .align 4 93.notequal_3: 94 addl $4,%edi 95.notequal_2: 96 addl $4,%edi 97.notequal_1: 98 addl $4,%edi 99.notequal_0: 100 popl %esi / restore registers 101 subl (%edi),%eax / return value is (*s1 - *--s2) 102 movl %edx,%edi 103 ret 104 SET_SIZE(wcsncmp) 105 106 ENTRY(wsncmp) 107 _prologue_ 108 movl _esp_(12),%ecx 109 movl _esp_(8),%eax 110 movl _esp_(4),%edx 111 pushl %ecx 112 pushl %eax 113 pushl %edx 114 call _fref_(wcsncmp) 115 addl $12,%esp 116 _epilogue_ 117 ret 118 SET_SIZE(wsncmp) 119