int main(void) { for(int i = 0; i < SIZE; i++) { head[i] = NULL; } char* input = "apple"; char* input2 = "avocado"; int box = hashfunc(input); insertlist(input, box); box = hashfunc(input2); insertlist(input2, box); node* ptr = head[0]; while( ptr != NULL) { printf("%s\n", ptr->s); ptr = ptr->next; } }
void create_nonexist_node(char * name,int type) { UploadNode *p0; p0=(UploadNode *)malloc(sizeof(UploadNode)); int len = strlen(name)+1; p0->filename = (char *)malloc(len); memset(p0->filename,0, len); strcpy(p0->filename,name); //state=UPLOAD_FILE_NONEXIST , not upload in time //BD if(type==1) { int len2=strlen(uploadPath->BDLocalPathPrefix)+1; p0->analysisCenterPath=(char *)malloc(len2); memset(p0->analysisCenterPath,0, len2); strcpy(p0->analysisCenterPath,uploadPath->BDLocalPathPrefix); } //GNSS else { int len2=strlen(uploadPath->GNSSLocalPathPrefix)+1; p0->analysisCenterPath=(char *)malloc(len2); memset(p0->analysisCenterPath,0, len2); strcpy(p0->analysisCenterPath,uploadPath->GNSSLocalPathPrefix); } p0->productCenterPath = (char *)malloc(1); memset(p0->productCenterPath,0, 1); p0->state=UPLOAD_FILE_NONEXIST; p0->type = type; pthread_mutex_unlock(&uploadMutex);//unlock insertlist(p0); pthread_mutex_lock(&uploadMutex);//lock }
int main(){ node* head=NULL; node* p = (node*)malloc(sizeof(node)); head = p; p->pre = p; p->next = p; p->data = 0 ; insertlist(&p,2); insertlist(&p,3); insertlist(&p,4); insertlist(&p,5); insertlist(&p,6); insertlist(&p,7); insertlist(&p,8); insertlist(&p,9); insertlist(&p,10); insertlist(&p,11); insertlist(&p,12); insertlist(&p,13); insertlist(&p,14); print(&p,1); printf("-------------\n"); print(&p,2); }
static void _inotify_event_handler(struct inotify_event *event) { /* Perform event dependent handler routines */ /* The mask is the magic that tells us what file operation occurred */ if(strstr(event->name,UNIX_Z)==0) { /*File was closed */ if(event->mask & IN_CLOSE_WRITE) { #ifdef DEBUG printf("wd:%d",event->wd); printf("IN_CLOSE_WRITE\n"); printf("event->name: %s\n", event->name); #endif char command[COMMAND_SIZE]={0}; FILE *pf; //get the command to compress the file with unix.z if(event->wd==1) sprintf(command,"compress -f %s%s",uploadPath->BDLocalPathPrefix,event->name); else sprintf(command,"compress -f %s%s",uploadPath->GNSSLocalPathPrefix,event->name); //execute the command of compression if((pf=popen(command,"r"))==NULL) { //compression failed #ifdef _DEBUG perror("压缩失败"); #endif } pclose(pf); up_delay(); } /* File was deleted means the compression is over*/ if(event->mask & IN_DELETE) { #ifdef DEBUG printf("IN_DELETE\n"); printf("event->name: %s\n", event->name); #endif int type = event-> wd; char name[STD_FILENAME_SIZE]="0"; strcpy(name,event->name); if(nodeIsExist(name,type)==1) { char * dir; UploadNode *p0; p0=(UploadNode *)malloc(sizeof(UploadNode)); int len1 = strlen(name)+strlen(UNIX_Z)+1; p0->filename=(char *)malloc(len1); memset(p0->filename,0, len1); sprintf(p0->filename,"%s%s",name,UNIX_Z); printf("filename:%s\n",p0->filename); //move the file to the backup folder dir = (char *)malloc(10); memset(dir,0,10); //move the file to the backup folder copyfile(p0->filename,type,dir); //BEIDOU if(type==1) { int len2=strlen(uploadPath->BDLocalPathPrefix)+1; p0->analysisCenterPath=(char *)malloc(len2); memset(p0->analysisCenterPath,0, len2); strcpy(p0->analysisCenterPath,uploadPath->BDLocalPathPrefix); int len3 = strlen(uploadPath->BDRemotePathPrefix)+strlen(dir)+strlen(PATH_SUFFIX)+1; p0->productCenterPath=(char *)malloc(len3); memset(p0->productCenterPath,0, len3); sprintf(p0->productCenterPath,"%s%s%s",uploadPath->BDRemotePathPrefix,dir,PATH_SUFFIX); } //GNSS else { int len2=strlen(uploadPath->GNSSLocalPathPrefix)+1; p0->analysisCenterPath=(char *)malloc(len2); memset(p0->analysisCenterPath,0, len2); strcpy(p0->analysisCenterPath,uploadPath->GNSSLocalPathPrefix); int len3 = strlen(uploadPath->GNSSRemotePathPrefix)+strlen(dir)+strlen(PATH_SUFFIX)+1; p0->productCenterPath=(char *)malloc(len3); memset(p0->productCenterPath,0, len3); sprintf(p0->productCenterPath,"%s%s%s",uploadPath->GNSSRemotePathPrefix,dir,PATH_SUFFIX); } p0->state=UPLOAD_FILE_EXIST; p0->type = type; p0->server=fs->next; #ifdef DEBUG printf("filename:%s\n",p0->filename); printf("传入:%s\n",p0->filename); log_checktask(p0->filename,"文件创建"); #endif //create a new node insertlist(p0); } } } }