xref: /minix/minix/lib/libsffs/name.c (revision ebfedea0)
1 /* This file contains path component name utility functions.
2  *
3  * The entry points into this file are:
4  *   normalize_name	normalize a path component name for hashing purposes
5  *   compare_name	check whether two path component names are equivalent
6  *
7  * Created:
8  *   April 2009 (D.C. van Moolenbroek)
9  */
10 
11 #include "inc.h"
12 
13 #include <ctype.h>
14 
15 /*===========================================================================*
16  *				normalize_name				     *
17  *===========================================================================*/
18 void normalize_name(char dst[NAME_MAX+1], char *src)
19 {
20 /* Normalize the given path component name, storing the result in the given
21  * buffer.
22  */
23   size_t i, size;
24 
25   size = strlen(src) + 1;
26 
27   assert(size <= NAME_MAX+1);
28 
29   if (sffs_params->p_case_insens) {
30 	for (i = 0; i < size; i++)
31 		*dst++ = tolower((int)*src++);
32   }
33   else memcpy(dst, src, size);
34 }
35 
36 /*===========================================================================*
37  *				compare_name				     *
38  *===========================================================================*/
39 int compare_name(char *name1, char *name2)
40 {
41 /* Return TRUE if the given path component names are equivalent, FALSE
42  * otherwise.
43  */
44   int r;
45 
46   if (sffs_params->p_case_insens)
47 	r = strcasecmp(name1, name2);
48   else
49 	r = strcmp(name1, name2);
50 
51   return r ? FALSE : TRUE;
52 }
53