nls.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef _LINUX_NLS_H
  2. #define _LINUX_NLS_H
  3. #include <linux/init.h>
  4. /* unicode character */
  5. typedef __u16 wchar_t;
  6. struct nls_table {
  7. char *charset;
  8. char *alias;
  9. int (*uni2char) (wchar_t uni, unsigned char *out, int boundlen);
  10. int (*char2uni) (const unsigned char *rawstring, int boundlen,
  11. wchar_t *uni);
  12. unsigned char *charset2lower;
  13. unsigned char *charset2upper;
  14. struct module *owner;
  15. struct nls_table *next;
  16. };
  17. /* this value hold the maximum octet of charset */
  18. #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
  19. /* nls.c */
  20. extern int register_nls(struct nls_table *);
  21. extern int unregister_nls(struct nls_table *);
  22. extern struct nls_table *load_nls(char *);
  23. extern void unload_nls(struct nls_table *);
  24. extern struct nls_table *load_nls_default(void);
  25. extern int utf8_mbtowc(wchar_t *, const __u8 *, int);
  26. extern int utf8_mbstowcs(wchar_t *, const __u8 *, int);
  27. extern int utf8_wctomb(__u8 *, wchar_t, int);
  28. extern int utf8_wcstombs(__u8 *, const wchar_t *, int);
  29. static inline unsigned char nls_tolower(struct nls_table *t, unsigned char c)
  30. {
  31. unsigned char nc = t->charset2lower[c];
  32. return nc ? nc : c;
  33. }
  34. static inline unsigned char nls_toupper(struct nls_table *t, unsigned char c)
  35. {
  36. unsigned char nc = t->charset2upper[c];
  37. return nc ? nc : c;
  38. }
  39. static inline int nls_strnicmp(struct nls_table *t, const unsigned char *s1,
  40. const unsigned char *s2, int len)
  41. {
  42. while (len--) {
  43. if (nls_tolower(t, *s1++) != nls_tolower(t, *s2++))
  44. return 1;
  45. }
  46. return 0;
  47. }
  48. #define MODULE_ALIAS_NLS(name) MODULE_ALIAS("nls_" __stringify(name))
  49. #endif /* _LINUX_NLS_H */