VirtualBox

source: vbox/trunk/src/VBox/Runtime/generic/RTPathIsSame-generic.cpp

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
1/* $Id: RTPathIsSame-generic.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * IPRT - Assertions, generic RTPathIsSame.
4 */
5
6/*
7 * Copyright (C) 2013-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include <iprt/path.h>
42#include "internal/iprt.h"
43
44#include <iprt/err.h>
45#include <iprt/string.h>
46
47
48RTDECL(int) RTPathIsSame(const char *pszPath1, const char *pszPath2)
49{
50 /*
51 * Simple checks based on the path values.
52 */
53 if (pszPath1 == pszPath2)
54 return true;
55 if (!pszPath1)
56 return false;
57 if (!pszPath2)
58 return false;
59 if (!strcmp(pszPath1, pszPath2))
60 return true;
61
62 /*
63 * If the files exist, try use the attributes.
64 */
65 RTFSOBJINFO ObjInfo1;
66 int rc = RTPathQueryInfoEx(pszPath1, &ObjInfo1, RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK);
67 if (RT_SUCCESS(rc))
68 {
69 RTFSOBJINFO ObjInfo2;
70 rc = RTPathQueryInfoEx(pszPath2, &ObjInfo2, RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK);
71 if (RT_SUCCESS(rc))
72 {
73 if ((ObjInfo1.Attr.fMode & RTFS_TYPE_MASK) != (ObjInfo2.Attr.fMode & RTFS_TYPE_MASK))
74 return false;
75 if (ObjInfo1.Attr.u.Unix.INodeIdDevice != ObjInfo2.Attr.u.Unix.INodeIdDevice)
76 return false;
77 if (ObjInfo1.Attr.u.Unix.INodeId != ObjInfo2.Attr.u.Unix.INodeId)
78 return false;
79 if (ObjInfo1.Attr.u.Unix.GenerationId != ObjInfo2.Attr.u.Unix.GenerationId)
80 return false;
81 if ( ObjInfo1.Attr.u.Unix.INodeIdDevice != 0
82 && ObjInfo1.Attr.u.Unix.INodeId != 0)
83 return true;
84 }
85 }
86
87 /*
88 * Fallback, compare absolute/real paths. Return failure on paths that are
89 * too long.
90 */
91 char szPath1[RTPATH_MAX];
92 rc = RTPathAbs(pszPath1, szPath1, sizeof(szPath1));
93 AssertRCReturn(rc, VERR_FILENAME_TOO_LONG);
94
95 char szPath2[RTPATH_MAX];
96 rc = RTPathAbs(pszPath2, szPath2, sizeof(szPath2)); AssertRC(rc);
97 AssertRCReturn(rc, VERR_FILENAME_TOO_LONG);
98
99 if (RTPathCompare(szPath1, szPath2) == 0)
100 return true;
101
102 /** @todo Relsolve any symbolic links in the paths. Too lazy for that right
103 * now. */
104 return false;
105}
106RT_EXPORT_SYMBOL(RTPathIsSame);
107
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use