* 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.
This commit is contained in:
Christopher Faylor 2000-05-23 14:08:52 +00:00
parent 8a06cd1b87
commit 2dd78662b7
4 changed files with 48 additions and 27 deletions

View File

@ -1,3 +1,18 @@
Tue May 23 10:01:07 2000 Christopher Faylor <cgf@cygnus.com>
* 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.
Tue May 23 01:13:33 2000 Christopher Faylor <cgf@cygnus.com>
* mkvers.sh: Use snapshot date as build date since it is more

View File

@ -1147,8 +1147,9 @@ mount_info::conv_to_posix_path (const char *src_path, char *posix_path,
trailing_slash_p = SLASH_P (*lastchar) && lastchar[-1] != ':';
}
debug_printf ("conv_to_posix_path (%s, %s)", src_path,
keep_rel_p ? "keep-rel" : "no-keep-rel");
debug_printf ("conv_to_posix_path (%s, %s, %s)", src_path,
keep_rel_p ? "keep-rel" : "no-keep-rel",
trailing_slash_p ? "add-slash" : "no-add-slash");
MALLOC_CHECK;
if (src_path_len >= MAX_PATH)
@ -1192,9 +1193,11 @@ mount_info::conv_to_posix_path (const char *src_path, char *posix_path,
/* SRC_PATH is in the mount table. */
int nextchar;
if (!pathbuf[mi.native_pathlen])
const char *p = pathbuf + mi.native_pathlen;
if (!*p || !p[1])
nextchar = 0;
else if (isdirsep (pathbuf[mi.native_pathlen]))
else if (isdirsep (*p))
nextchar = -1;
else
nextchar = 1;
@ -1206,9 +1209,9 @@ mount_info::conv_to_posix_path (const char *src_path, char *posix_path,
if (addslash)
strcat (posix_path, "/");
if (nextchar)
slashify (pathbuf + mi.native_pathlen,
slashify (p,
posix_path + addslash + (mi.posix_pathlen == 1 ? 0 : mi.posix_pathlen),
trailing_slash_p);
trailing_slash_p);
goto out;
}

View File

@ -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;
}

View File

@ -219,6 +219,7 @@ class reg_key
private:
HKEY key;
LONG key_is_invalid;
public:
@ -238,7 +239,6 @@ public:
int get_string (const char *, char *buf, size_t len, const char *def);
int set_string (const char *,const char *);
int set_int (const char *, int val);
int setone_string (const char *src, const char *name);
~reg_key ();
};