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.
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.
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]
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * split and splice name
36 splitname(char *name
, md_splitname
*spn
)
41 int retval
= METASPLIT_SUCCESS
;
43 lastslash
= strrchr(name
, '/');
44 if (lastslash
!= NULL
) {
45 prefixlen
= lastslash
- name
;
46 suffixlen
= (strlen(name
) - prefixlen
) - 1; /* slash dropped */
49 suffixlen
= strlen(name
);
51 if (prefixlen
> MD_MAXPREFIX
)
52 return (METASPLIT_LONGPREFIX
);
54 if (suffixlen
> MD_MAXSUFFIX
) {
55 lastslash
= META_LONGDISKNAME_STR
;
57 suffixlen
= strlen(lastslash
);
58 (void) memcpy(SPN_SUFFIX(spn
).suf_data
, lastslash
, suffixlen
);
59 SPN_SUFFIX(spn
).suf_len
= suffixlen
;
60 retval
= METASPLIT_LONGDISKNAME
;
62 (void) memcpy(SPN_SUFFIX(spn
).suf_data
, lastslash
+ 1,
64 SPN_SUFFIX(spn
).suf_len
= suffixlen
;
67 (void) memcpy(SPN_PREFIX(spn
).pre_data
, name
, prefixlen
);
68 SPN_PREFIX(spn
).pre_len
= prefixlen
;
74 splicename(md_splitname
*spn
)
81 prefixlen
= SPN_PREFIX(spn
).pre_len
;
82 suffixlen
= SPN_SUFFIX(spn
).suf_len
;
83 name
= Malloc(prefixlen
+ suffixlen
+ 2);
84 (void) memcpy(name
, SPN_PREFIX(spn
).pre_data
, prefixlen
);
85 name
[prefixlen
] = '/';
86 suffix
= name
+ (prefixlen
+ 1);
87 (void) memcpy(suffix
, SPN_SUFFIX(spn
).suf_data
, suffixlen
);
88 name
[prefixlen
+ suffixlen
+ 1] = 0;