2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1992-1998
5 Copyright (C) Jeremy Allison 1998-2002
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "system/network.h"
23 #include "system/filesys.h"
28 The idea is that this file will eventually have wrappers around all
29 important system calls in samba. The aims are:
31 - to enable easier porting by putting OS dependent stuff in here
33 - to allow for hooks into other "pseudo-filesystems"
35 - to allow easier integration of things like the japanese extensions
37 - to support the philosophy of Samba to expose the features of
38 the OS within the SMB model. In general whatever file/printer/variable
39 expansions/etc make sense to the OS should be acceptable to Samba.
42 /*******************************************************************
43 A wrapper for memalign
44 ********************************************************************/
46 void *sys_memalign( size_t align
, size_t size
)
48 #if defined(HAVE_POSIX_MEMALIGN)
50 int ret
= posix_memalign( &p
, align
, size
);
55 #elif defined(HAVE_MEMALIGN)
56 return memalign( align
, size
);
58 /* On *BSD systems memaligns doesn't exist, but memory will
59 * be aligned on allocations of > pagesize. */
60 #if defined(SYSCONF_SC_PAGESIZE)
61 size_t pagesize
= (size_t)sysconf(_SC_PAGESIZE
);
62 #elif defined(HAVE_GETPAGESIZE)
63 size_t pagesize
= (size_t)getpagesize();
65 size_t pagesize
= (size_t)-1;
67 if (pagesize
== (size_t)-1) {
68 DEBUG(0,("memalign functionalaity not available on this platform!\n"));
71 if (size
< pagesize
) {
78 /**************************************************************************
79 Wrapper for fork. Ensures we clear our pid cache.
80 ****************************************************************************/
82 static pid_t mypid
= (pid_t
)-1;
84 _PUBLIC_ pid_t
sys_fork(void)
86 pid_t forkret
= fork();
88 if (forkret
== (pid_t
)0) {
89 /* Child - reset mypid so sys_getpid does a system call. */
96 /**************************************************************************
97 Wrapper for getpid. Ensures we only do a system call *once*.
98 ****************************************************************************/
100 _PUBLIC_ pid_t
sys_getpid(void)
102 if (mypid
== (pid_t
)-1)
109 _PUBLIC_
int sys_getpeereid( int s
, uid_t
*uid
)
111 #if defined(HAVE_PEERCRED)
113 socklen_t cred_len
= sizeof(struct ucred
);
116 ret
= getsockopt(s
, SOL_SOCKET
, SO_PEERCRED
, (void *)&cred
, &cred_len
);
121 if (cred_len
!= sizeof(struct ucred
)) {
129 #if defined(HAVE_GETPEEREID)
131 return getpeereid(s
, uid
, &gid
);
138 _PUBLIC_
int sys_getnameinfo(const struct sockaddr
*psa
,
147 * For Solaris we must make sure salen is the
148 * correct length for the incoming sa_family.
151 if (salen
== sizeof(struct sockaddr_storage
)) {
152 salen
= sizeof(struct sockaddr_in
);
153 #if defined(HAVE_IPV6)
154 if (psa
->sa_family
== AF_INET6
) {
155 salen
= sizeof(struct sockaddr_in6
);
159 return getnameinfo(psa
, salen
, host
, hostlen
, service
, servlen
, flags
);
162 _PUBLIC_
int sys_connect(int fd
, const struct sockaddr
* addr
)
164 socklen_t salen
= (socklen_t
)-1;
166 if (addr
->sa_family
== AF_INET
) {
167 salen
= sizeof(struct sockaddr_in
);
168 } else if (addr
->sa_family
== AF_UNIX
) {
169 salen
= sizeof(struct sockaddr_un
);
171 #if defined(HAVE_IPV6)
172 else if (addr
->sa_family
== AF_INET6
) {
173 salen
= sizeof(struct sockaddr_in6
);
177 return connect(fd
, addr
, salen
);