libexplain  1.4.D001
libexplain/buffer/errno/closedir.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2008, 2009, 2013 Peter Miller
00004  *
00005  * This program is free software; you can redistribute it and/or modify it
00006  * under the terms of the GNU Lesser General Public License as published by
00007  * the Free Software Foundation; either version 3 of the License, or (at
00008  * your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public License
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00017  */
00018 
00019 #include <libexplain/ac/errno.h>
00020 
00021 #include <libexplain/buffer/dir_to_pathname.h>
00022 #include <libexplain/buffer/ebadf.h>
00023 #include <libexplain/buffer/efault.h>
00024 #include <libexplain/buffer/errno/generic.h>
00025 #include <libexplain/buffer/errno/close.h>
00026 #include <libexplain/buffer/errno/closedir.h>
00027 #include <libexplain/buffer/is_the_null_pointer.h>
00028 #include <libexplain/buffer/pointer.h>
00029 #include <libexplain/dir_to_fildes.h>
00030 #include <libexplain/explanation.h>
00031 
00032 
00033 static void
00034 explain_buffer_errno_closedir_system_call(explain_string_buffer_t *sb,
00035     int errnum, DIR *dir)
00036 {
00037     (void)errnum;
00038     explain_string_buffer_puts(sb, "closedir(dir = ");
00039     explain_buffer_pointer(sb, dir);
00040     /* libc has probably nuked it, but we live in hope */
00041     explain_buffer_dir_to_pathname(sb, dir);
00042     explain_string_buffer_putc(sb, ')');
00043 }
00044 
00045 
00046 static void
00047 explain_buffer_errno_closedir_explanation(explain_string_buffer_t *sb,
00048     int errnum, DIR *dir)
00049 {
00050     int             fildes;
00051 
00052     /*
00053      * http://www.opengroup.org/onlinepubs/009695399/functions/closedir.html
00054      */
00055     if (dir == NULL)
00056     {
00057         explain_buffer_is_the_null_pointer(sb, "dir");
00058         return;
00059     }
00060     if (errnum == EFAULT)
00061     {
00062         explain_buffer_efault(sb, "dir");
00063         return;
00064     }
00065     fildes = explain_dir_to_fildes(dir);
00066     if (fildes < 0)
00067     {
00068         explain_buffer_ebadf_dir(sb, "dir");
00069         return;
00070     }
00071     explain_buffer_errno_close_explanation(sb, errno, "closedir", fildes);
00072 }
00073 
00074 
00075 void
00076 explain_buffer_errno_closedir(explain_string_buffer_t *sb, int errnum,
00077     DIR *dir)
00078 {
00079     explain_explanation_t exp;
00080 
00081     explain_explanation_init(&exp, errnum);
00082     explain_buffer_errno_closedir_system_call
00083     (
00084         &exp.system_call_sb,
00085         errnum,
00086         dir
00087     );
00088     explain_buffer_errno_closedir_explanation
00089     (
00090         &exp.explanation_sb,
00091         errnum,
00092         dir
00093     );
00094     explain_explanation_assemble(&exp, sb);
00095 }
00096 
00097 
00098 /* vim: set ts=8 sw=4 et : */