summaryrefslogtreecommitdiffstats
path: root/private/crt32/convert/towupper.c
blob: 177da7e07761db770a7ee9ea9e56189a4e61482d (plain) (blame)
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
/***
*towupper.c - convert wide character to upper case
*
*	Copyright (c) 1985-1992, Microsoft Corporation. All rights reserved.
*
*Purpose:
*	Defines towupper().
*
*Revision History:
*	10-11-91  ETC	Created.
*	12-10-91  ETC	Updated nlsapi; added multithread.
*	04-06-92  KRS	Make work without _INTL also.
*       01-19-93  CFW   Changed LCMapString to LCMapStringW.
*       06-02-93  SRW   ignore _INTL if _NTSUBSET_ defined.
*	06-11-93  CFW	Fix error handling bug.
*       01-14-94  SRW   if _NTSUBSET_ defined call Rtl functions
*
*******************************************************************************/

#ifdef _NTSUBSET_
#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>
#endif
#include <cruntime.h>
#include <ctype.h>
#include <stdio.h>
#include <locale.h>
#ifdef _INTL
#include <setlocal.h>
#include <os2dll.h>
#endif

/***
*wchar_t towupper(c) - convert wide character to upper case
*
*Purpose:
*	towupper() returns the uppercase equivalent of its argument
*
*Entry:
*	c - wchar_t value of character to be converted
*
*Exit:
*	if c is a lower case letter, returns wchar_t value of upper case
*	representation of c. otherwise, it returns c.
*
*Exceptions:
*
*******************************************************************************/

wchar_t _CALLTYPE1 towupper (
	wchar_t c
	)
{
#if defined(_INTL) && !defined(_NTSUBSET_)
	wchar_t widechar;

	if (c == WEOF)
		return c;

	_mlock (_LC_CTYPE_LOCK);

	if (_lc_handle[LC_CTYPE] == _CLOCALEHANDLE) {
		if (iswlower(c))
			c = c - L'a' + L'A';
		_munlock (_LC_CTYPE_LOCK);
		return c;
	}

	/* if checking case of c does not require API call, do it */
	if (c < 256) {
		if (!iswlower(c)) {
			_munlock (_LC_CTYPE_LOCK);
			return c;
		}
	}

	/* convert wide char to uppercase */
	if (LCMapStringW(_lc_handle[LC_CTYPE], LCMAP_UPPERCASE, 
		(LPCWSTR)&c, 1, (LPWSTR)&widechar, 1) == 0) {
			_munlock (_LC_CTYPE_LOCK);
			return c;
	}
	
	_munlock (_LC_CTYPE_LOCK);
	return widechar;
#else
#ifdef _NTSUBSET_
        return RtlUpcaseUnicodeChar( c );
#else
	return (iswlower(c) ? (c - (wchar_t)(L'a' - L'A')) : c);
#endif
#endif /* _INTL */
}