7712 mandoc -Tlint does always exit with error code 0
[unleashed.git] / usr / src / lib / lvm / libmeta / common / metasplitname.c
blobafa4e4e33a6d4cf6133adbf24a848692c4ce986f
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
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
33 #include <meta.h>
35 int
36 splitname(char *name, md_splitname *spn)
38 size_t prefixlen;
39 size_t suffixlen;
40 char *lastslash;
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 */
47 } else {
48 prefixlen = 0;
49 suffixlen = strlen(name);
51 if (prefixlen > MD_MAXPREFIX)
52 return (METASPLIT_LONGPREFIX);
54 if (suffixlen > MD_MAXSUFFIX) {
55 lastslash = META_LONGDISKNAME_STR;
56 prefixlen = 0;
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;
61 } else {
62 (void) memcpy(SPN_SUFFIX(spn).suf_data, lastslash + 1,
63 suffixlen);
64 SPN_SUFFIX(spn).suf_len = suffixlen;
67 (void) memcpy(SPN_PREFIX(spn).pre_data, name, prefixlen);
68 SPN_PREFIX(spn).pre_len = prefixlen;
70 return (retval);
73 char *
74 splicename(md_splitname *spn)
76 char *name;
77 char *suffix;
78 size_t prefixlen;
79 size_t suffixlen;
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;
89 return (name);