Skip to content

Commit

Permalink
nls: add a nls_nullsize inline
Browse files Browse the repository at this point in the history
It's possible for character sets to require a multi-byte null
string terminator. Add a helper function that determines the size
of the null terminator at runtime.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
Acked-by: Suresh Jayaraman <sjayaraman@suse.de>
Signed-off-by: Steve French <sfrench@us.ibm.com>
  • Loading branch information
Jeff Layton authored and Steve French committed Apr 30, 2009
1 parent cbb7fe1 commit d37dc42
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions include/linux/nls.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ static inline int nls_strnicmp(struct nls_table *t, const unsigned char *s1,
return 0;
}

/*
* nls_nullsize - return length of null character for codepage
* @codepage - codepage for which to return length of NULL terminator
*
* Since we can't guarantee that the null terminator will be a particular
* length, we have to check against the codepage. If there's a problem
* determining it, assume a single-byte NULL terminator.
*/
static inline int
nls_nullsize(const struct nls_table *codepage)
{
int charlen;
char tmp[NLS_MAX_CHARSET_SIZE];

charlen = codepage->uni2char(0, tmp, NLS_MAX_CHARSET_SIZE);

return charlen > 0 ? charlen : 1;
}

#define MODULE_ALIAS_NLS(name) MODULE_ALIAS("nls_" __stringify(name))

#endif /* _LINUX_NLS_H */
Expand Down

0 comments on commit d37dc42

Please sign in to comment.