The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/fs/jfs/jfs_unicode.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  *   Copyright (c) International Business Machines Corp., 2000-2002
    3  *
    4  *   This program is free software;  you can redistribute it and/or modify
    5  *   it under the terms of the GNU General Public License as published by
    6  *   the Free Software Foundation; either version 2 of the License, or 
    7  *   (at your option) any later version.
    8  * 
    9  *   This program is distributed in the hope that it will be useful,
   10  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
   11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
   12  *   the GNU General Public License for more details.
   13  *
   14  *   You should have received a copy of the GNU General Public License
   15  *   along with this program;  if not, write to the Free Software 
   16  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
   17  */
   18 
   19 #include <linux/fs.h>
   20 #include <linux/slab.h>
   21 #include "jfs_types.h"
   22 #include "jfs_filsys.h"
   23 #include "jfs_unicode.h"
   24 #include "jfs_debug.h"
   25 
   26 /*
   27  * NAME:        jfs_strfromUCS()
   28  *
   29  * FUNCTION:    Convert little-endian unicode string to character string
   30  *
   31  */
   32 int jfs_strfromUCS_le(char *to, const wchar_t * from,   /* LITTLE ENDIAN */
   33                       int len, struct nls_table *codepage)
   34 {
   35         int i;
   36         int outlen = 0;
   37 
   38         for (i = 0; (i < len) && from[i]; i++) {
   39                 int charlen;
   40                 charlen =
   41                     codepage->uni2char(le16_to_cpu(from[i]), &to[outlen],
   42                                        NLS_MAX_CHARSET_SIZE);
   43                 if (charlen > 0) {
   44                         outlen += charlen;
   45                 } else {
   46                         to[outlen++] = '?';
   47                 }
   48         }
   49         to[outlen] = 0;
   50         return outlen;
   51 }
   52 
   53 /*
   54  * NAME:        jfs_strtoUCS()
   55  *
   56  * FUNCTION:    Convert character string to unicode string
   57  *
   58  */
   59 int jfs_strtoUCS(wchar_t * to,
   60                  const char *from, int len, struct nls_table *codepage)
   61 {
   62         int charlen;
   63         int i;
   64 
   65         for (i = 0; len && *from; i++, from += charlen, len -= charlen) {
   66                 charlen = codepage->char2uni(from, len, &to[i]);
   67                 if (charlen < 1) {
   68                         jfs_err("jfs_strtoUCS: char2uni returned %d.", charlen);
   69                         jfs_err("charset = %s, char = 0x%x",
   70                                 codepage->charset, (unsigned char) *from);
   71                         to[i] = 0x003f; /* a question mark */
   72                         charlen = 1;
   73                 }
   74         }
   75 
   76         to[i] = 0;
   77         return i;
   78 }
   79 
   80 /*
   81  * NAME:        get_UCSname()
   82  *
   83  * FUNCTION:    Allocate and translate to unicode string
   84  *
   85  */
   86 int get_UCSname(struct component_name * uniName, struct dentry *dentry,
   87                 struct nls_table *nls_tab)
   88 {
   89         int length = dentry->d_name.len;
   90 
   91         if (length > JFS_NAME_MAX)
   92                 return ENAMETOOLONG;
   93 
   94         uniName->name =
   95             kmalloc((length + 1) * sizeof(wchar_t), GFP_NOFS);
   96 
   97         if (uniName->name == NULL)
   98                 return ENOSPC;
   99 
  100         uniName->namlen = jfs_strtoUCS(uniName->name, dentry->d_name.name,
  101                                        length, nls_tab);
  102 
  103         return 0;
  104 }

Cache object: 3a8906c51d2dcb45efa7946bf23fcdc2


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.