libexplain  1.4.D001
libexplain/buffer/flock.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2008-2010, 2013 Peter Miller
00004  * Written by Peter Miller <pmiller@opensource.org.au>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as published by
00008  * the Free Software Foundation; either version 3 of the License, or (at
00009  * your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00018  */
00019 
00020 #include <libexplain/ac/fcntl.h>
00021 
00022 #include <libexplain/buffer/flock.h>
00023 #include <libexplain/buffer/int.h>
00024 #include <libexplain/buffer/lseek_whence.h>
00025 #include <libexplain/buffer/off_t.h>
00026 #include <libexplain/buffer/pid_t_star.h>
00027 #include <libexplain/parse_bits.h>
00028 #include <libexplain/string_buffer.h>
00029 
00030 
00031 static void
00032 explain_buffer_flock_type(explain_string_buffer_t *sb, int value)
00033 {
00034     static const explain_parse_bits_table_t table[] =
00035     {
00036         { "F_RDLCK", F_RDLCK },
00037         { "F_WRLCK", F_WRLCK },
00038         { "F_UNLCK", F_UNLCK },
00039 #ifdef F_UNLKSYS
00040         { "F_UNLKSYS", F_UNLKSYS },
00041 #endif
00042     };
00043 
00044     explain_parse_bits_print_single(sb, value, table, SIZEOF(table));
00045 }
00046 
00047 
00048 void
00049 explain_buffer_flock(explain_string_buffer_t *sb, const struct flock *flp)
00050 {
00051     explain_string_buffer_puts(sb, "{ l_type = ");
00052     explain_buffer_flock_type(sb, flp->l_type);
00053     explain_string_buffer_puts(sb, ", l_whence = ");
00054     explain_buffer_lseek_whence(sb, flp->l_whence);
00055     explain_string_buffer_puts(sb, ", l_start = ");
00056     explain_buffer_off_t(sb, flp->l_whence);
00057     explain_string_buffer_puts(sb, ", l_len = ");
00058     explain_buffer_off_t(sb, flp->l_len);
00059 #ifdef F_UNLKSYS
00060     if (flp->l_pid < 0)
00061     {
00062         explain_string_buffer_puts(sb, ", l_sysid = ");
00063         explain_buffer_pid_t(sb, flp->l_sysid);
00064     }
00065 #endif
00066     explain_string_buffer_puts(sb, ", l_pid = ");
00067     if (flp->l_pid > 0)
00068         explain_buffer_pid_t(sb, flp->l_pid);
00069     else
00070         explain_buffer_int(sb, (int)flp->l_pid);
00071     explain_string_buffer_puts(sb, " }");
00072 }
00073 
00074 
00075 #ifdef F_GETLK64
00076 #if F_GETLK64 != F_GETLK
00077 
00078 void
00079 explain_buffer_flock64(explain_string_buffer_t *sb,
00080     const struct flock64 *flp)
00081 {
00082     explain_string_buffer_puts(sb, "{ l_type = ");
00083     explain_buffer_flock_type(sb, flp->l_type);
00084     explain_string_buffer_puts(sb, ", l_whence = ");
00085     explain_buffer_lseek_whence(sb, flp->l_whence);
00086     explain_string_buffer_puts(sb, ", l_start = ");
00087     explain_buffer_off_t(sb, flp->l_whence);
00088     explain_string_buffer_puts(sb, ", l_len = ");
00089     explain_buffer_off_t(sb, flp->l_len);
00090 #ifdef F_UNLKSYS
00091     explain_string_buffer_puts(sb, ", l_sysid = ");
00092     explain_buffer_pid_t(sb, flp->l_sysid);
00093 #endif
00094     explain_string_buffer_puts(sb, ", l_pid = ");
00095     if (flp->l_pid > 0)
00096         explain_buffer_pid_t(sb, flp->l_pid);
00097     else
00098         explain_buffer_int(sb, (int)flp->l_pid);
00099     explain_string_buffer_puts(sb, " }");
00100 }
00101 
00102 #endif
00103 #endif
00104 
00105 
00106 /* vim: set ts=8 sw=4 et : */