コード例 #1
0
ファイル: ta.c プロジェクト: mendaomn/Timing-attack
void
read_datafile (char *name, int n)
{
  FILE *fp;      /* File descriptor for the data file. */
  int i;      /* Loop index */

  /* Open data file for reading, store file descriptor in variable fp. */
  fp = XFOPEN (name, "r");

  /* Read the first line and stores the value (plain text) in variable pt. If
   * read fails, exit with error message. */
  if (fscanf (fp, "%" PRIx64, &pt) != 1)
    {
      ERROR (-1, "cannot read plain text");
    }

  /* Allocates memory to store the cipher texts and timing measurements. Exit
   * with error message if memory allocation fails. */
  ct = XCALLOC (n, sizeof (uint64_t));
  t = XCALLOC (n, sizeof (double));

  /* Read the n experiments (cipher text and timing measurement). Store them in
   * the ct and t arrays. Exit with error message if read fails. */
  for (i = 0; i < n; i++)
    {
      if (fscanf (fp, "%" PRIx64 " %lf", &(ct[i]), &(t[i])) != 2)
        {
          ERROR (-1, "cannot read cipher text and/or timing measurement");
        }
    }
}
コード例 #2
0
ファイル: xm_filesel.c プロジェクト: texlive/texlive-source
static void
accept_callback(Widget w,
                XtPointer client_data,
                XtPointer call_data)
{
    XmFileSelectionBoxCallbackStruct *fcb;
    struct filesel_callback *callback;

    UNUSED(w);

    ASSERT(client_data != NULL, "struct filesel_callback pointer expected in client data");
    callback = (struct filesel_callback *)client_data;

    /* get the filename from the file selection box */
    fcb = (XmFileSelectionBoxCallbackStruct *)call_data;
    if (callback->browse_fname != NULL) {
        XtFree(callback->browse_fname);
        callback->browse_fname = NULL;
    }
    XmStringGetLtoR(fcb->value, G_charset, &callback->browse_fname);

    if (0 && callback->must_exist) {
        FILE *tmp_fp = XFOPEN(callback->browse_fname, "r");
        dviErrFlagT errflag = NO_ERROR;
        if (tmp_fp == NULL) {
            popup_message(XtParent(callback->shell),
                          MSG_ERR, NULL, "Could not open %s: %s.\n",
                          callback->browse_fname, strerror(errno));
            /* leave file selection box open */
            return;
        }
        else if (!process_preamble(tmp_fp, &errflag)
                 || !find_postamble(tmp_fp, &errflag)
                 || !read_postamble(tmp_fp, &errflag, True
#if DELAYED_MKTEXPK
                                    , False
#endif
                                   )) {
            popup_message(XtParent(callback->shell),
                          MSG_ERR, NULL, "Error opening %s:\n%s.",
                          callback->browse_fname, get_dvi_error(errflag));
            fclose(tmp_fp);
            /* leave file selection box open */
            return;
        }
        else { /* file is OK */
            fclose(tmp_fp);
        }
    }

    /* success; close dialog, and call our callback */
    XtUnmanageChild(callback->shell);
    callback->func_ptr(callback->browse_fname, callback->data);
}
コード例 #3
0
static void
fork_dvips(char **argv, struct save_or_print_info *info, childProcT proc)
{
    int print_io[2];
    int i;
    struct file_info *finfo = info->finfo;
    /*     printlog_append(argv[0], strlen(argv[0])); */
    FILE *fout = NULL;

    if (info->act == FILE_SAVE || info->print_target == TO_FILE) { /* printing to PS file, open file for writing */
	const char *out_file;

	if (info->print_target == TO_FILE || info->fmt == FMT_PS)
	    out_file = finfo->out_file;
	else
	    out_file = finfo->tmp_ps_file;
    
	if ((fout = XFOPEN(out_file, "w")) == NULL) {
	    popup_message(globals.widgets.top_level,
			  MSG_ERR,
			  NULL, "Could not open %s for writing: %s.",
			  out_file,
			  strerror(errno));
	    return;
	}
    }

    printlog_popup(info);

    printlog_append_str(info, "Calling: `");
    printlog_append_str(info, argv[0]);

    for (i = 1; argv[i] != NULL; i++) {
	printlog_append_str(info, " ");
	printlog_append_str(info, argv[i]);
    }
    printlog_append_str(info, "'\n");
    
    if (xpipe(print_io) != 0) {
 	perror("[xdvi] pipe");
 	return;
    }
 
    /* Fork process */
    
    /* flush output buffers to avoid double buffering (i.e. data
       waiting in the output buffer being written twice, by the parent
       and the child) */
    fflush(stderr);
    fflush(stdout);

    print_child.name = xstrdup(argv[0]);
    print_child.proc = proc;
    print_child.data = info;
    print_child.pid = fork();
    if (print_child.pid == 0) {	/* if child */
	/* change into dir of DVI file so that included image files etc. are found */
	(void)chdir(globals.dvi_file.dirname);

	/* make the input file pointer the STDIN of the dvips process */
	if (info->page_selection == PAGE_MARKED) { /* printing selected pages from temporary file */
	    ASSERT(finfo->tmp_dvi_fp != NULL, "tmp fp mustn't be NULL!");
	    (void)dup2(fileno(finfo->tmp_dvi_fp), STDIN_FILENO);
	}
	else { /* printing from main or backup file */
	    (void)dup2(fileno(finfo->in_fp), STDIN_FILENO);
	}
	(void)lseek(0, 0, SEEK_SET);
	
 	if (fout != NULL) { /* printing to file, make stdout of child go to fout */
	    (void)dup2(fileno(fout), STDOUT_FILENO);
 	    (void)close(fileno(fout));
 	}
	else { /* printing to printer, make stdout of child go to print_io[1] */
 	    (void)dup2(print_io[1], STDOUT_FILENO);
 	}

	/* make stderr of child go to print_io[1] */
 	(void)dup2(print_io[1], STDERR_FILENO);
 	(void)close(print_io[1]);
 	(void)close(print_io[0]);
 
 	if (setsid() == -1) {	/* so we can kill the process group */
 	    perror("setsid");
 	    fflush(stderr);
 	    _exit(1);
 	}
 	(void)execvp(*argv, argv);
 	popup_message(globals.widgets.top_level,
		      MSG_ERR,
		      NULL,
		      "Execution of \"%s\" failed: %s.\n", *argv, strerror(errno));
 	fflush(stderr);
 	_exit(1);
    }
 
    if (fout != NULL)
 	fclose(fout);
 
    if (print_child.pid == -1) {	/* error */
 	perror("[xdvi] vfork");
 	return;
    }
 
    set_chld(&print_child);
    dvips_sig = SIGINT;

    (void)close(print_io[1]);
 
    /* Set up file descriptor for non-blocking I/O */
    prep_fd(print_io[0], True);
    print_xio.fd = print_io[0];
    print_xio.data = info;
    set_io(&print_xio);
 
    dvips_status = DVIPS_STAT_RUN;	/* running */
}