libexplain  1.4.D001
libexplain/buffer/pid_t_star.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2009, 2011, 2013 Peter Miller
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU Lesser General Public License as
00007  * published by the Free Software Foundation; either version 3 of the
00008  * License, or (at 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/limits.h> /* for PATH_MAX on Solaris */
00020 #include <libexplain/ac/string.h>
00021 #include <libexplain/ac/sys/param.h> /* for PATH_MAX except Solaris */
00022 
00023 #include <libexplain/buffer/long.h>
00024 #include <libexplain/buffer/pid_t_star.h>
00025 #include <libexplain/buffer/pointer.h>
00026 #include <libexplain/fileinfo.h>
00027 #include <libexplain/is_efault.h>
00028 
00029 
00030 void
00031 explain_buffer_pid_t(explain_string_buffer_t *sb, pid_t pid)
00032 {
00033     char            path[PATH_MAX + 1];
00034 
00035     explain_buffer_long(sb, pid);
00036 
00037     if (explain_fileinfo_pid_exe(pid, path, sizeof(path)))
00038     {
00039         const char      *cp;
00040 
00041         cp = strrchr(path, '/');
00042         if (cp)
00043             ++cp;
00044         else
00045             cp = path;
00046         explain_string_buffer_putc(sb, ' ');
00047         explain_string_buffer_puts_quoted(sb, cp);
00048     }
00049 }
00050 
00051 
00052 void
00053 explain_buffer_pid_t_star(explain_string_buffer_t *sb, const pid_t *value)
00054 {
00055     if (explain_is_efault_pointer(value, sizeof(*value)))
00056         explain_buffer_pointer(sb, value);
00057     else
00058     {
00059         explain_string_buffer_puts(sb, "{ ");
00060         explain_buffer_pid_t(sb, *value);
00061         explain_string_buffer_puts(sb, " }");
00062     }
00063 }
00064 
00065 
00066 void
00067 explain_buffer_int_pid_star(explain_string_buffer_t *sb, const int *value)
00068 {
00069     if (explain_is_efault_pointer(value, sizeof(*value)))
00070         explain_buffer_pointer(sb, value);
00071     else
00072     {
00073         explain_string_buffer_puts(sb, "{ ");
00074         explain_buffer_pid_t(sb, *value);
00075         explain_string_buffer_puts(sb, " }");
00076     }
00077 }
00078 
00079 
00080 /* vim: set ts=8 sw=4 et : */