VirtualBox

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

Last change on this file since 56290 was 56290, checked in by vboxsync, 9 years ago

IPRT: Updated (C) year.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1/* $Id: RTPathIsSame-generic.cpp 56290 2015-06-09 14:01:31Z vboxsync $ */
2/** @file
3 * IPRT - Assertions, generic RTPathIsSame.
4 */
5
6/*
7 * Copyright (C) 2013-2015 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/string.h>
35
36
37RTDECL(int) RTPathIsSame(const char *pszPath1, const char *pszPath2)
38{
39 /*
40 * Simple checks based on the path values.
41 */
42 if (pszPath1 == pszPath2)
43 return true;
44 if (!pszPath1)
45 return false;
46 if (!pszPath2)
47 return false;
48 if (!strcmp(pszPath1, pszPath2))
49 return true;
50
51 /*
52 * If the files exist, try use the attributes.
53 */
54 RTFSOBJINFO ObjInfo1, ObjInfo2;
55 int rc = RTPathQueryInfoEx(pszPath1, &ObjInfo1, RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK);
56 if (RT_SUCCESS(rc))
57 rc = RTPathQueryInfoEx(pszPath2, &ObjInfo2, RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK);
58 if (RT_SUCCESS(rc))
59 {
60 if ((ObjInfo1.Attr.fMode & RTFS_TYPE_MASK) != (ObjInfo2.Attr.fMode & RTFS_TYPE_MASK))
61 return false;
62 if (ObjInfo1.Attr.u.Unix.INodeIdDevice != ObjInfo2.Attr.u.Unix.INodeIdDevice)
63 return false;
64 if (ObjInfo1.Attr.u.Unix.INodeId != ObjInfo2.Attr.u.Unix.INodeId)
65 return false;
66 if (ObjInfo1.Attr.u.Unix.GenerationId != ObjInfo2.Attr.u.Unix.GenerationId)
67 return false;
68 if ( ObjInfo1.Attr.u.Unix.INodeIdDevice != 0
69 && ObjInfo1.Attr.u.Unix.INodeId != 0)
70 return true;
71 }
72
73 /*
74 * Fallback, compare absolute/real paths. Return failure on paths that are
75 * too long.
76 */
77 char szPath1[RTPATH_MAX];
78 rc = RTPathAbs(pszPath1, szPath1, sizeof(szPath1));
79 AssertRCReturn(rc, VERR_FILENAME_TOO_LONG);
80
81 char szPath2[RTPATH_MAX];
82 rc = RTPathAbs(pszPath2, szPath2, sizeof(szPath2)); AssertRC(rc);
83 AssertRCReturn(rc, VERR_FILENAME_TOO_LONG);
84
85 if (RTPathCompare(szPath1, szPath2) == 0)
86 return true;
87
88 /** @todo Relsolve any symbolic links in the paths. Too lazy for that right
89 * now. */
90 return false;
91}
92RT_EXPORT_SYMBOL(RTPathIsSame);
93
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