Back to index

glibc  2.9
socket2.h
Go to the documentation of this file.
00001 /* Checking macros for socket functions.
00002    Copyright (C) 2005, 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 _SYS_SOCKET_H
00021 # error "Never include <bits/socket2.h> directly; use <sys/socket.h> instead."
00022 #endif
00023 
00024 extern ssize_t __recv_chk (int __fd, void *__buf, size_t __n, size_t __buflen,
00025                         int __flags);
00026 extern ssize_t __REDIRECT (__recv_alias, (int __fd, void *__buf, size_t __n,
00027                                      int __flags), recv);
00028 extern ssize_t __REDIRECT (__recv_chk_warn,
00029                         (int __fd, void *__buf, size_t __n, size_t __buflen,
00030                          int __flags), __recv_chk)
00031      __warnattr ("recv called with bigger length than size of destination "
00032                "buffer");
00033 
00034 __extern_always_inline ssize_t
00035 recv (int __fd, void *__buf, size_t __n, int __flags)
00036 {
00037   if (__bos0 (__buf) != (size_t) -1)
00038     {
00039       if (!__builtin_constant_p (__n))
00040        return __recv_chk (__fd, __buf, __n, __bos0 (__buf), __flags);
00041 
00042       if (__n > __bos0 (__buf))
00043        return __recv_chk_warn (__fd, __buf, __n, __bos0 (__buf), __flags);
00044     }
00045   return __recv_alias (__fd, __buf, __n, __flags);
00046 }
00047 
00048 extern ssize_t __recvfrom_chk (int __fd, void *__restrict __buf, size_t __n,
00049                             size_t __buflen, int __flags,
00050                             __SOCKADDR_ARG __addr,
00051                             socklen_t *__restrict __addr_len);
00052 extern ssize_t __REDIRECT (__recvfrom_alias,
00053                         (int __fd, void *__restrict __buf, size_t __n,
00054                          int __flags, __SOCKADDR_ARG __addr,
00055                          socklen_t *__restrict __addr_len), recvfrom);
00056 extern ssize_t __REDIRECT (__recvfrom_chk_warn,
00057                         (int __fd, void *__restrict __buf, size_t __n,
00058                          size_t __buflen, int __flags,
00059                          __SOCKADDR_ARG __addr,
00060                          socklen_t *__restrict __addr_len), __recvfrom_chk)
00061      __warnattr ("recvfrom called with bigger length than size of "
00062                "destination buffer");
00063 
00064 __extern_always_inline ssize_t
00065 recvfrom (int __fd, void *__restrict __buf, size_t __n, int __flags,
00066          __SOCKADDR_ARG __addr, socklen_t *__restrict __addr_len)
00067 {
00068   if (__bos0 (__buf) != (size_t) -1)
00069     {
00070       if (!__builtin_constant_p (__n))
00071        return __recvfrom_chk (__fd, __buf, __n, __bos0 (__buf), __flags,
00072                             __addr, __addr_len);
00073       if (__n > __bos0 (__buf))
00074        return __recvfrom_chk_warn (__fd, __buf, __n, __bos0 (__buf), __flags,
00075                                 __addr, __addr_len);
00076     }
00077   return __recvfrom_alias (__fd, __buf, __n, __flags, __addr, __addr_len);
00078 }