* 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> Tue May 23 01:13:33 2000 Christopher Faylor <cgf@cygnus.com>
* mkvers.sh: Use snapshot date as build date since it is more * 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] != ':'; trailing_slash_p = SLASH_P (*lastchar) && lastchar[-1] != ':';
} }
debug_printf ("conv_to_posix_path (%s, %s)", src_path, debug_printf ("conv_to_posix_path (%s, %s, %s)", src_path,
keep_rel_p ? "keep-rel" : "no-keep-rel"); keep_rel_p ? "keep-rel" : "no-keep-rel",
trailing_slash_p ? "add-slash" : "no-add-slash");
MALLOC_CHECK; MALLOC_CHECK;
if (src_path_len >= MAX_PATH) 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. */ /* SRC_PATH is in the mount table. */
int nextchar; int nextchar;
if (!pathbuf[mi.native_pathlen]) const char *p = pathbuf + mi.native_pathlen;
if (!*p || !p[1])
nextchar = 0; nextchar = 0;
else if (isdirsep (pathbuf[mi.native_pathlen])) else if (isdirsep (*p))
nextchar = -1; nextchar = -1;
else else
nextchar = 1; nextchar = 1;
@ -1206,9 +1209,9 @@ mount_info::conv_to_posix_path (const char *src_path, char *posix_path,
if (addslash) if (addslash)
strcat (posix_path, "/"); strcat (posix_path, "/");
if (nextchar) if (nextchar)
slashify (pathbuf + mi.native_pathlen, slashify (p,
posix_path + addslash + (mi.posix_pathlen == 1 ? 0 : mi.posix_pathlen), posix_path + addslash + (mi.posix_pathlen == 1 ? 0 : mi.posix_pathlen),
trailing_slash_p); trailing_slash_p);
goto out; goto out;
} }

View File

@ -49,6 +49,7 @@ reg_key::build_reg (HKEY top, REGSAM access, va_list av)
{ {
char *name; char *name;
HKEY r = top; HKEY r = top;
key_is_invalid = 0;
/* FIXME: Most of the time a valid mount area should exist. Perhaps /* 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 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; r = key;
if (res != ERROR_SUCCESS) if (res != ERROR_SUCCESS)
{ {
key = (HKEY) INVALID_HANDLE_VALUE; key_is_invalid = res;
debug_printf ("failed to create key %s in the registry", name); debug_printf ("failed to create key %s in the registry", name);
break; break;
} }
@ -95,11 +96,11 @@ reg_key::get_int (const char *name, int def)
DWORD dst; DWORD dst;
DWORD size = sizeof (dst); DWORD size = sizeof (dst);
LONG res = RegQueryValueExA (key, if (key_is_invalid)
name, return def;
0,
&type, LONG res = RegQueryValueExA (key, name, 0, &type, (unsigned char *) &dst,
(unsigned char *) &dst, &size); &size);
if (type != REG_DWORD || res != ERROR_SUCCESS) if (type != REG_DWORD || res != ERROR_SUCCESS)
return def; return def;
@ -113,6 +114,9 @@ int
reg_key::set_int (const char *name, int val) reg_key::set_int (const char *name, int val)
{ {
DWORD value = val; DWORD value = val;
if (key_is_invalid)
return key_is_invalid;
return (int) RegSetValueExA (key, name, 0, REG_DWORD, return (int) RegSetValueExA (key, name, 0, REG_DWORD,
(unsigned char *) &value, sizeof (value)); (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 size = max;
DWORD type; DWORD type;
LONG res = RegQueryValueExA (key, name, 0, &type, (unsigned char *) dst, LONG res;
&size);
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))) if ((def != 0) && ((type != REG_SZ) || (res != ERROR_SUCCESS)))
{ strcpy (dst, def);
strcpy (dst, def);
}
return (int) res; return (int) res;
} }
@ -140,17 +146,12 @@ reg_key::get_string (const char *name, char *dst, size_t max, const char * def)
int int
reg_key::set_string (const char *name, const char *src) 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, return (int) RegSetValueExA (key, name, 0, REG_SZ, (unsigned char*) src,
strlen (src) + 1); 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. */ /* Return the handle to key. */
HKEY HKEY
@ -165,12 +166,14 @@ reg_key::get_key ()
int int
reg_key::kill (const char *name) reg_key::kill (const char *name)
{ {
if (key_is_invalid)
return key_is_invalid;
return RegDeleteKeyA (key, name); return RegDeleteKeyA (key, name);
} }
reg_key::~reg_key () reg_key::~reg_key ()
{ {
if (key != (HKEY) INVALID_HANDLE_VALUE) if (!key_is_invalid)
RegCloseKey (key); RegCloseKey (key);
key = (HKEY) INVALID_HANDLE_VALUE; key_is_invalid = 1;
} }

View File

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