VirtualBox

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

Last change on this file since 93636 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette