本文整理汇总了C++中FCLOSE函数的典型用法代码示例。如果您正苦于以下问题:C++ FCLOSE函数的具体用法?C++ FCLOSE怎么用?C++ FCLOSE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FCLOSE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MountableDevice
/*
* 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;
}
示例2: DEHT_freeResources
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;
}
示例3: fileCopy
/******************************************************************************
* 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);
}
示例4: floats_to_bytes_from_file_ext
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);
}
示例5: isArcList
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;
}
示例6: write_qm_name
/*********************************************************************
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;
}
示例7: FOPEN
//テキストファイルの読み込み
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;
}
示例8: host_in_file
/*----------------------------------------------------------------------
* 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);
}
示例9: extract_fastfile
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);
}
示例10: ingest_polarimetry_data
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);
}
示例11: generate
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);
}
示例12: DENTER
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);
}
示例13: get_qmaster_heartbeat
/*--------------------------------------------------------------
* 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;
}
示例14: uninitRepair
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;
}
示例15: sge_peclose
/****** 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;
}