VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/posix/rtPathOpenPathFh.cpp@ 39626

Last change on this file since 39626 was 39626, checked in by vboxsync, 13 years ago

more symlink stuff

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1/* $Id: rtPathOpenPathFh.cpp 39626 2011-12-15 11:33:47Z vboxsync $ */
2/** @file
3 * IPRT - rtPathOpenFd.cpp
4 */
5
6/*
7 * Copyright (C) 2011 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
32#include <sys/types.h>
33#include <sys/stat.h>
34#include <errno.h>
35#include <fcntl.h>
36#include <unistd.h>
37
38#include "internal/iprt.h"
39#include "internal/path.h"
40#include <iprt/err.h>
41#include <iprt/path.h>
42#include <iprt/string.h>
43
44
45DECLHIDDEN(int) rtPathOpenPathNoFollowFh(const char *pszPath, int *pFh, const char **ppszName)
46{
47#if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
48 const char *psz = pszPath;
49 const char *pszName = pszPath;
50 int fh = -1;
51
52 AssertPtrReturn(pFh, VERR_INVALID_PARAMETER);
53 AssertPtrReturn(pszPath, VERR_INVALID_PARAMETER);
54 /* must be an absolute path */
55 AssertReturn(*pszPath == '/', VERR_INVALID_PARAMETER);
56
57 for (;; psz++)
58 {
59 switch (*psz)
60 {
61 /* handle separators. */
62 case '/':
63 {
64 int fhNew;
65 if (fh == -1)
66 {
67 /* root directory */
68 fhNew = open("/", O_RDONLY | O_NOFOLLOW);
69 }
70 else
71 {
72 /* subdirectory */
73 char szTmpPath[RTPATH_MAX + 1];
74 RTStrCopyEx(szTmpPath, sizeof(szTmpPath), pszName, psz - pszName);
75 fhNew = openat(fh, szTmpPath, O_RDONLY | O_NOFOLLOW);
76 close(fh);
77 }
78 if (fhNew < 0)
79 return RTErrConvertFromErrno(errno);
80 fh = fhNew;
81 pszName = psz + 1;
82 break;
83 }
84
85 /*
86 * The end. Complete the results.
87 */
88 case '\0':
89 {
90 if (ppszName)
91 *ppszName = *pszName != '\0' ? pszName : NULL;
92 *pFh = fh;
93 return VINF_SUCCESS;
94 }
95 }
96 }
97
98 /* will never get here */
99 return 0;
100#else
101 return VERR_NOT_IMPLEMENTED;
102#endif
103}
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