当前位置: 首页>>代码示例>>C++>>正文


C++ safe_fclose函数代码示例

本文整理汇总了C++中safe_fclose函数的典型用法代码示例。如果您正苦于以下问题:C++ safe_fclose函数的具体用法?C++ safe_fclose怎么用?C++ safe_fclose使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了safe_fclose函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: create_output_volumes

/*
 NAME:allocate_shot_memory
 PURPOSE: Create files to store final preconditioner and gradient results. Must be initialized with zeroes.
 
 outputfolder     (in) folder where snapshot data is store
 VolumeMemory     (in) memory needed to store the domain
 
 RETURN none
 */
void create_output_volumes(char *outputfolder, integer VolumeMemory)
{
    log_info ( "Creating output files in %s", outputfolder);

#ifndef DO_NOT_PERFOM_IO    
    char fnamePrecond[300], fnameGradient[300];
    
    sprintf( fnameGradient, "%s/resultGradient.res", outputfolder);
    sprintf( fnamePrecond , "%s/resultPrecond.res", outputfolder);
    
    FILE *fGradient = safe_fopen( fnameGradient, "wb", __FILE__, __LINE__ );
    FILE *fPrecond  = safe_fopen( fnamePrecond , "wb", __FILE__, __LINE__ );
     
    int numIts = ceil( VolumeMemory / IO_CHUNK_SIZE );
    
    /* create buffer array */
    real *tmparray = (real*) __malloc( ALIGN_INT, IO_CHUNK_SIZE );
    
    /* perform the accumulation of the chunks */
    for (int i=0; i<numIts; i++) {
        safe_fwrite(tmparray, 1, IO_CHUNK_SIZE, fGradient, __FILE__, __LINE__ );
        safe_fwrite(tmparray, 1, IO_CHUNK_SIZE, fPrecond , __FILE__, __LINE__ );
    }
    
    __free(tmparray);
    
    // close files
    safe_fclose( fnameGradient, fGradient, __FILE__, __LINE__ );
    safe_fclose( fnamePrecond , fPrecond , __FILE__, __LINE__ );
#endif

		log_info ("Output volumes created correctly");
}
开发者ID:srodrb,项目名称:FWI,代码行数:42,代码来源:fwi_common.c

示例2: rfc3676_space_stuff

/*
 * This routine does RfC3676 space stuffing since it's a MUST.
 * Space stuffing means that we have to add leading spaces to
 * certain lines:
 *   - lines starting with a space
 *   - lines starting with 'From '
 * This routine is only called once right after editing the
 * initial message so it's up to the user to take care of stuffing
 * when editing the message several times before actually sending it
 *
 * This is more or less a hack as it replaces the message's content with
 * a freshly created copy in a tempfile and modifies the file's mtime
 * so we don't trigger code paths watching for mtime changes
 */
void rfc3676_space_stuff (HEADER* hdr)
{
#if DEBUG
  int lc = 0;
  size_t len = 0;
  unsigned char c = '\0';
#endif
  FILE *in = NULL, *out = NULL;
  char buf[LONG_STRING];
  char tmpfile[_POSIX_PATH_MAX];

  if (!hdr || !hdr->content || !hdr->content->filename)
    return;

  dprint (2, (debugfile, "f=f: postprocess %s\n", hdr->content->filename));

  if ((in = safe_fopen (hdr->content->filename, "r")) == NULL)
    return;

  mutt_mktemp (tmpfile, sizeof (tmpfile));
  if ((out = safe_fopen (tmpfile, "w+")) == NULL)
  {
    safe_fclose (&in);
    return;
  }

  while (fgets (buf, sizeof (buf), in))
  {
    if (ascii_strncmp ("From ", buf, 5) == 0 || buf[0] == ' ') {
      fputc (' ', out);
#if DEBUG
      lc++;
      len = mutt_strlen (buf);
      if (len > 0)
      {
        c = buf[len-1];
        buf[len-1] = '\0';
      }
      dprint (4, (debugfile, "f=f: line %d needs space-stuffing: '%s'\n",
                  lc, buf));
      if (len > 0)
        buf[len-1] = c;
#endif
    }
    fputs (buf, out);
  }
  safe_fclose (&in);
  safe_fclose (&out);
  mutt_set_mtime (hdr->content->filename, tmpfile);
  unlink (hdr->content->filename);
  mutt_str_replace (&hdr->content->filename, tmpfile);
}
开发者ID:aschrab,项目名称:mutt,代码行数:66,代码来源:rfc3676.c

示例3: pager_close

void pager_close(void) {

        if (pager_pid <= 0)
                return;

        /* Inform pager that we are done */
        stdout = safe_fclose(stdout);
        stderr = safe_fclose(stderr);

        (void) kill(pager_pid, SIGCONT);
        (void) wait_for_terminate(pager_pid, NULL);
        pager_pid = 0;
}
开发者ID:Like-all,项目名称:tinysystemd-substrate,代码行数:13,代码来源:pager.c

