Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2000-05-23 18:08:52 +0400
committerChristopher Faylor <me@cgf.cx>2000-05-23 18:08:52 +0400
commit2dd78662b79be63eec5b141346e3e076c4f80e2f (patch)
tree5144085a0d32d8c31ea3aa9079d9e46677628417 /winsup/cygwin/registry.cc
parent8a06cd1b8718dffe2ede4f8b41b8a8c4afe06406 (diff)
* path.cc (mount_info::conv_to_posix_path): Avoid putting a trailing slash on a
directory name when the ms-dos path spec is a root directory of a device. * registry.cc (reg_key::build_reg): Set 'key_is_invalid' flag rather than using an INVALID_HANDLE_KEY. (reg_key::get_int): Test for key validity before performing registry operations. (reg_key::set_int): Ditto. (reg_key::get_string): Ditto. (reg_key::set_string): Ditto. (reg_key::kill): Ditto. (reg_key::~reg_key): Ditto.
Diffstat (limited to 'winsup/cygwin/registry.cc')
-rw-r--r--winsup/cygwin/registry.cc43
1 files changed, 23 insertions, 20 deletions
diff --git a/winsup/cygwin/registry.cc b/winsup/cygwin/registry.cc
index f0c11ca25..47092f576 100644
--- a/winsup/cygwin/registry.cc
+++ b/winsup/cygwin/registry.cc
@@ -49,6 +49,7 @@ reg_key::build_reg (HKEY top, REGSAM access, va_list av)
{
char *name;
HKEY r = top;
+ key_is_invalid = 0;
/* FIXME: Most of the time a valid mount area should exist. Perhaps
we should just try an open of the correct key first and only resort
@@ -72,7 +73,7 @@ reg_key::build_reg (HKEY top, REGSAM access, va_list av)
r = key;
if (res != ERROR_SUCCESS)
{
- key = (HKEY) INVALID_HANDLE_VALUE;
+ key_is_invalid = res;
debug_printf ("failed to create key %s in the registry", name);
break;
}
@@ -95,11 +96,11 @@ reg_key::get_int (const char *name, int def)
DWORD dst;
DWORD size = sizeof (dst);
- LONG res = RegQueryValueExA (key,
- name,
- 0,
- &type,
- (unsigned char *) &dst, &size);
+ if (key_is_invalid)
+ return def;
+
+ LONG res = RegQueryValueExA (key, name, 0, &type, (unsigned char *) &dst,
+ &size);
if (type != REG_DWORD || res != ERROR_SUCCESS)
return def;
@@ -113,6 +114,9 @@ int
reg_key::set_int (const char *name, int val)
{
DWORD value = val;
+ if (key_is_invalid)
+ return key_is_invalid;
+
return (int) RegSetValueExA (key, name, 0, REG_DWORD,
(unsigned char *) &value, sizeof (value));
}
@@ -125,13 +129,15 @@ reg_key::get_string (const char *name, char *dst, size_t max, const char * def)
{
DWORD size = max;
DWORD type;
- LONG res = RegQueryValueExA (key, name, 0, &type, (unsigned char *) dst,
- &size);
+ LONG res;
+
+ if (key_is_invalid)
+ res = key_is_invalid;
+ else
+ res = RegQueryValueExA (key, name, 0, &type, (unsigned char *) dst, &size);
if ((def != 0) && ((type != REG_SZ) || (res != ERROR_SUCCESS)))
- {
- strcpy (dst, def);
- }
+ strcpy (dst, def);
return (int) res;
}
@@ -140,17 +146,12 @@ reg_key::get_string (const char *name, char *dst, size_t max, const char * def)
int
reg_key::set_string (const char *name, const char *src)
{
+ if (key_is_invalid)
+ return key_is_invalid;
return (int) RegSetValueExA (key, name, 0, REG_SZ, (unsigned char*) src,
strlen (src) + 1);
}
-int
-reg_key::setone_string (const char *src, const char *name)
-{
- return (int) RegSetValueExA (key, name, 0, REG_SZ,
- (const unsigned char *) src, strlen (src) + 1);
-}
-
/* Return the handle to key. */
HKEY
@@ -165,12 +166,14 @@ reg_key::get_key ()
int
reg_key::kill (const char *name)
{
+ if (key_is_invalid)
+ return key_is_invalid;
return RegDeleteKeyA (key, name);
}
reg_key::~reg_key ()
{
- if (key != (HKEY) INVALID_HANDLE_VALUE)
+ if (!key_is_invalid)
RegCloseKey (key);
- key = (HKEY) INVALID_HANDLE_VALUE;
+ key_is_invalid = 1;
}