libexplain  1.4.D001
libexplain/buffer/errno/system.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/errno/fork.h>
00022 #include <libexplain/buffer/errno/generic.h>
00023 #include <libexplain/buffer/errno/system.h>
00024 #include <libexplain/buffer/errno/wait.h>
00025 #include <libexplain/buffer/pointer.h>
00026 #include <libexplain/explanation.h>
00027 
00028 
00029 static void
00030 explain_buffer_errno_system_system_call(explain_string_buffer_t *sb,
00031     int errnum, const char *command)
00032 {
00033     explain_string_buffer_puts(sb, "system(command = ");
00034     if (!command)
00035         explain_string_buffer_puts(sb, "NULL");
00036     else if (errnum == EFAULT)
00037         explain_buffer_pointer(sb, command);
00038     else
00039         explain_string_buffer_puts_quoted(sb, command);
00040     explain_string_buffer_putc(sb, ')');
00041 }
00042 
00043 
00044 static void
00045 explain_buffer_errno_system_explanation(explain_string_buffer_t *sb,
00046     int errnum, const char *syscall_name, const char *command)
00047 {
00048     int             junk;
00049 
00050     /*
00051      * Here is the relevant page of The Single Unix Standard:
00052      * http://www.opengroup.org/onlinepubs/009695399/functions/system.html
00053      */
00054     (void)command;
00055     switch (errnum)
00056     {
00057     case EAGAIN:
00058     case ENOMEM:
00059         explain_buffer_errno_fork_explanation(sb, errnum, syscall_name);
00060         break;
00061 
00062     case ECHILD:
00063     case EINTR:
00064     case EINVAL:
00065         explain_buffer_errno_wait_explanation(sb, errnum, syscall_name, &junk);
00066         break;
00067 
00068     default:
00069         explain_buffer_errno_generic(sb, errnum, syscall_name);
00070         break;
00071     }
00072 }
00073 
00074 
00075 void
00076 explain_buffer_errno_system(explain_string_buffer_t *sb, int errnum,
00077     const char *command)
00078 {
00079     explain_explanation_t exp;
00080 
00081     explain_explanation_init(&exp, errnum);
00082     explain_buffer_errno_system_system_call
00083     (
00084         &exp.system_call_sb,
00085         errnum,
00086         command
00087     );
00088     explain_buffer_errno_system_explanation
00089     (
00090         &exp.explanation_sb,
00091         errnum,
00092         "system",
00093         command
00094     );
00095     explain_explanation_assemble(&exp, sb);
00096 }
00097 
00098 
00099 /* vim: set ts=8 sw=4 et : */