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

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

Built on linux.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1/* $Id: kHlpBareEnv.c 3599 2007-10-04 19:09: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_DARWIN
35
36#elif K_OS == K_OS_LINUX
37
38#elif K_OS == K_OS_OS2
39# define INCL_BASE
40# define INCL_ERRORS
41# include <os2.h>
42
43#elif K_OS == K_OS_WINDOWS
44# include <Windows.h>
45
46#else
47# error "port me"
48#endif
49
50
51KHLP_DECL(int) kHlpGetEnv(const char *pszVar, char *pszVal, KSIZE cchVal)
52{
53#if K_OS == K_OS_DARWIN
54 /** @todo need to figure out where the stuff is or how it's inherited on darwin ... */
55 return KERR_ENVVAR_NOT_FOUND;
56
57#elif K_OS == K_OS_LINUX
58 /** @todo either read /proc/self/environ or figure out where in the memory the initial environment is... */
59 return KERR_ENVVAR_NOT_FOUND;
60
61#elif K_OS == K_OS_OS2
62 PSZ pszValue = NULL;
63 int rc;
64
65 *pszVal = '\0';
66 rc = DosScanEnv((PCSZ)pszVar, &pszValue);
67 if (!rc)
68 {
69 KSIZE cch = kHlpStrLen((const char *)pszValue);
70 if (cchVal > cch)
71 kHlpMemCopy(pszVal, pszValue, cch + 1);
72 else
73 rc = KERR_BUFFER_OVERFLOW;
74 }
75 else
76 rc = KERR_ENVVAR_NOT_FOUND;
77 return rc;
78
79#elif K_OS == K_OS_WINDOWS
80 DWORD cch;
81
82 SetLastError(0);
83 cch = GetEnvironmentVariable(pszVar, pszVal, cchVal);
84 if (cch > 0 && cch < cchVal)
85 return 0;
86
87 *pszVal = '\0';
88 if (cch >= cchVal)
89 return KERR_BUFFER_OVERFLOW;
90 if (GetLastError() == ERROR_ENVVAR_NOT_FOUND)
91 return KERR_ENVVAR_NOT_FOUND;
92 return GetLastError();
93
94#else
95# error "Port me"
96#endif
97}
98
Note: See TracBrowser for help on using the repository browser.