void buscar(char *home,const char *destino)
{
  DIR *dirp;
  struct dirent *dir;
  int fd,i,de,ds,nbytes;
  char *duplicado;
  char *pathdest;
  char *pathhome;
  char buffer[BUFSIZ];
 
                        if((dirp=opendir(home))==NULL)
                          {
                            perror(home);
                            exit(-1);
                          }
 
            
        
          if((pathdest=(char *)calloc(80,sizeof(char)))==NULL)
                           {
                              perror("malloc");
                              exit(-1);
                           }
 
                         if((pathhome=(char *)calloc(80,sizeof(char)))==NULL)
                           {
                              perror("malloc home");
                              exit(-1);
                           }
                     printf("memoria reservada\n");
     
                    while((dir=readdir(dirp))!=NULL)
                      {
       
                         
                
               printf("empezando while\n");
       
                         duplicado=strdup(dir->d_name);
 
                            for(i=strlen(dir->d_name)-1;i>0;i--)
                               if(duplicado[i]=='~')
                           {
                                  
                            pathhome=(char *)realloc(pathhome,((strlen(home))+((strlen(dir->d_name)))));
                                  pathdest=(char *)realloc(pathdest,((strlen(destino))+((strlen(duplicado)))));
             
                                
                                   sprintf(pathhome,"%s/%s",home,duplicado);
                             sprintf(pathdest,"%s/%s",destino,duplicado);
                                   
                
                                    if((fd=creat(pathdest,0666))==-1)
                                {
                                perror(pathdest);
                          exit(-1);
                         }
            
                       if((de=open(pathhome,O_RDONLY))==-1)
                                     {
                    perror(pathhome);
                                      exit(-1);
                         }
                   
                       if((ds=open(pathdest,O_WRONLY))==-1)
                         {
                                      perror(pathdest);
                                      exit(-1);
                                     }
                      
                     while((nbytes=read(de,buffer,sizeof(buffer)))>0)
                       if((write(ds,buffer,nbytes))!=nbytes)
                                   fprintf(stderr,"Error de escritura en %s\n",ds);
          
        
                        close(de);
                                    close(ds);
 
                       if((unlink(pathhome))==-1)
                        {
                                      perror(pathhome);
                                      exit(-1);
                                    }
                        // printf("petando aqui\n");
                                      
            
                        }
                               //printf("hola\n");
                                
                   printf("repitiendo while\n");
             }
      printf("acabando\n");
      
  
  closedir(dirp);
  free(source);
 printf("source liberado\n");
  free(destdir);
  printf("des liberado\n");
  free(pathdest);
  printf("pathdest liberado\n");
  free(duplicado);
  printf("duplicado liberado\n");
  free(pathhome);
  printf("pathhome liberado\n"); 
  }