libexplain
1.4.D001
|
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> 00020 #include <libexplain/ac/linux/kdev_t.h> 00021 #include <libexplain/ac/sys/stat.h> /* for major()/minor() except Solaris */ 00022 #include <libexplain/ac/sys/sysmacros.h> /* for major()/minor() on Solaris */ 00023 00024 #include <libexplain/buffer/dev_t.h> 00025 #include <libexplain/buffer/device_name.h> 00026 #include <libexplain/buffer/mount_point.h> 00027 #include <libexplain/buffer/pointer.h> 00028 #include <libexplain/option.h> 00029 #include <libexplain/parse_bits.h> 00030 #include <libexplain/is_efault.h> 00031 00032 00033 void 00034 explain_buffer_dev_t(explain_string_buffer_t *sb, dev_t dev) 00035 { 00036 #if defined(MKDEV) 00037 explain_string_buffer_printf 00038 ( 00039 sb, 00040 "MKDEV(%d, %d)", 00041 (int)MAJOR(dev), 00042 (int)MINOR(dev) 00043 ); 00044 #elif defined(makedev) 00045 explain_string_buffer_printf 00046 ( 00047 sb, 00048 "makedev(%ld, %ld)", 00049 (long)major(dev), 00050 (long)minor(dev) 00051 ); 00052 #else 00053 explain_string_buffer_printf(sb, "0x%04lX", (long)dev); 00054 #endif 00055 00056 if (explain_option_dialect_specific()) 00057 { 00058 explain_string_buffer_t path_buf; 00059 struct stat st; 00060 char path[PATH_MAX]; 00061 00062 /* find and print the device name */ 00063 explain_string_buffer_init(&path_buf, path, sizeof(path)); 00064 if (explain_buffer_device_name(&path_buf, dev, &st) >= 0) 00065 { 00066 explain_string_buffer_putc(sb, ' '); 00067 explain_string_buffer_puts_quoted(sb, path); 00068 } 00069 00070 /* find and print the mount point */ 00071 explain_buffer_mount_point_dev(sb, dev); 00072 } 00073 } 00074 00075 00076 int 00077 explain_parse_dev_t_or_die(const char *text, const char *caption) 00078 { 00079 return explain_parse_bits_or_die(text, 0, 0, caption); 00080 } 00081 00082 00083 /* vim: set ts=8 sw=4 et : */