1/*******************************************************************************
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#include <picolibc.h>
32
33	.file "strdup.s"
34#ifdef	__PIC
35	.pic
36#endif
37#ifdef	__PID
38	.pid
39#endif
40
41/*
42 * (c) copyright 1989,1993 Intel Corp., all rights reserved
43 */
44
45/*
46	procedure strdup  (optimized assembler version: 80960K series, 80960CA)
47
48	dest_addr = strdup (src_addr)
49
50	Allocate memory and copy thereto the string pointed to by src_addr.
51	Return the address of the copy, or null if unable to perform the
52	operation.
53*/
54
55	.text
56	.align	2
57	.globl	_strdup
58_strdup:
59	mov	g0,r3		# Keep a copy of the original string addr
60	callj	_strlen		# Determine how much to allocate
61	addo	1,g0,g0		# Add one byte for the null byte at end
62	callj	_malloc		# Allocate the storage
63	cmpo	0,g0
64	mov	r3,g1		# Original string addr is now src for copy
65	bne.t	_strcpy		# Jump if allocation was successful
66	ret			# Return the null ptr otherwise
67
68/* end of strdup */
69