xref: /netbsd-src/sys/fs/ntfs/ntfs_conv.c (revision 14c9669847f16225ecd8967d977ffad240a620ca)
1*14c96698Smaxv /*	$NetBSD: ntfs_conv.c,v 1.10 2015/02/20 17:08:13 maxv Exp $	*/
29accf4dfSjdolecek 
39accf4dfSjdolecek /*-
49accf4dfSjdolecek  * Copyright (c) 2001 The NetBSD Foundation, Inc.
59accf4dfSjdolecek  * All rights reserved.
69accf4dfSjdolecek  *
79accf4dfSjdolecek  * Redistribution and use in source and binary forms, with or without
89accf4dfSjdolecek  * modification, are permitted provided that the following conditions
99accf4dfSjdolecek  * are met:
109accf4dfSjdolecek  * 1. Redistributions of source code must retain the above copyright
119accf4dfSjdolecek  *    notice, this list of conditions and the following disclaimer.
129accf4dfSjdolecek  * 2. Redistributions in binary form must reproduce the above copyright
139accf4dfSjdolecek  *    notice, this list of conditions and the following disclaimer in the
149accf4dfSjdolecek  *    documentation and/or other materials provided with the distribution.
159accf4dfSjdolecek  *
169accf4dfSjdolecek  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
179accf4dfSjdolecek  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
189accf4dfSjdolecek  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
199accf4dfSjdolecek  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
209accf4dfSjdolecek  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
219accf4dfSjdolecek  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
229accf4dfSjdolecek  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
239accf4dfSjdolecek  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
249accf4dfSjdolecek  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
259accf4dfSjdolecek  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
269accf4dfSjdolecek  * POSSIBILITY OF SUCH DAMAGE.
279accf4dfSjdolecek  */
289accf4dfSjdolecek 
299accf4dfSjdolecek /*
309accf4dfSjdolecek  * File name recode stuff.
319accf4dfSjdolecek  */
329accf4dfSjdolecek 
339accf4dfSjdolecek #include <sys/cdefs.h>
34*14c96698Smaxv __KERNEL_RCSID(0, "$NetBSD: ntfs_conv.c,v 1.10 2015/02/20 17:08:13 maxv Exp $");
359accf4dfSjdolecek 
369accf4dfSjdolecek #include <sys/param.h>
379accf4dfSjdolecek #include <sys/systm.h>
389accf4dfSjdolecek #include <sys/namei.h>
399accf4dfSjdolecek #include <sys/kernel.h>
409accf4dfSjdolecek #include <sys/mount.h>
419accf4dfSjdolecek #include <sys/malloc.h>
429accf4dfSjdolecek 
439accf4dfSjdolecek #include <fs/ntfs/ntfs.h>
449accf4dfSjdolecek #include <fs/ntfs/ntfs_inode.h>
459accf4dfSjdolecek #include <fs/ntfs/ntfs_subr.h>
469accf4dfSjdolecek 
479accf4dfSjdolecek /* UTF-8 encoding stuff */
48a38a5c8cSjdolecek #include <fs/unicode.h>
499accf4dfSjdolecek 
509accf4dfSjdolecek /*
519accf4dfSjdolecek  * Read one wide character off the string, shift the string pointer
529accf4dfSjdolecek  * and return the character.
539accf4dfSjdolecek  */
549accf4dfSjdolecek wchar
ntfs_utf8_wget(const char ** str,size_t * sz)552ce9f451Sjdolecek ntfs_utf8_wget(const char **str, size_t *sz)
569accf4dfSjdolecek {
572ce9f451Sjdolecek 	return (wchar) wget_utf8(str, sz);
589accf4dfSjdolecek }
599accf4dfSjdolecek 
609accf4dfSjdolecek /*
619accf4dfSjdolecek  * Encode wide character and write it to the string. 'n' specifies
629accf4dfSjdolecek  * how much space there is in the string. Returns number of bytes written
639accf4dfSjdolecek  * to the target string.
649accf4dfSjdolecek  */
659accf4dfSjdolecek int
ntfs_utf8_wput(char * s,size_t n,wchar wc)669accf4dfSjdolecek ntfs_utf8_wput(char *s, size_t n, wchar wc)
679accf4dfSjdolecek {
68a38a5c8cSjdolecek 	return wput_utf8(s, n, (u_int16_t) wc);
699accf4dfSjdolecek }
709accf4dfSjdolecek 
719accf4dfSjdolecek /*
729accf4dfSjdolecek  * Compare two wide characters, returning 1, 0, -1 if the first is
739accf4dfSjdolecek  * bigger, equal or lower than the second.
749accf4dfSjdolecek  */
759accf4dfSjdolecek int
ntfs_utf8_wcmp(wchar wc1,wchar wc2)769accf4dfSjdolecek ntfs_utf8_wcmp(wchar wc1, wchar wc2)
779accf4dfSjdolecek {
789accf4dfSjdolecek 	/* no conversions needed for utf8 */
799accf4dfSjdolecek 
809accf4dfSjdolecek 	if (wc1 == wc2)
819accf4dfSjdolecek 		return 0;
829accf4dfSjdolecek 	else
839accf4dfSjdolecek 		return (int) wc1 - (int) wc2;
849accf4dfSjdolecek }
85