1 |
207 |
jeremybenn |
/*******************************************************************************
|
2 |
|
|
*
|
3 |
|
|
* Copyright (c) 1993 Intel Corporation
|
4 |
|
|
*
|
5 |
|
|
* Intel hereby grants you permission to copy, modify, and distribute this
|
6 |
|
|
* software and its documentation. Intel grants this permission provided
|
7 |
|
|
* that the above copyright notice appears in all copies and that both the
|
8 |
|
|
* copyright notice and this permission notice appear in supporting
|
9 |
|
|
* documentation. In addition, Intel grants this permission provided that
|
10 |
|
|
* you prominently mark as "not part of the original" any modifications
|
11 |
|
|
* made to this software or documentation, and that the name of Intel
|
12 |
|
|
* Corporation not be used in advertising or publicity pertaining to
|
13 |
|
|
* distribution of the software or the documentation without specific,
|
14 |
|
|
* written prior permission.
|
15 |
|
|
*
|
16 |
|
|
* Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR
|
17 |
|
|
* IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY
|
18 |
|
|
* OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or
|
19 |
|
|
* representations regarding the use of, or the results of the use of,
|
20 |
|
|
* the software and documentation in terms of correctness, accuracy,
|
21 |
|
|
* reliability, currentness, or otherwise; and you rely on the software,
|
22 |
|
|
* documentation and results solely at your own risk.
|
23 |
|
|
*
|
24 |
|
|
* IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS,
|
25 |
|
|
* LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES
|
26 |
|
|
* OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM
|
27 |
|
|
* PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER.
|
28 |
|
|
*
|
29 |
|
|
******************************************************************************/
|
30 |
|
|
|
31 |
|
|
.file "strdup.s"
|
32 |
|
|
#ifdef __PIC
|
33 |
|
|
.pic
|
34 |
|
|
#endif
|
35 |
|
|
#ifdef __PID
|
36 |
|
|
.pid
|
37 |
|
|
#endif
|
38 |
|
|
|
39 |
|
|
/*
|
40 |
|
|
* (c) copyright 1989,1993 Intel Corp., all rights reserved
|
41 |
|
|
*/
|
42 |
|
|
|
43 |
|
|
/*
|
44 |
|
|
procedure strdup (optimized assembler version: 80960K series, 80960CA)
|
45 |
|
|
|
46 |
|
|
dest_addr = strdup (src_addr)
|
47 |
|
|
|
48 |
|
|
Allocate memory and copy thereto the string pointed to by src_addr.
|
49 |
|
|
Return the address of the copy, or null if unable to perform the
|
50 |
|
|
operation.
|
51 |
|
|
*/
|
52 |
|
|
|
53 |
|
|
.text
|
54 |
|
|
.align 2
|
55 |
|
|
.globl _strdup
|
56 |
|
|
_strdup:
|
57 |
|
|
mov g0,r3 # Keep a copy of the original string addr
|
58 |
|
|
callj _strlen # Determine how much to allocate
|
59 |
|
|
addo 1,g0,g0 # Add one byte for the null byte at end
|
60 |
|
|
callj _malloc # Allocate the storage
|
61 |
|
|
cmpo 0,g0
|
62 |
|
|
mov r3,g1 # Original string addr is now src for copy
|
63 |
|
|
bne.t _strcpy # Jump if allocation was successful
|
64 |
|
|
ret # Return the null ptr otherwise
|
65 |
|
|
|
66 |
|
|
/* end of strdup */
|