Пример #1
0
int choice(int sfd,packet* pk,int* fd)
{
		switch(pk->type)
	    {
		case 0:
			get(pk,fd);
			break;
		case 1:
			mycd(pk);
			break;
		case 2:
			myls(pk);
			break;
		case 3:
			myputs(sfd,pk);
			break;
		case 4:
			mygets(pk,fd);
			break;
		case 5:
			myremove(pk);
			break;
		case 6:
			mypwd(pk);
			break;
		case 7:
			getend(fd);
			break;
		default:
			break;
		}
		return 0;
}
Пример #2
0
int
main( int argc, char* argv[]){
    if (argc != 2){
	printf("Numar insuficient de argumente!\n");
	exit(EXIT_FAILURE);
    }

    myremove(argv[1]);

    return EXIT_SUCCESS;
}
Пример #3
0
void
myremove( const char* cale){
    DIR* d;

    errno = 0;
    d = opendir(cale);
    if ( errno == ENOTDIR){
	/* fisier normal*/
	remove(cale);
    }
    else{
	if ( d == NULL){
	    perror(cale);
	    exit( EXIT_FAILURE);
	}
	else{
	    char* noua_cale = NULL;
	    char* aux = NULL;
	    struct dirent* id;

	    while (( id = readdir(d)) != NULL){
		if ((strcmp(id->d_name, ".") == 0) || ( strcmp( id->d_name, "..") == 0))
		    ;
		else{
		    aux = realloc ( noua_cale, strlen(cale) + strlen(id->d_name) + 2 );
		    if (aux == NULL)
			exit(EXIT_FAILURE);
		    noua_cale = aux;
		    strcpy( noua_cale, cale);
		    strcat( noua_cale, "/");
		    strcat( noua_cale, id->d_name);
		    myremove(noua_cale);
		    free(noua_cale);
		    noua_cale = NULL;
		}
	    }
	    if (noua_cale != NULL)
		free( noua_cale);

	    closedir(d);
	    remove(cale);
	}
    }
}
Пример #4
0
/*
 *选择:0<往链接写报文>/1<cd>/2<myls>/3<打开文件>/4<读取服务端文件内容并发给客户端>
 *******5<移除文件>/6<获取当前路径>/7<关闭链接>/8<退出循环>
 * */
int choice(node* n,packet* pk,int* running,char *filedir)
{
		switch(pk->type)
		{
				case 0:
						put(pk,n->put_fd);
						break;
				case 1:
						mycd(pk,n->curdir);
						send_pk(n->accept_fd,pk);
						break;
				case 2:
						myls(pk,n->curdir);
						send_pk(n->accept_fd,pk);
						break;
				case 3:
						myputs(pk,&(n->put_fd),filedir);
						send_pk(n->accept_fd,pk);
						break;
				case 4:
						mygets(n->accept_fd,pk,n->curdir);
						break;
				case 5:
						myremove(pk,n->curdir);
						send_pk(n->accept_fd,pk);
						break;
				case 6: 
						mypwd(pk,n->curdir);
						send_pk(n->accept_fd,pk);
						break;
				case 7:
						putend(&(n->put_fd));
						break;
				case 8:
						*running=0;
						break;
				default:break;
		}
		return 0;
}