2 Unix SMB/Netbios implementation.
6 Copyright (C) Andrew Tridgell 1992-1998
9 The Free Software Foundation, Inc.
11 This file is part of the Midnight Commander.
13 The Midnight Commander is free software: you can redistribute it
14 and/or modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation, either version 3 of the License,
16 or (at your option) any later version.
18 The Midnight Commander is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 extern int DEBUGLEVEL
;
32 The idea is that this file will eventually have wrappers around all
33 important system calls in samba. The aims are:
35 - to enable easier porting by putting OS dependent stuff in here
37 - to allow for hooks into other "pseudo-filesystems"
39 - to allow easier integration of things like the japanese extensions
41 - to support the philosophy of Samba to expose the features of
42 the OS within the SMB model. In general whatever file/printer/variable
43 expansions/etc make sense to the OS should be acceptable to Samba.
47 /*******************************************************************
48 this replaces the normal select() system call
49 return if some data has arrived on one of the file descriptors
51 ********************************************************************/
60 #elif defined(TCRDCHK)
61 (void) ioctl (fd
, TCRDCHK
, &r
);
63 (void) ioctl (fd
, FIONREAD
, &r
);
70 sys_select (int maxfd
, fd_set
* fds
, struct timeval
*tval
)
81 for (i
= 0; i
< maxfd
; i
++)
83 if (FD_ISSET (i
, fds
) && pollfd (i
) > 0)
92 memcpy ((void *) fds
, (void *) &fds2
, sizeof (fds2
));
96 if (tval
&& tval
->tv_sec
< counter
)
103 #else /* !NO_SELECT */
105 sys_select (int maxfd
, fd_set
* fds
, struct timeval
*tval
)
108 struct pollfd pfd
[256];
115 for (i
= 0; i
< maxfd
; i
++)
117 if (FD_ISSET (i
, fds
))
119 struct pollfd
*pfdp
= &pfd
[maxpoll
++];
121 pfdp
->events
= POLLIN
;
126 timeout
= (tval
!= NULL
) ? (tval
->tv_sec
* 1000) + (tval
->tv_usec
/ 1000) : -1;
130 pollrtn
= poll (&pfd
[0], maxpoll
, timeout
);
132 while (pollrtn
< 0 && errno
== EINTR
);
136 for (i
= 0; i
< maxpoll
; i
++)
137 if (pfd
[i
].revents
& POLLIN
)
138 FD_SET (pfd
[i
].fd
, fds
);
149 memcpy ((void *) &t2
, (void *) tval
, sizeof (t2
));
151 selrtn
= select (maxfd
, SELECT_CAST fds
, NULL
, NULL
, tval
? &t2
: NULL
);
153 while (selrtn
< 0 && errno
== EINTR
);
157 #endif /* USE_POLL */
158 #endif /* NO_SELECT */
160 /*******************************************************************
161 A stat() wrapper that will deal with 64 bit filesizes.
162 ********************************************************************/
165 sys_stat (const char *fname
, SMB_STRUCT_STAT
* sbuf
)
167 return stat (fname
, sbuf
);
170 /*******************************************************************
171 An lstat() wrapper that will deal with 64 bit filesizes.
172 ********************************************************************/
175 sys_lstat (const char *fname
, SMB_STRUCT_STAT
* sbuf
)
177 return lstat (fname
, sbuf
);
180 /*******************************************************************
181 An fseek() wrapper that will deal with 64 bit filesizes.
182 ********************************************************************/
185 sys_fseek (FILE * fp
, SMB_OFF_T offset
, int whence
)
187 return fseek (fp
, offset
, whence
);
190 /*******************************************************************
191 An ftell() wrapper that will deal with 64 bit filesizes.
192 ********************************************************************/
195 sys_ftell (FILE * fp
)
197 return (SMB_OFF_T
) ftell (fp
);
200 /*******************************************************************
201 An open() wrapper that will deal with 64 bit filesizes.
202 ********************************************************************/
205 sys_open (const char *path
, int oflag
, mode_t mode
)
207 return open (path
, oflag
, mode
);
210 /*******************************************************************
211 An fopen() wrapper that will deal with 64 bit filesizes.
212 ********************************************************************/
215 sys_fopen (const char *path
, const char *type
)
217 return fopen (path
, type
);
221 /*******************************************************************
222 A readdir wrapper that will deal with 64 bit filesizes.
223 ********************************************************************/
226 sys_readdir (DIR * dirp
)
228 return readdir (dirp
);
231 /*******************************************************************
232 system wrapper for getwd
233 ********************************************************************/
239 wd
= (char *) getcwd (s
, sizeof (pstring
));
241 wd
= (char *) getwd (s
);
246 /*******************************************************************
247 chown isn't used much but OS/2 doesn't have it
248 ********************************************************************/
251 sys_chown (const char *fname
, uid_t uid
, gid_t gid
)
257 DEBUG (1, ("WARNING: no chown!\n"));
261 return (chown (fname
, uid
, gid
));
265 /**************************************************************************
266 A wrapper for gethostbyname() that tries avoids looking up hostnames
267 in the root domain, which can cause dial-on-demand links to come up for no
269 ****************************************************************************/
271 sys_gethostbyname (const char *name
)
273 #ifdef REDUCE_ROOT_DNS_LOOKUPS
274 char query
[256], hostname
[256];
277 /* Does this name have any dots in it? If so, make no change */
279 if (strchr (name
, '.'))
280 return (gethostbyname (name
));
282 /* Get my hostname, which should have domain name
283 attached. If not, just do the gethostname on the
287 gethostname (hostname
, sizeof (hostname
) - 1);
288 hostname
[sizeof (hostname
) - 1] = 0;
289 if ((domain
= strchr (hostname
, '.')) == NULL
)
290 return (gethostbyname (name
));
292 /* Attach domain name to query and do modified query.
293 If names too large, just do gethostname on the
297 if ((strlen (name
) + strlen (domain
)) >= sizeof (query
))
298 return (gethostbyname (name
));
300 slprintf (query
, sizeof (query
) - 1, "%s%s", name
, domain
);
301 return (gethostbyname (query
));
302 #else /* REDUCE_ROOT_DNS_LOOKUPS */
303 return (gethostbyname (name
));
304 #endif /* REDUCE_ROOT_DNS_LOOKUPS */
307 /**************************************************************************
308 Wrapper for random().
309 ****************************************************************************/
314 #if defined(HAVE_RANDOM)
315 return (long) random ();
316 #elif defined(HAVE_RAND)
317 return (long) rand ();
319 DEBUG (0, ("Error - no random function available !\n"));
324 /**************************************************************************
325 Wrapper for srandom().
326 ****************************************************************************/
329 sys_srandom (unsigned int seed
)
331 #if defined(HAVE_SRANDOM)
333 #elif defined(HAVE_SRAND)
336 DEBUG (0, ("Error - no srandom function available !\n"));