Example #1
0
void test_3_1(void) {
  chidb *db;
  BTreeNode *btn;
  
  create_temp_file(TESTFILE_1);
	
  db = malloc(sizeof(chidb));
  chidb_Btree_open(TEMPFILE, db, &db->bt);
  
  chidb_Btree_getNodeByPage(db->bt, 1, &btn);
  btn->type = PGTYPE_INDEX_INTERNAL;
  btn->n_cells = 2;
  btn->right_page = 3;
  btn->free_offset = 116;
  btn->cells_offset = 1008;
  chidb_Btree_writeNode(db->bt, btn);
  chidb_Btree_freeMemNode(db->bt, btn);	
  
  chidb_Btree_getNodeByPage(db->bt, 1, &btn);
  btn_sanity_check(db->bt, btn, false);
  CU_ASSERT(btn->type == PGTYPE_INDEX_INTERNAL);
  CU_ASSERT(btn->n_cells == 2);
  CU_ASSERT(btn->right_page == 3);
  CU_ASSERT(btn->free_offset == 116);
  CU_ASSERT(btn->cells_offset == 1008);
  chidb_Btree_freeMemNode(db->bt, btn);	
  
  chidb_Btree_close(db->bt);
  free(db);
}
Example #2
0
void test_3_2(void)
{
  chidb *db;
  BTreeNode *btn;
  
  create_temp_file(TESTFILE_1);
  
  db = malloc(sizeof(chidb));
  chidb_Btree_open(TEMPFILE, db, &db->bt);
  
  chidb_Btree_getNodeByPage(db->bt, 2, &btn);
  btn->type = PGTYPE_INDEX_LEAF;
  btn->n_cells = 3;
  btn->free_offset = 14;
  btn->cells_offset = 616;
  chidb_Btree_writeNode(db->bt, btn);
  chidb_Btree_freeMemNode(db->bt, btn);	
  
  chidb_Btree_getNodeByPage(db->bt, 2, &btn);
  btn_sanity_check(db->bt, btn, false);
  CU_ASSERT(btn->type == PGTYPE_INDEX_LEAF);
  CU_ASSERT(btn->n_cells == 3);
  CU_ASSERT(btn->free_offset == 14);
  CU_ASSERT(btn->cells_offset == 616);
  chidb_Btree_freeMemNode(db->bt, btn);	
  
  chidb_Btree_close(db->bt);
  free(db);
}
Example #3
0
static void
prepare (void)
{
  fd = create_temp_file ("wrewind.", NULL);
  if (fd == -1)
    exit (3);
}
Example #4
0
svn_error_t  *
svn_repos__hooks_pre_revprop_change(svn_repos_t *repos,
                                    svn_revnum_t rev,
                                    const char *author,
                                    const char *name,
                                    const svn_string_t *new_value,
                                    char action,
                                    apr_pool_t *pool)
{
  const char *hook = svn_repos_pre_revprop_change_hook(repos, pool);
  svn_boolean_t broken_link;

  if ((hook = check_hook_cmd(hook, &broken_link, pool)) && broken_link)
    {
      return hook_symlink_error(hook);
    }
  else if (hook)
    {
      const char *args[7];
      apr_file_t *stdin_handle = NULL;
      char action_string[2];

      /* Pass the new value as stdin to hook */
      if (new_value)
        SVN_ERR(create_temp_file(&stdin_handle, new_value, pool));
      else
        SVN_ERR(svn_io_file_open(&stdin_handle, SVN_NULL_DEVICE_NAME,
                                 APR_READ, APR_OS_DEFAULT, pool));

      action_string[0] = action;
      action_string[1] = '\0';

      args[0] = hook;
      args[1] = svn_dirent_local_style(svn_repos_path(repos, pool), pool);
      args[2] = apr_psprintf(pool, "%ld", rev);
      args[3] = author ? author : "";
      args[4] = name;
      args[5] = action_string;
      args[6] = NULL;

      SVN_ERR(run_hook_cmd(NULL, SVN_REPOS__HOOK_PRE_REVPROP_CHANGE, hook,
                           args, repos->hooks_env, stdin_handle, pool));

      SVN_ERR(svn_io_file_close(stdin_handle, pool));
    }
  else
    {
      /* If the pre- hook doesn't exist at all, then default to
         MASSIVE PARANOIA.  Changing revision properties is a lossy
         operation; so unless the repository admininstrator has
         *deliberately* created the pre-hook, disallow all changes. */
      return
        svn_error_create
        (SVN_ERR_REPOS_DISABLED_FEATURE, NULL,
         _("Repository has not been enabled to accept revision propchanges;\n"
           "ask the administrator to create a pre-revprop-change hook"));
    }

  return SVN_NO_ERROR;
}
Example #5
0
static void
do_prepare (int argc, char *argv[])
{
  int fd = create_temp_file ("tst-sysvmsg.", &name);
  if (fd == -1)
    FAIL_EXIT1 ("cannot create temporary file (errno=%d)", errno);
}
Example #6
0
static void
do_prepare (void)
{
  int logfd = create_temp_file ("logfile", &logname);
  close (logfd);

  int fd1 = create_temp_file ("testscript", &fname1);
  dprintf (fd1, "echo foo $1 $2 $3 > %s\n", logname);
  fchmod (fd1, 0700);
  close (fd1);

  int fd2 = create_temp_file ("testscript", &fname2);
  dprintf (fd2, "echo foo > %s\n", logname);
  fchmod (fd2, 0700);
  close (fd2);
}
Example #7
0
/* Set *HANDLE to an open filehandle for a temporary file (i.e.,
   automatically deleted when closed), into which the LOCK_TOKENS have
   been written out in the format described in the pre-commit hook
   template.

   LOCK_TOKENS is as returned by svn_fs__access_get_lock_tokens().

   Allocate *HANDLE in POOL, and use POOL for temporary allocations. */
