summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/src/os_win/os_path.c
blob: 3ea25440617cca71d012129e81f56ae2cf119a81 (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
/*-
 * Copyright (c) 2014-present MongoDB, Inc.
 * Copyright (c) 2008-2014 WiredTiger, Inc.
 *	All rights reserved.
 *
 * See the file LICENSE for redistribution information.
 */

#include "wt_internal.h"

/*
 * __wt_absolute_path --
 *     Return if a filename is an absolute path.
 */
bool
__wt_absolute_path(const char *path)
{
    /*
     * https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247
     *
     * For Windows API functions that manipulate files, file names can often
     * be relative to the current directory, while some APIs require a fully
     * qualified path. A file name is relative to the current directory if
     * it does not begin with one of the following:
     *
     * -- A UNC name of any format, which always start with two backslash
     *    characters ("\\").
     * -- A disk designator with a backslash, for example "C:\" or "d:\".
     * -- A single backslash, for example, "\directory" or "\file.txt". This
     *    is also referred to as an absolute path.
     *
     * If a file name begins with only a disk designator but not the
     * backslash after the colon, it is interpreted as a relative path to
     * the current directory on the drive with the specified letter. Note
     * that the current directory may or may not be the root directory
     * depending on what it was set to during the most recent "change
     * directory" operation on that disk.
     *
     * -- "C:tmp.txt" refers to a file named "tmp.txt" in the current
     *    directory on drive C.
     * -- "C:tempdir\tmp.txt" refers to a file in a subdirectory to the
     *    current directory on drive C.
     */
    if (strlen(path) >= 3 && __wt_isalpha(path[0]) && path[1] == ':')
        path += 2;
    return (path[0] == '/' || path[0] == '\\');
}

/*
 * __wt_path_separator --
 *     Return the path separator string.
 */
const char *
__wt_path_separator(void)
{
    return ("\\");
}