summaryrefslogtreecommitdiff
path: root/libstore/unknown.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2002-01-20 01:17:08 +0000
committerRoland McGrath <roland@gnu.org>2002-01-20 01:17:08 +0000
commit9383d745a05a9c4cf2456291f58824ed7af33550 (patch)
tree612727ddf08e459678b81cce687a00390d0f6214 /libstore/unknown.c
parent90bbd7e58080f9edee4a222b14c95bd05d875550 (diff)
2002-01-19 Roland McGrath <roland@frob.com>
Support explicit open of unknown store (with no name), i.e. -Tunknown. * unknown.c (unknown_allocate_encoding): Return EOPNOTSUPP if STORE->hook is null. (unknown_encode): Likewise. (unknown_cleanup): Do nothing if STORE->hook if is null. (unknown_clone): Likewise. (unknown_validate_name, unknown_open): New functions. (store_unknown_class): Use them.
Diffstat (limited to 'libstore/unknown.c')
-rw-r--r--libstore/unknown.c52
1 files changed, 44 insertions, 8 deletions
diff --git a/libstore/unknown.c b/libstore/unknown.c
index fce6b558..48e486a9 100644
--- a/libstore/unknown.c
+++ b/libstore/unknown.c
@@ -1,6 +1,6 @@
/* Store backend for unknown encodings
- Copyright (C) 2001 Free Software Foundation, Inc.
+ Copyright (C) 2001,02 Free Software Foundation, Inc.
This file is part of the GNU Hurd.
@@ -122,10 +122,10 @@ store_unknown_decode (struct store_enc *enc,
(or lack thereof) and the leading string of its encoded data bytes. */
if (enc->cur_int == enc->num_ints)
asprintf (&(*store)->name, "notype:%.*s",
- us->data_len - us->cur_data, us->data + us->cur_data);
+ (int) (us->data_len - us->cur_data), us->data + us->cur_data);
else
asprintf (&(*store)->name, "type-%d:%.*s", enc->ints[enc->cur_int],
- us->data_len - us->cur_data, us->data + us->cur_data);
+ (int) ( us->data_len - us->cur_data), us->data + us->cur_data);
return 0;
}
@@ -135,6 +135,8 @@ error_t
unknown_allocate_encoding (const struct store *store, struct store_enc *enc)
{
const struct store_enc *us = store->hook;
+ if (us == NULL)
+ return EOPNOTSUPP;
enc->num_ports += us->num_ports;
enc->num_ints += us->num_ints;
enc->num_offsets += us->num_offsets;
@@ -146,6 +148,8 @@ error_t
unknown_encode (const struct store *store, struct store_enc *enc)
{
const struct store_enc *us = store->hook;
+ if (us == NULL)
+ return EOPNOTSUPP;
memcpy (enc->ports, us->ports, us->num_ports * sizeof enc->ports[0]);
enc->ports += us->num_ports;
@@ -164,8 +168,11 @@ unknown_encode (const struct store *store, struct store_enc *enc)
static void
unknown_cleanup (struct store *store)
{
- store_enc_dealloc (store->hook);
- free (store->hook);
+ if (store->hook != NULL)
+ {
+ store_enc_dealloc (store->hook);
+ free (store->hook);
+ }
}
/* Copy any format-dependent fields in FROM to TO; if there's some reason
@@ -174,14 +181,43 @@ unknown_cleanup (struct store *store)
static error_t
unknown_clone (const struct store *from, struct store *to)
{
+ if (from->hook == NULL)
+ return 0;
to->hook = duplicate_encoding (from->hook);
return to->hook ? 0 : ENOMEM;
}
+/* Unknown stores cannot be opened with a name. */
+static error_t
+unknown_validate_name (const char *name,
+ const struct store_class *const *classes)
+{
+ return name == NULL ? 0 : EINVAL;
+}
+
+static error_t
+unknown_open (const char *name, int flags,
+ const struct store_class *const *classes,
+ struct store **store)
+{
+ return (name == NULL
+ ? _store_create (&store_unknown_class, MACH_PORT_NULL,
+ STORE_ENFORCED, 0, NULL, 0, 0, store)
+ : EINVAL);
+}
const struct store_class store_unknown_class =
{
- -1, "unknown", noread, nowrite,
- unknown_allocate_encoding, unknown_encode, store_unknown_decode,
- noflags, noflags, unknown_cleanup, unknown_clone,
+ -1, "unknown",
+ read: noread,
+ write: nowrite,
+ allocate_encoding: unknown_allocate_encoding,
+ encode: unknown_encode,
+ decode: store_unknown_decode,
+ set_flags: noflags,
+ clear_flags: noflags,
+ cleanup: unknown_cleanup,
+ clone: unknown_clone,
+ open: unknown_open,
+ validate_name: unknown_validate_name,
};