示例4: tls_check_stored_hostname

static int tls_check_stored_hostname (const gnutls_datum *cert,
                                      const char *hostname)
{
  char buf[80];
  FILE *fp;
  char *linestr = NULL;
  size_t linestrsize;
  int linenum = 0;
  regex_t preg;
  regmatch_t pmatch[3];

  /* try checking against names stored in stored certs file */
  if ((fp = fopen (SslCertFile, "r")))
  {
    if (REGCOMP(&preg, "^#H ([a-zA-Z0-9_\\.-]+) ([0-9A-F]{4}( [0-9A-F]{4}){7})[ \t]*$",
                REG_ICASE) != 0)
    {
       return 0;
    }

    buf[0] = '\0';
    tls_fingerprint (GNUTLS_DIG_MD5, buf, sizeof (buf), cert);
    while ((linestr = mutt_read_line(linestr, &linestrsize, fp, &linenum, 0)) != NULL)
    {
      if(linestr[0] == '#' && linestr[1] == 'H')
      {
        if (regexec(&preg, linestr, 3, pmatch, 0) == 0)
        {
          linestr[pmatch[1].rm_eo] = '\0';
          linestr[pmatch[2].rm_eo] = '\0';
          if (strcmp(linestr + pmatch[1].rm_so, hostname) == 0 &&
              strcmp(linestr + pmatch[2].rm_so, buf) == 0)
          {
            regfree(&preg);
            FREE(&linestr);
            safe_fclose (&fp);
            return 1;
          }
        }
      }
    }

    regfree(&preg);
    safe_fclose (&fp);
  }

  /* not found a matching name */
  return 0;
}
开发者ID:Ishpeck,项目名称:mutt-kz,代码行数:49,代码来源:mutt_ssl_gnutls.c

示例5: check_certificate_by_digest

static int check_certificate_by_digest (X509 *peercert)
{
  unsigned char peermd[EVP_MAX_MD_SIZE];
  unsigned int peermdlen;
  X509 *cert = NULL;
  int pass = 0;
  FILE *fp;

  /* expiration check */
  if (option (OPTSSLVERIFYDATES) != M_NO)
  {
    if (X509_cmp_current_time (X509_get_notBefore (peercert)) >= 0)
    {
      dprint (2, (debugfile, "Server certificate is not yet valid\n"));
      mutt_error (_("Server certificate is not yet valid"));
      mutt_sleep (2);
      return 0;
    }
    if (X509_cmp_current_time (X509_get_notAfter (peercert)) <= 0)
    {
      dprint (2, (debugfile, "Server certificate has expired"));
      mutt_error (_("Server certificate has expired"));
      mutt_sleep (2);
      return 0;
    }
  }

  if ((fp = fopen (SslCertFile, "rt")) == NULL)
    return 0;

  if (!X509_digest (peercert, EVP_sha1(), peermd, &peermdlen))
  {
    safe_fclose (&fp);
    return 0;
  }

  while ((cert = READ_X509_KEY (fp, &cert)) != NULL)
  {
    pass = compare_certificates (cert, peercert, peermd, peermdlen) ? 0 : 1;

    if (pass)
      break;
  }
  X509_free (cert);
  safe_fclose (&fp);

  return pass;
}
开发者ID:Ishpeck,项目名称:mutt-kz,代码行数:48,代码来源:mutt_ssl.c

示例6: load_shot_parameters

void load_shot_parameters( int    shotid,
                          int     *stacki,
                          real    *dt,
                          int     *nt_fwd,
                          int     *nt_bwd,
                          real    *dz,
                          real    *dx,
                          real    *dy,
                          integer *dimmz,
                          integer *dimmx,
                          integer *dimmy,
                          char    *outputfolder)
{
    char name[200];
    
    sprintf(name, "%s/shotparams_%05d.dat",outputfolder, shotid);
    log_info ( "Storing parameters for shot %d into %s", shotid, name);

    FILE *fp = safe_fopen(name, "r", __FILE__, __LINE__);
    
    fscanf(fp, "%f\n",  (real*   ) dz     );
    fscanf(fp, "%f\n",  (real*   ) dx     );
    fscanf(fp, "%f\n",  (real*   ) dy     );
    fscanf(fp,  I"\n", (integer*) dimmz  );
    fscanf(fp,  I"\n", (integer*) dimmx  );
    fscanf(fp,  I"\n", (integer*) dimmy  );
    fscanf(fp, "%d\n",  (int*    ) nt_fwd );
    fscanf(fp, "%d\n",  (int*    ) nt_bwd );
    fscanf(fp, "%f\n",  (real*   ) dt     );
    fscanf(fp, "%d\n",  (int*    ) stacki );
    
    safe_fclose( name, fp, __FILE__, __LINE__);
};
开发者ID:srodrb,项目名称:FWI,代码行数:33,代码来源:fwi_common.c

