#include #include #include #include #include #include int try_lock(const char* path,const char* name) { struct flock fl; fl.l_type=F_RDLCK; fl.l_whence=SEEK_SET; fl.l_start=0; fl.l_len=1; std::string p(path); p+=name; int fd=open(p.c_str(),O_RDONLY); if(fd<0) { std::cerr<<"Error opening file: "<d_name<d_name[0]=='.') continue; strcpy(name,de->d_name); int fd=try_lock(path,name); if(fd>=0){ std::cout<<"Locked "<d_name)>=sizeof(name)-1) strcpy(name,"1"); else strncat(name,"1",sizeof(name)-1); if(rename(de->d_name,name)<0) std::cout<<"Error renaming: "<