2 Unix SMB/Netbios implementation.
5 Copyright (C) Andrew Tridgell 1998
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 2 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, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 /* NOTE: This file WILL produce compiler warnings. They are unavoidable
24 Do not try and get rid of them by including other include files or
25 by including includes.h or proto.h or you will break portability.
29 #include <sys/types.h>
31 #include "realcalls.h"
34 # define NULL ((void *)0)
37 int open(char *name
, int flags
, mode_t mode
)
39 if (smbw_path(name
)) {
40 return smbw_open(name
, flags
, mode
);
43 return real_open(name
, flags
, mode
);
47 int _open(char *name
, int flags
, mode_t mode
)
49 return open(name
, flags
, mode
);
52 int __open(char *name
, int flags
, mode_t mode
)
54 return open(name
, flags
, mode
);
60 int open64(char *name
, int flags
, mode_t mode
)
62 if (smbw_path(name
)) {
63 return smbw_open(name
, flags
, mode
);
66 return real_open64(name
, flags
, mode
);
70 #ifndef NO_OPEN64_ALIAS
72 int _open64(char *name
, int flags
, mode_t mode
)
74 return open64(name
, flags
, mode
);
77 int __open64(char *name
, int flags
, mode_t mode
)
79 return open64(name
, flags
, mode
);
85 ssize_t
pread(int fd
, void *buf
, size_t size
, off_t ofs
)
88 return smbw_pread(fd
, buf
, size
, ofs
);
91 return real_pread(fd
, buf
, size
, ofs
);
95 #if defined(HAVE_PREAD64) && defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT)
96 ssize_t
pread64(int fd
, void *buf
, size_t size
, off64_t ofs
)
99 return smbw_pread(fd
, buf
, size
, ofs
);
102 return real_pread64(fd
, buf
, size
, ofs
);
107 ssize_t
pwrite(int fd
, void *buf
, size_t size
, off_t ofs
)
110 return smbw_pwrite(fd
, buf
, size
, ofs
);
113 return real_pwrite(fd
, buf
, size
, ofs
);
117 #if defined(HAVE_PWRITE64) && defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT)
118 ssize_t
pwrite64(int fd
, void *buf
, size_t size
, off64_t ofs
)
121 return smbw_pwrite(fd
, buf
, size
, ofs
);
124 return real_pwrite64(fd
, buf
, size
, ofs
);
129 int chdir(char *name
)
131 return smbw_chdir(name
);
135 int __chdir(char *name
)
140 int _chdir(char *name
)
150 return smbw_close(fd
);
152 if (smbw_local_fd(fd
)) {
157 return real_close(fd
);
175 return smbw_fchdir(fd
);
191 int fcntl(int fd
, int cmd
, long arg
)
194 return smbw_fcntl(fd
, cmd
, arg
);
197 return real_fcntl(fd
, cmd
, arg
);
202 int __fcntl(int fd
, int cmd
, long arg
)
204 return fcntl(fd
, cmd
, arg
);
207 int _fcntl(int fd
, int cmd
, long arg
)
209 return fcntl(fd
, cmd
, arg
);
216 int getdents(int fd
, void *dirp
, unsigned int count
)
219 return smbw_getdents(fd
, dirp
, count
);
222 return real_getdents(fd
, dirp
, count
);
226 #ifdef HAVE___GETDENTS
227 int __getdents(int fd
, void *dirp
, unsigned int count
)
229 return getdents(fd
, dirp
, count
);
232 int _getdents(int fd
, void *dirp
, unsigned int count
)
234 return getdents(fd
, dirp
, count
);
239 off_t
lseek(int fd
, off_t offset
, int whence
)
242 return smbw_lseek(fd
, offset
, whence
);
245 return real_lseek(fd
, offset
, whence
);
249 off_t
__lseek(int fd
, off_t offset
, int whence
)
251 return lseek(fd
, offset
, whence
);
254 off_t
_lseek(int fd
, off_t offset
, int whence
)
256 return lseek(fd
, offset
, whence
);
261 ssize_t
read(int fd
, void *buf
, size_t count
)
264 return smbw_read(fd
, buf
, count
);
267 return real_read(fd
, buf
, count
);
271 ssize_t
__read(int fd
, void *buf
, size_t count
)
273 return read(fd
, buf
, count
);
276 ssize_t
_read(int fd
, void *buf
, size_t count
)
278 return read(fd
, buf
, count
);
283 ssize_t
write(int fd
, void *buf
, size_t count
)
286 return smbw_write(fd
, buf
, count
);
289 return real_write(fd
, buf
, count
);
293 ssize_t
__write(int fd
, void *buf
, size_t count
)
295 return write(fd
, buf
, count
);
298 ssize_t
_write(int fd
, void *buf
, size_t count
)
300 return write(fd
, buf
, count
);
306 int access(char *name
, int mode
)
308 if (smbw_path(name
)) {
309 return smbw_access(name
, mode
);
312 return real_access(name
, mode
);
317 int chmod(char *name
,mode_t mode
)
319 if (smbw_path(name
)) {
320 return smbw_chmod(name
, mode
);
323 return real_chmod(name
, mode
);
328 int chown(char *name
,uid_t owner
, gid_t group
)
330 if (smbw_path(name
)) {
331 return smbw_chown(name
, owner
, group
);
334 return real_chown(name
, owner
, group
);
338 char *getcwd(char *buf
, size_t size
)
340 return (char *)smbw_getcwd(buf
, size
);
346 int mkdir(char *name
, mode_t mode
)
348 if (smbw_path(name
)) {
349 return smbw_mkdir(name
, mode
);
352 return real_mkdir(name
, mode
);
357 int __fxstat(int vers
, int fd
, void *st
)
363 return smbw_fstat(fd
, st
);
366 ret
= real_fstat(fd
, xx
);
367 xstat_convert(vers
, st
, xx
);
373 int __xstat(int vers
, char *name
, void *st
)
378 if (smbw_path(name
)) {
379 return smbw_stat(name
, st
);
382 ret
= real_stat(name
, xx
);
383 xstat_convert(vers
, st
, xx
);
390 int __lxstat(int vers
, char *name
, void *st
)
395 if (smbw_path(name
)) {
396 return smbw_stat(name
, st
);
399 ret
= real_lstat(name
, xx
);
400 xstat_convert(vers
, st
, xx
);
406 int stat(char *name
, void *st
)
409 return __xstat(0, name
, st
);
411 if (smbw_path(name
)) {
412 return smbw_stat(name
, st
);
414 return real_stat(name
, st
);
418 int lstat(char *name
, void *st
)
421 return __lxstat(0, name
, st
);
423 if (smbw_path(name
)) {
424 return smbw_stat(name
, st
);
426 return real_lstat(name
, st
);
430 int fstat(int fd
, void *st
)
433 return __fxstat(0, fd
, st
);
436 return smbw_fstat(fd
, st
);
438 return real_fstat(fd
, st
);
443 int unlink(char *name
)
445 if (smbw_path(name
)) {
446 return smbw_unlink(name
);
449 return real_unlink(name
);
454 int utime(char *name
,void *tvp
)
456 if (smbw_path(name
)) {
457 return smbw_utime(name
, tvp
);
460 return real_utime(name
, tvp
);
466 #ifdef HAVE_SYS_TIME_H
467 #include <sys/time.h>
472 int utimes(const char *name
, const struct timeval
*tvp
)
474 if (smbw_path(name
)) {
475 return smbw_utimes(name
, tvp
);
478 return real_utimes(name
, tvp
);
482 int readlink(char *path
, char *buf
, size_t bufsize
)
484 if (smbw_path(path
)) {
485 return smbw_readlink(path
, buf
, bufsize
);
488 return real_readlink(path
, buf
, bufsize
);
492 int rename(char *oldname
,char *newname
)
495 p1
= smbw_path(oldname
);
496 p2
= smbw_path(newname
);
498 /* can't cross filesystem boundaries */
503 return smbw_rename(oldname
, newname
);
506 return real_rename(oldname
, newname
);
509 int rmdir(char *name
)
511 if (smbw_path(name
)) {
512 return smbw_rmdir(name
);
515 return real_rmdir(name
);
519 int symlink(char *topath
,char *frompath
)
522 p1
= smbw_path(topath
);
523 p2
= smbw_path(frompath
);
525 /* can't handle symlinks */
530 return real_symlink(topath
, frompath
);
542 int dup2(int oldfd
, int newfd
)
544 if (smbw_fd(newfd
)) {
548 if (smbw_fd(oldfd
)) {
549 return smbw_dup2(oldfd
, newfd
);
552 return real_dup2(oldfd
, newfd
);
556 void *opendir(char *name
)
558 if (smbw_path(name
)) {
559 return (void *)smbw_opendir(name
);
562 return (void *)real_opendir(name
);
567 void *readdir(void *dir
)
569 if (smbw_dirp(dir
)) {
570 return (void *)smbw_readdir(dir
);
573 return (void *)real_readdir(dir
);
578 int closedir(void *dir
)
580 if (smbw_dirp(dir
)) {
581 return smbw_closedir(dir
);
584 return real_closedir(dir
);
589 off_t
telldir(void *dir
)
591 if (smbw_dirp(dir
)) {
592 return smbw_telldir(dir
);
595 return real_telldir(dir
);
600 int seekdir(void *dir
, off_t offset
)
602 if (smbw_dirp(dir
)) {
603 smbw_seekdir(dir
, offset
);
607 real_seekdir(dir
, offset
);
613 #ifndef NO_ACL_WRAPPER
614 int acl(char *pathp
, int cmd
, int nentries
, void *aclbufp
)
616 if (smbw_path(pathp
)) {
617 return smbw_acl(pathp
, cmd
, nentries
, aclbufp
);
620 return real_acl(pathp
, cmd
, nentries
, aclbufp
);
624 #ifndef NO_FACL_WRAPPER
625 int facl(int fd
, int cmd
, int nentries
, void *aclbufp
)
628 return smbw_facl(fd
, cmd
, nentries
, aclbufp
);
631 return real_facl(fd
, cmd
, nentries
, aclbufp
);
635 int creat(char *path
, mode_t mode
)
637 extern int creat_bits
;
638 return open(path
, creat_bits
, mode
);
642 int creat64(char *path
, mode_t mode
)
644 extern int creat_bits
;
645 return open64(path
, creat_bits
, mode
);
650 int stat64(char *name
, void *st64
)
652 if (smbw_path(name
)) {
654 int ret
= stat(name
, xx
);
655 stat64_convert(xx
, st64
);
658 return real_stat64(name
, st64
);
661 int fstat64(int fd
, void *st64
)
665 int ret
= fstat(fd
, xx
);
666 stat64_convert(xx
, st64
);
669 return real_fstat64(fd
, st64
);
672 int lstat64(char *name
, void *st64
)
674 if (smbw_path(name
)) {
676 int ret
= lstat(name
, xx
);
677 stat64_convert(xx
, st64
);
680 return real_lstat64(name
, st64
);
685 offset_t
llseek(int fd
, offset_t ofs
, int whence
)
688 return lseek(fd
, ofs
, whence
);
690 return real_llseek(fd
, ofs
, whence
);
694 #ifdef HAVE_READDIR64
695 void *readdir64(void *dir
)
697 if (smbw_dirp(dir
)) {
698 static double xx
[70];
700 d
= (void *)readdir(dir
);
702 dirent64_convert(d
, xx
);
705 return (void *)real_readdir64(dir
);