• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ safe_fopen函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: readCoord

void readCoord(const char* filename, SOP& sop){
	//printf("Reading coordinates from '%s'.\n", filename);
	int is_xyz = 0;
	char buffer[BUF_SIZE+1];
	FILE* file = safe_fopen(filename, "r");
	if(file == NULL){
		DIE("ERROR: Coordinates file %s can not be found.\n", filename);
	}
	if (!strcmp(filename + strlen(filename)-4, ".xyz")) {
		is_xyz = 1;
		safe_fgets(buffer, BUF_SIZE, file);
		safe_fgets(buffer, BUF_SIZE, file);
	}
	int index = 0;
	while(fgets(buffer, BUF_SIZE, file) != NULL){
		if(is_xyz){
			char *pch = strtok(buffer, " \t\r\n");
			pch = strtok(NULL, " \t\r\n");
			sop.aminos[index].x = atof(pch);
			pch = strtok(NULL, " \t\r\n");
			sop.aminos[index].y = atof(pch);
			pch = strtok(NULL, " \t\r\n");
			sop.aminos[index].z = atof(pch);
			index++;
		}
		if(!is_xyz && strncmp(buffer, "ATOM", 4) == 0){
            PDBAtom tmp;
            tmp.parse(buffer);
			sop.aminos[index].x = tmp.x;
			sop.aminos[index].y = tmp.y;
			sop.aminos[index].z = tmp.z;
#ifdef DEBUG
			printf("%d: %f, %f, %f\n", index, sop.aminos[index].x, sop.aminos[index].y, sop.aminos[index].z);
#endif
			index++;
		}
	}
	fclose(file);
	if(index == 0){
		DIE("Can't read pdb file.\n");
	}
	if(index != sop.aminos.size()){
		DIE("Read coordinates for %d beads, yet topology has %zu beads.\n", index, sop.aminos.size());
	}
	//printf("Done reading coordinates.\n");
}
开发者ID:BarsegovGroup,项目名称:SOP-GPU,代码行数:46,代码来源:pdbio.cpp


示例2: parse_bam_list

void parse_bam_list( parameters** params)
{
	FILE* bam_list;
	char next_path[1024];
	int i;

	bam_list = safe_fopen( ( *params)->bam_list_path, "r");

	i = 0;
	while( fscanf( bam_list, "%s\n", next_path) == 1)
	{
		set_str( &( ( *params)->bam_file_list)[i], next_path);
		i = i + 1;
	}

	fclose( bam_list);
}
开发者ID:ayhun,项目名称:tardis,代码行数:17,代码来源:cmdline.c


示例3: LogHashChange

void LogHashChange(const char *file, FileState status, char *msg, const Promise *pp)
{
    FILE *fp;
    char fname[CF_BUFSIZE];
    time_t now = time(NULL);
    mode_t perm = 0600;
    static char prevFile[CF_MAXVARSIZE] = ""; /* GLOBAL_X */

// we might get called twice..
    if (strcmp(file, prevFile) == 0)
    {
        return;
    }

    strlcpy(prevFile, file, CF_MAXVARSIZE);

/* This is inefficient but we don't want to lose any data */

    snprintf(fname, CF_BUFSIZE, "%s/state/%s", CFWORKDIR, CF_FILECHANGE_NEW);
    MapName(fname);

#ifndef __MINGW32__
    struct stat sb;
    if (stat(fname, &sb) != -1)
    {
        if (sb.st_mode & (S_IWGRP | S_IWOTH))
        {
            Log(LOG_LEVEL_ERR, "File '%s' (owner %ju) is writable by others (security exception)", fname, (uintmax_t)sb.st_uid);
        }
    }
#endif /* !__MINGW32__ */

    if ((fp = safe_fopen(fname, "a")) == NULL)
    {
        Log(LOG_LEVEL_ERR, "Could not write to the hash change log. (fopen: %s)", GetErrorStr());
        return;
    }

    const char *handle = PromiseID(pp);

    fprintf(fp, "%ld,%s,%s,%c,%s\n", (long) now, handle, file, FileStateToChar(status), msg);
    fclose(fp);

    safe_chmod(fname, perm);
}
开发者ID:awsiv,项目名称:core,代码行数:45,代码来源:verify_files_hashes.c


