Back to index

glibc  2.9
mqueue2.h
Go to the documentation of this file.
00001 /* Checking macros for mq functions.
00002    Copyright (C) 2007 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library 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
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef       _FCNTL_H
00021 # error "Never include <bits/mqueue2.h> directly; use <mqueue.h> instead."
00022 #endif
00023 
00024 /* Check that calls to mq_open with O_CREAT set have an appropriate third and fourth
00025    parameter.  */
00026 extern mqd_t mq_open (__const char *__name, int __oflag, ...)
00027      __THROW __nonnull ((1));
00028 extern mqd_t __mq_open_2 (__const char *__name, int __oflag) __nonnull ((1));
00029 extern mqd_t __REDIRECT (__mq_open_alias, (__const char *__name, int __oflag, ...),
00030                       mq_open) __nonnull ((1));
00031 __errordecl (__mq_open_wrong_number_of_args,
00032             "mq_open can be called either with 2 or 4 arguments");
00033 __errordecl (__mq_open_missing_mode_and_attr,
00034             "mq_open with O_CREAT in second argument needs 4 arguments");
00035 
00036 __extern_always_inline mqd_t
00037 mq_open (__const char *__name, int __oflag, ...)
00038 {
00039   if (__va_arg_pack_len () != 0 && __va_arg_pack_len () != 2)
00040     __mq_open_wrong_number_of_args ();
00041 
00042   if (__builtin_constant_p (__oflag))
00043     {
00044       if ((__oflag & O_CREAT) != 0 && __va_arg_pack_len () == 0)
00045        {
00046          __mq_open_missing_mode_and_attr ();
00047          return __mq_open_2 (__name, __oflag);
00048        }
00049       return __mq_open_alias (__name, __oflag, __va_arg_pack ());
00050     }
00051 
00052   if (__va_arg_pack_len () == 0)
00053     return __mq_open_2 (__name, __oflag);
00054 
00055   return __mq_open_alias (__name, __oflag, __va_arg_pack ());
00056 }