static svn_error_t *
lock_token_content(apr_file_t **handle, apr_hash_t *lock_tokens,
                   apr_pool_t *pool)
{
  svn_stringbuf_t *lock_str = svn_stringbuf_create("LOCK-TOKENS:\n", pool);
  apr_hash_index_t *hi;

  for (hi = apr_hash_first(pool, lock_tokens); hi;
       hi = apr_hash_next(hi))
    {
      void *val;
      const char *path, *token;

      apr_hash_this(hi, (void *)&token, NULL, &val);
      path = val;
      svn_stringbuf_appendstr(lock_str,
        svn_stringbuf_createf(pool, "%s|%s\n",
                              svn_path_uri_autoescape(path, pool),
                              token));
    }

  svn_stringbuf_appendcstr(lock_str, "\n");
  return create_temp_file(handle,
                          svn_stringbuf__morph_into_string(lock_str), pool);
}
Example #8
0
static void
do_prepare (int argc, char **argv)
{
  temp_fd = create_temp_file ("tst-fallocate.", &temp_filename);
  if (temp_fd == -1)
    FAIL_EXIT1 ("cannot create temporary file: %m");
}
Example #9
0
/* Creates a list of global tags. Ideally, this should be created once during
 installations so that all users can use the same file. This is because a full
 scale global tag list can occupy several megabytes of disk space.
 @param pre_process The pre-processing command. This is executed via system(),
 so you can pass stuff like 'gcc -E -dD -P `gnome-config --cflags gnome`'.
 @param includes Include files to process. Wildcards such as '/usr/include/a*.h'
 are allowed.
 @param tags_file The file where the tags will be stored.
 @param lang The language to use for the tags file.
 @return TRUE on success, FALSE on failure.
*/
gboolean tm_workspace_create_global_tags(const char *pre_process, const char **includes,
	int includes_count, const char *tags_file, TMParserType lang)
{
	gboolean ret = FALSE;
	TMSourceFile *source_file;
	GList *includes_files;
	gchar *temp_file = create_temp_file("tmp_XXXXXX.cpp");

	if (!temp_file)
		return FALSE;

	includes_files = lookup_includes(includes, includes_count);

#ifdef TM_DEBUG
	g_message ("writing out files to %s\n", temp_file);
#endif
	if (pre_process)
		ret = write_includes_file(temp_file, includes_files);
	else
		ret = combine_include_files(temp_file, includes_files);

	g_list_free_full(includes_files, g_free);
	if (!ret)
		goto cleanup;
	ret = FALSE;

	if (pre_process)
	{
		gchar *temp_file2 = pre_process_file(pre_process, temp_file);

		if (temp_file2)
		{
			g_unlink(temp_file);
			g_free(temp_file);
			temp_file = temp_file2;
		}
		else
			goto cleanup;
	}

	source_file = tm_source_file_new(temp_file, tm_source_file_get_lang_name(lang));
	if (!source_file)
		goto cleanup;
	update_source_file(source_file, NULL, 0, FALSE, FALSE);
	if (source_file->tags_array->len == 0)
	{
		tm_source_file_free(source_file);
		goto cleanup;
	}

	tm_tags_sort(source_file->tags_array, global_tags_sort_attrs, TRUE, FALSE);
	ret = tm_source_file_write_tags_file(tags_file, source_file->tags_array);
	tm_source_file_free(source_file);

cleanup:
	g_unlink(temp_file);
	g_free(temp_file);
	return ret;
}
static void
do_prepare (void)
{
  int fd = create_temp_file ("testscript", &fname);
  dprintf (fd, "echo foo\n");
  fchmod (fd, 0700);
  close (fd);
}
Example #11
0
static void
do_prepare (void)
{
  char *temp_file;
  temp_fd = create_temp_file ("tst-ttyname_r.", &temp_file);
  if (temp_fd == -1)
    error (1, errno, "cannot create temporary file");
}
Example #12
0
void test_log_ts(CuTest* tc) {
    pthread_t t1, t2;
    FILE *f1, *f2;
    char *fn1, *fn2;
    sl* lst;

    log_init(LOG_VERB);
    logmsg("Logging initialized.\n");

    log_set_thread_specific();
    logmsg("Logging set thread specific.\n");

    fn1 = create_temp_file("log", "/tmp");
    fn2 = create_temp_file("log", "/tmp");

    logmsg("File 1 is %s\n", fn1);
    logmsg("File 2 is %s\n", fn2);

    f1 = fopen(fn1, "w");
    f2 = fopen(fn2, "w");

    CuAssertIntEquals(tc, 0, pthread_create(&t1, NULL, thread1, f1));
    CuAssertIntEquals(tc, 0, pthread_create(&t2, NULL, thread2, f2));

    CuAssertIntEquals(tc, 0, pthread_join(t1, NULL));
    CuAssertIntEquals(tc, 0, pthread_join(t2, NULL));

    fclose(f1);
    fclose(f2);

    lst = file_get_lines(fn1, FALSE);
    CuAssertIntEquals(tc, 0, strcmp(sl_get(lst, 0), STRING1A));
    CuAssertIntEquals(tc, 1, sl_size(lst));
    sl_free2(lst);

    lst = file_get_lines(fn2, FALSE);
    CuAssertIntEquals(tc, 0, strcmp(sl_get(lst, 0), STRING2A));
    CuAssertIntEquals(tc, 0, strcmp(sl_get(lst, 1), STRING2B));
    CuAssertIntEquals(tc, 2, sl_size(lst));
    sl_free2(lst);

    unlink(fn1);
    unlink(fn2);
    free(fn1);
    free(fn2);
}
Example #13
0
static int run_query(const char *query, DYNAMIC_STRING *ds_res,
                     my_bool force)
{
  int ret;
  File fd;
  char query_file_path[FN_REFLEN];
  const uchar sql_log_bin[]= "SET SQL_LOG_BIN=0;";

  DBUG_ENTER("run_query");
  DBUG_PRINT("enter", ("query: %s", query));
  if ((fd= create_temp_file(query_file_path, 
                            opt_tmpdir[0] ? opt_tmpdir : NULL,
                            "sql", O_CREAT | O_SHARE | O_RDWR,
                            MYF(MY_WME))) < 0)
    die("Failed to create temporary file for defaults");

  /*
    Master and slave should be upgraded separately. All statements executed
    by mysql_upgrade will not be binlogged.
    'SET SQL_LOG_BIN=0' is executed before any other statements.
   */
  if (!opt_write_binlog)
  {
    if (my_write(fd, sql_log_bin, sizeof(sql_log_bin)-1,
                 MYF(MY_FNABP | MY_WME)))
    {
      my_close(fd, MYF(0));
      my_delete(query_file_path, MYF(0));
      die("Failed to write to '%s'", query_file_path);
    }
  }

  if (my_write(fd, (uchar*) query, strlen(query),
               MYF(MY_FNABP | MY_WME)))
  {
    my_close(fd, MYF(0));
    my_delete(query_file_path, MYF(0));
    die("Failed to write to '%s'", query_file_path);
  }

  ret= run_tool(mysql_path,
                ds_res,
                "--no-defaults",
                ds_args.str,
                "--database=mysql",
                "--batch", /* Turns off pager etc. */
                force ? "--force": "--skip-force",
                ds_res || opt_silent ? "--silent": "",
                "<",
                query_file_path,
                "2>&1",
                NULL);

  my_close(fd, MYF(0));
  my_delete(query_file_path, MYF(0));

  DBUG_RETURN(ret);
}
Example #14
0
static void
do_prepare (void)
{
  if (create_temp_file ("tst-getopt_long1", &fname) < 0)
    {
      printf ("cannot create temp file: %m\n");
      exit (1);
    }
}
Example #15
0
static int
do_test (void)
{
  if (setlocale (LC_ALL, "ja_JP.UTF-8") == NULL)
    {
      printf ("Cannot set ja_JP.UTF-8 locale.\n");
      exit (1);
    }

  /* Retain messages in English.  */
  if (setlocale (LC_MESSAGES, "en_US.ISO-8859-1") == NULL)
    {
      printf ("Cannot set LC_MESSAGES to en_US.ISO-8859-1 locale.\n");
      exit (1);
    }

  int ret = 0;
  char *filename;
  int fd = create_temp_file ("tst-fseek.out", &filename);

  if (fd == -1)
    return 1;

  FILE *fp = fdopen (fd, "w+");
  if (fp == NULL)
    {
      printf ("seek_set: fopen: %s\n", strerror (errno));
      close (fd);
      return 1;
    }

  if (do_seek_set (fp))
    {
      printf ("SEEK_SET test failed\n");
      ret = 1;
    }

  /* Reopen the file.  */
  fclose (fp);
  fp = fopen (filename, "w+");
  if (fp == NULL)
    {
      printf ("seek_end: fopen: %s\n", strerror (errno));
      return 1;
    }

  if (do_seek_end (fp))
    {
      printf ("SEEK_END test failed\n");
      ret = 1;
    }

  fclose (fp);

  return ret;
}
Example #16
0
static void
do_prepare (void)
{
  fd = create_temp_file ("tst-unlockedio.", NULL);
  if (fd == -1)
    {
      printf ("cannot create temporary file: %m\n");
      exit (1);
    }
}
Example #17
0
static void
do_prepare (void)
{
  fd = create_temp_file ("bug-fclose1.", NULL);
  if (fd == -1)
    {
      printf ("cannot create temporary file: %m\n");
      exit (1);
    }
}
Example #18
0
static void
do_prepare (void)
{
  temp_fd = create_temp_file ("tst-trucate.", &temp_filename);
  if (temp_fd == -1)
    {
      printf ("cannot create temporary file: %m\n");
      exit (1);
    }
}
Example #19
0
/* Creates and returns a new external array. */
struct ext_array *
ext_array_create (void)
{
  struct ext_array *ea = xmalloc (sizeof *ea);
  ea->file = create_temp_file ();
  if (ea->file == NULL)
    error (0, errno, _("failed to create temporary file"));
  ea->position = 0;
  return ea;
}
Example #20
0
static gchar *pre_process_file(const gchar *cmd, const gchar *inf)
{
	gint ret;
	gchar *outf = create_temp_file("tmp_XXXXXX.cpp");
	gchar *tmp_errfile;
	gchar *errors = NULL;
	gchar *command;

	if (!outf)
		return NULL;

	tmp_errfile = create_temp_file("tmp_XXXXXX");
	if (!tmp_errfile)
	{
		g_unlink(outf);
		g_free(outf);
		return NULL;
	}

	command = g_strdup_printf("%s %s >%s 2>%s",
		cmd, inf, outf, tmp_errfile);
#ifdef TM_DEBUG
	g_message("Executing: %s", command);
#endif
	ret = system(command);
	g_free(command);

	g_file_get_contents(tmp_errfile, &errors, NULL, NULL);
	if (errors && *errors)
		g_printerr("%s", errors);
	g_free(errors);
	g_unlink(tmp_errfile);
	g_free(tmp_errfile);

	if (ret == -1)
	{
		g_unlink(outf);
		g_free(outf);
		return NULL;
	}

	return outf;
}
static void
prepare (void)
{
  fd = create_temp_file ("tst-fwrite.", NULL);
  if (fd == -1)
    {
      puts ("cannot create temporary file");
      exit (1);
    }
}
Example #22
0
void test_3_5(void)
{
  chidb *db;
  
  create_temp_file(TESTFILE_1);
  
  db = malloc(sizeof(chidb));
  chidb_Btree_open(TEMPFILE, db, &db->bt);
  test_init_empty(db->bt, PGTYPE_INDEX_INTERNAL);
  chidb_Btree_close(db->bt);
  free(db);
}
static void
do_prepare (void)
{
  int fd = create_temp_file ("bug-ungetc.", &temp_file);
  if (fd == -1)
    {
      printf ("cannot create temporary file: %m\n");
      exit (1);
    }
  write (fd, pattern, sizeof (pattern) - 1);
  close (fd);
}
Example #24
0
void test_3_10(void)
{
  chidb *db;
  
  create_temp_file(TESTFILE_1);
  
  db = malloc(sizeof(chidb));
  chidb_Btree_open(TEMPFILE, db, &db->bt);
  test_new_node(db->bt, PGTYPE_INDEX_LEAF);
  chidb_Btree_close(db->bt);
  free(db);
}
Example #25
0
int main(int argc, char **argv)
{
	unsigned char sha1[20];

	if (argc != 2 || get_sha1(argv[1], sha1))
		usage("git-unpack-file <sha1>");

	setup_git_directory();

	puts(create_temp_file(sha1));
	return 0;
}
Example #26
0
static void
do_prepare (void)
{
  temp_fd = create_temp_file ("tst-mmap-eofsync.", &temp_file);
  if (temp_fd == -1)
    error (1, errno, "cannot create temporary file");
  else
    {
      ssize_t cc = write (temp_fd, text1, sizeof text1 - 1);
      if (cc != sizeof text1 - 1)
	error (1, errno, "cannot write to temporary file");
    }
}
Example #27
0
/** Filters a file in-place. This is performed by creating a temporary
    file, writing the output to the temporary file, then deleting the
    original file and renaming the temporary file to the original file.

    To save unnecessary updation of time stamps, if no changes were made
    to the original file, then the temporary file is deleted and the
    original file is left as-is. If any errors occur, then an error
    message will be displayed and the program will be terminated.

    @param input_file_name Name of the input file. Must not be @c NULL.
    Note that @c "-" is <b>NOT</b> recognised as standard input/output. */
