?? wrapper.c
字號:
int symlink(const char *topath, const char *frompath){ int p1, p2; check_init("symlink"); p1 = smbw_path((char *) topath); p2 = smbw_path((char *) frompath); if (p1 || p2) { /* can't handle symlinks */ errno = EPERM; return -1; } return (* smbw_libc.symlink)((char *) topath, (char *) frompath);}int dup(int fd){ check_init("dup"); if (smbw_fd(fd)) { return smbw_dup(fd); } return (* smbw_libc.dup)(fd);}int dup2(int oldfd, int newfd){ check_init("dup2"); if (smbw_fd(newfd)) { (* smbw_libc.close)(newfd); } if (smbw_fd(oldfd)) { return smbw_dup2(oldfd, newfd); } return (* smbw_libc.dup2)(oldfd, newfd);}DIR *opendir(const char *name){ check_init("opendir"); if (smbw_path((char *) name)) { return (void *)smbw_opendir((char *) name); } return (* smbw_libc.opendir)((char *) name);}struct dirent *readdir(DIR *dir){ check_init("readdir"); if (smbw_dirp(dir)) { static struct dirent external; struct SMBW_dirent * internal = (void *)smbw_readdir(dir); if (internal != NULL) { dirent_convert(internal, &external); return &external; } return NULL; } return (* smbw_libc.readdir)(dir);}int closedir(DIR *dir){ check_init("closedir"); if (smbw_dirp(dir)) { return smbw_closedir(dir); } return (* smbw_libc.closedir)(dir);}long telldir(DIR *dir){ check_init("telldir"); if (smbw_dirp(dir)) { return (long) smbw_telldir(dir); } return (* smbw_libc.telldir)(dir);}void seekdir(DIR *dir, long offset){ check_init("seekdir"); if (smbw_dirp(dir)) { smbw_seekdir(dir, (long long) offset); return; } (* smbw_libc.seekdir)(dir, offset);}int creat(const char *path, mode_t mode){ extern int creat_bits; check_init("creat"); return openx((char *) path, creat_bits, mode, smbw_libc.open);}int creat64(const char *path, mode_t mode){ extern int creat_bits; check_init("creat64"); return openx((char *) path, creat_bits, mode, smbw_libc.open64);}int __xstat64 (int ver, const char *name, struct stat64 *st64){ check_init("__xstat64"); if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat64_convert(&statbuf, st64); return ret; } return (* smbw_libc.__xstat64)(ver, (char *) name, st64);}int stat64(const char *name, struct stat64 *st64){ check_init("stat64"); if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat64_convert(&statbuf, st64); return ret; } return (* smbw_libc.stat64)((char *) name, st64);}int __fxstat64(int ver, int fd, struct stat64 *st64){ check_init("__fxstat64"); if (smbw_fd(fd)) { struct SMBW_stat statbuf; int ret = smbw_fstat(fd, &statbuf); stat64_convert(&statbuf, st64); return ret; } return (* smbw_libc.__fxstat64)(ver, fd, st64);}int fstat64(int fd, struct stat64 *st64){ check_init("fstat64"); if (smbw_fd(fd)) { struct SMBW_stat statbuf; int ret = smbw_fstat(fd, &statbuf); stat64_convert(&statbuf, st64); return ret; } return (* smbw_libc.fstat64)(fd, st64);}int __lxstat64(int ver, const char *name, struct stat64 *st64){ check_init("__lxstat64"); if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat(name, &statbuf); stat64_convert(&statbuf, st64); return ret; } return (* smbw_libc.__lxstat64)(ver, (char *) name, st64);}int lstat64(const char *name, struct stat64 *st64){ check_init("lstat64"); if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat64_convert(&statbuf, st64); return ret; } return (* smbw_libc.lstat64)((char *) name, st64);}int _llseek(unsigned int fd, unsigned long offset_high, unsigned long offset_low, loff_t *result, unsigned int whence){ check_init("_llseek"); if (smbw_fd(fd)) { *result = lseek(fd, offset_low, whence); return (*result < 0 ? -1 : 0); } return (* smbw_libc._llseek)(fd, offset_high, offset_low, result, whence);}struct dirent64 *readdir64(DIR *dir){ check_init("readdir64"); if (smbw_dirp(dir)) { static struct dirent64 external; struct SMBW_dirent * internal = (void *)smbw_readdir(dir); if (internal != NULL) { dirent64_convert(internal, &external); return &external; } return NULL; } return (* smbw_libc.readdir64)(dir);}int readdir_r(DIR *dir, struct dirent *external, struct dirent **result){ check_init("readdir_r"); if (smbw_dirp(dir)) { struct SMBW_dirent internal; int ret = smbw_readdir_r(dir, &internal, NULL); if (ret == 0) { dirent_convert(&internal, external); *result = external; } return ret; } return (* smbw_libc.readdir_r)(dir, external, result);}int readdir64_r(DIR *dir, struct dirent64 *external, struct dirent64 **result){ check_init("readdir64_r"); if (smbw_dirp(dir)) { struct SMBW_dirent internal; int ret = smbw_readdir_r(dir, &internal, NULL); if (ret == 0) { dirent64_convert(&internal, external); *result = external; } return ret; } return (* smbw_libc.readdir64_r)(dir, external, result);}int fork(void){ check_init("fork"); return smbw_fork();}int setxattr(const char *fname, const char *name, const void *value, size_t size, int flags){ if (smbw_path(fname)) { return smbw_setxattr(fname, name, value, size, flags); } return (* smbw_libc.setxattr)(fname, name, value, size, flags);}int lsetxattr(const char *fname, const char *name, const void *value, size_t size, int flags){ if (smbw_path(fname)) { return smbw_lsetxattr(fname, name, value, size, flags); } return (* smbw_libc.lsetxattr)(fname, name, value, size, flags);}int fsetxattr(int fd, const char *name, const void *value, size_t size, int flags){ if (smbw_fd(fd)) { return smbw_fsetxattr(fd, name, value, size, flags); } return (* smbw_libc.fsetxattr)(fd, name, value, size, flags);}int getxattr(const char *fname, const char *name, const void *value, size_t size){ if (smbw_path(fname)) { return smbw_getxattr(fname, name, value, size); } return (* smbw_libc.getxattr)(fname, name, value, size);}int lgetxattr(const char *fname, const char *name, const void *value, size_t size){ if (smbw_path(fname)) { return smbw_lgetxattr(fname, name, value, size); } return (* smbw_libc.lgetxattr)(fname, name, value, size);}int fgetxattr(int fd, const char *name, const void *value, size_t size){ if (smbw_fd(fd)) { return smbw_fgetxattr(fd, name, value, size); } return (* smbw_libc.fgetxattr)(fd, name, value, size);}int removexattr(const char *fname, const char *name){ if (smbw_path(fname)) { return smbw_removexattr(fname, name); } return (* smbw_libc.removexattr)(fname, name);}int lremovexattr(const char *fname, const char *name){ if (smbw_path(fname)) { return smbw_lremovexattr(fname, name); } return (* smbw_libc.lremovexattr)(fname, name);}int fremovexattr(int fd, const char *name){ if (smbw_fd(fd)) { return smbw_fremovexattr(fd, name); } return (* smbw_libc.fremovexattr)(fd, name);}int listxattr(const char *fname, char *list, size_t size){ if (smbw_path(fname)) { return smbw_listxattr(fname, list, size); } return (* smbw_libc.listxattr)(fname, list, size);}int llistxattr(const char *fname, char *list, size_t size){ if (smbw_path(fname)) { return smbw_llistxattr(fname, list, size); } return (* smbw_libc.llistxattr)(fname, list, size);}int flistxattr(int fd, char *list, size_t size){ if (smbw_fd(fd)) { return smbw_flistxattr(fd, list, size); } return (* smbw_libc.flistxattr)(fd, list, size);}/* * We're ending up with a different implementation of malloc() with smbwrapper * than without it. The one with it does not support returning a non-NULL * pointer from a call to malloc(0), and many apps depend on getting a valid * pointer when requesting zero length (e.g. df, emacs). * * Unfortunately, initializing the smbw_libc[] array via the dynamic link * library (libdl) requires malloc so we can't just do the same type of * mapping to the C library as we do with everything else. We need to * implement a different way of allocating memory that ensures that the C * library version of malloc() gets used. This is the only place where we * kludge the code to use an undocumented interface to the C library. * * If anyone can come up with a way to dynamically link to the C library * rather than using this undocumented interface, I'd sure love to hear about * it. Better yet, if you can figure out where the alternate malloc() * functions are coming from and arrange for them not to be called, that would * be even better. We should try to avoid wrapping functions that don't * really require it. */void *malloc(size_t size){ void *__libc_malloc(size_t size); return __libc_malloc(size);}void *calloc(size_t nmemb, size_t size){ void *__libc_calloc(size_t nmemb, size_t size); return __libc_calloc(nmemb, size);}void *realloc(void *ptr, size_t size){ void *__libc_realloc(void *ptr, size_t size); return __libc_realloc(ptr, size);}void free(void *ptr){ static int in_progress = 0; void __libc_free(void *ptr); if (in_progress) return; in_progress = 1; __libc_free(ptr); in_progress = 0;}#if 0 /* SELECT */static struct sigaction user_action[_NSIG];static voidsmbw_sigaction_handler(int signum, siginfo_t *info, void *context){ /* Our entire purpose for trapping signals is to call this! */ sys_select_signal(); /* Call the user's handler */ if (user_action[signum].sa_handler != SIG_IGN && user_action[signum].sa_handler != SIG_DFL && user_action[signum].sa_handler != SIG_ERR) { (* user_action[signum].sa_sigaction)(signum, info, context); }}/* * Every Samba signal handler must call sys_select_signal() to avoid a race * condition, so we'll take whatever signal handler is currently assigned, * call call sys_select_signal() in addition to their call. */static intdo_select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout, int (* select_fn)(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)){ int i; int ret; int saved_errno; sigset_t sigset; struct sigaction new_action; saved_errno = errno; for (i=1; i<_NSIG; i++) { sigemptyset(&sigset); new_action.sa_mask = sigset; new_action.sa_flags = SA_SIGINFO; new_action.sa_sigaction = smbw_sigaction_handler; if (sigaction(i, &new_action, &user_action[i]) < 0) { if (errno != EINVAL) { return -1; } } } errno = saved_errno; ret = (* select_fn)(n, readfds, writefds, exceptfds, timeout); saved_errno = errno; for (i=0; i<_NSIG; i++) { (void) sigaction(i, &user_action[i], NULL); } errno = saved_errno; return ret;}intselect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout){ check_init("select"); return do_select(n, readfds, writefds, exceptfds, timeout, smbw_libc.select);}int_select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout){ check_init("_select"); return do_select(n, readfds, writefds, exceptfds, timeout, smbw_libc._select);}int__select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout){ check_init("__select"); return do_select(n, readfds, writefds, exceptfds, timeout, smbw_libc.__select);}#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -