/* * See if device can be mounted by looking in /etc/fstab. * If so, set device name and mount point name, and return 1, * otherwise return 0. */ static int MountableDevice(const char *name, char **mountName, char **deviceName) { FILE *fp; char line[1024]; char s1[1024]; char s2[1024]; int rc; fp = fopen("/etc/fstab", "r"); if (fp == NULL) { /* * /etc/fstab may be unreadable in some situations due to passwords in the * file. */ return -1; } while (fgets(line, sizeof(line), fp) != 0) { rc = sscanf(line, "%1023s %1023s", s1, s2); if (rc >= 2 && s1[0] != '#' && strcmp(s2, name) == 0) { FCLOSE(fp); *deviceName = estrdup(s1); *mountName = estrdup(s2); return 1; } } FCLOSE(fp); return 0; }
static void DEHT_freeResources(DEHT * ht, bool_t removeFiles) { TRACE_FUNC_ENTRY(); CHECK (NULL != ht); (void) fflush(ht->keyFP); FCLOSE(ht->keyFP); (void) fflush(ht->dataFP); FCLOSE(ht->dataFP); /* free ht cache if present */ FREE(ht->hashTableOfPointersImageInMemory); FREE(ht->hashPointersForLastBlockImageInMemory); FREE(ht->userBuf); if (removeFiles) { /* attempt to remove bad files. Errors are silenced */ CHECK(DEHT_removeFilesInternal(ht)); } /* finally, free the ht itself */ FREE(ht); goto LBL_CLEANUP; LBL_ERROR: /* do nothing special - just quit */ TRACE_FUNC_ERROR(); LBL_CLEANUP: /* bye */ TRACE_FUNC_EXIT(); return; }
/****************************************************************************** * fileCopy: * Copy the file specified by "src" to the file specified by "dst". Error * checking is taken care of by the caplib functions (ie FOPEN, FWRITE, etc) */ void fileCopy(const char *src, const char *dst) { char buffer[BUFFER_SIZE]; FILE *srcFp; FILE *dstFp; unsigned int amount; srcFp = FOPEN( src, "rb" ); dstFp = FOPEN( dst, "wb" ); do { amount = fread( buffer, sizeof(char), BUFFER_SIZE, srcFp ); if (amount) { int a = fwrite( buffer, sizeof(char), amount, dstFp ); if (a<amount) { asfPrintError("Error copying file %s -> %s\n" "Only %d of %d bytes written.\n%s\n", src, dst, a, amount, strerror(errno)); } } /* when amount read is < BUFSZ, copy is done */ } while (amount == BUFFER_SIZE); FCLOSE(srcFp); FCLOSE(dstFp); }
void floats_to_bytes_from_file_ext(const char *inFile, const char *outFile, char *band, float mask, scale_t scaling, float scale_factor) { FILE *fp; meta_parameters *meta; float *float_data; unsigned char *byte_data; int ii, band_number; long long pixel_count; long offset; meta = meta_read(inFile); band_number = (!band || strlen(band) == 0 || strcmp(band, "???")==0) ? 0 : get_band_number(meta->general->bands, meta->general->band_count, band); pixel_count = meta->general->line_count * meta->general->sample_count; offset = meta->general->line_count * band_number; float_data = (float *) MALLOC(sizeof(float) * pixel_count); fp = FOPEN(inFile, "rb"); get_float_lines(fp, meta, offset, meta->general->line_count, float_data); FCLOSE(fp); byte_data = floats_to_bytes_ext(float_data, pixel_count, mask, scaling, scale_factor); for (ii=0; ii<pixel_count; ii++) float_data[ii] = (float) byte_data[ii]; meta->general->data_type = ASF_BYTE; meta_write(meta, outFile); fp = FOPEN(outFile, "wb"); put_float_lines(fp, meta, offset, meta->general->line_count, float_data); FCLOSE(fp); FREE(float_data); FREE(byte_data); meta_free(meta); }
static int isArcList(const char *sensor, const char *file) { if (!file) return FALSE; if (!strstr(file, "arclist")) return FALSE; if (!fileExists(file)) return FALSE; FILE *fp = FOPEN(file, "r"); if (!fp) return FALSE; char line[1024]; if (fgets(line, 1024, fp) == NULL) { FCLOSE(fp); return FALSE; } FCLOSE(fp); if (!strstr(line, sensor)) return FALSE; return TRUE; }
/********************************************************************* Write the actual qmaster into the master_file -> master_file and master_host <- return -1 error in err_str 0 means OK NOTES MT-NOTE: write_qm_name() is MT safe *********************************************************************/ int write_qm_name( const char *master_host, const char *master_file, char *err_str ) { FILE *fp; if (!(fp = fopen(master_file, "w"))) { if (err_str) sprintf(err_str, MSG_GDI_OPENWRITEMASTERHOSTNAMEFAILED_SS, master_file, strerror(errno)); return -1; } if (fprintf(fp, "%s\n", master_host) == EOF) { if (err_str) sprintf(err_str, MSG_GDI_WRITEMASTERHOSTNAMEFAILED_S , master_file); FCLOSE(fp); return -1; } FCLOSE(fp); return 0; FCLOSE_ERROR: return -1; }
//テキストファイルの読み込み bool TextAnalyseW::load( const char *path ) { FILEPOINTER fp; unsigned char temp[2]; if( enable ) release(); fp = FOPEN( path ); if( fp == 0 ) return false; FREAD( temp, 2, fp ); if( temp[0] != 0xff || temp[1] != 0xfe ) { FCLOSE( fp ); return false; } FSIZE( path, fp, strsize ); strsize = ( strsize - 2 ) / sizeof( wchar_t ); buffer = new wchar_t[strsize + 1]; FREAD( buffer, strsize * sizeof( wchar_t ), fp ); FSEEK( fp, 2, SEEK_SET ); FCLOSE( fp ); buffer[strsize] = L'\0'; enable = true; mem = false; pos = buffer; last = buffer + strsize; return true; }
/*---------------------------------------------------------------------- * host_in_file * look if resolved host is in "file" * return * 0 if present * 1 if not * -1 error occured *----------------------------------------------------------------------*/ static int host_in_file( const char *host, const char *file ) { FILE *fp; char buf[512], *cp; DENTER(TOP_LAYER, "host_in_file"); fp = fopen(file, "r"); if (!fp) { DRETURN(-1); } while (fgets(buf, sizeof(buf), fp)) { for (cp = strtok(buf, " \t\n,"); cp; cp = strtok(NULL, " \t\n,")) { char* resolved_host = NULL; cl_com_cached_gethostbyname(cp,&resolved_host,NULL,NULL,NULL); if (resolved_host) { if (!sge_hostcmp(host, resolved_host )) { FCLOSE(fp); sge_free(&resolved_host); DRETURN(0); } sge_free(&resolved_host); } } } FCLOSE(fp); DRETURN(1); FCLOSE_ERROR: DRETURN(0); }
int extract_fastfile(char * infilename, char * outfilename) { FILE *fd, *fdo = NULL; uint32_t inlen, outlen; int i, files; char *file_input, *file_output, *file_offset; setbuf(stdout, NULL); setbuf(stderr, NULL); file_input = infilename; file_output = outfilename; file_offset = "0x15"; printf("Extracting fastfile: %s\n", file_input); fd = fopen(file_input, "rb"); if(!fd) std_err(); if(minzip > INSZ) minzip = INSZ; if(minzip < 1) minzip = 1; in = malloc(INSZ); out = malloc(OUTSZ); filebuff = malloc(FBUFFSZ); if(!in || !out || !filebuff) std_err(); offset = get_num(file_offset); // do not skip, needed for buffseek buffseek(fd, offset, SEEK_SET); z.zalloc = (alloc_func)0; z.zfree = (free_func)0; z.opaque = (voidpf)0; if(inflateInit2(&z, zipwbits) != Z_OK) zlib_err(Z_INIT_ERROR); fdo = save_file(file_output); unzip(fd, &fdo, &inlen, &outlen); FCLOSE(fdo) printf("\n" "%u bytes compressed\n" "%u bytes extracted\n", inlen, outlen); FCLOSE(fdo) FCLOSE(fd) inflateEnd(&z); free(in); free(out); free(filebuff); return(0); }
static void ingest_polarimetry_data(char *inFile, char *inBaseName, char *outFile, char band, int create) { FILE *fpIn, *fpOut; meta_parameters *meta = NULL; char tmp[10]; int ii, kk; float *power = NULL; char *byteBuf = NULL; fpIn = FOPEN(inFile, "rb"); append_ext_if_needed(outFile, ".img", NULL); if (create) fpOut = FOPEN(outFile, "wb"); else fpOut = FOPEN(outFile, "ab"); if (create) { meta = import_airsar_meta(inFile, inBaseName, TRUE); meta->general->data_type = REAL32; meta->general->band_count = 1; sprintf(meta->general->bands, "AMP-%c", band); meta->general->image_data_type = IMAGE_LAYER_STACK; } else { meta = meta_read(outFile); meta->general->band_count += 1; sprintf(tmp, ",AMP-%c", band); strcat(meta->general->bands, tmp); } power = (float *) MALLOC(sizeof(float)*meta->general->sample_count); byteBuf = (char *) MALLOC(sizeof(char)*10); airsar_header *header = read_airsar_header(inFile); long offset = header->first_data_offset; FSEEK(fpIn, offset, SEEK_SET); for (ii=0; ii<meta->general->line_count; ii++) { for (kk=0; kk<meta->general->sample_count; kk++) { FREAD(byteBuf, sizeof(char), 10, fpIn); power[kk] = sqrt(((float)byteBuf[1]/254.0 + 1.5) * pow(2, byteBuf[0])); } put_float_line(fpOut, meta, ii, power); asfLineMeter(ii, meta->general->line_count); } FCLOSE(fpIn); FCLOSE(fpOut); meta_write(meta, outFile); if (power) FREE(power); if (byteBuf) FREE(byteBuf); if (meta) meta_free(meta); }
void generate(char* source, char* destination){ FILE *ip,*op; printf("File to work on : %s\n",source); ip = FOPEN(source,"rb"); op = FOPEN(destination,"ab"); unsigned long len; unsigned long offset=0; char *buf = NULL, *buf_orig = NULL, *buf_read=NULL; // Opening input and output file char header[MAX_FILE_NAME]; if(verbose){ strcpy(header,"String, File Name, md5, offset, size \n"); FWRITE(header, "header", op); } if((buf = (char*)malloc(4*1024)) == NULL){ printf("Error in allocating memory"); } buf_orig=buf; buf_read = buf; while((len=fread(buf,1,RDLEN,ip))!=0){ // Generate MD5 here char out[MD5_DIGEST_LENGTH*2+1]; getMD5(buf,out,len); if(verbose){ FWRITE(buf_read, "buf",op); FWRITE(",",",",op); } if(fileNameRequired){ FWRITE(source, "fileName",op); FWRITE(",",",",op); } FWRITE(out,"md5value",op); FWRITE(",",",",op); char offset_str[MAX_BUF_LEN]; sprintf(offset_str, "%lu",offset); FWRITE(offset_str,"offset",op); FWRITE(",",",",op); char size_str[MAX_BUF_LEN]; sprintf(size_str, "%lu",len); FWRITE(size_str,"size",op); FWRITE("\n","New Line",op); offset += len; } free(buf); FCLOSE(op); FCLOSE(ip); }
char *qmonReadText(const char *filename, lList **alpp) { char *text = NULL; SGE_STRUCT_STAT statb; FILE *fp = NULL; DENTER(GUI_LAYER, "qmonReadText"); if (filename == NULL) { answer_list_add_sprintf(alpp, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, "No filename specified"); DRETURN(NULL); } /* ** make sure the file is a regular text file and open it */ if (SGE_STAT(filename, &statb) == -1 || (statb.st_mode & S_IFMT) != S_IFREG || !(fp = fopen(filename, "r"))) { answer_list_add_sprintf(alpp, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, MSG_FILE_OPENFAILED_S, filename); DRETURN(NULL); } /* ** put the contents of the file in the Text widget by allocating ** enough space for the entire file, reading the file into the ** allocated space, and using XmTextFieldSetString() to show the file. */ if ((text = XtMalloc((unsigned)(statb.st_size + 1))) == NULL) { answer_list_add_sprintf(alpp, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, "%s", MSG_MEMORY_MALLOCFAILED); FCLOSE(fp); DRETURN(NULL); } if (!fread(text, sizeof (char), statb.st_size + 1, fp)) { answer_list_add_sprintf(alpp, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, MSG_FILE_FREADFAILED_SS, filename, strerror(errno)); } text[statb.st_size] = 0; /* be sure to NULL-terminate */ FCLOSE(fp); DRETURN(text); FCLOSE_ERROR: XtFree(text); answer_list_add_sprintf(alpp, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, MSG_FILE_NOCLOSE_SS, filename, strerror(errno)); DRETURN(NULL); }
/*-------------------------------------------------------------- * Name: get_qmaster_heartbeat * Descr: get number found in qmaster heartbeat file * Return: > 0 number found in given heartbeat file * -1 can't open file * -2 can't read entry * -3 read timeout * -4 fclose error *-------------------------------------------------------------*/ int get_qmaster_heartbeat( char *file, int read_timeout ) { FILE *fp = NULL; int hb = 0; struct timeval start_time; struct timeval end_time; unsigned long read_time; DENTER(TOP_LAYER, "get_qmaster_heartbeat"); if (file == NULL) { ERROR((SGE_EVENT, SFNMAX, MSG_HEART_NO_FILENAME)); DEXIT; return -1; } gettimeofday(&start_time,NULL); fp = fopen(file, "r"); if (!fp) { ERROR((SGE_EVENT, MSG_HEART_CANNOTOPEN_SS, file, strerror(errno))); DEXIT; return -1; } if (fscanf(fp, "%d", &hb) != 1) { FCLOSE(fp); ERROR((SGE_EVENT, MSG_HEART_CANNOT_READ_FILE_S, strerror(errno))); DEXIT; return -2; } FCLOSE(fp); /* This is only for testsuite testing */ if (sge_testmode_timeout_value > 0 && hb == sge_testmode_timeout_at_heartbeat ) { sleep(sge_testmode_timeout_value); } gettimeofday(&end_time,NULL); read_time = end_time.tv_sec - start_time.tv_sec; if (read_time > read_timeout) { ERROR((SGE_EVENT, MSG_HEART_READ_TIMEOUT_S, file)); DEXIT; return -3; } DEXIT; return hb; FCLOSE_ERROR: ERROR((SGE_EVENT, MSG_HEART_CLOSE_ERROR_SS, file, strerror(errno))); DEXIT; return -4; }
void uninitRepair (PROG_INFO *prog_struct, BLOCK_INFO *block_struct) { /* ** If output was sent to a file, then put an end of file marker ** on the prelude file and close both the seq and prel files. */ if (prog_struct -> prel_file != NULL) { writeBits (prog_struct -> prel_file, 1, 1, R_FALSE); writeBits (prog_struct -> prel_file, 0, 0, R_FALSE); writeBits (prog_struct -> prel_file, 0, 0, R_FALSE); writeBits (prog_struct -> prel_file, 0, 0, R_TRUE); FCLOSE (prog_struct -> seq_file); FCLOSE (prog_struct -> prel_file); if (prog_struct -> prel_text_file != NULL) { FCLOSE (prog_struct -> prel_text_file); } } #ifdef DEBUG fprintf (stderr, "\nOverall Statistics:\n\n"); fprintf (stderr, "Input filename: %s\n", prog_struct -> base_filename != NULL ? prog_struct -> base_filename : "N/A"); fprintf (stderr, "Input file size: %d\n", prog_struct -> base_filename != NULL ? prog_struct -> in_file_size : 0); fprintf (stderr, "Total number of phrases: %d\n", prog_struct -> total_num_phrases); fprintf (stderr, "Total number of blocks: %d\n", prog_struct -> total_blocks); fprintf (stderr, "Total sequence length: %d\n", prog_struct -> total_num_symbols); if (prog_struct -> prel_text_file != NULL) { fprintf (stderr, "Average length of phrases: %f per phrase\n", (R_DOUBLE) prog_struct -> total_sum_phrase_length / (R_DOUBLE) prog_struct -> total_num_phrases); fprintf (stderr, "The longest phrases was:\n"); fprintf (stderr, "\tphrase number: %d\n", prog_struct -> max_longest_phrase_num); fprintf (stderr, "\tblock number: %d\n", prog_struct -> max_longest_phrase_block); fprintf (stderr, "\tphrase length: %d\n", prog_struct -> max_longest_phrase_length); } fprintf (stderr, "\nMaximum for one phrase hierarchy:\n"); fprintf (stderr, "\tNumber of primitives and phrases: %d\n", prog_struct -> maximum_total_num_phrases); fprintf (stderr, "\tGeneration: %d\n", prog_struct -> maximum_generations + 1); /* Add 1 since generation is 0-based */ fprintf (stderr, "\tNumber of primitives: %d\n", prog_struct -> maximum_primitives); #endif /* Must add 1 to maximum_generations since it is 0-based */ if (prog_struct -> verbose_level == R_TRUE) { fprintf (stderr, "-------------------------------------------------------------------------\n"); fprintf (stderr, "%5u\t%5u\t%7u\t %15u\t%11u\t%7u\n", prog_struct -> total_blocks, prog_struct -> total_num_prims, prog_struct -> total_num_phrases, prog_struct -> total_num_prims + prog_struct -> total_num_phrases, prog_struct -> maximum_generations + 1, prog_struct -> total_num_symbols); } wfree (prog_struct -> seq_nodelist); wfree (prog_struct -> progname); wfree (prog_struct -> base_filename); return; }
/****** uti/stdio/sge_peclose() *********************************************** * NAME * sge_peclose() -- pclose() call which is suitable for sge_peopen() * * SYNOPSIS * int sge_peclose(pid_t pid, FILE *fp_in, FILE *fp_out, * FILE *fp_err, struct timeval *timeout) * * FUNCTION * ??? * * INPUTS * pid_t pid - pid returned by peopen() * FILE *fp_in * FILE *fp_out * FILE *fp_err * struct timeval *timeout * * RESULT * int - exit code of command or -1 in case of errors * * SEE ALSO * uti/stdio/peopen() * * NOTES * MT-NOTE: sge_peclose() is MT safe ******************************************************************************/ int sge_peclose(pid_t pid, FILE *fp_in, FILE *fp_out, FILE *fp_err, struct timeval *timeout) { int i, status; DENTER(TOP_LAYER, "sge_peclose"); if (fp_in != NULL) { FCLOSE(fp_in); } if (fp_out != NULL) { FCLOSE(fp_out); } if (fp_err != NULL) { FCLOSE(fp_err); } do { i = waitpid(pid, &status, timeout?WNOHANG:0); if (i==-1) { DEXIT; return -1; } if (i==0) { /* not yet exited */ if (timeout->tv_sec == 0) { #ifdef WIN32 /* kill not called */ /* CygWin has no kill command */ DPRINTF(("killing not yet implemented\n")); timeout = NULL; /* kill(pid, SIGKILL); */ #else DPRINTF(("killing\n")); timeout = NULL; kill(pid, SIGKILL); #endif /* WIN32 */ } else { DPRINTF(("%d seconds waiting for exit\n", timeout->tv_sec)); sleep(1); timeout->tv_sec -= 1; } } } while (i != pid); if (status & 0xff) { /* terminated by signal */ DEXIT; return -1; } DEXIT; return (status&0xff00) >> 8; /* return exitcode */ FCLOSE_ERROR: return -1; }
void reset_colors( char_data * ch ) { if( !ch->isnpc( ) ) { char filename[256]; snprintf( filename, 256, "%s%s", COLOR_DIR, "default" ); if( exists_file( filename ) ) { FILE *fp; int max_colors = 0; if( !( fp = fopen( filename, "r" ) ) ) { memcpy( &ch->pcdata->colors, &default_set, sizeof( default_set ) ); return; } while( !feof( fp ) ) { char *word = fread_word( fp ); if( !str_cmp( word, "MaxColors" ) ) { max_colors = fread_number( fp ); continue; } if( !str_cmp( word, "Colors" ) ) { for( int x = 0; x < max_colors; ++x ) ch->pcdata->colors[x] = fread_number( fp ); continue; } if( !str_cmp( word, "End" ) ) { FCLOSE( fp ); return; } } FCLOSE( fp ); return; } else memcpy( &ch->pcdata->colors, &default_set, sizeof( default_set ) ); } else log_printf( "%s: Attempting to reset NPC colors: %s", __func__, ch->short_descr ); }
int main(int argc, char** argv) { int result = -1; Cookie cookie; memset(&cookie, 0, sizeof(Cookie)); next_file(&cookie); for (;;) { uint8_t name_size; char* name = NULL; #if 0 printf("Volume %i, offset 0x%08lx\n", cookie.index, ftell(cookie.input_file)); #endif if (sizeof(name_size) != reader(&name_size, sizeof(name_size), &cookie)) break; name = malloc(MAX_FILENAME_SIZE); if (MAX_FILENAME_SIZE != reader(name, MAX_FILENAME_SIZE, &cookie)) { fprintf(stderr, "read name failed\n"); break; } name[name_size] = '\0'; printf("extracting: %s\n", name); cookie.output_file = fopen(name, "w"); result = dynamite_explode(reader, writer, &cookie); FCLOSE(cookie.output_file); if (DYNAMITE_SUCCESS != result) { fprintf(stderr, "Error %i\n", result); break; } } FCLOSE(cookie.input_file); FCLOSE(cookie.output_file); return result; }
int dem_to_mask(char *inDemFile, char *outMaskFile, float cutoff) { meta_parameters *inDemMeta = meta_read(inDemFile); meta_parameters *outDemMeta = meta_read(inDemFile); // out metadata will differ from in only in the data type outDemMeta->general->data_type = ASF_BYTE; int x_size = inDemMeta->general->sample_count; int y_size = inDemMeta->general->line_count; float *maskbuffer = MALLOC(sizeof(float) * x_size); float *floatbuffer = MALLOC(sizeof(float) * x_size); FILE *in = fopenImage(inDemFile, "rb"); FILE *out = fopenImage(outMaskFile, "wb"); float mv = masked_value(); float umv = unmasked_value(); int y,x; for (y=0; y<y_size; y++) { get_float_line(in, inDemMeta, y, floatbuffer); for (x=0; x < x_size; x++) maskbuffer[x] = floatbuffer[x] <= cutoff ? mv : umv; put_float_line(out, outDemMeta, y, maskbuffer); asfLineMeter(y, y_size); } FCLOSE(in); FCLOSE(out); FREE(floatbuffer); FREE(maskbuffer); meta_write(outDemMeta, outMaskFile); meta_free(inDemMeta); meta_free(outDemMeta); asfPrintStatus("Created Mask file '%s' from DEM '%s'.\n", outMaskFile, inDemFile); return 0; }
STATICFNDEF char *read_table(char *b, int l, FILE *f) { char *t; int fclose_res; ext_source_column = 0; FGETS(b, l, f, t); if (NULL == t) { if (0 != ferror(f)) { FCLOSE(f, fclose_res); /* Expand error message */ rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) errno); } else assert(feof(f) != 0); } else { /* Unfortunately, fgets does not strip the NL, we will do it for it */ for (ext_source_line_len = 0; *t ; t++) { ext_source_line[ext_source_line_len++] = *t; if (CR == *t) { *t = 0; ext_source_line_num += 1; break; } } } return t; }
meta_parameters *read_asf_meta(const char *meta_name) { meta_parameters *meta = meta_read(meta_name); // If the ASF internal format file is a single-band image with RGB color map // in the metadata, then store the color map as an ASF style look-up table if (meta->colormap) { int i; meta_colormap *mc = meta->colormap; char lut_file[256]; char *lut_loc = (char *)MALLOC(sizeof(char)*(strlen(get_asf_share_dir())+128)); sprintf(lut_loc, "%s%clook_up_tables", get_asf_share_dir(), DIR_SEPARATOR); sprintf(lut_file,"%s%c%s", lut_loc, DIR_SEPARATOR, EMBEDDED_ASF_COLORMAP_LUT_FILE); FILE *lutFP = (FILE *)FOPEN(lut_file, "wt"); fprintf(lutFP, "# Look up table type: %s\n", mc->look_up_table); fprintf(lutFP, "# Originating source: %s\n", meta_name); fprintf(lutFP, "# Index Red Green Blue\n"); for (i=0; i<mc->num_elements; i++) { fprintf(lutFP, "%03d %03d %03d %03d\n", i, mc->rgb[i].red, mc->rgb[i].green, mc->rgb[i].blue); } fprintf(lutFP, "\n"); FCLOSE(lutFP); } return meta; }
static int met_save_para(U8 bForce) { if(met_mem.bModify) { if(met_mem.nChkSec==1 || met_mem.nChkCnt==1 || bForce) { FHANDLE fp; fp=FOPEN("met.bin","w"); if(fp==NULL)fp=FOPEN("met.bin","wb"); if(fp) { //FSEEK(fp,met_mem.met*MET_ITEM_SIZE,SEEK_SET); if(met_mem.pbuf!=NULL) FWRITE(met_mem.pbuf,MET_BUF_SIZE,1,fp); FCLOSE(fp); met_mem.wCnt++; met_mem.bModify=0; } met_mem.nChkSec=0; met_mem.nChkCnt=0; } if(met_mem.nChkSec)met_mem.nChkSec--; } return 1; }
bool shepherd_read_exit_status_file(int *return_code) { bool ret = true; FILE *fp = NULL; const char *const filename = "exit_status"; fp = fopen(filename, "r"); if (fp != NULL) { int arguments = fscanf(fp, "%d\n", return_code); /* retrieve first exit status from exit status file */ if (arguments != 1) { shepherd_trace("could not read exit_status file"); *return_code = ESSTATE_NO_EXITSTATUS; ret = false; } } else { shepherd_error(1, MSG_FILE_NOOPEN_SS, filename, strerror(errno)); ret = false; } FCLOSE(fp); return ret; FCLOSE_ERROR: shepherd_error(1, MSG_FILE_NOCLOSE_SS, filename, strerror(errno)); return false; }
void ReleaseFileOutput( REMUXER *pRemuxer ) { if ( pRemuxer->output_track != NULL ) { _output_statistic( pRemuxer ); if ( pRemuxer->output_track[0] ) ReleaseTracks( pRemuxer->output_track[0] ); } if ( pRemuxer->ps_builder != NULL ) { ReleasePSBuilder( pRemuxer->ps_builder ); pRemuxer->ps_builder = NULL; } if ( pRemuxer->ts_builder != NULL ) { ReleaseTSBuilder( pRemuxer->ts_builder ); pRemuxer->ts_builder = NULL; } if ( pRemuxer->output_file > 0 ) { FCLOSE( pRemuxer->output_file ); pRemuxer->output_file = 0; } }
void acc_mme_logreset(void) { FILE * fcmd; fcmd = FFOPEN(CMD_LOG_FILE, "wb"); FCLOSE(fcmd); }
/* * This generates keys. It's only called in the first fsort pass */ int makekey(FILE *fp, RECHEADER *recbuf, u_char *bufend, struct field *ftbl) { static u_char *line_data; static ssize_t line_size; static int overflow = 0; /* We get re-entered after returning BUFFEND - save old data */ if (overflow) { overflow = enterkey(recbuf, bufend, line_data, line_size, ftbl); return overflow ? BUFFEND : 0; } line_size = seq(fp, &line_data); if (line_size == 0) { FCLOSE(fp); return EOF; } if (line_size > bufend - recbuf->data) { overflow = 1; } else { overflow = enterkey(recbuf, bufend, line_data, line_size, ftbl); } return overflow ? BUFFEND : 0; }
bool shepherd_read_qrsh_file(const char* pid_file_name, pid_t *qrsh_pid) { bool ret = true; FILE *fp = NULL; fp = fopen(pid_file_name, "r"); if (fp != NULL) { int arguments = fscanf(fp, pid_t_fmt, qrsh_pid); /* retrieve first exit status from exit status file */ if (arguments != 1) { shepherd_trace("could not read qrsh_pid_file '%s'", pid_file_name); *qrsh_pid = 0; ret = false; } FCLOSE(fp); } else { /* * CR 6588743 - raising a shepherd_error here would set the queue in * error state and rerun the job */ shepherd_trace(MSG_FILE_NOOPEN_SS, pid_file_name, strerror(errno)); ret = false; } return ret; FCLOSE_ERROR: /* * CR 6588743 - raising a shepherd_error here would set the queue in * error state and rerun the job */ shepherd_trace(MSG_FILE_NOCLOSE_SS, pid_file_name, strerror(errno)); return false; }
bool shepherd_read_processor_set_number_file(int *proc_set) { bool ret = true; FILE *fp = NULL; const char *const filename = "processor_set_number"; fp = fopen(filename, "r"); if (fp != NULL) { int arguments = fscanf(fp, "%d", proc_set); if (arguments != 1) { shepherd_trace("could not read processor_set_number file"); *proc_set = 0; ret = false; } } else { shepherd_error(1, MSG_FILE_NOOPEN_SS, filename, strerror(errno)); ret = false; } FCLOSE(fp); return ret; FCLOSE_ERROR: shepherd_error(1, MSG_FILE_NOCLOSE_SS, filename, strerror(errno)); return false; }
static int sys_save_para(U8 bForce) { if(sys_mem.bModify) { if(sys_mem.nChkSec==1 || sys_mem.nChkCnt==1 || bForce) { FHANDLE fp; fp=FOPEN("sys.bin","w"); //if(fp==NULL)fp=FOPEN("sys.bin","wb"); // 系统出错时会导致丢参数, 2014.2.18去掉 if(fp) { if(sys_mem.pbuf!=NULL) FWRITE(sys_mem.pbuf,SYS_BUF_SIZE,1,fp); FCLOSE(fp); // sys_mem.crc=CHECK_CRC(sys_mem.pbuf,sys_mem.size); sys_mem.wCnt++; sys_mem.bModify=0; // return 1; } sys_mem.nChkSec=0; sys_mem.nChkCnt=0; } if(sys_mem.nChkSec)sys_mem.nChkSec--; // if(sys_mem.nChkCnt)sys_mem.nChkCnt--; } return 1; }
int child_func(void *params) { child_params_t *cp = (child_params_t *)params; c2v_config *cfg = init_fill_c2v_config(); char *lf = appendExt(cp->out_file, ".log"); strcpy(logFile, lf); free(lf); quietflag = FALSE; logflag = TRUE; fLog = FOPEN(logFile, "a"); strcpy(cfg->input_file, cp->in_file); strcpy(cfg->output_file, cp->out_file); strcpy(cfg->input_format, cp->in_format); strcpy(cfg->output_format, cp->out_format); int ret = convert2vector(cfg); asfPrintStatus("Successful completion!\n"); FCLOSE(fLog); return ret==1 ? 0 : 1; }
bool shepherd_write_pid_file(pid_t pid, dstring *errmsg) { bool ret = true; FILE *fp = NULL; fp = fopen("pid", "w"); if (fp != NULL) { if (fprintf(fp, pid_t_fmt"\n", pid) < 0) { sge_dstring_sprintf(errmsg, MSG_FILE_CANNOT_WRITE_SS, "pid", strerror(errno)); ret = false; } else { if (fflush(fp) < 0) { sge_dstring_sprintf(errmsg, MSG_FILE_CANNOT_FLUSH_SS, "pid", strerror(errno)); ret = false; } } FCLOSE(fp); } else { sge_dstring_sprintf(errmsg, MSG_FILE_NOOPEN_SS, "pid", strerror(errno)); ret = false; } return ret; FCLOSE_ERROR: sge_dstring_sprintf(errmsg, MSG_FILE_NOCLOSE_SS, "pid", strerror(errno)); return false; }