source: trunk/kStuff/kHlp/Bare/kHlpBareEnv.c@ 3582

Last change on this file since 3582 was 3575, checked in by bird, 18 years ago

env, paths, page allocation.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1/* $Id: kHlpBareEnv.c 3575 2007-09-02 20:05:39Z bird $ */
2/** @file
3 * kHlpBare - Environment Manipulation.
4 */
5
6/*
7 * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net>
8 *
9 * This file is part of kStuff.
10 *
11 * kStuff is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * kStuff is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with kStuff; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 *
25 */
26
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#include <k/kHlpEnv.h>
31#include <k/kHlpString.h>
32#include <k/kErrors.h>
33
34#if K_OS == K_OS_OS2
35# define INCL_BASE
36# define INCL_ERRORS
37# include <os2.h>
38#elif K_OS == K_OS_WINDOWS
39# include <Windows.h>
40#else
41# error "port me"
42#endif
43
44
45KHLP_DECL(int) kHlpGetEnv(const char *pszVar, char *pszVal, KSIZE cchVal)
46{
47#if K_OS == K_OS_OS2
48 PSZ pszValue = NULL;
49 int rc;
50
51 *pszVal = '\0';
52 rc = DosScanEnv((PCSZ)pszVar, &pszValue);
53 if (!rc)
54 {
55 KSIZE cch = kHlpStrLen((const char *)pszValue);
56 if (cchVal > cch)
57 kHlpMemCopy(pszVal, pszValue, cch + 1);
58 else
59 rc = KERR_BUFFER_OVERFLOW;
60 }
61 else
62 rc = KERR_ENVVAR_NOT_FOUND;
63 return rc;
64
65#elif K_OS == K_OS_WINDOWS
66 DWORD cch;
67
68 SetLastError(0);
69 cch = GetEnvironmentVariable(pszVar, pszVal, cchVal);
70 if (cch > 0 && cch < cchVal)
71 return 0;
72
73 *pszVal = '\0';
74 if (cch >= cchVal)
75 return KERR_BUFFER_OVERFLOW;
76 if (GetLastError() == ERROR_ENVVAR_NOT_FOUND)
77 return KERR_ENVVAR_NOT_FOUND;
78 return GetLastError();
79
80#else
81# error "Port me"
82#endif
83}
84
Note: See TracBrowser for help on using the repository browser.