コード例 #1
0
/*
 *	Remove unneeded leaves from the old tree.
 *	Remove directories from the lookup chains.
 */
void
removeoldleaves(void)
{
	struct entry *ep;
	ino_t i;

	Vprintf(stdout, "Mark entries to be removed.\n");
	for (i = ROOTINO + 1; i < maxino; i++) {
		ep = lookupino(i);
		if (ep == NULL)
			continue;
		if (TSTINO(i, usedinomap))
			continue;
		for ( ; ep != NULL; ep = ep->e_links) {
			Dprintf(stdout, "%s: REMOVE\n", myname(ep));
			if (ep->e_type == LEAF) {
				removeleaf(ep);
				freeentry(ep);
			} else {
				mktempname(ep);
				deleteino(ep->e_ino);
				ep->e_next = removelist;
				removelist = ep;
			}
		}
	}
}
コード例 #2
0
ファイル: record.c プロジェクト: MaChao5/pdfviewer-win32
void gfxdevice_record_init(gfxdevice_t*dev, char use_tempfile)
{
    internal_t*i = (internal_t*)rfx_calloc(sizeof(internal_t));
    memset(dev, 0, sizeof(gfxdevice_t));
    
    dev->name = "record";

    dev->internal = i;
  
    i->use_tempfile = use_tempfile;
    if(!use_tempfile) {
	writer_init_growingmemwriter(&i->w, 1048576);
    } else {
	char buffer[128];
	i->filename = strdup(mktempname(buffer, "gfx"));
	writer_init_filewriter2(&i->w, i->filename);
    }
    i->fontlist = gfxfontlist_create();
    i->cliplevel = 0;

    dev->setparameter = record_setparameter;
    dev->startpage = record_startpage;
    dev->startclip = record_startclip;
    dev->endclip = record_endclip;
    dev->stroke = record_stroke;
    dev->fill = record_fill;
    dev->fillbitmap = record_fillbitmap;
    dev->fillgradient = record_fillgradient;
    dev->addfont = record_addfont;
    dev->drawchar = record_drawchar;
    dev->drawlink = record_drawlink;
    dev->endpage = record_endpage;
    dev->finish = record_finish;
}
コード例 #3
0
ファイル: pdf.c プロジェクト: MaChao5/pdfviewer-win32
void pdf_startpage(gfxdevice_t*dev, int width, int height)
{
    internal_t*i = (internal_t*)dev->internal;

    if(!i->tempfile) {
	i->tempfile = strdup(mktempname(0, "pdf"));

	PDF_begin_document(i->p, i->tempfile, 0, "");
	//PDF_set_value(i->p, "compress", 0);
	PDF_set_parameter(i->p, "usercoordinates", "true");
	PDF_set_parameter(i->p, "topdown", "true");
    }

    int width_plus_pad = width+floor(i->config_xpad*2);
    int height_plus_pad = height+floor(i->config_ypad*2);
    PDF_begin_page_ext(i->p, width_plus_pad, height_plus_pad, i->page_opts);
    PDF_set_value(i->p, "CropBox/llx", 0);
    PDF_set_value(i->p, "CropBox/lly", 0);
    PDF_set_value(i->p, "CropBox/urx", width_plus_pad);
    PDF_set_value(i->p, "CropBox/ury", height_plus_pad);
    if(i->config_xpad || i->config_ypad) {
	PDF_set_value(i->p, "TrimBox/llx", i->config_xpad);
	PDF_set_value(i->p, "TrimBox/lly", i->config_ypad);
	PDF_set_value(i->p, "TrimBox/urx", i->config_xpad+width);
	PDF_set_value(i->p, "TrimBox/ury", i->config_ypad+height);
    }

    PDF_set_parameter(i->p, "fillrule", "evenodd");
    i->width = width;
    i->height = height;
    i->num_pages++;

    reset_matrix(i);
}
コード例 #4
0
ファイル: ptunit-section.c プロジェクト: BwRy/processor-trace
static struct ptunit_result sfix_init(struct section_fixture *sfix)
{
	sfix->section = NULL;
	sfix->file = NULL;
	sfix->name = NULL;

	sfix->name = mktempname();
	ptu_ptr(sfix->name);

	sfix->file = fopen(sfix->name, "wb");
	ptu_ptr(sfix->file);

