X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fdata%2Ffile-handle-def.c;h=09340833be4134d4125eefb96ec2ff1141884a11;hb=9d24b4fb4d831d7a2bebb51fd111726f0e682e45;hp=075f7b07901c79150e84b1b27014ca7202270d53;hpb=cb08510bbbab7646bc1031427243489024d22a3b;p=pspp diff --git a/src/data/file-handle-def.c b/src/data/file-handle-def.c index 075f7b0790..09340833be 100644 --- a/src/data/file-handle-def.c +++ b/src/data/file-handle-def.c @@ -25,6 +25,7 @@ #include "data/dataset.h" #include "data/variable.h" +#include "libpspp/assertion.h" #include "libpspp/cast.h" #include "libpspp/compiler.h" #include "libpspp/hash-functions.h" @@ -221,7 +222,7 @@ static struct file_handle * create_handle (const char *id, char *handle_name, enum fh_referent referent, const char *encoding) { - struct file_handle *handle = xzalloc (sizeof *handle); + struct file_handle *handle = XZALLOC (struct file_handle); handle->ref_cnt = 1; handle->id = xstrdup_if_nonnull (id); @@ -392,6 +393,40 @@ fh_get_encoding (const struct file_handle *handle) return handle->encoding; } +/* Returns true if A and B refer to the same file or dataset, false + otherwise. */ +bool +fh_equal (const struct file_handle *a, const struct file_handle *b) +{ + if (a->referent != b->referent) + return false; + + switch (a->referent) + { + case FH_REF_FILE: + { + struct file_identity *a_id = fh_get_identity (a); + struct file_identity *b_id = fh_get_identity (b); + + int cmp = fh_compare_file_identities (a_id, b_id); + + fh_free_identity (a_id); + fh_free_identity (b_id); + + return cmp == 0; + } + + case FH_REF_INLINE: + return true; + + case FH_REF_DATASET: + return a->ds == b->ds; + + default: + NOT_REACHED (); + } +} + /* Returns the dataset handle associated with HANDLE. Applicable to only FH_REF_DATASET files. */ struct dataset *