summaryrefslogtreecommitdiff
path: root/minix/lib/libsffs/name.c
blob: 80585ea0dc57b7aee08b60c1d7fd974db7f89aff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* This file contains path component name utility functions.
 *
 * The entry points into this file are:
 *   normalize_name	normalize a path component name for hashing purposes
 *   compare_name	check whether two path component names are equivalent
 *
 * Created:
 *   April 2009 (D.C. van Moolenbroek)
 */

#include "inc.h"

#include <ctype.h>

/*===========================================================================*
 *				normalize_name				     *
 *===========================================================================*/
void normalize_name(char dst[NAME_MAX+1], char *src)
{
/* Normalize the given path component name, storing the result in the given
 * buffer.
 */
  size_t i, size;

  size = strlen(src) + 1;

  assert(size <= NAME_MAX+1);

  if (sffs_params->p_case_insens) {
	for (i = 0; i < size; i++)
		*dst++ = tolower((int)*src++);
  }
  else memcpy(dst, src, size);
}

/*===========================================================================*
 *				compare_name				     *
 *===========================================================================*/
int compare_name(char *name1, char *name2)
{
/* Return TRUE if the given path component names are equivalent, FALSE
 * otherwise.
 */
  int r;

  if (sffs_params->p_case_insens)
	r = strcasecmp(name1, name2);
  else
	r = strcmp(name1, name2);

  return r ? FALSE : TRUE;
}