void do_rename(const char *filename) { FILE *f; int a, len; unsigned char crc; unsigned char buf[130]; char name[100], type[100]; f = fopen(filename, "rb"); if (f == NULL) return; len = fread(buf, 1, 130, f); if (len != 130) { printf("# i/o error reading first block of file '%s'\n", filename); return; } crc = 0; for (a = 1;a < 129;a++) crc += buf[a]; if (crc != buf[129]) { printf("# crc error: in file %02xh, calculated %02xh\n", buf[129], crc); return; } if (check_file_type(name, type, buf)) printf("mv '%s' '%s' # type = %s\n", filename, name, type); else printf("# can't determine type of file '%s'\n", filename); }
int init_analyzing( CHAR *filename, file_analyzer *analyzer ) { int ret; byte *data; dword data_len; ASSERT( NULL != analyzer ); ret = read_all_file_data( filename, &data, &data_len ); analyzer->all_file_data = data; analyzer->file_data_len = data_len; if( 0 != ret ) { if( NULL != analyzer->error_handler ) { error_infos info; info.err_code = ERR_FILE_NOT_EXIST; info.desc = "This file is not existing"; analyzer->error_handler( &info ); } return -1; } analyzer->file_type = check_file_type( data, data_len ); if( PE_FILE_TYPE == analyzer->file_type ) { ret = init_pe_writer( &analyzer->pe_write_info ); if( 0 > ret ) { return ret; } ret = analyze_pe_file_struct( data, data_len, analyzer ); if( 0 > ret ) { return ret; } } else if( LIB_FILE_TYPE == analyzer->file_type ) { ret = analyze_lib_file_struct( data, data_len, analyzer ); } else if( COFF_FILE_TYPE == analyzer->file_type ) { ret = analyze_coff_file_struct( data, data_len, 0, analyzer ); } return ret; }
void FSName::set_name(const char* file_name, const char* suffix, const int32_t cluster_id) { file_name_[0] = '\0'; cluster_id_ = cluster_id; memset(&filev1_, 0, sizeof(FileBitsV1)); memset(&filev2_, 0, sizeof(FileBitsV2)); if (NULL != file_name && file_name[0] != '\0') { TfsFileType file_type = check_file_type(file_name); if (INVALID_TFS_FILE_TYPE == file_type) { is_valid_ = false; } else { int32_t file_name_len = 0; if (TFS_FILE_NAME_V1 == version_) { file_name_len = FILE_NAME_LEN; decode(file_name + 2, (char*) &filev1_, file_name_len - 2); } else { file_name_len = FILE_NAME_LEN_V2; decode(file_name + 3, (char*) &filev2_, file_name_len - 3); } if (NULL == suffix) { suffix = file_name + file_name_len; } set_suffix(suffix); if (0 == cluster_id_) { cluster_id_ = file_name[1] - '0'; } } } }
int makeflow_clean_mount_target(const char *target) { file_type t_type; if(!target || !*target) return 0; /* Check whether target already exists. */ if(access(target, F_OK)) { debug(D_DEBUG, "the target (%s) does not exist!\n", target); return 0; } /* Check whether the target is an absolute path. */ if(target[0] == '/') { debug(D_DEBUG, "the target (%s) should not be an absolute path!\n", target); fprintf(stderr, "the target (%s) should not be an absolute path!\n", target); return -1; } /* check whether target includes .. */ if(path_has_doubledots(target)) { debug(D_DEBUG, "the target (%s) include ..!\n", target); fprintf(stderr, "the target (%s) include ..!\n", target); return -1; } /* check whether target is REG, LNK, DIR */ if((t_type = check_file_type(target)) == FILE_TYPE_UNSUPPORTED) return -1; if(unlink_recursive(target)) { debug(D_DEBUG, "Failed to remove %s!\n", target); fprintf(stderr, "Failed to remove %s!\n", target); return -1; } return 0; }
int NC_infermodel(const char* path, int* omodep, int iscreate, int useparallel, void* params, NCmodel* model, char** newpathp) { int stat = NC_NOERR; char* newpath = NULL; NCURI* uri = NULL; int omode = *omodep; int isuri = 0; NClist* modeargs = nclistnew(); if((stat = processuri(path, &uri, &newpath, modeargs))) goto done; isuri = (uri != NULL); /* Phase 1: compute the IOSP */ if((stat = extractiosp(modeargs,omode,model))) goto done; assert(model->iosp != 0); /* Phase 2: Process the non-iosp mode arguments */ if(!modelcomplete(model) && isuri) { int i; for(i=0;i<nclistlength(modeargs);i++) { const char* arg = nclistget(modeargs,i); if((stat=processmodearg(arg,model))) goto done; } } /* Phase 3: See if we can infer DAP */ if(!modelcomplete(model) && isuri) { if((stat = NC_dapinfer(modeargs,model))) goto done; } /* Phase 4: mode inference */ if(!modelcomplete(model)) { if((stat = NC_omodeinfer(omode,model))) goto done; } /* Phase 5: Infer from file content, if possible; this has highest precedence, so it may override previous decisions. */ if(!iscreate && isreadable(model->iosp)) { /* Ok, we need to try to read the file */ if((stat = check_file_type(path, omode, useparallel, params, model, uri))) goto done; } /* Phase 6: Infer impl from format */ if(!modelcomplete(model)) { if((stat = NC_implinfer(useparallel, model))) goto done; } assert(modelcomplete(model)); /* Force flag consistency */ switch (model->impl) { case NC_FORMATX_NC4: case NC_FORMATX_NC_HDF4: case NC_FORMATX_DAP4: case NC_FORMATX_UDF0: case NC_FORMATX_UDF1: omode |= NC_NETCDF4; if(model->format == NC_FORMAT_NETCDF4_CLASSIC) omode |= NC_CLASSIC_MODEL; break; case NC_FORMATX_DAP2: omode &= ~(NC_NETCDF4|NC_64BIT_OFFSET|NC_64BIT_DATA); break; case NC_FORMATX_NC3: omode &= ~NC_NETCDF4; /* must be netcdf-3 (CDF-1, CDF-2, CDF-5) */ if(model->format == NC_FORMAT_64BIT_OFFSET) omode |= NC_64BIT_OFFSET; else if(model->format == NC_FORMAT_64BIT_DATA) omode |= NC_64BIT_DATA; break; case NC_FORMATX_PNETCDF: omode &= ~NC_NETCDF4; /* must be netcdf-3 (CDF-1, CDF-2, CDF-5) */ if(model->format == NC_FORMAT_64BIT_OFFSET) omode |= NC_64BIT_OFFSET; else if(model->format == NC_FORMAT_64BIT_DATA) omode |= NC_64BIT_DATA; break; default: {stat = NC_ENOTNC; goto done;} } done: if(uri) ncurifree(uri); nclistfreeall(modeargs); if(stat == NC_NOERR && newpathp) {*newpathp = newpath; newpath = NULL;} nullfree(newpath); *omodep = omode; /* in/out */ return check(stat); }
int GzipFile::ParserHeader(){ printf("%s \n",__func__); head_length = 0; int ret = File::read((char*)fixed_head,sizeof(fixed_head)); if(!check_file_type((char*)fixed_head,8)){ printf("not a Gzip file \n"); return -1; } head_length += sizeof(fixed_head); printf("head_length = %d line = %d \n",head_length,__LINE__); if(fixed_head[FLG] & FLAG_EXTRA_VALUE ){ ALOGE("%s\n","has extra value"); ret = File::read((char *)extra_len,sizeof(extra_len)); head_length += sizeof(extra_len); unsigned int extra_length=0; extra_length |= extra_len[0]; extra_length |= extra_len[1]<<8; ALOGE("extra length = %d \n",extra_length); if(extra_info != NULL){ free(extra_info); extra_info = NULL; } extra_info = (unsigned char *)malloc(extra_length); memset(extra_info,0,extra_length); ret = File::read((char *)extra_info,extra_length); head_length += extra_length; } printf("head_length = %d line = %d \n",head_length,__LINE__); if(fixed_head[FLG] & FLAG_NAME_VALUE){ ALOGE("%s\n","FLAG_NAME_VALUE"); //string ALOGE("%x \n",File::lseek(SEEK_CUR,0)); File::readline(zip_name,sizeof(zip_name)); ALOGE("%s \n",zip_name); head_length += strlen(zip_name) + 1; } printf("head_length = %d line = %d \n",head_length,__LINE__); if(fixed_head[FLG]&FLAG_COMMENT_VALUE){ ALOGE("%s\n","FLAG_COMMENT_VALUE"); //string File::readline(comment,sizeof(comment)); ALOGE("%s \n",comment); head_length += strlen(comment) + 1; } printf("head_length = %d line = %d \n",head_length,__LINE__); if(fixed_head[FLG]&FLAG_HCRC_VALUE){ ALOGE("%s\n","FLAG_HCRC_VALUE"); File::read((char *)crc16_head,sizeof(crc16_head)); head_length += sizeof(crc16_head); } printf("head_length = %d line = %d ",head_length,__LINE__); File::lseek(SEEK_END,-8); File::read((char*)crc32_info,sizeof(crc32_info)); unsigned int size =0; size |= crc32_info[4]; size |= crc32_info[5]<<8; size |= crc32_info[6]<<16; size |= crc32_info[7]<<24; printf("size = %d \n",size); }
/*! ************************************************************************************* * \function check_command_line * * \brief * This function checks for comaand line args. * * ************************************************************************************* */ int check_command_line(int argc, char *argv[], en_options *p_opts, char *outfile ) { FILE *f_logfile=NULL ; st_input_format bmp_info ; int ret_val ; int count ; /* Generating a Logfile for details */ #ifdef GEN_LOGFILE f_logfile = fopen("sample_log.txt", "w" ) ; if ( f_logfile == NULL ) { printf("Warning : Cannot open the log file \n") ; } #endif /* Checking for the number of parameters on the command line */ if( argc < 5 ) { usage(f_logfile) ; if ( f_logfile ) fclose(f_logfile) ; return RETN ; } /* Check for the order of command line */ if ( stricmp(argv[1], "-input" ) != 0 ) { usage(f_logfile) ; if ( f_logfile ) fclose(f_logfile) ; return RETN ; } /* Checking for the input file attributes */ if(in_file_attribute(argv[2]) == RETN ) { return RETN ; } ret_val = check_file_type(argv[2], &bmp_info ) ; if ( ret_val == BMP ) count = 3 ; else if(ret_val == YUV) { if (isnumber_int(argv[3], 1) == RETN || isnumber_int(argv[4], 1) == RETN ) { printf("Error: Invalid argument specified for 'yuv' file \n") ; return RETN ; } if( check_yuvformat(argv[5]) == RETN ) { printf("Error: Invalid yuv file format\n") ; return RETN ; } count = 6 ; } while( count != argc ) { /* negate */ if(stricmp("-negate", argv[count]) == 0 ) { *p_opts++ = NEGATE ; count++ ; } /* remove */ else if(stricmp("-remove", argv[count]) == 0 ) { if ( check_removearg(argv[count+1]) == RETN ) { printf("Error: Invalid argument specified for '-remove' option \n") ; return RETN ; } *p_opts++ = REMOVE ; count += 2 ; } /* crop */ else if(stricmp("-crop", argv[count]) == 0 ) { if (isnumber_int(argv[count+1], 1) == RETN || isnumber_int(argv[count+2], 1) == RETN ) { printf("Error: Invalid argument specified for '-crop' option \n") ; return RETN ; } if ( ( atoi( argv[count+1] ) <= 0 ) || ( atoi( argv[count+2]) <= 0) ) { printf("Error: Invalid argument specified for '-crop' option \n") ; return RETN ; } *p_opts++ = CROP ; count += 3 ; } /* add */ else if(stricmp("-addimage", argv[count]) == 0 ) { *p_opts++ = ADD ; if ( in_file_attribute(argv[count+1]) == RETN ) return RETN ; ret_val = check_file_type(argv[count+1], &bmp_info ) ; if ( ret_val == BMP ) count += 2 ; else if(ret_val == YUV) { if (isnumber_int(argv[count+2], 1) == RETN || isnumber_int(argv[count+3], 1) == RETN ) { printf("Error: Invalid argument specified for 'yuv' file \n") ; return RETN ; } if( check_yuvformat(argv[count+4]) == RETN ) { printf("Error: Invalid yuv file format\n") ; return RETN ; } count += 5 ; } } /* addC */ else if(stricmp("-addC", argv[count]) == 0 ) { if (isnumber_int(argv[count+1], 1) == RETN || isnumber_int(argv[count+2], 1) == RETN || isnumber_int(argv[count+3], 1) == RETN ) { printf("Error: Invalid argument specified for '-addC' option \n") ; return RETN ; } if ( check_range(argv[count+1], 0, 255 ) == RETN || check_range(argv[count+2], 0, 255 ) == RETN || check_range(argv[count+3], 0, 255 ) == RETN ) { printf("Error: Invalid argument specified for '-addC' option \n") ; return RETN ; } *p_opts++ = ADDC ; count += 4 ; } /* sub */ else if(stricmp("-subimage", argv[count]) == 0 ) { *p_opts++ = SUB ; if ( in_file_attribute(argv[count+1]) == RETN ) return RETN ; ret_val = check_file_type(argv[count+1], &bmp_info ) ; if ( ret_val == BMP ) count += 2 ; else if(ret_val == YUV) { if (isnumber_int(argv[count+2], 1) == RETN || isnumber_int(argv[count+3], 1) == RETN ) { printf("Error: Invalid argument specified for 'yuv' file \n") ; return RETN ; } if( check_yuvformat(argv[count+4]) == RETN ) { printf("Error: Invalid yuv file format\n") ; return RETN ; } count += 5 ; } } /* subC */ else if(stricmp("-subC", argv[count]) == 0 ) { if (isnumber_int(argv[count+1], 1) == RETN || isnumber_int(argv[count+2], 1) == RETN || isnumber_int(argv[count+3], 1) == RETN ) { printf("Error: Invalid argument specified for '-subC' option \n") ; return RETN ; } if ( check_range(argv[count+1], 0, 255 ) == RETN || check_range(argv[count+2], 0, 255 ) == RETN || check_range(argv[count+3], 0, 255 ) == RETN ) { printf("Error: Invalid argument specified for '-subC' option \n") ; return RETN ; } *p_opts++ = SUBC ; count += 4 ; } /* xor */ else if(stricmp("-xorimage", argv[count]) == 0 ) { *p_opts++ = XOR ; if ( in_file_attribute(argv[count+1]) == RETN ) return RETN ; ret_val = check_file_type(argv[count+1], &bmp_info ) ; if ( ret_val == BMP ) count += 2 ; else if(ret_val == YUV) { if (isnumber_int(argv[count+2], 1) == RETN || isnumber_int(argv[count+3], 1) == RETN ) { printf("Error: Invalid argument specified for 'yuv' file \n") ; return RETN ; } if( check_yuvformat(argv[count+4]) == RETN ) { printf("Error: Invalid yuv file format\n") ; return RETN ; } count += 5 ; } } /* output */ else if(stricmp("-output", argv[count]) == 0 ) { *p_opts++ = OUTPUT ; if ( in_file_attribute(argv[count+1]) == RETN ) return RETN ; strcpy(outfile,argv[count+1]) ; ret_val = check_file_type(outfile, &bmp_info ) ; if ( ret_val == BMP ) count += 2 ; else if(ret_val == YUV) count += 5 ; if( count != argc ) { printf("Error in command line \n" ) ; return RETN ; } } /* roi */ else if(stricmp("--roi", argv[count]) == 0 ) { if (isnumber_int(argv[count+1], 1) == RETN || isnumber_int(argv[count+2], 1) == RETN ) { printf("Error: Invalid argument specified for '--roi' option \n") ; return RETN ; } if ( ( atoi( argv[count+1] ) <= 0 ) || ( atoi( argv[count+2]) <= 0) ) { printf("Error: Invalid argument specified for '--roi' option \n") ; return RETN ; } *p_opts++ = ROI ; count += 3 ; } /* flip */ else if(stricmp("-flip", argv[count]) == 0 ) { if (isnumber_int(argv[count+1], 1) == RETN ) { printf("Error: Invalid argument specified for '-flip' option \n") ; return RETN ; } if ( check_range(argv[count+1], 0, 2 ) == RETN ) { printf("Error: Invalid argument specified for '-flip' option \n") ; return RETN ; } *p_opts++ = FLIP ; count += 2 ; } /* rotate */ else if(stricmp("-rotate", argv[count]) == 0 ) { if (isnumber_float(argv[count+1], -1) == RETN ) { printf("Error: Invalid argument specified for '-rotate' option \n") ; return RETN ; } if ( check_range_float(argv[count+1], -360.0, +360.0 ) == RETN ) { printf("Error: Invalid argument specified for '-rotate' option \n") ; return RETN ; } *p_opts++ = ROTATE ; count += 2 ; } /* resize */ else if(stricmp("-resize", argv[count]) == 0 ) { if (isnumber_float(argv[count+1], -1) == RETN || isnumber_float(argv[count+2], -1) == RETN ) { printf("Error: Invalid argument specified for '-resize' option \n") ; return RETN ; } *p_opts++ = RESIZE ; count += 3 ; } /* brightness */ else if(stricmp("-bright", argv[count]) == 0 ) { if (isnumber_int(argv[count+1], -1) == RETN ) { printf("Error: Invalid argument specified for '-bright' option \n") ; return RETN ; } if ( check_range(argv[count+1], -255, 255 ) == RETN ) { printf("Error: Invalid argument specified for '-bright' option \n") ; return RETN ; } *p_opts++ = BRIGHT ; count += 2 ; } /* contrast */ else if(stricmp("-contrast", argv[count]) == 0 ) { if (isnumber_int(argv[count+1], -1) == RETN ) { printf("Error: Invalid argument specified for '-contrast' option \n") ; return RETN ; } if ( check_range(argv[count+1], -100, 100 ) == RETN ) { printf("Error: Invalid argument specified for '-contrast' option \n") ; return RETN ; } *p_opts++ = CONTRAST ; count += 2 ; } /* greyscaling */ else if(stricmp("-grey", argv[count]) == 0 ) { *p_opts++ = GREY ; count++ ; } /* edge detection */ else if(stricmp("-edge", argv[count]) == 0 ) { *p_opts++ = EDGE ; count++ ; } /* border */ else if(stricmp("-border", argv[count]) == 0 ) { if (isnumber_int(argv[count+1], 1) == RETN || isnumber_int(argv[count+2], 1) == RETN || isnumber_int(argv[count+3], 1) == RETN ) { printf("Error: Invalid argument specified for '-border' option \n") ; return RETN ; } if ( check_range(argv[count+1], 0, 255 ) == RETN || check_range(argv[count+2], 0, 255 ) == RETN || check_range(argv[count+3], 0, 255 ) == RETN ) { printf("Error: Invalid argument specified for '-border' option \n") ; return RETN ; } *p_opts++ = BORDER ; count+= 4 ; } #ifndef SOL /* blur */ else if(stricmp("-blur", argv[count]) == 0 ) { *p_opts++ = BLUR ; count++ ; } /* sharpen */ else if(stricmp("-sharp", argv[count]) == 0 ) { *p_opts++ = SHARP ; count++ ; } /* Median Filter */ else if(stricmp("-filter_median", argv[count]) == 0 ) { *p_opts++ = F_MEDIAN ; count++ ; } /* Gaussian Filter */ else if(stricmp("-filter_gauss", argv[count]) == 0 ) { *p_opts++ = F_GAUSS ; count++ ; } /* Laplace Filter */ else if(stricmp("-filter_laplace", argv[count]) == 0 ) { *p_opts++ = F_LAPLACE ; count++ ; } /* Lowpass Filter */ else if(stricmp("-filter_lowpass", argv[count]) == 0 ) { *p_opts++ = F_LOWPASS ; count++ ; } /* Highpass Filter */ else if(stricmp("-filter_hipass", argv[count]) == 0 ) { *p_opts++ = F_HIGHPASS ; count++ ; } /* Median Cross Filter */ else if(stricmp("-filter_medcross", argv[count]) == 0 ) { *p_opts++ = F_MEDCROSS; count++ ; } /* Median Vertical Filter */ else if(stricmp("-filter_medvert", argv[count]) == 0 ) { *p_opts++ = F_MEDVERT; count++ ; } /* Median Horizontal Filter */ else if(stricmp("-filter_medhoriz", argv[count]) == 0 ) { *p_opts++ = F_MEDHORIZ; count++ ; } /* Sobel Vertical Filter */ else if(stricmp("-filter_sobvert", argv[count]) == 0 ) { *p_opts++ = F_SOBVERT; count++ ; } /* Sobel Horizontal Filter */ else if(stricmp("-filter_sobhoriz", argv[count]) == 0 ) { *p_opts++ = F_SOBHORIZ; count++ ; } /* Filter Minimum */ else if(stricmp("-filter_min", argv[count]) == 0 ) { *p_opts++ = F_MIN; count++ ; } /* Filter Maximum */ else if(stricmp("-filter_max", argv[count]) == 0 ) { *p_opts++ = F_MAX; count++ ; } /* Roberts Up Filter */ else if(stricmp("-filter_robup", argv[count]) == 0 ) { *p_opts++ = F_ROBUP; count++ ; } /* Roberts Down Filter */ else if(stricmp("-filter_robdown", argv[count]) == 0 ) { *p_opts++ = F_ROBDOWN; count++ ; } /* Prewitts Vertical Filter */ else if(stricmp("-filter_prewvert", argv[count]) == 0 ) { *p_opts++ = F_PREWVERT; count++ ; } /* Prewitts Horizontal Filter */ else if(stricmp("-filter_prewhoriz", argv[count]) == 0 ) { *p_opts++ = F_PREWHORIZ; count++ ; } /* Row Filter */ else if(stricmp("-filter_row", argv[count]) == 0 ) { *p_opts++ = F_ROW; count++ ; } /* Column Filter */ else if(stricmp("-filter_column", argv[count]) == 0 ) { *p_opts++ = F_COLUMN; count++ ; } /* Filter with rectangular kernel */ else if(stricmp("-filter_rectkernel", argv[count]) == 0 ) { *p_opts++ = F_RECTKERNEL; count++ ; } /* Median Color Filter */ else if(stricmp("-filter_medcolor", argv[count]) == 0 ) { *p_opts++ = F_MEDCOLOR; count++ ; } #endif /* Gamma Correction */ else if(stricmp("-gamma", argv[count]) == 0 ) { if (isnumber_float(argv[count+1], 1) == RETN ) { printf("Error: Invalid argument specified for '-gamma' option \n") ; return RETN ; } if ( check_range_float(argv[count+1], 0.0, 10.0 ) == RETN ) { printf("Error: Invalid argument specified for '-gamma' option \n") ; return RETN ; } *p_opts++ = GAMMA; count += 2 ; } /* Saturation */ else if(stricmp("-saturate", argv[count]) == 0 ) { if (isnumber_float(argv[count+1], 1) == RETN ) { printf("Error: Invalid argument specified for '-saturate' option \n") ; return RETN ; } if ( check_range_float(argv[count+1], 0.0, 2.0 ) == RETN ) { printf("Error: Invalid argument specified for '-saturate' option \n") ; return RETN ; } *p_opts++ = SATURATE; count += 2 ; } /* Hue */ else if(stricmp("-hue", argv[count]) == 0 ) { if (isnumber_float(argv[count+1], 1) == RETN ) { printf("Error: Invalid argument specified for '-hue' option \n") ; return RETN ; } if ( check_range_float(argv[count+1], 0.0, 360.0 ) == RETN ) { printf("Error: Invalid argument specified for '-hue' option \n") ; return RETN ; } *p_opts++ = HUE; count += 2 ; } /* grid */ else if(stricmp("-grid", argv[count]) == 0 ) { if (isnumber_int(argv[count+1], 1) == RETN ) { printf("Error: Invalid argument specified for '-grid' option \n") ; return RETN ; } if ( check_range(argv[count+1], 10, 100 ) == RETN ) { printf("Error: Invalid argument specified for '-grid' option \n") ; return RETN ; } *p_opts++ = GRID; count += 2 ; } /* noise */ else if(stricmp("-noise", argv[count]) == 0 ) { if (isnumber_int(argv[count+1], 1) == RETN ) { printf("Error: Invalid argument specified for '-noise' option \n") ; return RETN ; } if ( check_range(argv[count+1], 0, 100 ) == RETN ) { printf("Error: Invalid argument specified for '-noise' option \n") ; return RETN ; } *p_opts++ = NOISE; count += 2 ; } /* blinds */ else if(stricmp("-blinds", argv[count]) == 0 ) { if (isnumber_int(argv[count+1], 1) == RETN || isnumber_int(argv[count+2], 1) == RETN || isnumber_int(argv[count+3], 1) == RETN || isnumber_int(argv[count+4], 1) == RETN) { printf("Error: Invalid argument specified for '-blinds' option \n") ; return RETN ; } if ( check_range(argv[count+1], 0, 1 ) == RETN ) { printf("Error: Invalid argument specified for '-blinds' option \n") ; return RETN ; } if ( check_range(argv[count+2], 0, 255 ) == RETN || check_range(argv[count+3], 0, 255 ) == RETN || check_range(argv[count+4], 0, 255 ) == RETN ) { printf("Error: Invalid argument specified for '-blinds' option \n") ; return RETN ; } *p_opts++ = BLINDS; count += 5 ; } /* emboss */ else if(stricmp("-emboss", argv[count]) == 0 ) { *p_opts++ = EMBOSS; count += 1 ; } /* deinterlace */ else if(stricmp("-deinterlace", argv[count]) == 0 ) { if (isnumber_int(argv[count+1], 1) == RETN ) { printf("Error: Invalid argument specified for '-deinterlace' option \n") ; return RETN ; } if ( check_range(argv[count+1], 0, 1 ) == RETN ) { printf("Error: Invalid argument specified for '-deinterlace' option \n") ; return RETN ; } *p_opts++ = DEINTERLACE; count += 2 ; } /* explosion */ else if(stricmp("-explode", argv[count]) == 0 ) { *p_opts++ = EXPLODE; count += 1 ; } /* glassy */ else if(stricmp("-glassy", argv[count]) == 0 ) { if (isnumber_int(argv[count+1], 1) == RETN || isnumber_int(argv[count+2], 1) == RETN ) { printf("Error: Invalid argument specified for '-glassy' option \n") ; return RETN ; } if ( check_range(argv[count+1], 5, 75 ) == RETN || check_range(argv[count+2], 5, 75 ) == RETN ) { printf("Error: Invalid argument specified for '-glassy' option \n") ; return RETN ; } *p_opts++ = GLASSY; count += 3 ; } /* illusion */ else if(stricmp("-illusion", argv[count]) == 0 ) { if (isnumber_int(argv[count+1], 1) == RETN ) { printf("Error: Invalid argument specified for '-illusion' option \n") ; return RETN ; } if ( check_range(argv[count+1], 0, 100 ) == RETN ) { printf("Error: Invalid argument specified for '-illusion' option \n") ; return RETN ; } *p_opts++ = ILLUSION; count += 2 ; } /* halftone */ else if(stricmp("-halftone", argv[count]) == 0 ) { *p_opts++ = TONEHALF; count += 1 ; } /* video */ else if(stricmp("-video", argv[count]) == 0 ) { if (isnumber_int(argv[count+1], 1) == RETN ) { printf("Error: Invalid argument specified for '-video' option \n") ; return RETN ; } if ( check_range(argv[count+1], 0, 3 ) == RETN ) { printf("Error: Invalid argument specified for '-video' option \n") ; return RETN ; } *p_opts++ = VIDEO; count += 2 ; } /* else */ else { printf("Error in command line ...Unrecognized option/argument\n") ; return RETN ; count++ ; } } return CONT ; }
/* Loop though files in a package and perform full file property checking. */ int check_pkg_full(alpm_pkg_t *pkg) { const char *root, *pkgname; size_t errors = 0; size_t rootlen; char filepath[PATH_MAX]; struct archive *mtree; struct archive_entry *entry = NULL; size_t file_count = 0; const alpm_list_t *lp; root = alpm_option_get_root(config->handle); rootlen = strlen(root); if(rootlen + 1 > PATH_MAX) { /* we are in trouble here */ pm_printf(ALPM_LOG_ERROR, _("path too long: %s%s\n"), root, ""); return 1; } strcpy(filepath, root); pkgname = alpm_pkg_get_name(pkg); mtree = alpm_pkg_mtree_open(pkg); if(mtree == NULL) { /* TODO: check error to confirm failure due to no mtree file */ if(!config->quiet) { printf(_("%s: no mtree file\n"), pkgname); } return 0; } while(alpm_pkg_mtree_next(pkg, mtree, &entry) == ARCHIVE_OK) { struct stat st; const char *path = archive_entry_pathname(entry); mode_t type; size_t file_errors = 0; int backup = 0; /* strip leading "./" from path entries */ if(path[0] == '.' && path[1] == '/') { path += 2; } if(strcmp(path, ".INSTALL") == 0) { char filename[PATH_MAX]; snprintf(filename, PATH_MAX, "%slocal/%s-%s/install", alpm_option_get_dbpath(config->handle) + 1, pkgname, alpm_pkg_get_version(pkg)); archive_entry_set_pathname(entry, filename); path = archive_entry_pathname(entry); } else if(strcmp(path, ".CHANGELOG") == 0) { char filename[PATH_MAX]; snprintf(filename, PATH_MAX, "%slocal/%s-%s/changelog", alpm_option_get_dbpath(config->handle) + 1, pkgname, alpm_pkg_get_version(pkg)); archive_entry_set_pathname(entry, filename); path = archive_entry_pathname(entry); } else if(*path == '.') { continue; } file_count++; if(rootlen + 1 + strlen(path) > PATH_MAX) { pm_printf(ALPM_LOG_WARNING, _("path too long: %s%s\n"), root, path); continue; } strcpy(filepath + rootlen, path); if(check_file_exists(pkgname, filepath, &st) == 1) { errors++; continue; } type = archive_entry_filetype(entry); if(type != AE_IFDIR && type != AE_IFREG && type != AE_IFLNK) { pm_printf(ALPM_LOG_WARNING, _("file type not recognized: %s%s\n"), root, path); continue; } if(check_file_type(pkgname, filepath, &st, entry) == 1) { errors++; continue; } file_errors += check_file_permissions(pkgname, filepath, &st, entry); if(type == AE_IFLNK) { file_errors += check_file_link(pkgname, filepath, &st, entry); } /* the following checks are expected to fail if a backup file has been modified */ for(lp = alpm_pkg_get_backup(pkg); lp; lp = lp->next) { alpm_backup_t *bl = lp->data; if(strcmp(path, bl->name) == 0) { backup = 1; break; } } if(type != AE_IFDIR) { /* file or symbolic link */ file_errors += check_file_time(pkgname, filepath, &st, entry, backup); } if(type == AE_IFREG) { /* TODO: these are expected to be changed with backup files */ file_errors += check_file_size(pkgname, filepath, &st, entry, backup); /* file_errors += check_file_md5sum(pkgname, filepath, &st, entry, backup); */ } if(config->quiet && file_errors) { printf("%s %s\n", pkgname, filepath); } errors += (file_errors != 0 ? 1 : 0); } alpm_pkg_mtree_close(pkg, mtree); if(!config->quiet) { printf(_n("%s: %jd total file, ", "%s: %jd total files, ", (unsigned long)file_count), pkgname, (intmax_t)file_count); printf(_n("%jd altered file\n", "%jd altered files\n", (unsigned long)errors), (intmax_t)errors); } return (errors != 0 ? 1 : 0); }