libexplain  1.4.D001
libexplain/buffer/eloop.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  * Written by Peter Miller <pmiller@opensource.org.au>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as
00008  * published by the Free Software Foundation; either version 3 of the
00009  * License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018  */
00019 
00020 #include <libexplain/ac/errno.h>
00021 #include <libexplain/ac/stdio.h>
00022 
00023 #include <libexplain/buffer/eloop.h>
00024 #include <libexplain/buffer/errno/path_resolution.h>
00025 #include <libexplain/option.h>
00026 #include <libexplain/symloopmax.h>
00027 
00028 
00029 static void
00030 report_error(explain_string_buffer_t *sb, const char *caption)
00031 {
00032     explain_string_buffer_printf
00033     (
00034         sb,
00035         "too many symbolic links were encountered in resolving %s",
00036         caption
00037     );
00038     if (explain_option_dialect_specific())
00039     {
00040         int             symloop_max;
00041 
00042         symloop_max = explain_symloopmax();
00043         explain_string_buffer_printf(sb, " (%d)", symloop_max);
00044     }
00045 }
00046 
00047 
00048 void
00049 explain_buffer_eloop(explain_string_buffer_t *sb, const char *pathname,
00050     const char *pathname_caption, const explain_final_t *final_component)
00051 {
00052     if
00053     (
00054         explain_buffer_errno_path_resolution
00055         (
00056             sb,
00057             ELOOP,
00058             pathname,
00059             pathname_caption,
00060             final_component
00061         )
00062     )
00063     {
00064         /*
00065          * Unable to find a specific cause,
00066          * emit the generic explanation.
00067          */
00068         report_error(sb, pathname_caption);
00069     }
00070 }
00071 
00072 
00073 void
00074 explain_buffer_eloop2(explain_string_buffer_t *sb,
00075     const char *oldpath, const char *oldpath_caption,
00076     const explain_final_t *oldpath_final_component,
00077     const char *newpath, const char *newpath_caption,
00078     const explain_final_t *newpath_final_component)
00079 {
00080     if
00081     (
00082         explain_buffer_errno_path_resolution
00083         (
00084             sb,
00085             ELOOP,
00086             oldpath,
00087             oldpath_caption,
00088             oldpath_final_component
00089         )
00090     &&
00091         explain_buffer_errno_path_resolution
00092         (
00093             sb,
00094             ELOOP,
00095             newpath,
00096             newpath_caption,
00097             newpath_final_component
00098         )
00099     )
00100     {
00101         char            buffer[40];
00102 
00103         /*
00104          * Unable to find a specific cause,
00105          * emit the generic explanation.
00106          */
00107         snprintf
00108         (
00109             buffer,
00110             sizeof(buffer),
00111             "%s or %s",
00112             oldpath_caption,
00113             newpath_caption
00114         );
00115         report_error(sb, buffer);
00116     }
00117 }
00118 
00119 
00120 /* vim: set ts=8 sw=4 et : */