Unnamed Fossil Project

Check-in [48f7346e40]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:import missing functions from illumos
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:48f7346e4048d13898786a15353a5f8daec3b1a9
User & Date: labla 2012-05-17 19:11:32
Context
2012-05-17
19:16
fix headers in imported compat files check-in: 28b3fd99fc user: labla tags: trunk
19:11
import missing functions from illumos check-in: 48f7346e40 user: labla tags: trunk
19:09
add missing headers and missing declarations check-in: 1e5b57e115 user: labla tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added wsdup.c.













































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
 */

/*	Copyright (c) 1986 AT&T	*/
/*	  All Rights Reserved  	*/

/*
 *	string duplication
 *	returns pointer to a new string which is the duplicate of string
 *	pointed to by s1
 *	NULL is returned if new string can't be created
 */

#include "lint.h"
#include <stdlib.h>
#include <widec.h>
#include "libc.h"

wchar_t *
wcsdup(const wchar_t *s1)
{
	wchar_t *s2;

	s2 = malloc((wcslen(s1) + 1) * sizeof (wchar_t));
	return (s2 == NULL ? NULL : wcscpy(s2, s1));
}

wchar_t *
wsdup(const wchar_t *s1)
{
	return (wcsdup(s1));
}

Added wslen.c.

















































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*	Copyright (c) 1986 AT&T	*/
/*	  All Rights Reserved  	*/

#pragma ident	"%Z%%M%	%I%	%E% SMI"

/*
 * Returns the number of non-NULL characters in s.
 */

#pragma weak _wcslen = wcslen
#pragma weak _wslen = wslen

#include <stdlib.h>
#include <wchar.h>

size_t
wcslen(const wchar_t *s)
{
	const wchar_t *s0 = s + 1;

	while (*s++)
		;
	return (s - s0);
}

size_t
wslen(const wchar_t *s)
{
	return (wcslen(s));
}

Added wsprintf.c.



































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*	Copyright (c) 1986 AT&T	*/
/*	  All Rights Reserved  	*/

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include "lint.h"
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <widec.h>
#include <string.h>
#include <limits.h>

/*
 * 	wsprintf -- this function will output a wchar_t string
 *		    according to the conversion format.
 *		    Note that the maximum length of the output
 *		    string is 1024 bytes.
 */

/*VARARGS2*/
int
wsprintf(wchar_t *wstring, const char *format, ...)
{
	va_list	ap;
	char	tempstring[1024];
	char *p2;
	size_t len;
	int malloced = 0;
	char *p1 = (char *)wstring;
	int retcode;
	int	i;

	va_start(ap, format);
	if (vsprintf(p1, format, ap) == -1) {
		va_end(ap);
		return (-1);
	}
	va_end(ap);
	len = strlen(p1) + 1;
	if (len > 1024) {
		p2 = malloc(len);
		if (p2 == NULL)
			return (-1);
		malloced = 1;
	} else
		p2 = tempstring;
	(void) strcpy(p2, p1);

	if (mbstowcs(wstring, p2, len) == (size_t)-1) {
		for (i = 0; i < len; i++) {
			if ((retcode = mbtowc(wstring, p2, MB_CUR_MAX)) == -1) {
				*wstring = (wchar_t)*p2 & 0xff;
				p2++;
			} else {
				p2 += retcode;
			}
			if (*wstring++ == (wchar_t)0) {
				break;
			}
		}
	}

	if (malloced == 1)
		free(p2);
	len = wcslen(wstring);
	if (len <= INT_MAX)
		return ((int)len);
	else
		return (EOF);
}