DEBUG(0, -> DEBUG(10, Caught by Andrew Bartlett (thanks !).
[Samba.git] / source / smbwrapper / wrapped.c
blob904ae68f92815debfa7abf6a8069c381038b3b31
1 /*
2 Unix SMB/Netbios implementation.
3 Version 2.0
4 SMB wrapper functions
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.
28 #include "config.h"
29 #include <sys/types.h>
30 #include <errno.h>
31 #include "realcalls.h"
33 #ifndef NULL
34 # define NULL ((void *)0)
35 #endif
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);
46 #ifdef HAVE__OPEN
47 int _open(char *name, int flags, mode_t mode)
49 return open(name, flags, mode);
51 #elif HAVE___OPEN
52 int __open(char *name, int flags, mode_t mode)
54 return open(name, flags, mode);
56 #endif
59 #ifdef HAVE_OPEN64
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);
68 #endif
70 #ifndef NO_OPEN64_ALIAS
71 #ifdef HAVE__OPEN64
72 int _open64(char *name, int flags, mode_t mode)
74 return open64(name, flags, mode);
76 #elif HAVE___OPEN64
77 int __open64(char *name, int flags, mode_t mode)
79 return open64(name, flags, mode);
81 #endif
82 #endif
84 #ifdef HAVE_PREAD
85 ssize_t pread(int fd, void *buf, size_t size, off_t ofs)
87 if (smbw_fd(fd)) {
88 return smbw_pread(fd, buf, size, ofs);
91 return real_pread(fd, buf, size, ofs);
93 #endif
95 #if defined(HAVE_PREAD64) && defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT)
96 ssize_t pread64(int fd, void *buf, size_t size, off64_t ofs)
98 if (smbw_fd(fd)) {
99 return smbw_pread(fd, buf, size, ofs);
102 return real_pread64(fd, buf, size, ofs);
104 #endif
106 #ifdef HAVE_PWRITE
107 ssize_t pwrite(int fd, void *buf, size_t size, off_t ofs)
109 if (smbw_fd(fd)) {
110 return smbw_pwrite(fd, buf, size, ofs);
113 return real_pwrite(fd, buf, size, ofs);
115 #endif
117 #if defined(HAVE_PWRITE64) && defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT)
118 ssize_t pwrite64(int fd, void *buf, size_t size, off64_t ofs)
120 if (smbw_fd(fd)) {
121 return smbw_pwrite(fd, buf, size, ofs);
124 return real_pwrite64(fd, buf, size, ofs);
126 #endif
129 int chdir(char *name)
131 return smbw_chdir(name);
134 #ifdef HAVE___CHDIR
135 int __chdir(char *name)
137 return chdir(name);
139 #elif HAVE__CHDIR
140 int _chdir(char *name)
142 return chdir(name);
144 #endif
147 int close(int fd)
149 if (smbw_fd(fd)) {
150 return smbw_close(fd);
152 if (smbw_local_fd(fd)) {
153 errno = EBADF;
154 return -1;
157 return real_close(fd);
160 #ifdef HAVE___CLOSE
161 int __close(int fd)
163 return close(fd);
165 #elif HAVE__CLOSE
166 int _close(int fd)
168 return close(fd);
170 #endif
173 int fchdir(int fd)
175 return smbw_fchdir(fd);
178 #ifdef HAVE___FCHDIR
179 int __fchdir(int fd)
181 return fchdir(fd);
183 #elif HAVE__FCHDIR
184 int _fchdir(int fd)
186 return fchdir(fd);
188 #endif
191 int fcntl(int fd, int cmd, long arg)
193 if (smbw_fd(fd)) {
194 return smbw_fcntl(fd, cmd, arg);
197 return real_fcntl(fd, cmd, arg);
201 #ifdef HAVE___FCNTL
202 int __fcntl(int fd, int cmd, long arg)
204 return fcntl(fd, cmd, arg);
206 #elif HAVE__FCNTL
207 int _fcntl(int fd, int cmd, long arg)
209 return fcntl(fd, cmd, arg);
211 #endif
215 #ifdef real_getdents
216 int getdents(int fd, void *dirp, unsigned int count)
218 if (smbw_fd(fd)) {
219 return smbw_getdents(fd, dirp, count);
222 return real_getdents(fd, dirp, count);
224 #endif
226 #ifdef HAVE___GETDENTS
227 int __getdents(int fd, void *dirp, unsigned int count)
229 return getdents(fd, dirp, count);
231 #elif HAVE__GETDENTS
232 int _getdents(int fd, void *dirp, unsigned int count)
234 return getdents(fd, dirp, count);
236 #endif
239 off_t lseek(int fd, off_t offset, int whence)
241 if (smbw_fd(fd)) {
242 return smbw_lseek(fd, offset, whence);
245 return real_lseek(fd, offset, whence);
248 #ifdef HAVE___LSEEK
249 off_t __lseek(int fd, off_t offset, int whence)
251 return lseek(fd, offset, whence);
253 #elif HAVE__LSEEK
254 off_t _lseek(int fd, off_t offset, int whence)
256 return lseek(fd, offset, whence);
258 #endif
261 ssize_t read(int fd, void *buf, size_t count)
263 if (smbw_fd(fd)) {
264 return smbw_read(fd, buf, count);
267 return real_read(fd, buf, count);
270 #ifdef HAVE___READ
271 ssize_t __read(int fd, void *buf, size_t count)
273 return read(fd, buf, count);
275 #elif HAVE__READ
276 ssize_t _read(int fd, void *buf, size_t count)
278 return read(fd, buf, count);
280 #endif
283 ssize_t write(int fd, void *buf, size_t count)
285 if (smbw_fd(fd)) {
286 return smbw_write(fd, buf, count);
289 return real_write(fd, buf, count);
292 #ifdef HAVE___WRITE
293 ssize_t __write(int fd, void *buf, size_t count)
295 return write(fd, buf, count);
297 #elif HAVE__WRITE
298 ssize_t _write(int fd, void *buf, size_t count)
300 return write(fd, buf, count);
302 #endif
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);
356 #if HAVE___FXSTAT
357 int __fxstat(int vers, int fd, void *st)
359 double xx[32];
360 int ret;
362 if (smbw_fd(fd)) {
363 return smbw_fstat(fd, st);
366 ret = real_fstat(fd, xx);
367 xstat_convert(vers, st, xx);
368 return ret;
370 #endif
372 #if HAVE___XSTAT
373 int __xstat(int vers, char *name, void *st)
375 double xx[32];
376 int ret;
378 if (smbw_path(name)) {
379 return smbw_stat(name, st);
382 ret = real_stat(name, xx);
383 xstat_convert(vers, st, xx);
384 return ret;
386 #endif
389 #if HAVE___LXSTAT
390 int __lxstat(int vers, char *name, void *st)
392 double xx[32];
393 int ret;
395 if (smbw_path(name)) {
396 return smbw_stat(name, st);
399 ret = real_lstat(name, xx);
400 xstat_convert(vers, st, xx);
401 return ret;
403 #endif
406 int stat(char *name, void *st)
408 #if HAVE___XSTAT
409 return __xstat(0, name, st);
410 #else
411 if (smbw_path(name)) {
412 return smbw_stat(name, st);
414 return real_stat(name, st);
415 #endif
418 int lstat(char *name, void *st)
420 #if HAVE___LXSTAT
421 return __lxstat(0, name, st);
422 #else
423 if (smbw_path(name)) {
424 return smbw_stat(name, st);
426 return real_lstat(name, st);
427 #endif
430 int fstat(int fd, void *st)
432 #if HAVE___LXSTAT
433 return __fxstat(0, fd, st);
434 #else
435 if (smbw_fd(fd)) {
436 return smbw_fstat(fd, st);
438 return real_fstat(fd, st);
439 #endif
443 int unlink(char *name)
445 if (smbw_path(name)) {
446 return smbw_unlink(name);
449 return real_unlink(name);
453 #ifdef HAVE_UTIME
454 int utime(char *name,void *tvp)
456 if (smbw_path(name)) {
457 return smbw_utime(name, tvp);
460 return real_utime(name, tvp);
462 #endif
464 #ifdef HAVE_UTIMES
466 #ifdef HAVE_SYS_TIME_H
467 #include <sys/time.h>
468 #else
469 #include <time.h>
470 #endif
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);
480 #endif
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)
494 int p1, p2;
495 p1 = smbw_path(oldname);
496 p2 = smbw_path(newname);
497 if (p1 ^ p2) {
498 /* can't cross filesystem boundaries */
499 errno = EXDEV;
500 return -1;
502 if (p1 && p2) {
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)
521 int p1, p2;
522 p1 = smbw_path(topath);
523 p2 = smbw_path(frompath);
524 if (p1 || p2) {
525 /* can't handle symlinks */
526 errno = EPERM;
527 return -1;
530 return real_symlink(topath, frompath);
533 int dup(int fd)
535 if (smbw_fd(fd)) {
536 return smbw_dup(fd);
539 return real_dup(fd);
542 int dup2(int oldfd, int newfd)
544 if (smbw_fd(newfd)) {
545 close(newfd);
548 if (smbw_fd(oldfd)) {
549 return smbw_dup2(oldfd, newfd);
552 return real_dup2(oldfd, newfd);
555 #ifdef real_opendir
556 void *opendir(char *name)
558 if (smbw_path(name)) {
559 return (void *)smbw_opendir(name);
562 return (void *)real_opendir(name);
564 #endif
566 #ifdef real_readdir
567 void *readdir(void *dir)
569 if (smbw_dirp(dir)) {
570 return (void *)smbw_readdir(dir);
573 return (void *)real_readdir(dir);
575 #endif
577 #ifdef real_closedir
578 int closedir(void *dir)
580 if (smbw_dirp(dir)) {
581 return smbw_closedir(dir);
584 return real_closedir(dir);
586 #endif
588 #ifdef real_telldir
589 off_t telldir(void *dir)
591 if (smbw_dirp(dir)) {
592 return smbw_telldir(dir);
595 return real_telldir(dir);
597 #endif
599 #ifdef real_seekdir
600 int seekdir(void *dir, off_t offset)
602 if (smbw_dirp(dir)) {
603 smbw_seekdir(dir, offset);
604 return 0;
607 real_seekdir(dir, offset);
608 return 0;
610 #endif
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);
622 #endif
624 #ifndef NO_FACL_WRAPPER
625 int facl(int fd, int cmd, int nentries, void *aclbufp)
627 if (smbw_fd(fd)) {
628 return smbw_facl(fd, cmd, nentries, aclbufp);
631 return real_facl(fd, cmd, nentries, aclbufp);
633 #endif
635 int creat(char *path, mode_t mode)
637 extern int creat_bits;
638 return open(path, creat_bits, mode);
641 #ifdef HAVE_CREAT64
642 int creat64(char *path, mode_t mode)
644 extern int creat_bits;
645 return open64(path, creat_bits, mode);
647 #endif
649 #ifdef HAVE_STAT64
650 int stat64(char *name, void *st64)
652 if (smbw_path(name)) {
653 double xx[32];
654 int ret = stat(name, xx);
655 stat64_convert(xx, st64);
656 return ret;
658 return real_stat64(name, st64);
661 int fstat64(int fd, void *st64)
663 if (smbw_fd(fd)) {
664 double xx[32];
665 int ret = fstat(fd, xx);
666 stat64_convert(xx, st64);
667 return ret;
669 return real_fstat64(fd, st64);
672 int lstat64(char *name, void *st64)
674 if (smbw_path(name)) {
675 double xx[32];
676 int ret = lstat(name, xx);
677 stat64_convert(xx, st64);
678 return ret;
680 return real_lstat64(name, st64);
682 #endif
684 #ifdef HAVE_LLSEEK
685 offset_t llseek(int fd, offset_t ofs, int whence)
687 if (smbw_fd(fd)) {
688 return lseek(fd, ofs, whence);
690 return real_llseek(fd, ofs, whence);
692 #endif
694 #ifdef HAVE_READDIR64
695 void *readdir64(void *dir)
697 if (smbw_dirp(dir)) {
698 static double xx[70];
699 void *d;
700 d = (void *)readdir(dir);
701 if (!d) return NULL;
702 dirent64_convert(d, xx);
703 return xx;
705 return (void *)real_readdir64(dir);
707 #endif
709 int fork(void)
711 return smbw_fork();