#include #include #include #include #include #include #include #include #include #include int remove_directory(const char *path) { DIR *d = opendir(path); size_t path_len = strlen(path); int r = -1; if (d != NULL ) { struct dirent *p; r = 0; while (!r && (p=readdir(d))) { int r2 = -1; char *buf; size_t len; /* Skip the names "." and ".." as we don't want to recurse on them. */ if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..")) { continue; } len = path_len + strlen(p->d_name) + 2; buf = malloc(len); if (buf) { struct stat statbuf; snprintf(buf, len, "%s/%s", path, p->d_name); if (!stat(buf, &statbuf)) { if (S_ISDIR(statbuf.st_mode)) { r2 = remove_directory(buf); } else { r2 = unlink(buf); } } free(buf); } r = r2; } closedir(d); } if (!r) { r = rmdir(path); } return r; } char *getMark() { static char buffer[100]; strcpy(buffer, ";!@self"); strcat(buffer,"extract@!\n"); return buffer; } int findMark(int fd) { static char buffer[1024*50]; int x=lseek(fd,0,SEEK_SET); if( x<0 ) { printf("seek 0 error\n"); return -1; } x=read(fd,buffer,1024*50); if( x<0 ) { printf("read error\n"); return -1; } char *mark = getMark(); int markSize = strlen(mark); char *p; for( p=buffer ; p