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

📄 clitar.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
int cmd_tar(void){	fstring buf;	char **argl = NULL;	int argcl = 0;	int ret;	if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {		DEBUG(0,("tar <c|x>[IXbgan] <filename>\n"));		return 1;	}	argl=toktocliplist(&argcl, NULL);	if (!tar_parseargs(argcl, argl, buf, 0))		return 1;	ret = process_tar();	SAFE_FREE(argl);	return ret;}/****************************************************************************Command line (option) version***************************************************************************/int process_tar(void){	int rc = 0;	initarbuf();	switch(tar_type) {		case 'x':#if 0			do_tarput2();#else			do_tarput();#endif			SAFE_FREE(tarbuf);			close(tarhandle);			break;		case 'r':		case 'c':			if (clipn && tar_excl) {				int i;				pstring tarmac;				for (i=0; i<clipn; i++) {					DEBUG(5,("arg %d = %s\n", i, cliplist[i]));					if (*(cliplist[i]+strlen(cliplist[i])-1)=='\\') {						*(cliplist[i]+strlen(cliplist[i])-1)='\0';					}						if (strrchr_m(cliplist[i], '\\')) {						pstring saved_dir;	  						pstrcpy(saved_dir, cur_dir);	  						if (*cliplist[i]=='\\') {							pstrcpy(tarmac, cliplist[i]);						} else {							pstrcpy(tarmac, cur_dir);							pstrcat(tarmac, cliplist[i]);						}						pstrcpy(cur_dir, tarmac);						*(strrchr_m(cur_dir, '\\')+1)='\0';						DEBUG(5, ("process_tar, do_list with tarmac: %s\n", tarmac));						do_list(tarmac,attribute,do_tar, False, True);						pstrcpy(cur_dir,saved_dir);					} else {						pstrcpy(tarmac, cur_dir);						pstrcat(tarmac, cliplist[i]);						DEBUG(5, ("process_tar, do_list with tarmac: %s\n", tarmac));						do_list(tarmac,attribute,do_tar, False, True);					}				}			} else {				pstring mask;				pstrcpy(mask,cur_dir);				DEBUG(5, ("process_tar, do_list with mask: %s\n", mask));				pstrcat(mask,"\\*");				do_list(mask,attribute,do_tar,False, True);			}    			if (ntarf)				dotareof(tarhandle);			close(tarhandle);			SAFE_FREE(tarbuf);    			DEBUG(0, ("tar: dumped %d files and directories\n", ntarf));			DEBUG(0, ("Total bytes written: %.0f\n", (double)ttarf));			break;	}	if (must_free_cliplist) {		int i;		for (i = 0; i < clipn; ++i) {			SAFE_FREE(cliplist[i]);		}		SAFE_FREE(cliplist);		cliplist = NULL;		clipn = 0;		must_free_cliplist = False;	}	return rc;}/****************************************************************************Find a token (filename) in a clip list***************************************************************************/static int clipfind(char **aret, int ret, char *tok){	if (aret==NULL)		return 0;	/* ignore leading slashes or dots in token */	while(strchr_m("/\\.", *tok))		tok++;	while(ret--) {		char *pkey=*aret++;		/* ignore leading slashes or dots in list */		while(strchr_m("/\\.", *pkey))			pkey++;		if (!strslashcmp(pkey, tok))			return 1;	}	return 0;}/****************************************************************************Read list of files to include from the file and initialize cliplistaccordingly.***************************************************************************/static int read_inclusion_file(char *filename){	XFILE *inclusion = NULL;	char buf[PATH_MAX + 1];	char *inclusion_buffer = NULL;	int inclusion_buffer_size = 0;	int inclusion_buffer_sofar = 0;	char *p;	char *tmpstr;	int i;	int error = 0;	clipn = 0;	buf[PATH_MAX] = '\0'; /* guarantee null-termination */	if ((inclusion = x_fopen(filename, O_RDONLY, 0)) == NULL) {		/* XXX It would be better to include a reason for failure, but without		 * autoconf, it's hard to use strerror, sys_errlist, etc.		 */		DEBUG(0,("Unable to open inclusion file %s\n", filename));		return 0;	}	while ((! error) && (x_fgets(buf, sizeof(buf)-1, inclusion))) {		if (inclusion_buffer == NULL) {			inclusion_buffer_size = 1024;			if ((inclusion_buffer = SMB_MALLOC(inclusion_buffer_size)) == NULL) {				DEBUG(0,("failure allocating buffer to read inclusion file\n"));				error = 1;				break;			}		}    		if (buf[strlen(buf)-1] == '\n') {			buf[strlen(buf)-1] = '\0';		}    		if ((strlen(buf) + 1 + inclusion_buffer_sofar) >= inclusion_buffer_size) {			char *ib;			inclusion_buffer_size *= 2;			ib = SMB_REALLOC(inclusion_buffer,inclusion_buffer_size);			if (! ib) {				DEBUG(0,("failure enlarging inclusion buffer to %d bytes\n",						inclusion_buffer_size));				error = 1;				break;			} else {				inclusion_buffer = ib;			}		}    		safe_strcpy(inclusion_buffer + inclusion_buffer_sofar, buf, inclusion_buffer_size - inclusion_buffer_sofar);		inclusion_buffer_sofar += strlen(buf) + 1;		clipn++;	}	x_fclose(inclusion);	if (! error) {		/* Allocate an array of clipn + 1 char*'s for cliplist */		cliplist = SMB_MALLOC_ARRAY(char *, clipn + 1);		if (cliplist == NULL) {			DEBUG(0,("failure allocating memory for cliplist\n"));			error = 1;		} else {			cliplist[clipn] = NULL;			p = inclusion_buffer;			for (i = 0; (! error) && (i < clipn); i++) {				/* set current item to NULL so array will be null-terminated even if						* malloc fails below. */				cliplist[i] = NULL;				if ((tmpstr = (char *)SMB_MALLOC(strlen(p)+1)) == NULL) {					DEBUG(0, ("Could not allocate space for a cliplist item, # %i\n", i));					error = 1;				} else {					unfixtarname(tmpstr, p, strlen(p) + 1, True);					cliplist[i] = tmpstr;					if ((p = strchr_m(p, '\000')) == NULL) {						DEBUG(0,("INTERNAL ERROR: inclusion_buffer is of unexpected contents.\n"));						abort();					}				}				++p;			}			must_free_cliplist = True;		}	}	SAFE_FREE(inclusion_buffer);	if (error) {		if (cliplist) {			char **pp;			/* We know cliplist is always null-terminated */			for (pp = cliplist; *pp; ++pp) {				SAFE_FREE(*pp);			}			SAFE_FREE(cliplist);			cliplist = NULL;			must_free_cliplist = False;		}		return 0;	}  	/* cliplist and its elements are freed at the end of process_tar. */	return 1;}/****************************************************************************Parse tar arguments. Sets tar_type, tar_excl, etc.***************************************************************************/int tar_parseargs(int argc, char *argv[], const char *Optarg, int Optind){	int newOptind = Optind;	char tar_clipfl='\0';	/* Reset back to defaults - could be from interactive version 	 * reset mode and archive mode left as they are though	 */	tar_type='\0';	tar_excl=True;	dry_run=False;	while (*Optarg) {		switch(*Optarg++) {			case 'c':				tar_type='c';				break;			case 'x':				if (tar_type=='c') {					printf("Tar must be followed by only one of c or x.\n");					return 0;				}				tar_type='x';				break;			case 'b':				if (Optind>=argc || !(blocksize=atoi(argv[Optind]))) {					DEBUG(0,("Option b must be followed by valid blocksize\n"));					return 0;				} else {					Optind++;					newOptind++;				}				break;			case 'g':				tar_inc=True;				break;			case 'N':				if (Optind>=argc) {					DEBUG(0,("Option N must be followed by valid file name\n"));					return 0;				} else {					SMB_STRUCT_STAT stbuf;						if (sys_stat(argv[Optind], &stbuf) == 0) {						newer_than = stbuf.st_mtime;						DEBUG(1,("Getting files newer than %s",							asctime(localtime(&newer_than))));						newOptind++;						Optind++;					} else {						DEBUG(0,("Error setting newer-than time\n"));						return 0;					}				}				break;			case 'a':				tar_reset=True;				break;			case 'q':				tar_noisy=False;				break;			case 'I':				if (tar_clipfl) {					DEBUG(0,("Only one of I,X,F must be specified\n"));					return 0;				}				tar_clipfl='I';				break;			case 'X':				if (tar_clipfl) {					DEBUG(0,("Only one of I,X,F must be specified\n"));					return 0;				}				tar_clipfl='X';				break;			case 'F':				if (tar_clipfl) {					DEBUG(0,("Only one of I,X,F must be specified\n"));					return 0;				}				tar_clipfl='F';				break;			case 'r':				DEBUG(0, ("tar_re_search set\n"));				tar_re_search = True;				break;			case 'n':				if (tar_type == 'c') {					DEBUG(0, ("dry_run set\n"));					dry_run = True;				} else {					DEBUG(0, ("n is only meaningful when creating a tar-file\n"));					return 0;				}				break;			default:				DEBUG(0,("Unknown tar option\n"));				return 0;		}	}	if (!tar_type) {		printf("Option T must be followed by one of c or x.\n");		return 0;	}	/* tar_excl is true if cliplist lists files to be included.	 * Both 'I' and 'F' mean include. */	tar_excl=tar_clipfl!='X';	if (tar_clipfl=='F') {		if (argc-Optind-1 != 1) {			DEBUG(0,("Option F must be followed by exactly one filename.\n"));			return 0;		}		newOptind++;		/* Optind points at the tar output file, Optind+1 at the inclusion file. */		if (! read_inclusion_file(argv[Optind+1])) {			return 0;		}	} else if (Optind+1<argc && !tar_re_search) { /* For backwards compatibility */		char *tmpstr;		char **tmplist;		int clipcount;		cliplist=argv+Optind+1;		clipn=argc-Optind-1;		clipcount = clipn;		if ((tmplist=SMB_MALLOC_ARRAY(char *,clipn)) == NULL) {			DEBUG(0, ("Could not allocate space to process cliplist, count = %i\n", clipn));			return 0;		}		for (clipcount = 0; clipcount < clipn; clipcount++) {			DEBUG(5, ("Processing an item, %s\n", cliplist[clipcount]));			if ((tmpstr = (char *)SMB_MALLOC(strlen(cliplist[clipcount])+1)) == NULL) {				DEBUG(0, ("Could not allocate space for a cliplist item, # %i\n", clipcount));				return 0;			}			unfixtarname(tmpstr, cliplist[clipcount], strlen(cliplist[clipcount]) + 1, True);			tmplist[clipcount] = tmpstr;			DEBUG(5, ("Processed an item, %s\n", tmpstr));			DEBUG(5, ("Cliplist is: %s\n", cliplist[0]));		}		cliplist = tmplist;		must_free_cliplist = True;		newOptind += clipn;	}	if (Optind+1<argc && tar_re_search && tar_clipfl != 'F') {		/* Doing regular expression seaches not from an inclusion file. */		clipn=argc-Optind-1;		cliplist=argv+Optind+1;		newOptind += clipn;	}	if (Optind>=argc || !strcmp(argv[Optind], "-")) {		/* Sets tar handle to either 0 or 1, as appropriate */		tarhandle=(tar_type=='c');		/*		 * Make sure that dbf points to stderr if we are using stdout for 		 * tar output		 */		if (tarhandle == 1)  {			dbf = x_stderr;		}		if (!argv[Optind]) {			DEBUG(0,("Must specify tar filename\n"));			return 0;		}		if (!strcmp(argv[Optind], "-")) {			newOptind++;		}	} else {		if (tar_type=='c' && dry_run) {			tarhandle=-1;		} else if ((tar_type=='x' && (tarhandle = sys_open(argv[Optind], O_RDONLY, 0)) == -1)					|| (tar_type=='c' && (tarhandle=sys_creat(argv[Optind], 0644)) < 0)) {			DEBUG(0,("Error opening local file %s - %s\n", argv[Optind], strerror(errno)));			return(0);		}		newOptind++;	}	return newOptind;}

⌨️ 快捷键说明

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