示例4: mutt_help

void mutt_help (int menu)
{
  char t[_POSIX_PATH_MAX];
  char buf[SHORT_STRING];
  const char *desc;
  FILE *f;
  const struct binding_t *funcs;

  mutt_mktemp (t, sizeof (t));

  funcs = km_get_table (menu);
  desc = mutt_getnamebyvalue (menu, Menus);
  if (!desc)
    desc = _("<UNKNOWN>");
  
  do {
    if ((f = safe_fopen (t, "w")) == NULL)
    {
      mutt_perror (t);
      return;
    }
  
    dump_menu (f, menu);
    if (menu != MENU_EDITOR && menu != MENU_PAGER)
    {
      fputs (_("\nGeneric bindings:\n\n"), f);
      dump_menu (f, MENU_GENERIC);
    }
  
    fputs (_("\nUnbound functions:\n\n"), f);
    if (funcs)
      dump_unbound (f, funcs, Keymaps[menu], NULL);
    if (menu != MENU_PAGER)
      dump_unbound (f, OpGeneric, Keymaps[MENU_GENERIC], Keymaps[menu]);
  
    safe_fclose (&f);
  
    snprintf (buf, sizeof (buf), _("Help for %s"), desc);
  }
  while
    (mutt_do_pager (buf, t,
		    M_PAGER_RETWINCH | M_PAGER_MARKER | M_PAGER_NSKIP | M_PAGER_NOWRAP,
		    NULL)
     == OP_REFORMAT_WINCH);
}
开发者ID:2ion,项目名称:mutt-1.5.22,代码行数:45,代码来源:help.c


示例5: ParserStateReset

Policy *ParserParseFile(AgentType agent_type, const char *path, unsigned int warnings, unsigned int warnings_error)
{
    ParserStateReset(&P, false);

    P.agent_type = agent_type;
    P.policy = PolicyNew();

    P.warnings = warnings;
    P.warnings_error = warnings_error;

    strncpy(P.filename, path, CF_MAXVARSIZE);

    yyin = safe_fopen(path, "rt");
    if (yyin == NULL)
    {
        Log(LOG_LEVEL_ERR, "While opening file '%s' for parsing. (fopen: %s)", path, GetErrorStr());
        exit(EXIT_FAILURE);
    }

    while (!feof(yyin))
    {
        yyparse();

        if (ferror(yyin))
        {
            perror("cfengine");
            exit(EXIT_FAILURE);
        }
    }

    fclose(yyin);

    if (P.error_count > 0)
    {
        PolicyDestroy(P.policy);
        ParserStateReset(&P, true);
        ParserStateClean(&P);
        return NULL;
    }

    Policy *policy = P.policy;
    ParserStateReset(&P, false);
    ParserStateClean(&P);
    return policy;
}
开发者ID:awsiv,项目名称:core,代码行数:45,代码来源:parser.c


示例6: mutt_bcache_get

FILE* mutt_bcache_get(body_cache_t *bcache, const char *id)
{
  char path[_POSIX_PATH_MAX];
  FILE* fp = NULL;

  if (!id || !*id || !bcache)
    return NULL;

  path[0] = '\0';
  safe_strncat (path, sizeof (path), bcache->path, bcache->pathlen);
  safe_strncat (path, sizeof (path), id, mutt_strlen (id));

  fp = safe_fopen (path, "r");

  dprint (3, (debugfile, "bcache: get: '%s': %s\n", path, fp == NULL ? "no" : "yes"));

  return fp;
}
开发者ID:SteveClement,项目名称:mutt,代码行数:18,代码来源:bcache.c


示例7: main

