libexplain  1.4.D001
libexplain/buffer/ebusy.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2009, 2011, 2013, 2014 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/fcntl.h>
00020 #include <libexplain/ac/stdio.h>
00021 #include <libexplain/ac/sys/stat.h>
00022 #include <libexplain/ac/unistd.h>
00023 
00024 #include <libexplain/buffer/ebusy.h>
00025 #include <libexplain/buffer/file_type.h>
00026 #include <libexplain/buffer/gettext.h>
00027 
00028 
00029 void
00030 explain_buffer_ebusy_path(explain_string_buffer_t *sb, const char *path,
00031     const char *path_caption, const char *syscall_name)
00032 {
00033     int fildes = open(path, O_RDONLY);
00034     explain_buffer_ebusy_fildes(sb, fildes, path_caption, syscall_name);
00035     close(fildes);
00036 }
00037 
00038 
00039 void
00040 explain_buffer_ebusy_fildes(explain_string_buffer_t *sb, int fildes,
00041     const char *fildes_caption, const char *syscall_name)
00042 {
00043     struct stat     st;
00044     char            file_type[100];
00045 
00046     if (fstat(fildes, &st) >= 0)
00047     {
00048         explain_string_buffer_t buf;
00049 
00050         explain_string_buffer_init(&buf, file_type, sizeof(file_type));
00051         explain_buffer_file_type_st(&buf, &st);
00052     }
00053     else
00054         snprintf(file_type, sizeof(file_type), "file");
00055 
00056     /*
00057      * some nebulous default explanation
00058      */
00059     explain_string_buffer_printf_gettext
00060     (
00061         sb,
00062         /*
00063          * xgettext: This error message is issued when a system call
00064          * reports an EBUSY error.
00065          *
00066          * %1$s => The name of the offending argument
00067          * %2$s => The file type (e.g. block special) of the offending
00068          *          argument, alredaytranslated.
00069          * %3$s => The name of the offended system call.
00070          */
00071         i18n("the %s %s is in use by another process or by the system "
00072             "and this prevents the %s system call from operating"),
00073         fildes_caption,
00074         file_type,
00075         syscall_name
00076     );
00077 }
00078 
00079 
00080 /* vim: set ts=8 sw=4 et : */