static void process_file_in_place(
    const char *input_file_name,
    jmp_buf *jmp_if_error)
{
    /* temp_file_name: Name of the temporary file */
    /* input_file: Input file object stream */
    /* output_file: Temporary output file object stream */
    /* on_clean_stream_error: Handler for I/O errors in clean_stream() */
    char temp_file_name[PATH_MAX];
    FILE *input_file;
    FILE *temp_file;
    jmp_buf on_clean_stream_error;

    /* Open the input file and create a temporary output file. */
    open_file(input_file_name, INPUT_MODE, &input_file, jmp_if_error);
    create_temp_file(input_file_name, OUTPUT_MODE,
                     temp_file_name, &temp_file, jmp_if_error);

    /* Filter the input file contents into the temporary file. */
    if(setjmp(on_clean_stream_error))
    {
        /* Execution branches here if clean_stream() encounters an I/O error */
        error(0, errno, "%s", input_file_name);
        close_remove_file(temp_file, temp_file_name, jmp_if_error);
        longjmp(*jmp_if_error, TRUE);
        /* Non-local return */
    }
    switch(clean_stream(input_file, temp_file, &on_clean_stream_error))
    {
    case CSR_STREAM_UNMODIFIED:
        /* No modifications were made to the stream, so the
           temporary file is identical to the input file. So we can
           avoid unnecessarily updating the time stamps on the input
           file, we'll close and remove the temporary file name
           instead. Close the input file as well. */
        close_remove_file(temp_file, temp_file_name, jmp_if_error);
        close_file(input_file, input_file_name, jmp_if_error);
        break;
    case CSR_STREAM_MODIFIED:
        /* Modifications were made to the stream content. The
           temporary file and input files are not identical. Close
           both files, then delete the input file and rename the
           temporary file to the input file. */
        close_file_guarantee_complete_or_remove(
            temp_file, temp_file_name, jmp_if_error);
        close_file(input_file, input_file_name, jmp_if_error);
        replace_file(input_file_name, temp_file_name, jmp_if_error);
        break;
    }
}
Example #28
0
/**
 * Bind content of @vectors over /proc/{@ptracee->pid}/auxv.  This
 * function returns -1 if an error occurred, otherwise 0.
 */