int main(){
	char *file_name = safe_malloc(sizeof(char) * MAX_FILENAME);
	char *chunk = safe_malloc(sizeof(char)*READSIZE);
	//read file name from the master process and call map function
	//on that file, return the result to the master process
	while(safe_read(STDIN_FILENO, file_name, MAX_FILENAME) > 0){
		FILE *file = safe_fopen(file_name, "r");	
		while(fread(chunk, READSIZE-1, 1, file) > 0){
			//make sure the chunk is null-terminated
			chunk[READSIZE-1] = '\0';
			map(chunk, STDOUT_FILENO);
		}
		safe_fclose(file);
	}
	free(file_name);
	free(chunk);
	return 0;
}
开发者ID:CEYeYuan,项目名称:CSC209-Software-tools-and-system-programming,代码行数:18,代码来源:mapworker.c


示例8: EvalFileWrite

void EvalFileWrite(const void *mode, qCtx *ctx, qStr *out, qArgAry *args)
{
	CStr path = ctx->ParseStr((*args)[0]);
	FILE *fp;
	int err = 0;

#ifndef WIN32
	CStr perm_str = ctx->ParseStr((*args)[2]);
	int perms = strtol(perm_str.SafeP(),(char **)NULL, 0);
	mode_t prev_perms;
	if (perms) {
		prev_perms = umask((mode_t)~perms);
		printf("umask: %d (%d)\n", perms, prev_perms);
	}
	try {	
#endif

	if (path.IsEmpty())
		return;

	fp = safe_fopen(ctx, path, (const char *) mode);

	if (!fp) err = GetLastError();

#ifndef WIN32
	} catch (qCtxEx ex) {
	        if (perms) umask(prev_perms);
		throw ex;
	}
        if (perms) umask(prev_perms);
#endif

	if (!fp) {
		ctx->ThrowF(out, 601, "Failed to open file for writing. %y", err);
		return;
	}

	qStrFileO fo(fp, true);

	qCtxTmp sub(ctx);
	sub.MapObj(fp, EvalFileFlush,"flush");
	sub.Parse(args->GetAt(1), &fo);
}
开发者ID:BackupTheBerlios,项目名称:smx-svn,代码行数:43,代码来源:file.cpp


示例9: PrintFile

static bool PrintFile(const char *filename, size_t max_lines)
{
    if (!filename)
    {
        Log(LOG_LEVEL_VERBOSE, "Printfile promise was incomplete, with no filename.");
        return false;
    }

    FILE *fp = safe_fopen(filename, "r");
    if (!fp)
    {
        Log(LOG_LEVEL_ERR, "Printing of file '%s' was not possible. (fopen: %s)", filename, GetErrorStr());
        return false;
    }

    size_t line_size = CF_BUFSIZE;
    char *line = xmalloc(line_size);

    for (size_t i = 0; i < max_lines; i++)
    {
        if (CfReadLine(&line, &line_size, fp) == -1)
        {
            if (ferror(fp))
            {
                Log(LOG_LEVEL_ERR, "Failed to read line from stream, (getline: %s)", GetErrorStr());
                free(line);
                return false;
            }
            else
            {
                break;
            }
        }

        ReportToLog(line);
    }

    fclose(fp);
    free(line);

    return true;
}
开发者ID:dstam,项目名称:core,代码行数:42,代码来源:verify_reports.c


示例10: _mutt_rename_file

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

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


示例11: PrintFile

static void PrintFile(EvalContext *ctx, Attributes a, Promise *pp)
{
    FILE *fp;
    char buffer[CF_BUFSIZE];
    int lines = 0;

    if (a.report.filename == NULL)
    {
        Log(LOG_LEVEL_VERBOSE, "Printfile promise was incomplete, with no filename.");
        return;
    }

    if ((fp = safe_fopen(a.report.filename, "r")) == NULL)
    {
        cfPS(ctx, LOG_LEVEL_ERR, PROMISE_RESULT_INTERRUPTED, pp, a, "Printing of file '%s' was not possible. (fopen: %s)", a.report.filename, GetErrorStr());
        return;
    }

    while ((lines < a.report.numlines))
    {
        if (fgets(buffer, sizeof(buffer), fp) == NULL)
        {
            if (ferror(fp))
            {
                UnexpectedError("Failed to read line from stream");
                break;
            }
            else /* feof */
            {
                break;
            }
        }
        Log(LOG_LEVEL_ERR, "R: %s", buffer);
        lines++;
    }

    fclose(fp);
}
开发者ID:dardevelin,项目名称:core-1,代码行数:38,代码来源:verify_reports.c


示例12: 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


示例13: initialise_3d_displacement_maps

void initialise_3d_displacement_maps ( char *filename )
{

	FILE
		*fp;

	int
		count;

	fp = safe_fopen ( filename, "rb" );

	fread ( &number_of_displacement_maps, sizeof ( int ), 1, fp );

	if ( number_of_displacement_maps )
	{

		displacement_maps = safe_malloc ( sizeof ( displacement_map ) * number_of_displacement_maps );
	
		for ( count = 0; count < number_of_displacement_maps; count++ )
		{

			int
				width,
				height;
	
			fread ( &width, sizeof ( int ), 1, fp );
			fread ( &height, sizeof ( int ), 1, fp );

			displacement_maps[count].width = width;
			displacement_maps[count].height = height;

			displacement_maps[count].data = safe_malloc ( width * height );

			fread ( displacement_maps[count].data, width, height, fp );
		}
	}
}
开发者ID:DexterWard,项目名称:comanche,代码行数:37,代码来源:3ddisp.c


示例14: printf

void PDB::read(const char* filename){
	printf("Reading %s.\n", filename);
	this->is_xyz = (!strcmp(filename + strlen(filename)-4, ".xyz"));
	if (this->is_xyz) {
		this->readXYZ(filename);
		return;
	}

	char buffer[BUF_SIZE];
	FILE* file = safe_fopen(filename, "r");

	while(fgets(buffer, BUF_SIZE, file) != NULL){
		if(strncmp(buffer,"SSBOND",6) == 0){
            this->ssbonds.push_back(PDBSSBond(buffer));
		}
		if(strncmp(buffer, "ATOM", 4) == 0){
            this->atoms.push_back(PDBAtom(buffer));
		}
	}

	printf("Found %zu atoms and %zu SS-bonds.\n", this->atoms.size(), this->ssbonds.size());
	printf("Done reading '%s'.\n", filename);
	fclose(file);
}
开发者ID:BarsegovGroup,项目名称:SOP-GPU,代码行数:24,代码来源:pdbio.cpp


示例15: mutt_decode_save_attachment

/* returns 0 on success, -1 on error */
int mutt_decode_save_attachment (FILE *fp, BODY *m, char *path,
				 int displaying, int flags)
{
  STATE s;
  unsigned int saved_encoding = 0;
  BODY *saved_parts = NULL;
  HEADER *saved_hdr = NULL;

  memset (&s, 0, sizeof (s));
  s.flags = displaying;

  if (flags == M_SAVE_APPEND)
    s.fpout = fopen (path, "a");
  else if (flags == M_SAVE_OVERWRITE)
    s.fpout = fopen (path, "w");	/* __FOPEN_CHECKED__ */
  else
    s.fpout = safe_fopen (path, "w");

  if (s.fpout == NULL)
  {
    mutt_perror ("fopen");
    return (-1);
  }

  if (fp == NULL)
  {
    /* When called from the compose menu, the attachment isn't parsed,
     * so we need to do it here. */
    struct stat st;

    if (stat (m->filename, &st) == -1)
    {
      mutt_perror ("stat");
      safe_fclose (&s.fpout);
      return (-1);
    }

    if ((s.fpin = fopen (m->filename, "r")) == NULL)
    {
      mutt_perror ("fopen");
      return (-1);
    }

    saved_encoding = m->encoding;
    if (!is_multipart (m))
      m->encoding = ENC8BIT;
    
    m->length = st.st_size;
    m->offset = 0;
    saved_parts = m->parts;
    saved_hdr = m->hdr;
    mutt_parse_part (s.fpin, m);

    if (m->noconv || is_multipart (m))
      s.flags |= M_CHARCONV;
  }
  else
  {
    s.fpin = fp;
    s.flags |= M_CHARCONV;
  }

  mutt_body_handler (m, &s);

  safe_fclose (&s.fpout);
  if (fp == NULL)
  {
    m->length = 0;
    m->encoding = saved_encoding;
    if (saved_parts)
    {
      mutt_free_header (&m->hdr);
      m->parts = saved_parts;
      m->hdr = saved_hdr;
    }
    safe_fclose (&s.fpin);
  }

  return (0);
}
开发者ID:BackupTheBerlios,项目名称:mutt-win32,代码行数:81,代码来源:attach.c


示例16: mutt_prepare_template


//.........这里部分代码省略.........

    /* what follows is roughly a receive-mode variant of
     * mutt_get_tmp_attachment () from muttlib.c
     */

    file[0] = '\0';
    if (b->filename)
    {
      strfcpy (file, b->filename, sizeof (file));
      b->d_filename = safe_strdup (b->filename);
    }
    else
    {
      /* avoid Content-Disposition: header with temporary filename */
      b->use_disp = 0;
    }

    /* set up state flags */

    s.flags = 0;

    if (b->type == TYPETEXT)
    {
      if (!ascii_strcasecmp ("yes", mutt_get_parameter ("x-mutt-noconv", b->parameter)))
	b->noconv = 1;
      else
      {
	s.flags |= M_CHARCONV;
	b->noconv = 0;
      }

      mutt_delete_parameter ("x-mutt-noconv", &b->parameter);
    }

    mutt_adv_mktemp (file, sizeof(file));
    if ((s.fpout = safe_fopen (file, "w")) == NULL)
      goto bail;


    if ((WithCrypto & APPLICATION_PGP)
	&& (mutt_is_application_pgp (b) & (ENCRYPT|SIGN)))
    {

      mutt_body_handler (b, &s);

      newhdr->security |= mutt_is_application_pgp (newhdr->content);

      b->type = TYPETEXT;
      mutt_str_replace (&b->subtype, "plain");
      mutt_delete_parameter ("x-action", &b->parameter);
    }
    else
      mutt_decode_attachment (b, &s);

    if (safe_fclose (&s.fpout) != 0)
      goto bail;

    mutt_str_replace (&b->filename, file);
    b->unlink = 1;

    mutt_stamp_attachment (b);

    mutt_free_body (&b->parts);
    if (b->hdr) b->hdr->content = NULL; /* avoid dangling pointer */
  }

  /* Fix encryption flags. */

  /* No inline if multipart. */
  if (WithCrypto && (newhdr->security & INLINE) && newhdr->content->next)
    newhdr->security &= ~INLINE;

  /* Do we even support multiple mechanisms? */
  newhdr->security &= WithCrypto | ~(APPLICATION_PGP|APPLICATION_SMIME);

  /* Theoretically, both could be set. Take the one the user wants to set by default. */
  if ((newhdr->security & APPLICATION_PGP) && (newhdr->security & APPLICATION_SMIME))
  {
    if (option (OPTSMIMEISDEFAULT))
      newhdr->security &= ~APPLICATION_PGP;
    else
      newhdr->security &= ~APPLICATION_SMIME;
  }

  rv = 0;

  bail:

  /* that's it. */
  if (bfp != fp) safe_fclose (&bfp);
  if (msg) mx_close_message (&msg);

  if (rv == -1)
  {
    mutt_free_envelope (&newhdr->env);
    mutt_free_body (&newhdr->content);
  }

  return rv;
}
开发者ID:sunny256,项目名称:mutt,代码行数:101,代码来源:postpone.c


示例17: main

