libexplain  1.4.D001
libexplain/buffer/errno/fsync.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 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,but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty
00012  * ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNULesser
00013  * 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/ebadf.h>
00022 #include <libexplain/buffer/eio.h>
00023 #include <libexplain/buffer/enosys.h>
00024 #include <libexplain/buffer/erofs.h>
00025 #include <libexplain/buffer/errno/generic.h>
00026 #include <libexplain/buffer/errno/fsync.h>
00027 #include <libexplain/buffer/fildes.h>
00028 #include <libexplain/explanation.h>
00029 
00030 
00031 static void
00032 explain_buffer_errno_fsync_system_call(explain_string_buffer_t *sb, int errnum,
00033     int fildes)
00034 {
00035     (void)errnum;
00036     explain_string_buffer_puts(sb, "fsync(fildes = ");
00037     explain_buffer_fildes(sb, fildes);
00038     explain_string_buffer_putc(sb, ')');
00039 }
00040 
00041 
00042 void
00043 explain_buffer_errno_fsync_explanation(explain_string_buffer_t *sb, int errnum,
00044     const char *syscall_name, int fildes)
00045 {
00046     /*
00047      * http://www.opengroup.org/onlinepubs/009695399/functions/fsync.html
00048      */
00049     switch (errnum)
00050     {
00051     case EBADF:
00052         explain_buffer_ebadf(sb, fildes, "fildes");
00053         break;
00054 
00055     case EIO:
00056         explain_buffer_eio_fildes(sb, fildes);
00057         break;
00058 
00059     case EROFS:
00060         explain_buffer_erofs_fildes(sb, fildes, "fildes");
00061         break;
00062 
00063     case EINVAL:
00064     case ENOSYS:
00065 #if defined(EOPNOTSUPP) && (EOPNOTSUPP != ENOSYS)
00066     case EOPNOTSUPP:
00067 #endif
00068 #if defined(ENOTSUP) && (ENOTSUP != EOPNOTSUPP)
00069     case ENOTSUP:
00070 #endif
00071         explain_buffer_enosys_fildes(sb, fildes, "fildes", syscall_name);
00072         break;
00073 
00074     default:
00075         explain_buffer_errno_generic(sb, errnum, syscall_name);
00076         break;
00077     }
00078 }
00079 
00080 
00081 void
00082 explain_buffer_errno_fsync(explain_string_buffer_t *sb, int errnum, int fildes)
00083 {
00084     explain_explanation_t exp;
00085 
00086     explain_explanation_init(&exp, errnum);
00087     explain_buffer_errno_fsync_system_call(&exp.system_call_sb, errnum, fildes);
00088     explain_buffer_errno_fsync_explanation(&exp.explanation_sb, errnum, "fsync",
00089         fildes);
00090     explain_explanation_assemble(&exp, sb);
00091 }
00092 
00093 
00094 /* vim: set ts=8 sw=4 et : */