1433d6423SLionel Sambuc /* This file contains path component name utility functions.
2433d6423SLionel Sambuc *
3433d6423SLionel Sambuc * The entry points into this file are:
4433d6423SLionel Sambuc * normalize_name normalize a path component name for hashing purposes
5433d6423SLionel Sambuc * compare_name check whether two path component names are equivalent
6433d6423SLionel Sambuc *
7433d6423SLionel Sambuc * Created:
8433d6423SLionel Sambuc * April 2009 (D.C. van Moolenbroek)
9433d6423SLionel Sambuc */
10433d6423SLionel Sambuc
11433d6423SLionel Sambuc #include "inc.h"
12433d6423SLionel Sambuc
13433d6423SLionel Sambuc #include <ctype.h>
14433d6423SLionel Sambuc
15433d6423SLionel Sambuc /*===========================================================================*
16433d6423SLionel Sambuc * normalize_name *
17433d6423SLionel Sambuc *===========================================================================*/
normalize_name(char dst[NAME_MAX+1],char * src)18433d6423SLionel Sambuc void normalize_name(char dst[NAME_MAX+1], char *src)
19433d6423SLionel Sambuc {
20433d6423SLionel Sambuc /* Normalize the given path component name, storing the result in the given
21433d6423SLionel Sambuc * buffer.
22433d6423SLionel Sambuc */
23433d6423SLionel Sambuc size_t i, size;
24433d6423SLionel Sambuc
25433d6423SLionel Sambuc size = strlen(src) + 1;
26433d6423SLionel Sambuc
27433d6423SLionel Sambuc assert(size <= NAME_MAX+1);
28433d6423SLionel Sambuc
29433d6423SLionel Sambuc if (sffs_params->p_case_insens) {
30433d6423SLionel Sambuc for (i = 0; i < size; i++)
31*a99c939dSDavid van Moolenbroek *dst++ = tolower((int)*src++);
32433d6423SLionel Sambuc }
33433d6423SLionel Sambuc else memcpy(dst, src, size);
34433d6423SLionel Sambuc }
35433d6423SLionel Sambuc
36433d6423SLionel Sambuc /*===========================================================================*
37433d6423SLionel Sambuc * compare_name *
38433d6423SLionel Sambuc *===========================================================================*/
compare_name(char * name1,char * name2)39433d6423SLionel Sambuc int compare_name(char *name1, char *name2)
40433d6423SLionel Sambuc {
41433d6423SLionel Sambuc /* Return TRUE if the given path component names are equivalent, FALSE
42433d6423SLionel Sambuc * otherwise.
43433d6423SLionel Sambuc */
44433d6423SLionel Sambuc int r;
45433d6423SLionel Sambuc
46433d6423SLionel Sambuc if (sffs_params->p_case_insens)
47433d6423SLionel Sambuc r = strcasecmp(name1, name2);
48433d6423SLionel Sambuc else
49433d6423SLionel Sambuc r = strcmp(name1, name2);
50433d6423SLionel Sambuc
51433d6423SLionel Sambuc return r ? FALSE : TRUE;
52433d6423SLionel Sambuc }
53