int main(int argc, char** argv) {
    int32_t opt,nqrys,qrylen,i;
    char* idxname;char* textname;
    uint8_t* T;
    uint32_t n;
    FILE* f;
    FM* FMIdx;
	uint8_t** queries;
	char buf[4096];
	uint32_t start,stop,cnt;
    
    /* parse command line parameter */
    if (argc <= 3) {
        print_usage(argv[0]);
        exit(EXIT_FAILURE);
    }
    
	opt = -1;
    idxname = textname = NULL;
    while ((opt = getopt(argc, argv, "vhi:l:t:n:")) != -1) {
        switch (opt) {
            case 'l':
                qrylen = atoi(optarg);
                break;
            case 'n':
                nqrys = atoi(optarg);
                break;
            case 't':
                textname = optarg;
                break;
			case 'i':
				idxname = optarg;
				break;
			case 'v':
				FM::verbose = 1;
				break;
            case 'h':
            default:
                print_usage(argv[0]);
                exit(EXIT_FAILURE);
        }
    }
	
		
	/* load index */
	FMIdx = FM::load(idxname);
	if(!FMIdx) {
		perror("error loading index from file");
		exit(EXIT_FAILURE);
	}
	
	/* generate queries */
    f = safe_fopen(textname,"r");
    n = safe_filesize(f);
    T = (uint8_t*) safe_malloc(n*sizeof(uint8_t));
    if( fread(T,1,n,f) != n ) {
        perror("error reading text");
        exit(EXIT_FAILURE);
    }
	fclose(f);

	FM::info("generating queries");
	srand( gettime() );
	queries = (uint8_t**) safe_malloc(nqrys * sizeof(uint8_t*));
	for(i=0;i<nqrys;i++) {
	    start = (rand()*rand()) % (n-qrylen-1);
        memcpy(buf,(uint8_t*)(T+start),qrylen);
        queries[i] = (uint8_t*) safe_strdup(buf);
    }
	
	start = gettime();
	for(i=0;i<nqrys;i++) {
		cnt = FMIdx->count(queries[i],strlen((char*)queries[i]));
	}
	stop = gettime();
	FM::info("finished processing %d queries: %f sec",nqrys,((float)(stop-start))/1000000);
	
	/* clean up */
	for(i=0;i<nqrys;i++) free(queries[i]);
	free(queries);
	free(T);
	delete FMIdx;
    
    return (EXIT_SUCCESS);
}
开发者ID:VisBlank,项目名称:FM-Index,代码行数:85,代码来源:bench_fmcount.cpp


示例18: CompareResult

