diff options
author | Miles Bader <miles@gnu.org> | 1996-03-22 01:11:49 +0000 |
---|---|---|
committer | Miles Bader <miles@gnu.org> | 1996-03-22 01:11:49 +0000 |
commit | e9e07f424a1e259422263577fb4f195075c27bdb (patch) | |
tree | 339b2b096a3b8c0d908c21fe3558df55f6e1a652 /libstore | |
parent | ca870026d30398b8a916dfff7759f7ccb71e0be6 (diff) |
entered into RCS
Diffstat (limited to 'libstore')
-rw-r--r-- | libstore/enc.c | 73 |
1 files changed, 61 insertions, 12 deletions
diff --git a/libstore/enc.c b/libstore/enc.c index 02969d6b..8091eb89 100644 --- a/libstore/enc.c +++ b/libstore/enc.c @@ -20,19 +20,68 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "store.h" - -/* Encode STORE into ENC, or return an error. The contents of ENC may - then be return as the value of file_get_storage_info; if for some reason - this can't be done, store_enc_dealloc may be used to deallocate the - mmemory used by the unsent vectors. */ -error_t store_encode (const struct store *store, struct store_enc *enc); +#include <string.h> -/* Decode ENC, either returning a new store in STORE, or an error. If - nothing else is to be done with ENC, its contents may then be freed using - store_enc_dealloc. */ -error_t store_decode (struct store_enc *enc, struct store *store); +#include "store.h" + +/* Initialize ENC. The given vector and sizes will be used for the encoding + if they are big enough (otherwise new ones will be automatically + allocated). */ +void +store_enc_init (struct store_enc *enc, + mach_port_t *ports, mach_msg_type_number_t ports_len, + int *ints, mach_msg_type_number_t ints_len, + off_t *offsets, mach_msg_type_number_t offsets_len, + char *data, mach_msg_type_number_t data_len) +{ + bzero (enc, sizeof (*enc)); + enc->ports = enc->init_ports = ports; + enc->ports_len = ports_len; + enc->ints = enc->init_ints = ints; + enc->ints_len = ints_len; + enc->offsets = enc->init_offsets = offsets; + enc->offsets_len = offsets_len; + enc->data = enc->init_data = data; + enc->data_len = data_len; +} + /* Deallocate storage used by the fields in ENC (but nothing is done with ENC itself). */ -void store_enc_dealloc (struct store_enc *enc); +void +store_enc_dealloc (struct store_enc *enc) +{ + if (enc->ports && enc->ports_len > 0) + /* For ports, we must deallocate each port as well. */ + { + while (enc->cur_port < enc->ports_len) + { + mach_port_t port = enc->ports[enc->cur_port++]; + if (port != MACH_PORT_NULL) + mach_port_deallocate (mach_task_self (), port); + } + + if (enc->ports != enc->init_ports) + vm_deallocate (mach_task_self (), + (vm_address_t)enc->ports, + enc->ports_len * sizeof (*enc->ports)); + } + + if (enc->ints && enc->ints_len > 0 && enc->ints != enc->init_ints) + vm_deallocate (mach_task_self (), + (vm_address_t)enc->ints, + enc->ints_len * sizeof (*enc->ints)); + + if (enc->offsets && enc->offsets_len > 0 + && enc->offsets != enc->init_offsets) + vm_deallocate (mach_task_self (), + (vm_address_t)enc->offsets, + enc->offsets_len * sizeof (*enc->offsets)); + + if (enc->data && enc->data_len > 0 && enc->data != enc->init_data) + vm_deallocate (mach_task_self (), + (vm_address_t)enc->data, enc->data_len); + + /* For good measure... */ + bzero (enc, sizeof (*enc)); +} |