	ptu_test(ptunit_thrd_init, &sfix->thrd);

	return ptu_passed();
}
コード例 #5
0
ファイル: getspool.c プロジェクト: pgul/lgate
static int rcbmail(void)
{
  int r, hunc, saveout;
  static char tmprbname[SSIZE];

  strcpy(tmpmask, tmpdir);
  strcat(tmpmask, TMPUNZNAME);
  mktempname(tmpmask, tmprbname);
  sprintf(cmdline, uncompress, "");
  hunc=open(tmprbname, O_BINARY|O_RDWR|O_CREAT|O_EXCL, S_IREAD|S_IWRITE);
  if (hunc==-1)
  { logwrite('?',"Can't create %s: %s!\n", tmprbname, strerror(errno));
    return 1;
  }
  saveout=dup(fileno(stdout));
  dup2(hunc, fileno(stdout));
  close(hunc);
  debug(4,"rcbmail: run '%s'", cmdline);
  if (!quiet)
  { fputs("Uncompressing batchmail-packet...", stderr);
    fflush(stderr);
  }
  r=swap_system(cmdline);
  if (!quiet)
    fputs("\n", stderr);
  if (r)
  { dup2(saveout,fileno(stdout));
    close(saveout);
    unlink(tmprbname);
    logwrite('!', "Uncompress retcode %d\n", r);
    return 1;
  }
  r=dup(fileno(stdin));
  rewind(stdout);
  dup2(fileno(stdout), fileno(stdin));
  dup2(saveout, fileno(stdout));
  close(saveout);
  saveout=r;
  if (!quiet)
    fputs("\n", stderr);
  r=rbmail();
  debug(4, "rbmail retcode %d", r);
  dup2(saveout, fileno(stdin));
  close(saveout);
  unlink(tmprbname);
  return r;
}
コード例 #6
0
ファイル: restore.c プロジェクト: MattDooner/freebsd-west
/*
 *	Remove invalid whiteouts from the old tree.
 *	Remove unneeded leaves from the old tree.
 *	Remove directories from the lookup chains.
 */
void
removeoldleaves(void)
{
	struct entry *ep, *nextep;
	ino_t i, mydirino;

	vprintf(stdout, "Mark entries to be removed.\n");
	if ((ep = lookupino(WINO))) {
		vprintf(stdout, "Delete whiteouts\n");
		for ( ; ep != NULL; ep = nextep) {
			nextep = ep->e_links;
			mydirino = ep->e_parent->e_ino;
			/*
			 * We remove all whiteouts that are in directories
			 * that have been removed or that have been dumped.
			 */
			if (TSTINO(mydirino, usedinomap) &&
			    !TSTINO(mydirino, dumpmap))
				continue;
			delwhiteout(ep);
			freeentry(ep);
		}
	}
	for (i = ROOTINO + 1; i < maxino; i++) {
		ep = lookupino(i);
		if (ep == NULL)
			continue;
		if (TSTINO(i, usedinomap))
			continue;
		for ( ; ep != NULL; ep = ep->e_links) {
			dprintf(stdout, "%s: REMOVE\n", myname(ep));
			if (ep->e_type == LEAF) {
				removeleaf(ep);
				freeentry(ep);
			} else {
				mktempname(ep);
				deleteino(ep->e_ino);
				ep->e_next = removelist;
				removelist = ep;
			}
		}
	}
}
コード例 #7
0
ファイル: restore.c プロジェクト: MattDooner/freebsd-west
/*
 *	For each directory entry on the incremental tape, determine which
 *	category it falls into as follows:
 *	KEEP - entries that are to be left alone.
 *	NEW - new entries to be added.
 *	EXTRACT - files that must be updated with new contents.
 *	LINK - new links to be added.
 *	Renames are done at the same time.
 */
long
nodeupdates(char *name, ino_t ino, int type)
{
	struct entry *ep, *np, *ip;
	long descend = GOOD;
	int lookuptype = 0;
	int key = 0;
		/* key values */
#		define ONTAPE	0x1	/* inode is on the tape */
#		define INOFND	0x2	/* inode already exists */
#		define NAMEFND	0x4	/* name already exists */
#		define MODECHG	0x8	/* mode of inode changed */

	/*
	 * This routine is called once for each element in the
	 * directory hierarchy, with a full path name.
	 * The "type" value is incorrectly specified as LEAF for
	 * directories that are not on the dump tape.
	 *
	 * Check to see if the file is on the tape.
	 */
	if (TSTINO(ino, dumpmap))
		key |= ONTAPE;
	/*
	 * Check to see if the name exists, and if the name is a link.
	 */
	np = lookupname(name);
	if (np != NULL) {
		key |= NAMEFND;
		ip = lookupino(np->e_ino);
		if (ip == NULL)
			panic("corrupted symbol table\n");
		if (ip != np)
			lookuptype = LINK;
	}
	/*
	 * Check to see if the inode exists, and if one of its links
	 * corresponds to the name (if one was found).
	 */
	ip = lookupino(ino);
	if (ip != NULL) {
		key |= INOFND;
		for (ep = ip->e_links; ep != NULL; ep = ep->e_links) {
			if (ep == np) {
				ip = ep;
				break;
			}
		}
	}
	/*
	 * If both a name and an inode are found, but they do not
	 * correspond to the same file, then both the inode that has
	 * been found and the inode corresponding to the name that
	 * has been found need to be renamed. The current pathname
	 * is the new name for the inode that has been found. Since
	 * all files to be deleted have already been removed, the
	 * named file is either a now unneeded link, or it must live
	 * under a new name in this dump level. If it is a link, it
	 * can be removed. If it is not a link, it is given a
	 * temporary name in anticipation that it will be renamed
	 * when it is later found by inode number.
	 */
	if (((key & (INOFND|NAMEFND)) == (INOFND|NAMEFND)) && ip != np) {
		if (lookuptype == LINK) {
			removeleaf(np);
			freeentry(np);
		} else {
			dprintf(stdout, "name/inode conflict, mktempname %s\n",
				myname(np));
			mktempname(np);
		}
		np = NULL;
		key &= ~NAMEFND;
	}
	if ((key & ONTAPE) &&
	  (((key & INOFND) && ip->e_type != type) ||
	   ((key & NAMEFND) && np->e_type != type)))
		key |= MODECHG;

	/*
	 * Decide on the disposition of the file based on its flags.
	 * Note that we have already handled the case in which
	 * a name and inode are found that correspond to different files.
	 * Thus if both NAMEFND and INOFND are set then ip == np.
	 */
	switch (key) {

	/*
	 * A previously existing file has been found.
	 * Mark it as KEEP so that other links to the inode can be
	 * detected, and so that it will not be reclaimed by the search
	 * for unreferenced names.
	 */
	case INOFND|NAMEFND:
		ip->e_flags |= KEEP;
		dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
			flagvalues(ip));
		break;

	/*
	 * A file on the tape has a name which is the same as a name
	 * corresponding to a different file in the previous dump.
	 * Since all files to be deleted have already been removed,
	 * this file is either a now unneeded link, or it must live
	 * under a new name in this dump level. If it is a link, it
	 * can simply be removed. If it is not a link, it is given a
	 * temporary name in anticipation that it will be renamed
	 * when it is later found by inode number (see INOFND case
	 * below). The entry is then treated as a new file.
	 */
	case ONTAPE|NAMEFND:
	case ONTAPE|NAMEFND|MODECHG:
		if (lookuptype == LINK) {
			removeleaf(np);
			freeentry(np);
		} else {
			mktempname(np);
		}
		/* FALLTHROUGH */

	/*
	 * A previously non-existent file.
	 * Add it to the file system, and request its extraction.
	 * If it is a directory, create it immediately.
	 * (Since the name is unused there can be no conflict)
	 */
	case ONTAPE:
		ep = addentry(name, ino, type);
		if (type == NODE)
			newnode(ep);
		ep->e_flags |= NEW|KEEP;
		dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
			flagvalues(ep));
		break;

	/*
	 * A file with the same inode number, but a different
	 * name has been found. If the other name has not already
	 * been found (indicated by the KEEP flag, see above) then
	 * this must be a new name for the file, and it is renamed.
	 * If the other name has been found then this must be a
	 * link to the file. Hard links to directories are not
	 * permitted, and are either deleted or converted to
	 * symbolic links. Finally, if the file is on the tape,
	 * a request is made to extract it.
	 */
	case ONTAPE|INOFND:
		if (type == LEAF && (ip->e_flags & KEEP) == 0)
			ip->e_flags |= EXTRACT;
		/* FALLTHROUGH */
	case INOFND:
		if ((ip->e_flags & KEEP) == 0) {
			renameit(myname(ip), name);
			moveentry(ip, name);
			ip->e_flags |= KEEP;
			dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
				flagvalues(ip));
			break;
		}
		if (ip->e_type == NODE) {
			descend = FAIL;
			fprintf(stderr,
				"deleted hard link %s to directory %s\n",
				name, myname(ip));
			break;
		}
		ep = addentry(name, ino, type|LINK);
		ep->e_flags |= NEW;
		dprintf(stdout, "[%s] %s: %s|LINK\n", keyval(key), name,
			flagvalues(ep));
		break;

	/*
	 * A previously known file which is to be updated. If it is a link,
	 * then all names referring to the previous file must be removed
	 * so that the subset of them that remain can be recreated.
	 */
	case ONTAPE|INOFND|NAMEFND:
		if (lookuptype == LINK) {
			removeleaf(np);
			freeentry(np);
			ep = addentry(name, ino, type|LINK);
			if (type == NODE)
			        newnode(ep);
			ep->e_flags |= NEW|KEEP;
			dprintf(stdout, "[%s] %s: %s|LINK\n", keyval(key), name,
				flagvalues(ep));
			break;
		}
		if (type == LEAF && lookuptype != LINK)
			np->e_flags |= EXTRACT;
		np->e_flags |= KEEP;
		dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
			flagvalues(np));
		break;

	/*
	 * An inode is being reused in a completely different way.
	 * Normally an extract can simply do an "unlink" followed
	 * by a "creat". Here we must do effectively the same
	 * thing. The complications arise because we cannot really
	 * delete a directory since it may still contain files
	 * that we need to rename, so we delete it from the symbol
	 * table, and put it on the list to be deleted eventually.
	 * Conversely if a directory is to be created, it must be
	 * done immediately, rather than waiting until the
	 * extraction phase.
	 */
	case ONTAPE|INOFND|MODECHG:
	case ONTAPE|INOFND|NAMEFND|MODECHG:
		if (ip->e_flags & KEEP) {
			badentry(ip, "cannot KEEP and change modes");
			break;
		}
		if (ip->e_type == LEAF) {
			/* changing from leaf to node */
			for (ip = lookupino(ino); ip != NULL; ip = ip->e_links) {
				if (ip->e_type != LEAF)
					badentry(ip, "NODE and LEAF links to same inode");
				removeleaf(ip);
				freeentry(ip);
			}
			ip = addentry(name, ino, type);
			newnode(ip);
		} else {
			/* changing from node to leaf */
			if ((ip->e_flags & TMPNAME) == 0)
				mktempname(ip);
			deleteino(ip->e_ino);
			ip->e_next = removelist;
			removelist = ip;
			ip = addentry(name, ino, type);
		}
		ip->e_flags |= NEW|KEEP;
		dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
			flagvalues(ip));
		break;

	/*
	 * A hard link to a directory that has been removed.
	 * Ignore it.
	 */
	case NAMEFND:
		dprintf(stdout, "[%s] %s: Extraneous name\n", keyval(key),
			name);
		descend = FAIL;
		break;

	/*
	 * If we find a directory entry for a file that is not on
	 * the tape, then we must have found a file that was created
	 * while the dump was in progress. Since we have no contents
	 * for it, we discard the name knowing that it will be on the
	 * next incremental tape.
	 */
	case 0:
		fprintf(stderr, "%s: (inode %ju) not found on tape\n",
		    name, (uintmax_t)ino);
		break;

	/*
	 * If any of these arise, something is grievously wrong with
	 * the current state of the symbol table.
	 */
	case INOFND|NAMEFND|MODECHG:
	case NAMEFND|MODECHG:
	case INOFND|MODECHG:
		fprintf(stderr, "[%s] %s: inconsistent state\n", keyval(key),
			name);
		break;

	/*
	 * These states "cannot" arise for any state of the symbol table.
	 */
	case ONTAPE|MODECHG:
	case MODECHG:
	default:
		panic("[%s] %s: impossible state\n", keyval(key), name);
		break;
	}
	return (descend);
}
コード例 #8
0
ファイル: pdf.c プロジェクト: MaChao5/pdfviewer-win32
void pdf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform)
{
    internal_t*i = (internal_t*)dev->internal;

    int t,size=img->width*img->height;
    int has_alpha=0;
    for(t=0;t<size;t++) {
	if(img->data[t].a!=255) {
	    has_alpha=1;
	    break;
	}
    }

    double w = sqrt(matrix->m00*matrix->m00+matrix->m01*matrix->m01);
    double h = sqrt(matrix->m10*matrix->m10+matrix->m11*matrix->m11);
    double l1 = w*img->width;
    double l2 = h*img->height;

    double dpi_x = 72.0 / w;
    double dpi_y = 72.0 / h;
    double dpi = dpi_x>dpi_y?dpi_x:dpi_y;
    gfximage_t*rescaled_image = 0;
    if(i->config_maxdpi && dpi > i->config_maxdpi) {
	int newwidth = img->width*i->config_maxdpi/dpi;
	int newheight = img->height*i->config_maxdpi/dpi;
	rescaled_image = gfximage_rescale(img, newwidth, newheight);
	msg("<notice> Downscaling %dx%d image (dpi %f, %.0fx%.0f on page) to %dx%d (dpi %d)", 
		img->width, img->height, dpi, l1, l2, newwidth, newheight, i->config_maxdpi);
	img = rescaled_image;
    }
    if(i->config_mindpi && dpi < i->config_mindpi && img->width>1 && img->height>1) {
	msg("<error> Found image of size %dx%d with dpi %f, minimum allowed dpi is %d", 
		img->width, img->height, dpi, i->config_mindpi);
	exit(1);
    }

    char tempfile[128];
    mktempname(tempfile, "jpg");

    gfximage_save_jpeg(img, tempfile, 96);

    int imgid=-1;
    if(has_alpha) {
	char tempfile2[128];
	mktempname(tempfile2, "jpg");
	int t;
	int size = img->width*img->height;
	unsigned char*alpha = malloc(size);
	for(t=0;t<size;t++) {
	    alpha[t] = img->data[t].a;
	}
	jpeg_save_gray(alpha, img->width, img->height, 97, tempfile2);
	free(alpha);
	int maskid = PDF_load_image(i->p, "jpeg", tempfile2, 0, "mask");
	unlink(tempfile2);
	char masked[80];
	if(maskid<0) {
	    msg("<error> Couldn't process mask jpeg of size %dx%d: error code %d", img->width, img->height, maskid);
	    return;
	}
	sprintf(masked, "masked %d", maskid);
	imgid = PDF_load_image(i->p, "jpeg", tempfile, 0, masked);
    } else {
	imgid = PDF_load_image(i->p, "jpeg", tempfile, 0, "");
    }

    if(imgid<0) {
	msg("<error> Couldn't process jpeg of size %dx%d: error code %d, file %s", img->width, img->height, imgid, tempfile);
	return;
    }
    unlink(tempfile);
    
    char options[80];
    set_matrix(i, matrix->m00, matrix->m01, matrix->m10, matrix->m11);
    /* an image's (0,0) is at the lower left corner */
    double x=matrix->tx + i->config_xpad + matrix->m10*img->height;
    double y=matrix->ty + i->config_ypad + matrix->m11*img->height;
    double tx,ty;
    transform_back(i, x, y, &tx, &ty);
    PDF_place_image(i->p, imgid, tx, ty, 1.0);
    PDF_close_image(i->p, imgid);

    if(rescaled_image)
	gfximage_free(rescaled_image);
}
コード例 #9
0
ファイル: execute.c プロジェクト: swhobbit/UUPC
int execute( const char *command,
             const char *parameters,
             const char *input,
             const char *output,
             const KWBoolean synchronous,
             const KWBoolean foreground )
{
   int result;

   KWBoolean useBat = (input != NULL) || (output != NULL );

   char path[COMMAND_TEXT_MAX];     /* String for executable file   */
   char batchFile[FILENAME_MAX];    /* String for batch driver file */
   char perfect[FILENAME_MAX];      /* String for results test file */

/*--------------------------------------------------------------------*/
/*                    Validate command redirection                    */
/*--------------------------------------------------------------------*/

   if ( ((input != NULL) || (output != NULL)) && ! synchronous )
   {
      printmsg(0, "execute: Internal error, cannot redirect asynchronous"
                  " command %s",
                 command );
      panic();
   }

/*--------------------------------------------------------------------*/
/*                          Locate the command                        */
/*--------------------------------------------------------------------*/

   if ( internal( command ) )
   {
      strcpy( path , command );
      useBat = KWTrue;
   }
   else if (batch( command, path ))
   {
      if (useBat)                      /* Using redirection?          */
      {
         printmsg(0,"Cannot use redirection with batch file %s",
                     path );
         return -2;
      }
   } /* else */
   else if ( !*path )                  /* Error returned from search? */
      return -1;                       /* Yes --> Error already reported */

/*--------------------------------------------------------------------*/
/*     Generate a batch file for redirected DOS programs, if needed   */
/*--------------------------------------------------------------------*/

   if ( useBat )
   {
      FILE *stream ;

      mktempname( batchFile, "bat");
      mktempname( perfect, "tmp");
      stream = FOPEN( batchFile, "w", TEXT_MODE );

      if ( stream == NULL )
      {
         printmsg(0,"execute: Cannot generate batch file %s",
                     batchFile );
         printerr( batchFile );
         panic();
      }

      fprintf( stream ,
               "@echo off\n%s %s",
               path,
               parameters == NULL ? "" : parameters );

      if ( input != NULL )
         fprintf( stream, " < %s", input );

      if ( output != NULL )
         fprintf( stream, " > %s", output );

      fprintf( stream,
              "\nif errorlevel 1 erase %s\n",
               perfect );

      fclose ( stream );

      stream = FOPEN( perfect, "w", TEXT_MODE );
      if ( stream == NULL )
      {
         printmsg(0,"Cannot generate test batch file %s", perfect );
         printerr( perfect );
         panic();
      }

      fclose( stream );

      strcpy( path, batchFile );             /* Run the batch command */

   } /* if ( useBat ) */

/*--------------------------------------------------------------------*/
/*                       Actually run the command                     */
/*--------------------------------------------------------------------*/

   result = SpawnWait( path,
                       parameters,
                       synchronous,
                       foreground ? SW_MAXIMIZE : SW_SHOWMINNOACTIVE );

/*--------------------------------------------------------------------*/
/*       For batch files, we can only report zero/non-zero            */
/*       results.  Do so, and clean up our input file at the same     */
/*       time.                                                        */
/*--------------------------------------------------------------------*/

   if ( useBat )
   {
      int unlinkResult = REMOVE( perfect );

      if (( result == 0 ) && (unlinkResult != 0))
         result = 255;

      if (REMOVE( batchFile ))
      {

         printmsg(0,"Cannot delete batch file %s", batchFile );
         printerr( batchFile );
      }

   } /* if ( useBat ) */

/*--------------------------------------------------------------------*/
/*                     Report results of command                      */
/*--------------------------------------------------------------------*/

   printmsg( 4,"Result of spawn %s is ... %d", command, result);

   return result;

} /* execute */
コード例 #10
0
ファイル: getspool.c プロジェクト: pgul/lgate
static int rbmail(void)
{
  int hrmail, savein, r;
  long len;
  unsigned short crc, mycrc;
  static char addrlist[1026];
  char *p;

  strcpy(tmpmask, tmpdir);
  strcat(tmpmask, TMPUNZNAME);
  debug(6, "rbmail started");
  while (fgets(str, sizeof(str), stdin))
  {
    p=strchr(str, '\n');
    if (p==NULL)
    { logwrite('!', "Bad rbmail-packet (line too long)!\n");
      return 1;
    }
    *p='\0';
    debug(18, "rbmail: readed control line \"%s\"\n");
    if (sscanf(str, "%ld %hx %s", &len, &crc, addrlist)!=3)
    { logwrite('!', "Bad rbmail-packet (incorrect line format)!\n");
      return 1;
    }
    mktempname(tmpmask, tmpname);
    hrmail=open(tmpname, O_BINARY|O_RDWR|O_CREAT|O_EXCL, S_IREAD|S_IWRITE);
    if (hrmail==-1)
    { logwrite('?',"Can't create %s: %s!\n", tmpname, strerror(errno));
      return 1;
    }
    mycrc=0;
    while (len)
    { int i=sizeof(str);
      if (i>len) i=(int)len;
      if (fread(str, i, 1, stdin)!=1)
      { close(hrmail);
        unlink(tmpname);
        logwrite('!', "Bad rbmail-packet (no message data)!\n");
        return 1;
      }
      if (write(hrmail, str, i)!=i)
      { logwrite('?', "Can't write to file: %s!\n", strerror(errno));
        close(hrmail);
        unlink(tmpname);
        return 1;
      }
      len-=i;
      for (p=str; p-str<i; p++)
        mycrc=updatecrc(*p, mycrc);
    }
    if (mycrc!=crc)
    { logwrite('?', "rbmail crc error: %04x!=%04x\n", mycrc, crc);
      close(hrmail);
      unlink(tmpname);
      return 1;
    }
    savein=dup(fileno(stdin));
    lseek(hrmail, 0, SEEK_SET);
    dup2(hrmail, fileno(stdin));
    close(hrmail);
    r=rmailfunc(addrlist);
    dup2(savein, fileno(stdin));
    close(savein);
    unlink(tmpname);
    if (r) return r;
  }
  debug(6, "rbmail ok");
  return 0;
}
コード例 #11
0
ファイル: imfile.c プロジェクト: swhobbit/UUPC
IMFILE *imopen(const long length,
                const char *mode)
{
   IMFILE *imf = malloc(sizeof (IMFILE));

/*--------------------------------------------------------------------*/
/*          Allocate our control structure and initialize it          */
/*--------------------------------------------------------------------*/

   checkref(imf);
   memset(imf, 0, sizeof *imf);

/*--------------------------------------------------------------------*/
/*       Determine if the file is image (binary) or text              */
/*--------------------------------------------------------------------*/

   if (equal(mode, TEXT_MODE))
      imf->flag |= IM_FLAG_TEXT;

/*--------------------------------------------------------------------*/
/*       Grab an imf buffer unless IM files are disabled, the file    */
/*       is too large, or we cannot allocate the buffer.              */
/*--------------------------------------------------------------------*/

   if (bflag[F_IMFILE] && (length <= IM_MAX_LENGTH))
   {

      if (length <= 0)
         imf->length = IM_MAX_LENGTH / 10;
      else
         imf->length = (unsigned long) length;

      imf->buffer = MALLOC((size_t) imf->length);

      if (imf->buffer == NULL)
         printerr("malloc");

   }  /* if (length <= IM_MAX_LENGTH) */
   else
      printmsg(2,"imopen: Using disk for %ld byte file (max i-m is %ld)",
                  length,
                  (long) IM_MAX_LENGTH);

/*--------------------------------------------------------------------*/
/*   Open a real file if we don't have a buffer for whatever reason   */
/*--------------------------------------------------------------------*/

   if (imf->buffer == NULL)
   {
      imf->filename = mktempname(NULL, "TMP");

      if (imf->flag & IM_FLAG_TEXT)
         imf->stream = FOPEN(imf->filename,
                              "w+",
                              TEXT_MODE);
      else
         imf->stream = FOPEN(imf->filename,
                              "w+",
                              IMAGE_MODE);

      if (imf->stream == NULL)
      {
         imclose(imf);
         return NULL;
      } /* if (imf->stream == NULL) */

   } /* if (imf->buffer == NULL) */

/*--------------------------------------------------------------------*/
/*                     Return success to the caller                   */
/*--------------------------------------------------------------------*/

   imStatus(imf);

   return imf;

}  /* imopen */
コード例 #12
0
ファイル: imfile.c プロジェクト: swhobbit/UUPC
static int imReserve(IMFILE *imf, const unsigned long length)
{

   unsigned long newLength = length + imf->position ;

/*--------------------------------------------------------------------*/
/*            If we have the memory allocated, return quietly         */
/*--------------------------------------------------------------------*/

   if ((imf->buffer == NULL) || (newLength <= imf->length))
      return 0;

/*--------------------------------------------------------------------*/
/*             Attempt to allocate the longer buffer needed           */
/*--------------------------------------------------------------------*/

   if (newLength <= IM_MAX_LENGTH)
   {
      char UUFAR *newBuffer;

      newLength += newLength;   /* Add a 100 percent pad             */

      if (newLength > IM_MAX_LENGTH)      /* Is the pad allowed?     */
         newLength = IM_MAX_LENGTH; /* No --> Just use max           */

      newBuffer = REALLOC(imf->buffer, (size_t) newLength);

      if (newBuffer == NULL)
      {
         printerr("realloc");
         imf->flag |= IM_FLAG_ERROR;
         return -1;
      }
      else {
         imf->length = newLength;
         imf->buffer = newBuffer;
         return 0;
      }

   } /* if (newLength <= IM_MAX_LENGTH) */

/*--------------------------------------------------------------------*/
/*       For wharever reason, we need to convert processing to a      */
/*       file; do so.                                                 */
/*--------------------------------------------------------------------*/

   imf->filename = mktempname(NULL, "TMP");

   printmsg(2,"imReserve: Switching to disk file %s after %ld/%ld bytes",
               imf->filename,
               imf->inUse,
               newLength);

   if (imf->flag & IM_FLAG_TEXT)
   {
      /* We can't translate the position on non-binary files */
      if (imf->flag & IM_FLAG_TELL)
      {
         printmsg(0,"imReserve: Internal error, imtell() issued on TEXT file");
         panic();
      }

      imf->stream = FOPEN(imf->filename,
                           "w+",
                           TEXT_MODE);
   }
   else
      imf->stream = FOPEN(imf->filename,
                           "w+",
                           IMAGE_MODE);

   if (imf->stream == NULL)
   {
      printerr(imf->filename);
      imf->flag |= IM_FLAG_ERROR;
      return -1;
   }

   imrewind(imf);

   if (imunload(imf->stream, imf))
   {
      printerr(imf->filename);
      imf->flag |= IM_FLAG_ERROR;
      return -1;
   }

/*--------------------------------------------------------------------*/
/*       Drop the old buffer and set pointer to NULL so routines      */
/*       know what sort of I/O to perform.                            */
/*--------------------------------------------------------------------*/

   FREE(imf->buffer);
   imf->buffer = NULL;

   imf->length = imf->inUse = imf->position = 0;

   return 0;

} /* imReserve */
コード例 #13
0
ファイル: imfile.c プロジェクト: swhobbit/UUPC
int executeIMFCommand(const char *command,
                       IMFILE  *imf,
                       const char *output,
                       const KWBoolean synchronous,
                       const KWBoolean foreground)
{
   char tempName[ FILENAME_MAX ];
   FILE *stream;
   int status;

/*--------------------------------------------------------------------*/
/*       If we are using a disk based work file, we close the file    */
/*       (to prevent sharing errors) and then pass the file name      */
/*       directly into executeCommand.                                */
/*                                                                    */
/*       Note that we reopen the file, we open for append to avoid    */
/*       clobbering the contents.  Since the open should _never_      */
/*       fail, we halt if it does.                                    */
/*--------------------------------------------------------------------*/

   if (imf->buffer == NULL)
   {
      int result;

      fclose(imf->stream);

      result = executeCommand(command,
                               imf->filename,
                               output,
                               synchronous,
                               foreground);

      if (imf->flag & IM_FLAG_TEXT)
         imf->stream = FOPEN(imf->filename,
                              "a+",
                              TEXT_MODE);
      else
         imf->stream = FOPEN(imf->filename,
                              "a+",
                              IMAGE_MODE);

      if (imf->stream == NULL)
      {
         perror(imf->filename);
         panic();
      }

      return result;

   } /* if (imf->buffer == NULL) */

/*--------------------------------------------------------------------*/
/*       The data is in memory, we need to write it out an            */
/*       external program to see it.                                  */
/*--------------------------------------------------------------------*/

   mktempname(tempName, "TMP");

   stream = FOPEN(tempName,
                   "w+",
                   TEXT_MODE);

   if (stream == NULL)
   {
      printerr(tempName);
      return -1;
   }

   if (imunload(stream, imf))
   {
      printerr(tempName);
      return -1;
   }

   fclose(stream);

   status = executeCommand(command,
                            tempName,
                            output,
                            synchronous,
                            foreground);

   REMOVE(tempName);

   return status;

}  /* executeIMFCommand */