Commit a240ec01 by Celine Mercier

Added error checking when closing file descriptors

parent 0a3c23d9
......@@ -543,7 +543,12 @@ int enlarge_view_file(Obiview_p view, size_t new_size)
// Set new size
(view->infos)->file_size = rounded_new_size;
close(obiview_file_descriptor);
if (close(obiview_file_descriptor) < 0)
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nError closing a view file");
return -1;
}
return 0;
}
......@@ -616,7 +621,12 @@ int create_obiview_file(OBIDMS_p dms, const char* view_name)
return -1;
}
close(obiview_file_descriptor);
if (close(obiview_file_descriptor) < 0)
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nError closing a view file");
return -1;
}
return 0;
}
......@@ -1512,7 +1522,12 @@ Obiview_infos_p obi_view_map_file(OBIDMS_p dms, const char* view_name)
return NULL;
}
close(obiview_file_descriptor);
if (close(obiview_file_descriptor) < 0)
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nError closing a view file");
return NULL;
}
return view_infos;
}
......@@ -1520,40 +1535,45 @@ Obiview_infos_p obi_view_map_file(OBIDMS_p dms, const char* view_name)
int obi_view_unmap_file(OBIDMS_p dms, Obiview_infos_p view_infos)
{
char* file_name;
int obiview_file_descriptor;
size_t file_size;
// Get file name
file_name = build_obiview_file_name(view_infos->name);
if (file_name == NULL)
return -1;
char* file_name;
int obiview_file_descriptor;
size_t file_size;
// Open view file
obiview_file_descriptor = openat(dms->view_dir_fd, file_name, O_RDWR, 0777);
if (obiview_file_descriptor < 0)
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nError opening an obiview file");
free(file_name);
return -1;
}
// Get file name
file_name = build_obiview_file_name(view_infos->name);
if (file_name == NULL)
return -1;
// Open view file
obiview_file_descriptor = openat(dms->view_dir_fd, file_name, O_RDWR, 0777);
if (obiview_file_descriptor < 0)
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nError opening an obiview file");
free(file_name);
return -1;
}
// Unmap the view infos structure
file_size = view_infos->file_size;
if (munmap(view_infos, file_size) < 0)
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nError unmapping an obiview file");
close(obiview_file_descriptor);
return -1;
}
free(file_name);
// Unmap the view infos structure
file_size = view_infos->file_size;
if (munmap(view_infos, file_size) < 0)
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nError unmapping an obiview file");
close(obiview_file_descriptor);
return -1;
}
return 0;
if (close(obiview_file_descriptor) < 0)
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nError closing a view file");
return -1;
}
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment