Update SWAT documentation
[Samba/gebeck_regimport.git] / source / smbwrapper / wrapped.c
blob338ee0d5b1b8887087bb5c3c4eb731e41024f34e
1 /*
2 Unix SMB/CIFS implementation.
3 SMB wrapper functions
4 Copyright (C) Andrew Tridgell 1998
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 /* NOTE: This file WILL produce compiler warnings. They are unavoidable
23 Do not try and get rid of them by including other include files or
24 by including includes.h or proto.h or you will break portability.
27 #include "config.h"
28 #include <sys/types.h>
29 #include <errno.h>
30 #include "realcalls.h"
32 #ifndef NULL
33 # define NULL ((void *)0)
34 #endif
36 int open(char *name, int flags, mode_t mode)
38 if (smbw_path(name)) {
39 return smbw_open(name, flags, mode);
42 return real_open(name, flags, mode);
45 #ifdef HAVE__OPEN
46 int _open(char *name, int flags, mode_t mode)
48 return open(name, flags, mode);
50 #elif HAVE___OPEN
51 int __open(char *name, int flags, mode_t mode)
53 return open(name, flags, mode);
55 #endif
58 #ifdef HAVE_OPEN64
59 int open64(char *name, int flags, mode_t mode)
61 if (smbw_path(name)) {
62 return smbw_open(name, flags, mode);
65 return real_open64(name, flags, mode);
67 #endif
69 #ifndef NO_OPEN64_ALIAS
70 #ifdef HAVE__OPEN64
71 int _open64(char *name, int flags, mode_t mode)
73 return open64(name, flags, mode);
75 #elif HAVE___OPEN64
76 int __open64(char *name, int flags, mode_t mode)
78 return open64(name, flags, mode);
80 #endif
81 #endif
83 #ifdef HAVE_PREAD
84 ssize_t pread(int fd, void *buf, size_t size, off_t ofs)
86 if (smbw_fd(fd)) {
87 return smbw_pread(fd, buf, size, ofs);
90 return real_pread(fd, buf, size, ofs);
92 #endif
94 #if defined(HAVE_PREAD64) && defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT)
95 ssize_t pread64(int fd, void *buf, size_t size, off64_t ofs)
97 if (smbw_fd(fd)) {
98 return smbw_pread(fd, buf, size, ofs);
101 return real_pread64(fd, buf, size, ofs);
103 #endif
105 #ifdef HAVE_PWRITE
106 ssize_t pwrite(int fd, void *buf, size_t size, off_t ofs)
108 if (smbw_fd(fd)) {
109 return smbw_pwrite(fd, buf, size, ofs);
112 return real_pwrite(fd, buf, size, ofs);
114 #endif
116 #if defined(HAVE_PWRITE64) && defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT)
117 ssize_t pwrite64(int fd, void *buf, size_t size, off64_t ofs)
119 if (smbw_fd(fd)) {
120 return smbw_pwrite(fd, buf, size, ofs);
123 return real_pwrite64(fd, buf, size, ofs);
125 #endif
128 int chdir(char *name)
130 return smbw_chdir(name);
133 #ifdef HAVE___CHDIR
134 int __chdir(char *name)
136 return chdir(name);
138 #elif HAVE__CHDIR
139 int _chdir(char *name)
141 return chdir(name);
143 #endif
146 int close(int fd)
148 if (smbw_fd(fd)) {
149 return smbw_close(fd);
151 if (smbw_local_fd(fd)) {
152 errno = EBADF;
153 return -1;
156 return real_close(fd);
159 #ifdef HAVE___CLOSE
160 int __close(int fd)
162 return close(fd);
164 #elif HAVE__CLOSE
165 int _close(int fd)
167 return close(fd);
169 #endif
172 int fchdir(int fd)
174 return smbw_fchdir(fd);
177 #ifdef HAVE___FCHDIR
178 int __fchdir(int fd)
180 return fchdir(fd);
182 #elif HAVE__FCHDIR
183 int _fchdir(int fd)
185 return fchdir(fd);
187 #endif
190 int fcntl(int fd, int cmd, long arg)
192 if (smbw_fd(fd)) {
193 return smbw_fcntl(fd, cmd, arg);
196 return real_fcntl(fd, cmd, arg);
200 #ifdef HAVE___FCNTL
201 int __fcntl(int fd, int cmd, long arg)
203 return fcntl(fd, cmd, arg);
205 #elif HAVE__FCNTL
206 int _fcntl(int fd, int cmd, long arg)
208 return fcntl(fd, cmd, arg);
210 #endif
214 #ifdef real_getdents
215 int getdents(int fd, void *dirp, unsigned int count)
217 if (smbw_fd(fd)) {
218 return smbw_getdents(fd, dirp, count);
221 return real_getdents(fd, dirp, count);
223 #endif
225 #ifdef HAVE___GETDENTS
226 int __getdents(int fd, void *dirp, unsigned int count)
228 return getdents(fd, dirp, count);
230 #elif HAVE__GETDENTS
231 int _getdents(int fd, void *dirp, unsigned int count)
233 return getdents(fd, dirp, count);
235 #endif
238 off_t lseek(int fd, off_t offset, int whence)
240 if (smbw_fd(fd)) {
241 return smbw_lseek(fd, offset, whence);
244 return real_lseek(fd, offset, whence);
247 #ifdef HAVE___LSEEK
248 off_t __lseek(int fd, off_t offset, int whence)
250 return lseek(fd, offset, whence);
252 #elif HAVE__LSEEK
253 off_t _lseek(int fd, off_t offset, int whence)
255 return lseek(fd, offset, whence);
257 #endif
260 ssize_t read(int fd, void *buf, size_t count)
262 if (smbw_fd(fd)) {
263 return smbw_read(fd, buf, count);
266 return real_read(fd, buf, count);
269 #ifdef HAVE___READ
270 ssize_t __read(int fd, void *buf, size_t count)
272 return read(fd, buf, count);
274 #elif HAVE__READ
275 ssize_t _read(int fd, void *buf, size_t count)
277 return read(fd, buf, count);
279 #endif
282 ssize_t write(int fd, void *buf, size_t count)
284 if (smbw_fd(fd)) {
285 return smbw_write(fd, buf, count);
288 return real_write(fd, buf, count);
291 #ifdef HAVE___WRITE
292 ssize_t __write(int fd, void *buf, size_t count)
294 return write(fd, buf, count);
296 #elif HAVE__WRITE
297 ssize_t _write(int fd, void *buf, size_t count)
299 return write(fd, buf, count);
301 #endif
305 int access(char *name, int mode)
307 if (smbw_path(name)) {
308 return smbw_access(name, mode);
311 return real_access(name, mode);
316 int chmod(char *name,mode_t mode)
318 if (smbw_path(name)) {
319 return smbw_chmod(name, mode);
322 return real_chmod(name, mode);
327 int chown(char *name,uid_t owner, gid_t group)
329 if (smbw_path(name)) {
330 return smbw_chown(name, owner, group);
333 return real_chown(name, owner, group);
337 char *getcwd(char *buf, size_t size)
339 return (char *)smbw_getcwd(buf, size);
345 int mkdir(char *name, mode_t mode)
347 if (smbw_path(name)) {
348 return smbw_mkdir(name, mode);
351 return real_mkdir(name, mode);
355 #if HAVE___FXSTAT
356 int __fxstat(int vers, int fd, void *st)
358 double xx[32];
359 int ret;
361 if (smbw_fd(fd)) {
362 return smbw_fstat(fd, st);
365 ret = real_fstat(fd, xx);
366 xstat_convert(vers, st, xx);
367 return ret;
369 #endif
371 #if HAVE___XSTAT
372 int __xstat(int vers, char *name, void *st)
374 double xx[32];
375 int ret;
377 if (smbw_path(name)) {
378 return smbw_stat(name, st);
381 ret = real_stat(name, xx);
382 xstat_convert(vers, st, xx);
383 return ret;
385 #endif
388 #if HAVE___LXSTAT
389 int __lxstat(int vers, char *name, void *st)
391 double xx[32];
392 int ret;
394 if (smbw_path(name)) {
395 return smbw_stat(name, st);
398 ret = real_lstat(name, xx);
399 xstat_convert(vers, st, xx);
400 return ret;
402 #endif
405 int stat(char *name, void *st)
407 #if HAVE___XSTAT
408 return __xstat(0, name, st);
409 #else
410 if (smbw_path(name)) {
411 return smbw_stat(name, st);
413 return real_stat(name, st);
414 #endif
417 int lstat(char *name, void *st)
419 #if HAVE___LXSTAT
420 return __lxstat(0, name, st);
421 #else
422 if (smbw_path(name)) {
423 return smbw_stat(name, st);
425 return real_lstat(name, st);
426 #endif
429 int fstat(int fd, void *st)
431 #if HAVE___LXSTAT
432 return __fxstat(0, fd, st);
433 #else
434 if (smbw_fd(fd)) {
435 return smbw_fstat(fd, st);
437 return real_fstat(fd, st);
438 #endif
442 int unlink(char *name)
444 if (smbw_path(name)) {
445 return smbw_unlink(name);
448 return real_unlink(name);
452 #ifdef HAVE_UTIME
453 int utime(char *name,void *tvp)
455 if (smbw_path(name)) {
456 return smbw_utime(name, tvp);
459 return real_utime(name, tvp);
461 #endif
463 #ifdef HAVE_UTIMES
464 int utimes(const char *name, const struct timeval *tvp)
466 if (smbw_path(name)) {
467 return smbw_utimes(name, tvp);
470 return real_utimes(name, tvp);
472 #endif
474 int readlink(char *path, char *buf, size_t bufsize)
476 if (smbw_path(path)) {
477 return smbw_readlink(path, buf, bufsize);
480 return real_readlink(path, buf, bufsize);
484 int rename(char *oldname,char *newname)
486 int p1, p2;
487 p1 = smbw_path(oldname);
488 p2 = smbw_path(newname);
489 if (p1 ^ p2) {
490 /* can't cross filesystem boundaries */
491 errno = EXDEV;
492 return -1;
494 if (p1 && p2) {
495 return smbw_rename(oldname, newname);
498 return real_rename(oldname, newname);
501 int rmdir(char *name)
503 if (smbw_path(name)) {
504 return smbw_rmdir(name);
507 return real_rmdir(name);
511 int symlink(char *topath,char *frompath)
513 int p1, p2;
514 p1 = smbw_path(topath);
515 p2 = smbw_path(frompath);
516 if (p1 || p2) {
517 /* can't handle symlinks */
518 errno = EPERM;
519 return -1;
522 return real_symlink(topath, frompath);
525 int dup(int fd)
527 if (smbw_fd(fd)) {
528 return smbw_dup(fd);
531 return real_dup(fd);
534 int dup2(int oldfd, int newfd)
536 if (smbw_fd(newfd)) {
537 close(newfd);
540 if (smbw_fd(oldfd)) {
541 return smbw_dup2(oldfd, newfd);
544 return real_dup2(oldfd, newfd);
547 #ifdef real_opendir
548 void *opendir(char *name)
550 if (smbw_path(name)) {
551 return (void *)smbw_opendir(name);
554 return (void *)real_opendir(name);
556 #endif
558 #ifdef real_readdir
559 void *readdir(void *dir)
561 if (smbw_dirp(dir)) {
562 return (void *)smbw_readdir(dir);
565 return (void *)real_readdir(dir);
567 #endif
569 #ifdef real_closedir
570 int closedir(void *dir)
572 if (smbw_dirp(dir)) {
573 return smbw_closedir(dir);
576 return real_closedir(dir);
578 #endif
580 #ifdef real_telldir
581 off_t telldir(void *dir)
583 if (smbw_dirp(dir)) {
584 return smbw_telldir(dir);
587 return real_telldir(dir);
589 #endif
591 #ifdef real_seekdir
592 int seekdir(void *dir, off_t offset)
594 if (smbw_dirp(dir)) {
595 smbw_seekdir(dir, offset);
596 return 0;
599 real_seekdir(dir, offset);
600 return 0;
602 #endif
605 #ifndef NO_ACL_WRAPPER
606 int acl(char *pathp, int cmd, int nentries, void *aclbufp)
608 if (smbw_path(pathp)) {
609 return smbw_acl(pathp, cmd, nentries, aclbufp);
612 return real_acl(pathp, cmd, nentries, aclbufp);
614 #endif
616 #ifndef NO_FACL_WRAPPER
617 int facl(int fd, int cmd, int nentries, void *aclbufp)
619 if (smbw_fd(fd)) {
620 return smbw_facl(fd, cmd, nentries, aclbufp);
623 return real_facl(fd, cmd, nentries, aclbufp);
625 #endif
627 int creat(char *path, mode_t mode)
629 extern int creat_bits;
630 return open(path, creat_bits, mode);
633 #ifdef HAVE_CREAT64
634 int creat64(char *path, mode_t mode)
636 extern int creat_bits;
637 return open64(path, creat_bits, mode);
639 #endif
641 #ifdef HAVE_STAT64
642 int stat64(char *name, void *st64)
644 if (smbw_path(name)) {
645 double xx[32];
646 int ret = stat(name, xx);
647 stat64_convert(xx, st64);
648 return ret;
650 return real_stat64(name, st64);
653 int fstat64(int fd, void *st64)
655 if (smbw_fd(fd)) {
656 double xx[32];
657 int ret = fstat(fd, xx);
658 stat64_convert(xx, st64);
659 return ret;
661 return real_fstat64(fd, st64);
664 int lstat64(char *name, void *st64)
666 if (smbw_path(name)) {
667 double xx[32];
668 int ret = lstat(name, xx);
669 stat64_convert(xx, st64);
670 return ret;
672 return real_lstat64(name, st64);
674 #endif
676 #ifdef HAVE_LLSEEK
677 offset_t llseek(int fd, offset_t ofs, int whence)
679 if (smbw_fd(fd)) {
680 return lseek(fd, ofs, whence);
682 return real_llseek(fd, ofs, whence);
684 #endif
686 #ifdef HAVE_READDIR64
687 void *readdir64(void *dir)
689 if (smbw_dirp(dir)) {
690 static double xx[70];
691 void *d;
692 d = (void *)readdir(dir);
693 if (!d) return NULL;
694 dirent64_convert(d, xx);
695 return xx;
697 return (void *)real_readdir64(dir);
699 #endif
701 int fork(void)
703 return smbw_fork();