static int bind_proc_pid_auxv(const Tracee *ptracee)
{
	word_t vectors_address;
	ElfAuxVector *vectors;

	const char *guest_path;
	const char *host_path;
	Binding *binding;
	int status;

	vectors_address = get_elf_aux_vectors_address(ptracee);
	if (vectors_address == 0)
		return -1;

	vectors = fetch_elf_aux_vectors(ptracee, vectors_address);
	if (vectors == NULL)
		return -1;

	/* Path to these ELF auxiliary vectors.  */
	guest_path = talloc_asprintf(ptracee->ctx, "/proc/%d/auxv", ptracee->pid);
	if (guest_path == NULL)
		return -1;

	/* Remove binding to this path, if any.  It contains ELF
	 * auxiliary vectors of the previous execve(2).  */
	binding = get_binding(ptracee, GUEST, guest_path);
	if (binding != NULL && compare_paths(binding->guest.path, guest_path) == PATHS_ARE_EQUAL) {
		remove_binding_from_all_lists(ptracee, binding);
		TALLOC_FREE(binding);
	}

	host_path = create_temp_file(ptracee->ctx, "auxv");
	if (host_path == NULL)
		return -1;

	status = fill_file_with_auxv(ptracee, host_path, vectors);
	if (status < 0)
		return -1;

	/* Note: this binding will be removed once ptracee gets freed.  */
	binding = insort_binding3(ptracee, ptracee->life_context, host_path, guest_path);
	if (binding == NULL)
		return -1;

	/* This temporary file (host_path) will be removed once the
	 * binding is freed.  */
	talloc_reparent(ptracee->ctx, binding, host_path);

	return 0;
}
Example #29
0
static int make_tempfile(char *filename, const char *ext)
{
  int fd= 0;

  if ((fd=create_temp_file(filename, NullS, ext, O_CREAT | O_WRONLY,
         MYF(MY_WME))) < 0)
  {
    fprintf(stderr, "ERROR: Cannot generate temporary file. Error code: %d.\n",
            fd);
    return 1;
  }
  my_close(fd, MYF(0));
  return 0;
}
Example #30
0
svn_error_t  *
svn_repos__hooks_post_revprop_change(svn_repos_t *repos,
                                     apr_hash_t *hooks_env,
                                     svn_revnum_t rev,
                                     const char *author,
                                     const char *name,
                                     const svn_string_t *old_value,
                                     char action,
                                     apr_pool_t *pool)
{
  const char *hook = svn_repos_post_revprop_change_hook(repos, pool);
  svn_boolean_t broken_link;

  if ((hook = check_hook_cmd(hook, &broken_link, pool)) && broken_link)
    {
      return hook_symlink_error(hook);
    }
  else if (hook)
    {
      const char *args[7];
      apr_file_t *stdin_handle = NULL;
      char action_string[2];

      /* Pass the old value as stdin to hook */
      if (old_value)
        SVN_ERR(create_temp_file(&stdin_handle, old_value, pool));
      else
        SVN_ERR(svn_io_file_open(&stdin_handle, SVN_NULL_DEVICE_NAME,
                                 APR_READ, APR_OS_DEFAULT, pool));

      action_string[0] = action;
      action_string[1] = '\0';

      args[0] = hook;
      args[1] = svn_dirent_local_style(svn_repos_path(repos, pool), pool);
      args[2] = apr_psprintf(pool, "%ld", rev);
      args[3] = author ? author : "";
      args[4] = name;
      args[5] = action_string;
      args[6] = NULL;

      SVN_ERR(run_hook_cmd(NULL, SVN_REPOS__HOOK_POST_REVPROP_CHANGE, hook,
                           args, hooks_env, stdin_handle, pool));

      SVN_ERR(svn_io_file_close(stdin_handle, pool));
    }

  return SVN_NO_ERROR;
}