VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/RTPathTemp.cpp@ 85561

Last change on this file since 85561 was 83991, checked in by vboxsync, 5 years ago

IPRT,VBoxAddInstallNt3x.cpp: Split out the IPRT bits from VBoxAddInstallNt3x.cpp and move template to /Config.kmk.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 2.6 KB
Line 
1/* $Id: RTPathTemp.cpp 83991 2020-04-27 10:08:37Z vboxsync $ */
2/** @file
3 * IPRT - Path Manipulation, RTPathTemp.
4 */
5
6/*
7 * Copyright (C) 2006-2020 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 "internal/iprt.h"
32#include <iprt/path.h>
33
34#include <iprt/assert.h>
35#include <iprt/env.h>
36#include <iprt/err.h>
37#include <iprt/string.h>
38#include "internal/path.h"
39
40
41RTDECL(int) RTPathTemp(char *pszPath, size_t cchPath)
42{
43 /*
44 * Try get it from the environment first.
45 */
46 static const char * const s_apszVars[] =
47 {
48 "IPRT_TMPDIR"
49#if defined(RT_OS_WINDOWS)
50 , "TMP", "TEMP", "USERPROFILE"
51#elif defined(RT_OS_OS2)
52 , "TMP", "TEMP", "TMPDIR"
53#else
54 , "TMPDIR"
55#endif
56 };
57 for (size_t iVar = 0; iVar < RT_ELEMENTS(s_apszVars); iVar++)
58 {
59 int rc = RTEnvGetEx(RTENV_DEFAULT, s_apszVars[iVar], pszPath, cchPath, NULL);
60 if (rc != VERR_ENV_VAR_NOT_FOUND)
61 return rc;
62 }
63
64 /*
65 * Here we should use some sane system default, instead we just use
66 * the typical unix temp dir for now.
67 */
68 /** @todo Windows should default to the windows directory, see GetTempPath.
69 * Some unixes has path.h and _PATH_TMP. There is also a question about
70 * whether /var/tmp wouldn't be a better place... */
71 if (cchPath < sizeof("/tmp") )
72 return VERR_BUFFER_OVERFLOW;
73 memcpy(pszPath, "/tmp", sizeof("/tmp"));
74 return VINF_SUCCESS;
75}
76
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