HMAP_FOR_EACH_SAFE (handle, next,
struct file_handle, name_node, &named_handles)
unname_handle (handle);
+
+ free_handle (inline_file);
}
/* Free HANDLE and remove it from the global list. */
static void
free_handle (struct file_handle *handle)
{
+ if (handle == NULL)
+ return;
+
/* Remove handle from global list. */
if (handle->id != NULL)
hmap_delete (&named_handles, &handle->name_node);
struct file_handle *
fh_ref (struct file_handle *handle)
{
+ if (handle == fh_inline_file ())
+ return handle;
assert (handle->ref_cnt > 0);
handle->ref_cnt++;
return handle;
{
if (handle != NULL)
{
+ if (handle == fh_inline_file ())
+ return;
assert (handle->ref_cnt > 0);
if (--handle->ref_cnt == 0)
free_handle (handle);
struct file_handle *handle = xzalloc (sizeof *handle);
handle->ref_cnt = 1;
- handle->id = id != NULL ? xstrdup (id) : NULL;
+ handle->id = xstrdup_if_nonnull (id);
handle->name = handle_name;
handle->referent = referent;
handle->encoding = xstrdup (encoding);
handle_name = id != NULL ? xstrdup (id) : xasprintf ("`%s'", file_name);
handle = create_handle (id, handle_name, FH_REF_FILE, properties->encoding);
handle->file_name = xstrdup (file_name);
- handle->file_name_encoding = file_name_encoding ? xstrdup (file_name_encoding) : NULL;
+ handle->file_name_encoding = xstrdup_if_nonnull (file_name_encoding);
handle->mode = properties->mode;
handle->line_ends = properties->line_ends;
handle->record_width = properties->record_width;
fh_unref (default_handle);
default_handle = new_default_handle;
if (default_handle != NULL)
- fh_ref (default_handle);
+ default_handle = fh_ref (default_handle);
}
\f
/* Information about a file handle's readers or writers. */
HMAP_FOR_EACH_WITH_HASH (lock, struct fh_lock, node, hash, &locks)
{
- if ( 0 == compare_fh_locks (lock, key))
+ if (0 == compare_fh_locks (lock, key))
{
found_lock = true;
break;
}
}
- if ( found_lock )
+ if (found_lock)
{
if (strcmp (lock->type, type))
{
return NULL;
}
lock->open_cnt++;
-
+
free_key (key);
free (key);
found_lock = false;
HMAP_FOR_EACH_WITH_HASH (lock, struct fh_lock, node, hash, &locks)
{
- if ( 0 == compare_fh_locks (lock, key))
+ if (0 == compare_fh_locks (lock, key))
{
found_lock = true;
break;
HMAP_FOR_EACH_WITH_HASH (k, struct fh_lock, node, hash, &locks)
{
- if ( 0 == compare_fh_locks (k, &key))
+ if (0 == compare_fh_locks (k, &key))
{
is_locked = true;
break;
struct file_identity *identity = xmalloc (sizeof *identity);
const char *file_name = fh_get_file_name (fh);
-
+
#if !(defined _WIN32 || defined __WIN32__)
struct stat s;
if (lstat (file_name, &s) == 0)
size_t bufsize;
size_t pathlen = 255;
char *cname = NULL;
- do
+ do
{
bufsize = pathlen;
cname = xrealloc (cname, bufsize);