示例7: log_error

void log_error (const char *fmt, ...) 
{

		/* locate myself into the MPI world */
		int mpi_rank;
		MPI_Comm_rank( MPI_COMM_WORLD, &mpi_rank);

		/* build log file name */
		char logname[50];
		sprintf( logname, "mpi_%02d.log", mpi_rank);
		FILE* flog = safe_fopen( logname, "a+", __FILE__, __LINE__ );
	
		/* create the string from variadic input arguments */
		char str[1000];
    va_list args;
    va_start(args, fmt);
    vsprintf(str, fmt, args);
    va_end(args);

		/* create time string */
		char timestr[20];
    struct tm *sTm;
    time_t now = time (0);
    sTm = gmtime (&now);
    strftime ( timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", sTm);

		/* print actual line to log file  */
   	fprintf( flog, "-----> ERROR :: %s: %s\n", timestr, str);

		/*  close file  */
		safe_fclose( logname, flog, __FILE__, __LINE__ );
};
开发者ID:srodrb,项目名称:FWI,代码行数:32,代码来源:fwi_common.c

示例8: session_read_data

static void
session_read_data(struct session *s, char *line)
{
	size_t datalen;
	size_t len;
	size_t i;

	if (strcmp(line, ".") == 0) {
		s->s_datalen = ftell(s->datafp);
		if (! safe_fclose(s->datafp))
			s->s_dstatus |= DS_TEMPFAILURE;
		s->datafp = NULL;

		if (s->s_dstatus & DS_PERMFAILURE) {
			session_respond(s, "554 5.0.0 Transaction failed");
			session_enter_state(s, S_HELO);
		} else if (s->s_dstatus & DS_TEMPFAILURE) {
			session_respond(s, "421 4.0.0 Temporary failure");
			session_enter_state(s, S_QUIT);
			stat_increment("smtp.tempfail", 1);
		} else {
			session_imsg(s, PROC_QUEUE, IMSG_QUEUE_COMMIT_MESSAGE,
			    0, 0, -1, &s->s_msg, sizeof(s->s_msg));
			session_enter_state(s, S_DONE);
		}
		return;
	}

	/* Don't waste resources on message if it's going to bin anyway. */
	if (s->s_dstatus & (DS_PERMFAILURE|DS_TEMPFAILURE))
		return;

	/* "If the first character is a period and there are other characters
	 *  on the line, the first character is deleted." [4.5.2]
	 */
	if (*line == '.')
		line++;

	len = strlen(line);

	/* If size of data overflows a size_t or exceeds max size allowed
	 * for a message, set permanent failure.
	 */
	datalen = ftell(s->datafp);
	if (SIZE_MAX - datalen < len + 1 ||
	    datalen + len + 1 > env->sc_maxsize) {
		s->s_dstatus |= DS_PERMFAILURE;
		return;
	}

	if (! (s->s_flags & F_8BITMIME)) {
		for (i = 0; i < len; ++i)
			if (line[i] & 0x80)
				line[i] = line[i] & 0x7f;
	}

	if (fprintf(s->datafp, "%s\n", line) != (int)len + 1)
		s->s_dstatus |= DS_TEMPFAILURE;
}
开发者ID:clongeau,项目名称:opensmtpd,代码行数:59,代码来源:smtp_session.c

示例9: safe_fsync_close

int safe_fsync_close (FILE **f)
{
  int r = 0;

  if (*f)
  {
    if (fflush (*f) || fsync (fileno (*f)))
    {
      r = -1;
      safe_fclose (f);
    }
    else
      r = safe_fclose (f);
  }

  return r;
}
开发者ID:SteveClement,项目名称:mutt,代码行数:17,代码来源:lib.c

示例10: mutt_expand_file_fmt

static QUERY *run_query (char *s, int quiet)
{
        FILE *fp;
        QUERY *first = NULL;
        QUERY *cur = NULL;
        char cmd[_POSIX_PATH_MAX];
        char *buf = NULL;
        size_t buflen;
        int dummy = 0;
        char msg[STRING];
        char *p;
        pid_t thepid;

        mutt_expand_file_fmt (cmd, sizeof(cmd), QueryCmd, s);

        if ((thepid = mutt_create_filter (cmd, NULL, &fp, NULL)) < 0) {
                dprint (1, (debugfile, "unable to fork command: %s", cmd));
                return 0;
        }
        if (!quiet)
                mutt_message _("Waiting for response...");
        fgets (msg, sizeof (msg), fp);
        if ((p = strrchr (msg, '\n')))
                *p = '\0';
        while ((buf = mutt_read_line (buf, &buflen, fp, &dummy, 0)) != NULL) {
                if ((p = strtok(buf, "\t\n"))) {
                        if (first == NULL) {
                                first = (QUERY *) safe_calloc (1, sizeof (QUERY));
                                cur = first;
                        }
                        else {
                                cur->next = (QUERY *) safe_calloc (1, sizeof (QUERY));
                                cur = cur->next;
                        }

                        cur->addr = rfc822_parse_adrlist (cur->addr, p);
                        p = strtok(NULL, "\t\n");
                        if (p) {
                                cur->name = safe_strdup (p);
                                p = strtok(NULL, "\t\n");
                                if (p)
                                        cur->other = safe_strdup (p);
                        }
                }
        }
        FREE (&buf);
        safe_fclose (&fp);
        if (mutt_wait_filter (thepid)) {
                dprint (1, (debugfile, "Error: %s\n", msg));
                if (!quiet)  mutt_error ("%s", msg);
        }
        else {
                if (!quiet)
                        mutt_message ("%s", msg);
        }

        return first;
}
开发者ID:tejux,项目名称:mutt-hacks,代码行数:58,代码来源:query.c

示例11: imap_commit_message

int imap_commit_message (CONTEXT *ctx, MESSAGE *msg)
{
  int r = safe_fclose (&msg->fp);

  if (r)
    return r;

  return imap_append_message (ctx, msg);
}
开发者ID:aschrab,项目名称:mutt,代码行数:9,代码来源:message.c

示例12: DMALogClose

void DMALogClose()
{
	safe_fclose(DMA4LogFile);
	safe_fclose(DMA7LogFile);
	safe_fclose(REGWRTLogFile[0]);
	safe_fclose(REGWRTLogFile[1]);
	safe_fclose(ADMA4LogFile);
	safe_fclose(ADMA7LogFile);
	safe_fclose(ADMAOutLogFile);
}
开发者ID:madnessw,项目名称:thesnow,代码行数:10,代码来源:Dma.cpp

示例13: fix_end_of_file

static void fix_end_of_file (const char *data)
{
  FILE *fp;
  int c;
  
  if ((fp = safe_fopen (data, "a+")) == NULL)
    return;
  fseek (fp,-1,SEEK_END);
  if ((c = fgetc(fp)) != '\n')
    fputc ('\n', fp);
  safe_fclose (&fp);
}
开发者ID:Ishpeck,项目名称:mutt-kz,代码行数:12,代码来源:send.c

示例14: mutt_rename_file

int mutt_rename_file (char *oldfile, char *newfile)
{
  FILE *ofp, *nfp;

  if (access (oldfile, F_OK) != 0)
    return 1;
  if (access (newfile, F_OK) == 0)
    return 2;
  if ((ofp = fopen (oldfile,"r")) == NULL)
    return 3;
  if ((nfp = safe_fopen (newfile,"w")) == NULL)
  {
    safe_fclose (&ofp);
    return 3;
  }
  mutt_copy_stream (ofp,nfp);
  safe_fclose (&nfp);
  safe_fclose (&ofp);
  mutt_unlink (oldfile);
  return 0;
}
开发者ID:harishpillay,项目名称:mutt-kz,代码行数:21,代码来源:rfc1524.c

示例15: mutt_get_tmp_attachment

int mutt_get_tmp_attachment (BODY *a)
{
  char type[STRING];
  char tempfile[_POSIX_PATH_MAX];
  rfc1524_entry *entry = rfc1524_new_entry();
  FILE *fpin = NULL, *fpout = NULL;
  struct stat st;
  
  if(a->unlink)
    return 0;

  snprintf(type, sizeof(type), "%s/%s", TYPE(a), a->subtype);
  rfc1524_mailcap_lookup(a, type, entry, 0);
  rfc1524_expand_filename(entry->nametemplate, a->filename, 
			  tempfile, sizeof(tempfile));
  
  rfc1524_free_entry(&entry);

  if(stat(a->filename, &st) == -1)
    return -1;

  if((fpin = fopen(a->filename, "r")) && (fpout = safe_fopen(tempfile, "w")))  /* __FOPEN_CHECKED__ */
  {
    mutt_copy_stream (fpin, fpout);
    mutt_str_replace (&a->filename, tempfile);
    a->unlink = 1;

    if(a->stamp >= st.st_mtime)
      mutt_stamp_attachment(a);
  }
  else
    mutt_perror(fpin ? tempfile : a->filename);
  
  if(fpin)  safe_fclose (&fpin);
  if(fpout) safe_fclose (&fpout);
  
  return a->unlink ? 0 : -1;
}
开发者ID:BackupTheBerlios,项目名称:mutt-win32,代码行数:38,代码来源:attach.c


注:本文中的safe_fclose函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。