static int CompareResult(const char *filename, const char *prev_file)
{
    Log(LOG_LEVEL_VERBOSE, "Comparing files  %s with %s", prev_file, filename);

    int rtn = 0;

    FILE *old_fp = safe_fopen(prev_file, "r");
    FILE *new_fp = safe_fopen(filename, "r");
    if (old_fp && new_fp)
    {
        const char *errptr;
        int erroffset;
        pcre_extra *regex_extra = NULL;
        // Match timestamps and remove them. Not Y21K safe! :-)
        pcre *regex = pcre_compile(LOGGING_TIMESTAMP_REGEX, PCRE_MULTILINE, &errptr, &erroffset, NULL);
        if (!regex)
        {
            UnexpectedError("Compiling regular expression failed");
            rtn = 1;
        }
        else
        {
            regex_extra = pcre_study(regex, 0, &errptr);
        }

        while (regex)
        {
            char old_line[CF_BUFSIZE];
            char new_line[CF_BUFSIZE];
            char *old_msg = old_line;
            char *new_msg = new_line;
            if (CfReadLine(old_line, sizeof(old_line), old_fp) <= 0)
            {
                old_msg = NULL;
            }
            if (CfReadLine(new_line, sizeof(new_line), new_fp) <= 0)
            {
                new_msg = NULL;
            }
            if (!old_msg || !new_msg)
            {
                if (old_msg != new_msg)
                {
                    rtn = 1;
                }
                break;
            }

            char *index;
            if (pcre_exec(regex, regex_extra, old_msg, strlen(old_msg), 0, 0, NULL, 0) >= 0)
            {
                index = strstr(old_msg, ": ");
                if (index != NULL)
                {
                    old_msg = index + 2;
                }
            }
            if (pcre_exec(regex, regex_extra, new_msg, strlen(new_msg), 0, 0, NULL, 0) >= 0)
            {
                index = strstr(new_msg, ": ");
                if (index != NULL)
                {
                    new_msg = index + 2;
                }
            }

            if (strcmp(old_msg, new_msg) != 0)
            {
                rtn = 1;
                break;
            }
        }

        if (regex_extra)
        {
            free(regex_extra);
        }
        free(regex);
    }
    else
    {
        /* no previous file */
        rtn = 1;
    }

    if (old_fp)
    {
        fclose(old_fp);
    }
    if (new_fp)
    {
        fclose(new_fp);
    }

    if (!ThreadLock(cft_count))
    {
        Log(LOG_LEVEL_ERR, "Severe lock error when mailing in exec");
        return 1;
    }

//.........这里部分代码省略.........
开发者ID:gc3-uzh-ch,项目名称:cfengine,代码行数:101,代码来源:cf-execd-runner.c


示例19: imap_read_headers

/* imap_read_headers:
 * Changed to read many headers instead of just one. It will return the
 * msgno of the last message read. It will return a value other than
 * msgend if mail comes in while downloading headers (in theory).
 */
int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
{
  CONTEXT* ctx;
  char *hdrreq = NULL;
  FILE *fp;
  char tempfile[_POSIX_PATH_MAX];
  int msgno, idx = msgbegin - 1;
  IMAP_HEADER h;
  IMAP_STATUS* status;
  int rc, mfhrc, oldmsgcount;
  int fetchlast = 0;
  int maxuid = 0;
  static const char * const want_headers = "DATE FROM SUBJECT TO CC MESSAGE-ID REFERENCES CONTENT-TYPE CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES LIST-POST X-LABEL";
  progress_t progress;
  int retval = -1;

#if USE_HCACHE
  char buf[LONG_STRING];
  unsigned int *uid_validity = NULL;
  unsigned int *puidnext = NULL;
  unsigned int uidnext = 0;
  int evalhc = 0;
#endif /* USE_HCACHE */

  ctx = idata->ctx;

  if (mutt_bit_isset (idata->capabilities,IMAP4REV1))
  {
    safe_asprintf (&hdrreq, "BODY.PEEK[HEADER.FIELDS (%s%s%s)]",
                           want_headers, ImapHeaders ? " " : "", NONULL (ImapHeaders));
  }
  else if (mutt_bit_isset (idata->capabilities,IMAP4))
  {
    safe_asprintf (&hdrreq, "RFC822.HEADER.LINES (%s%s%s)",
                           want_headers, ImapHeaders ? " " : "", NONULL (ImapHeaders));
  }
  else
  {	/* Unable to fetch headers for lower versions */
    mutt_error _("Unable to fetch headers from this IMAP server version.");
    mutt_sleep (2);	/* pause a moment to let the user see the error */
    goto error_out_0;
  }

  /* instead of downloading all headers and then parsing them, we parse them
   * as they come in. */
  mutt_mktemp (tempfile, sizeof (tempfile));
  if (!(fp = safe_fopen (tempfile, "w+")))
  {
    mutt_error (_("Could not create temporary file %s"), tempfile);
    mutt_sleep (2);
    goto error_out_0;
  }
  unlink (tempfile);

  /* make sure context has room to hold the mailbox */
  while ((msgend) >= idata->ctx->hdrmax)
    mx_alloc_memory (idata->ctx);

  oldmsgcount = ctx->msgcount;
  idata->reopen &= ~(IMAP_REOPEN_ALLOW|IMAP_NEWMAIL_PENDING);
  idata->newMailCount = 0;

#if USE_HCACHE
  idata->hcache = imap_hcache_open (idata, NULL);

  if (idata->hcache && !msgbegin)
  {
    uid_validity = mutt_hcache_fetch_raw (idata->hcache, "/UIDVALIDITY", imap_hcache_keylen);
    puidnext = mutt_hcache_fetch_raw (idata->hcache, "/UIDNEXT", imap_hcache_keylen);
    if (puidnext)
    {
      uidnext = *puidnext;
      FREE (&puidnext);
    }
    if (uid_validity && uidnext && *uid_validity == idata->uid_validity)
      evalhc = 1;
    FREE (&uid_validity);
  }
  if (evalhc)
  {
    /* L10N:
       Comparing the cached data with the IMAP server's data */
    mutt_progress_init (&progress, _("Evaluating cache..."),
			MUTT_PROGRESS_MSG, ReadInc, msgend + 1);

    snprintf (buf, sizeof (buf),
      "UID FETCH 1:%u (UID FLAGS)", uidnext - 1);

    imap_cmd_start (idata, buf);

    rc = IMAP_CMD_CONTINUE;
    for (msgno = msgbegin; rc == IMAP_CMD_CONTINUE; msgno++)
    {
      mutt_progress_update (&progress, msgno + 1, -1);

//.........这里部分代码省略.........
开发者ID:aschrab,项目名称:mutt,代码行数:101,代码来源:message.c


示例20: imap_fetch_message

int imap_fetch_message (CONTEXT *ctx, MESSAGE *msg, int msgno)
{
  IMAP_DATA* idata;
  HEADER* h;
  ENVELOPE* newenv;
  char buf[LONG_STRING];
  char path[_POSIX_PATH_MAX];
  char *pc;
  long bytes;
  progress_t progressbar;
  int uid;
  int cacheno;
  IMAP_CACHE *cache;
  int read;
  int rc;
  /* Sam's weird courier server returns an OK response even when FETCH
   * fails. Thanks Sam. */
  short fetched = 0;

  idata = (IMAP_DATA*) ctx->data;
  h = ctx->hdrs[msgno];

  if ((msg->fp = msg_cache_get (idata, h)))
  {
    if (HEADER_DATA(h)->parsed)
      return 0;
    else
      goto parsemsg;
  }

  /* we still do some caching even if imap_cachedir is unset */
  /* see if we already have the message in our cache */
  cacheno = HEADER_DATA(h)->uid % IMAP_CACHE_LEN;
  cache = &idata->cache[cacheno];

  if (cache->path)
  {
    /* don't treat cache errors as fatal, just fall back. */
    if (cache->uid == HEADER_DATA(h)->uid &&
        (msg->fp = fopen (cache->path, "r")))
      return 0;
    else
    {
      unlink (cache->path);
      FREE (&cache->path);
    }
  }

  if (!isendwin())
    mutt_message _("Fetching message...");

  if (!(msg->fp = msg_cache_put (idata, h)))
  {
    cache->uid = HEADER_DATA(h)->uid;
    mutt_mktemp (path, sizeof (path));
    cache->path = safe_strdup (path);
    if (!(msg->fp = safe_fopen (path, "w+")))
    {
      FREE (&cache->path);
      return -1;
    }
  }

  /* mark this header as currently inactive so the command handler won't
   * also try to update it. HACK until all this code can be moved into the
   * command handler */
  h->active = 0;

  snprintf (buf, sizeof (buf), "UID FETCH %u %s", HEADER_DATA(h)->uid,
	    (mutt_bit_isset (idata->capabilities, IMAP4REV1) ?
	     (option (OPTIMAPPEEK) ? "BODY.PEEK[]" : "BODY[]") :
	     "RFC822"));

  imap_cmd_start (idata, buf);
  do
  {
    if ((rc = imap_cmd_step (idata)) != IMAP_CMD_CONTINUE)
      break;

    pc = idata->buf;
    pc = imap_next_word (pc);
    pc = imap_next_word (pc);

    if (!ascii_strncasecmp ("FETCH", pc, 5))
    {
      while (*pc)
      {
	pc = imap_next_word (pc);
	if (pc[0] == '(')
	  pc++;
	if (ascii_strncasecmp ("UID", pc, 3) == 0)
	{
	  pc = imap_next_word (pc);
	  uid = atoi (pc);
	  if (uid != HEADER_DATA(h)->uid)
	    mutt_error (_("The message index is incorrect. Try reopening the mailbox."));
	}
	else if ((ascii_strncasecmp ("RFC822", pc, 6) == 0) ||
		 (ascii_strncasecmp ("BODY[]", pc, 6) == 0))
	{
//.........这里部分代码省略.........
开发者ID:aschrab,项目名称:mutt,代码行数:101,代码来源:message.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ safe_free函数代码示例发布时间:2022-05-30
下一篇:
C++ safe_fclose函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap