summaryrefslogtreecommitdiff
path: root/db/os/os_rpath.c
blob: 28a0a48261ec03be038e897c778a999dbe642055 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 1997-2004
 *	Sleepycat Software.  All rights reserved.
 *
 * $Id: os_rpath.c,v 11.9 2004/01/28 03:36:18 bostic Exp $
 */

#include "db_config.h"

#ifndef NO_SYSTEM_INCLUDES
#include <string.h>
#endif

#include "db_int.h"
#ifdef HAVE_VXWORKS
#include "iosLib.h"
#endif

/*
 * __db_rpath --
 *	Return the last path separator in the path or NULL if none found.
 *
 * PUBLIC: char *__db_rpath __P((const char *));
 */
char *
__db_rpath(path)
	const char *path;
{
	const char *s, *last;
#ifdef HAVE_VXWORKS
	DEV_HDR *dummy;
	char *ptail;

	/*
	 * VxWorks devices can be rooted at any name.  We want to
	 * skip over the device name and not take into account any
	 * PATH_SEPARATOR characters that might be in that name.
	 *
	 * XXX [#2393]
	 * VxWorks supports having a filename directly follow a device
	 * name with no separator.  I.e. to access a file 'xxx' in
	 * the top level directory of a device mounted at "mydrive"
	 * you could say "mydrivexxx" or "mydrive/xxx" or "mydrive\xxx".
	 * We do not support the first usage here.
	 * XXX
	 */
	if ((dummy = iosDevFind((char *)path, &ptail)) == NULL)
		s = path;
	else
		s = ptail;
#else
	s = path;
#endif

	last = NULL;
	if (PATH_SEPARATOR[1] != '\0') {
		for (; s[0] != '\0'; ++s)
			if (strchr(PATH_SEPARATOR, s[0]) != NULL)
				last = s;
	} else
		for (; s[0] != '\0'; ++s)
			if (s[0] == PATH_SEPARATOR[0])
				last = s;
	return ((char *)last);
}