⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 system.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
/*    Unix SMB/CIFS implementation.   Samba system utilities   Copyright (C) Andrew Tridgell 1992-1998   Copyright (C) Jeremy Allison  1998-2005   Copyright (C) Timur Bakeyev        2005      This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 2 of the License, or   (at your option) any later version.      This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.      You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/#include "includes.h"/*   The idea is that this file will eventually have wrappers around all   important system calls in samba. The aims are:   - to enable easier porting by putting OS dependent stuff in here   - to allow for hooks into other "pseudo-filesystems"   - to allow easier integration of things like the japanese extensions   - to support the philosophy of Samba to expose the features of     the OS within the SMB model. In general whatever file/printer/variable     expansions/etc make sense to the OS should be acceptable to Samba.*//******************************************************************* A wrapper for usleep in case we don't have one.********************************************************************/int sys_usleep(long usecs){#ifndef HAVE_USLEEP	struct timeval tval;#endif	/*	 * We need this braindamage as the glibc usleep	 * is not SPEC1170 complient... grumble... JRA.	 */	if(usecs < 0 || usecs > 1000000) {		errno = EINVAL;		return -1;	}#if HAVE_USLEEP	usleep(usecs);	return 0;#else /* HAVE_USLEEP */	/*	 * Fake it with select...	 */	tval.tv_sec = 0;	tval.tv_usec = usecs/1000;	select(0,NULL,NULL,NULL,&tval);	return 0;#endif /* HAVE_USLEEP */}/*******************************************************************A read wrapper that will deal with EINTR.********************************************************************/ssize_t sys_read(int fd, void *buf, size_t count){	ssize_t ret;	do {		ret = read(fd, buf, count);	} while (ret == -1 && errno == EINTR);	return ret;}/*******************************************************************A write wrapper that will deal with EINTR.********************************************************************/ssize_t sys_write(int fd, const void *buf, size_t count){	ssize_t ret;	do {		ret = write(fd, buf, count);	} while (ret == -1 && errno == EINTR);	return ret;}/*******************************************************************A pread wrapper that will deal with EINTR and 64-bit file offsets.********************************************************************/#if defined(HAVE_PREAD) || defined(HAVE_PREAD64)ssize_t sys_pread(int fd, void *buf, size_t count, SMB_OFF_T off){	ssize_t ret;	do {#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_PREAD64)		ret = pread64(fd, buf, count, off);#else		ret = pread(fd, buf, count, off);#endif	} while (ret == -1 && errno == EINTR);	return ret;}#endif/*******************************************************************A write wrapper that will deal with EINTR and 64-bit file offsets.********************************************************************/#if defined(HAVE_PWRITE) || defined(HAVE_PWRITE64)ssize_t sys_pwrite(int fd, const void *buf, size_t count, SMB_OFF_T off){	ssize_t ret;	do {#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_PWRITE64)		ret = pwrite64(fd, buf, count, off);#else		ret = pwrite(fd, buf, count, off);#endif	} while (ret == -1 && errno == EINTR);	return ret;}#endif/*******************************************************************A send wrapper that will deal with EINTR.********************************************************************/ssize_t sys_send(int s, const void *msg, size_t len, int flags){	ssize_t ret;	do {		ret = send(s, msg, len, flags);	} while (ret == -1 && errno == EINTR);	return ret;}/*******************************************************************A sendto wrapper that will deal with EINTR.********************************************************************/ssize_t sys_sendto(int s,  const void *msg, size_t len, int flags, const struct sockaddr *to, socklen_t tolen){	ssize_t ret;	do {		ret = sendto(s, msg, len, flags, to, tolen);	} while (ret == -1 && errno == EINTR);	return ret;}/*******************************************************************A recvfrom wrapper that will deal with EINTR.********************************************************************/ssize_t sys_recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen){	ssize_t ret;	do {		ret = recvfrom(s, buf, len, flags, from, fromlen);	} while (ret == -1 && errno == EINTR);	return ret;}/*******************************************************************A fcntl wrapper that will deal with EINTR.********************************************************************/int sys_fcntl_ptr(int fd, int cmd, void *arg){	int ret;	do {		ret = fcntl(fd, cmd, arg);	} while (ret == -1 && errno == EINTR);	return ret;}/*******************************************************************A fcntl wrapper that will deal with EINTR.********************************************************************/int sys_fcntl_long(int fd, int cmd, long arg){	int ret;	do {		ret = fcntl(fd, cmd, arg);	} while (ret == -1 && errno == EINTR);	return ret;}/*******************************************************************A stat() wrapper that will deal with 64 bit filesizes.********************************************************************/int sys_stat(const char *fname,SMB_STRUCT_STAT *sbuf){	int ret;#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_STAT64)	ret = stat64(fname, sbuf);#else	ret = stat(fname, sbuf);#endif	/* we always want directories to appear zero size */	if (ret == 0 && S_ISDIR(sbuf->st_mode)) sbuf->st_size = 0;	return ret;}/******************************************************************* An fstat() wrapper that will deal with 64 bit filesizes.********************************************************************/int sys_fstat(int fd,SMB_STRUCT_STAT *sbuf){	int ret;#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_FSTAT64)	ret = fstat64(fd, sbuf);#else	ret = fstat(fd, sbuf);#endif	/* we always want directories to appear zero size */	if (ret == 0 && S_ISDIR(sbuf->st_mode)) sbuf->st_size = 0;	return ret;}/******************************************************************* An lstat() wrapper that will deal with 64 bit filesizes.********************************************************************/int sys_lstat(const char *fname,SMB_STRUCT_STAT *sbuf){	int ret;#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_LSTAT64)	ret = lstat64(fname, sbuf);#else	ret = lstat(fname, sbuf);#endif	/* we always want directories to appear zero size */	if (ret == 0 && S_ISDIR(sbuf->st_mode)) sbuf->st_size = 0;	return ret;}/******************************************************************* An ftruncate() wrapper that will deal with 64 bit filesizes.********************************************************************/int sys_ftruncate(int fd, SMB_OFF_T offset){#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_FTRUNCATE64)	return ftruncate64(fd, offset);#else	return ftruncate(fd, offset);#endif}/******************************************************************* An lseek() wrapper that will deal with 64 bit filesizes.********************************************************************/SMB_OFF_T sys_lseek(int fd, SMB_OFF_T offset, int whence){#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_LSEEK64)	return lseek64(fd, offset, whence);#else	return lseek(fd, offset, whence);#endif}/******************************************************************* An fseek() wrapper that will deal with 64 bit filesizes.********************************************************************/int sys_fseek(FILE *fp, SMB_OFF_T offset, int whence){#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FSEEK64)	return fseek64(fp, offset, whence);#elif defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FSEEKO64)	return fseeko64(fp, offset, whence);#else	return fseek(fp, offset, whence);#endif}/******************************************************************* An ftell() wrapper that will deal with 64 bit filesizes.********************************************************************/SMB_OFF_T sys_ftell(FILE *fp){#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FTELL64)	return (SMB_OFF_T)ftell64(fp);#elif defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FTELLO64)	return (SMB_OFF_T)ftello64(fp);#else	return (SMB_OFF_T)ftell(fp);#endif}/******************************************************************* A creat() wrapper that will deal with 64 bit filesizes.********************************************************************/int sys_creat(const char *path, mode_t mode){#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_CREAT64)	return creat64(path, mode);#else	/*	 * If creat64 isn't defined then ensure we call a potential open64.	 * JRA.	 */	return sys_open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);#endif}/******************************************************************* An open() wrapper that will deal with 64 bit filesizes.********************************************************************/int sys_open(const char *path, int oflag, mode_t mode){#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OPEN64)	return open64(path, oflag, mode);#else	return open(path, oflag, mode);#endif}/******************************************************************* An fopen() wrapper that will deal with 64 bit filesizes.********************************************************************/FILE *sys_fopen(const char *path, const char *type){#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_FOPEN64)	return fopen64(path, type);#else	return fopen(path, type);#endif}/******************************************************************* An opendir wrapper that will deal with 64 bit filesizes.********************************************************************/SMB_STRUCT_DIR *sys_opendir(const char *name){#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OPENDIR64)	return opendir64(name);#else	return opendir(name);#endif}/******************************************************************* A readdir wrapper that will deal with 64 bit filesizes.********************************************************************/SMB_STRUCT_DIRENT *sys_readdir(SMB_STRUCT_DIR *dirp){#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_READDIR64)	return readdir64(dirp);#else	return readdir(dirp);#endif}/******************************************************************* A seekdir wrapper that will deal with 64 bit filesizes.********************************************************************/void sys_seekdir(SMB_STRUCT_DIR *dirp, long offset){#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_SEEKDIR64)	seekdir64(dirp, offset);#else	seekdir(dirp, offset);#endif}/******************************************************************* A telldir wrapper that will deal with 64 bit filesizes.********************************************************************/long sys_telldir(SMB_STRUCT_DIR *dirp){#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_TELLDIR64)	return (long)telldir64(dirp);#else	return (long)telldir(dirp);#endif}/******************************************************************* A rewinddir wrapper that will deal with 64 bit filesizes.********************************************************************/void sys_rewinddir(SMB_STRUCT_DIR *dirp){#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_REWINDDIR64)	rewinddir64(dirp);#else	rewinddir(dirp);#endif}/******************************************************************* A close wrapper that will deal with 64 bit filesizes.********************************************************************/int sys_closedir(SMB_STRUCT_DIR *dirp){#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_CLOSEDIR64)	return closedir64(dirp);#else	return closedir(dirp);#endif}/******************************************************************* An mknod() wrapper that will deal with 64 bit filesizes.********************************************************************/int sys_mknod(const char *path, mode_t mode, SMB_DEV_T dev){#if defined(HAVE_MKNOD) || defined(HAVE_MKNOD64)#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_MKNOD64) && defined(HAVE_DEV64_T)	return mknod64(path, mode, dev);#else	return mknod(path, mode, dev);#endif#else	/* No mknod system call. */	errno = ENOSYS;	return -1;#endif}/******************************************************************* Wrapper for realpath.********************************************************************/char *sys_realpath(const char *path, char *resolved_path){#if defined(HAVE_REALPATH)	return realpath(path, resolved_path);#else	/* As realpath is not a system call we can't return ENOSYS. */	errno = EINVAL;	return NULL;#endif}/*******************************************************************The wait() calls vary between systems********************************************************************/int sys_waitpid(pid_t pid,int *status,int options){#ifdef HAVE_WAITPID	return waitpid(pid,status,options);#else /* HAVE_WAITPID */	return wait4(pid, status, options, NULL);#endif /* HAVE_WAITPID */}/******************************************************************* System wrapper for getwd********************************************************************/char *sys_getwd(char *s){	char *wd;#ifdef HAVE_GETCWD	wd = (char *)getcwd(s, sizeof (pstring));#else	wd = (char *)getwd(s);#endif	return wd;}/*******************************************************************system wrapper for symlink********************************************************************/int sys_symlink(const char *oldpath, const char *newpath){#ifndef HAVE_SYMLINK	errno = ENOSYS;	return -1;#else	return symlink(oldpath, newpath);#endif}/*******************************************************************system wrapper for readlink********************************************************************/int sys_readlink(const char *path, char *buf, size_t bufsiz){#ifndef HAVE_READLINK

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -