Exemplo n.º 1
0
Arquivo: files.c Projeto: srfrog/epic5
int *	open_exec_for_in_out_err (const char *filename, char * const *args)
{
	Filename expand;
	FILE **files;
static	int ret[3];

struct  epic_loadfile *elf;
        File * fr;

	if (normalize_filename(filename, expand))
		strlcpy(expand, filename, sizeof(expand));

	if ((files = open_exec(filename, args)))
	{
		int foo;
		for (foo = 0; foo < 3; foo++) 
		{
                        if (!(elf=(struct epic_loadfile *)malloc(sizeof(struct epic_loadfile)))) {
                            yell("Not enough memory.");
                            return NULL;
                        }

                        elf->fp=files[foo];
#ifdef HAVE_LIBARCHIVE
                        elf->a=NULL;
#endif
                        fr=new_file(elf);
			ret[foo] = fr->id;
                }
                return ret;
	}
	else 
		return NULL;
}
Exemplo n.º 2
0
void
systrace_parameters(void)
{
	struct passwd *pw;
	char *normcwd;
	uid_t uid = getuid();

	iamroot = getuid() == 0;

	/* Find out current username. */
	if ((pw = getpwuid(uid)) == NULL) {
		snprintf(username, sizeof(username), "uid %u", uid);
	} else {
		strlcpy(username, pw->pw_name, sizeof(username));
		strlcpy(home, pw->pw_dir, sizeof(home));
	}

	/* Determine current working directory for filtering */
	if (getcwd(cwd, sizeof(cwd)) == NULL)
		err(1, "getcwd");
	if ((normcwd = normalize_filename(-1, 0, cwd, ICLINK_ALL)) == NULL)
		errx(1, "normalize_filename");
	if (strlcpy(cwd, normcwd, sizeof(cwd)) >= sizeof(cwd))
		errx(1, "cwd too long");
}
Exemplo n.º 3
0
/*
 * set_log_file: sets the log file name.  If logging is on already, this
 * closes the last log file and reopens it with the new name.  This is called
 * automatically when you SET LOGFILE. 
 */
void	set_log_file (const void *stuff)
{
	const char *filename = (const char *)stuff;
	Filename expand;

	if (!filename)
		return;

	if (normalize_filename(filename, expand))
	{
		say("SET LOGFILE: %s contains an invalid directory", filename);
		return;
	}

	set_string_var(LOGFILE_VAR, expand);
	if (irclog_fp)
	{
		int	value;

		value = 0;
		logger(&value);
		value = 1;
		logger(&value);
	}
}
Exemplo n.º 4
0
static struct directory *
attach_directory (const char *name)
{
  char *cname = normalize_filename (name);
  struct directory *dir = make_directory (name, cname);
  if (dirtail)
    dirtail->next = dir;
  else
    dirhead = dir;
  dirtail = dir;
  return dir;
}
Exemplo n.º 5
0
/* Return a directory entry for a given file NAME, or zero if none found.  */
static struct directory *
find_directory (const char *name)
{
  if (! directory_table)
    return 0;
  else
    {
      char *caname = normalize_filename (name);
      struct directory *dir = make_directory (name, caname);
      struct directory *ret = hash_lookup (directory_table, dir);
      free_directory (dir);
      return ret;
    }
}
Exemplo n.º 6
0
Arquivo: files.c Projeto: srfrog/epic5
int	open_file_for_write (const char *filename, const char *mode)
{
	Filename expand;
        struct epic_loadfile *elf;

        File * fr;

	if (normalize_filename(filename, expand))
		strlcpy(expand, filename, sizeof(expand));

	if (!(elf = epic_fopen(expand, mode, 1)))
		return -1;

	fr=new_file(elf);
	return fr->id;
}
Exemplo n.º 7
0
static FILE *open_log (const char *logfile, FILE **fp)
{
	time_t	t;
	char	my_buffer[256];
	struct	tm	*ugh;
	Filename fullname;

	time(&t);
	ugh = localtime(&t);		/* Not gmtime, m'kay? */
	/* Ugh.  Solaris. */
	strftime(my_buffer, 255, "%a %b %d %H:%M:%S %Y", ugh);

	if (*fp) 
	{
		say("Logging is already on");
		return *fp;
	}

	if (!logfile)
		return NULL;
			
	if (normalize_filename(logfile, fullname))
	{
		say("SET LOGFILE: %s contains an invalid directory", logfile);
		return NULL;
	}

	if ((*fp = fopen(fullname, "a")) != NULL)
	{
		chmod(fullname, S_IREAD | S_IWRITE);
		say("Starting logfile %s", fullname);

		fprintf(*fp, "IRC log started %s\n", my_buffer);
		fflush(*fp);
	}
	else
	{
		say("Couldn't open logfile %s: %s", fullname, strerror(errno));
		*fp = NULL;
	}

	return (*fp);
}
Exemplo n.º 8
0
Arquivo: unlink.c Projeto: abligh/tar
void
queue_deferred_unlink (const char *name, bool is_dir)
{
  struct deferred_unlink *p;

  if (dunlink_head
      && records_written > dunlink_head->records_written + deferred_unlink_delay)
    flush_deferred_unlinks (false);

  p = dunlink_alloc ();
  p->next = NULL;
  p->file_name = normalize_filename (name);
  p->is_dir = is_dir;
  p->records_written = records_written;

  if (dunlink_tail)
    dunlink_tail->next = p;
  else
    dunlink_head = p;
  dunlink_tail = p;
  dunlink_count++;
}
Exemplo n.º 9
0
void
file_chooser_with_entry(char * title, GtkWidget * parent, GtkFileChooserAction action, int filter,
			GtkWidget * entry, char * destpath) {

        GtkWidget * dialog;
	const gchar * selected_filename = gtk_entry_get_text(GTK_ENTRY(entry));
	char path[MAXLEN];

	path[0] = '\0';

        dialog = gtk_file_chooser_dialog_new(title,
                                             GTK_WINDOW(parent),
					     action,
                                             GTK_STOCK_APPLY, GTK_RESPONSE_ACCEPT,
                                             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                             NULL);

	if (options.show_hidden) {
		gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(dialog), options.show_hidden);
	}

        if (strlen(selected_filename)) {
      		char * filename = g_filename_from_utf8(selected_filename, -1, NULL, NULL, NULL);

		if (filename == NULL) {
			gtk_widget_destroy(dialog);
			return;
		}

		normalize_filename(filename, path);
		g_free(filename);
	} else {
		strncpy(path, destpath, MAXLEN-1);
	}

	gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), path);

	if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
		char * bname = g_path_get_basename(path);
		gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), bname);
		g_free(bname);
	}

        gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER_ON_PARENT);
        gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
	assign_fc_filters(GTK_FILE_CHOOSER(dialog), filter);

        if (aqualung_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {

		char * utf8;

                selected_filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
		utf8 = g_filename_to_utf8(selected_filename, -1, NULL, NULL, NULL);

		if (utf8 == NULL) {
			gtk_widget_destroy(dialog);
		}

		gtk_entry_set_text(GTK_ENTRY(entry), utf8);

                strncpy(destpath, selected_filename, MAXLEN-1);
		g_free(utf8);
        }

        gtk_widget_destroy(dialog);
}
Exemplo n.º 10
0
/*
** PC to BR meta-function
*/
int		pctobr(t_env* env)
{
  char end = 0;
  int i = 0;
  unsigned int count = 0;
  unsigned char conv = 0;
  unsigned int lines = 0;
  unsigned char		buf[BUFFER_SIZE]; /* received buffer */
  unsigned char	str[BUFFER_SIZE];  /* sent buffer */
  char* tmpfilename = "/tmp/eutp.tmp";

  for (i = 0; i < BUFFER_SIZE; i++)
    {
      buf[i] = 0;
      str[i] = 0;
    }
  conv = normalize_filename(env);
  if ((env->fd = open(env->list[env->pcfilenum]->d_name, O_RDONLY)) == -1)
    {
      brl_message("!Erreur ouv pc", 0);
      sleep(1);
      return 0;
    }
  env->fs = fdopen(env->fd, "r");
  /* Ouverture fichier en écriture sur le terminal braille */
  str[0] = '\x0C';
  strncpy((char*)&str[1], "Fo\x00", 3);
  str[4] = env->curext;
  strncpy((char*)&str[5], env->filename, 8);
  brl_write(str+1, 12);
  brl_read(buf);
  if (!strncmp((char*)buf, "\003FE\x21", 4))
    {
      if (brl_yesno_question("! Remplacer ?      #"))
	  str[3] = 1;
      else
	return 1;
      brl_write(str+1, 12);
      brl_read(buf);
    }
  if (strncmp((char*)buf, "\002FW", 3))
    {
      brl_lasting_message("! erreur ouv br");
      brl_writeStr(CLOSE_FILE);
      return 1;
    }
  while (!end)
    {
      end = read_trame_from_file(env, str, &count);
      for (i = 0; i < 30; i++)
	printf(",%d,", str[i]);
      printf("\n");
      if (count == 4242) /* fin fichier */
	{
	  printf("fin fichier\n");
	  end = 1;
	}
      brl_write(str+1, count);
      brl_read(buf);
      if (strncmp((char*)buf, (char*)"\002FW", 3))
	{
	  printf("erreur transfert\n");
	  for (i = 0; i < 30; i++)
	    printf(",%d,", buf[i]);
	  printf("\n");
	  brl_lasting_message("! Erreur transfert");
	  brl_writeStr(CLOSE_FILE);
	  return 1;
	}
      lines++;
      sprintf((char*)str, "... %s.%c %d", env->filename, env->curext, lines);
      brl_message((char*)str, 0);
    }
  brl_writeStr(CLOSE_FILE);
  brl_read(buf);
  if (strncmp((char*)buf, "\003FE\x10", 4))
    {
      printf("errer fermeture\n");
      for (i = 0; i < 30; i++)
	printf(",%d,", buf[i]);
      printf("\n");
      brl_lasting_message("! err fermeture");
      fclose(env->fs);
      close(env->fd);
      return 1;
    }
  brl_message("! Fin transfert", 0);
  sleep(1);
  fclose(env->fs);
  close(env->fd);
  if (conv)
    unlink(tmpfilename);
  return 1;
}
Exemplo n.º 11
0
static FILE *	open_log (const char *logfile, FILE **fp)
{
	char *		tempname;
	size_t		templen;
	Filename 	fullname;

	/* If the user hasn't specified a logfile, do nothing */
	if (!logfile)
		return NULL;

	/* If the user is already logging here, tell them. */
	if (*fp) 
	{
		say("Logging is already on");
		return *fp;
	}

	/* If necessary, remove "s on the outside of the filename */
	/* I do this way too much on accident; it's annoying not to have it */
	tempname = LOCAL_COPY(logfile);
	templen = strlen(tempname);
	if (templen > 2 && tempname[0] == '"' 
			&& tempname[templen - 1] == '"')
	{
		tempname[templen - 1] = 0;
		tempname++;
	}

	/* If the result is an empty filename then just punt */
	if (!tempname || !*tempname)
	{
		yell("Cannot log to the filename [%s] because the result "
			"was an empty filename", logfile);
		return NULL;
	}

	if (normalize_filename(tempname, fullname))
	{
		yell("Warning: I could not normalize the filename [%s] "
			"(the result was [%s] -- watch out", 
			logfile, fullname);
		(void)0;		/* Do nothing... */
	}

	if ((*fp = fopen(fullname, "a")) != NULL)
	{
		time_t		t;
		struct	tm *	ltime;
		char		timestr[256];

		/* Convert the time to a string to insert in the file */
		time(&t);
		ltime = localtime(&t);		/* Not gmtime, m'kay? */
		strftime(timestr, 255, "%a %b %d %H:%M:%S %Y", ltime);

		chmod(fullname, S_IREAD | S_IWRITE);
		say("Starting logfile %s", fullname);
		fprintf(*fp, "IRC log started %s\n", timestr);
		fflush(*fp);
	}
	else
	{
		yell("Couldn't open logfile %s: %s", fullname, strerror(errno));
		*fp = NULL;
	}

	return (*fp);
}
Exemplo n.º 12
0
void
collect_and_sort_names (void)
{
  struct name *name;
  struct name *next_name, *prev_name;
  int num_names;
  struct stat statbuf;
  Hash_table *nametab;
  
  name_gather ();

  if (!namelist)
    addname (".", 0, false, NULL);

  if (listed_incremental_option)
    {
      switch (chdir_count ())
	{
	case 0:
	  break;

	case 1:
	  if (namelist->change_dir == 0)
	    USAGE_ERROR ((0, 0,
			  _("Using -C option inside file list is not "
			    "allowed with --listed-incremental")));
	  break;

	default:
	  USAGE_ERROR ((0, 0,
			_("Only one -C option is allowed with "
			  "--listed-incremental")));
	}

      read_directory_file ();
    }
  
  num_names = 0;
  for (name = namelist; name; name = name->next, num_names++)
    {
      if (name->found_count || name->directory)
	continue;
      if (name->matching_flags & EXCLUDE_WILDCARDS)
	/* NOTE: EXCLUDE_ANCHORED is not relevant here */
	/* FIXME: just skip regexps for now */
	continue;
      chdir_do (name->change_dir);

      if (name->name[0] == 0)
	continue;

      if (deref_stat (dereference_option, name->name, &statbuf) != 0)
	{
	  stat_diag (name->name);
	  continue;
	}
      if (S_ISDIR (statbuf.st_mode))
	{
	  name->found_count++;
	  add_hierarchy_to_namelist (name, statbuf.st_dev, true);
	}
    }

  namelist = merge_sort (namelist, num_names, compare_names);

  num_names = 0;
  nametab = hash_initialize (0, 0,
			     name_hash,
			     name_compare, NULL);
  for (name = namelist; name; name = next_name)
    {
      next_name = name->next;
      name->caname = normalize_filename (name->name);
      if (prev_name)
	{
	  struct name *p = hash_lookup (nametab, name);
	  if (p)
	    {
	      /* Keep the one listed in the command line */
	      if (!name->parent)
		{
		  if (p->child)
		    rebase_child_list (p->child, name);
		  /* FIXME: remove_directory (p->caname); ? */
		  remname (p);
		  free_name (p);
		  num_names--;
		}
	      else
		{
		  if (name->child)
		    rebase_child_list (name->child, p);
		  /* FIXME: remove_directory (name->caname); ? */
		  remname (name);
		  free_name (name);
		  continue;
		}
	    }
	}
      name->found_count = 0;
      if (!hash_insert (nametab, name))
	xalloc_die ();
      prev_name = name;
      num_names++;
    }
  nametail = prev_name;
  hash_free (nametab);

  namelist = merge_sort (namelist, num_names, compare_names_found);

  if (listed_incremental_option)
    {
      for (name = namelist; name && name->name[0] == 0; name++)
	;
      if (name)
	append_incremental_renames (name->directory);
    }
}
Exemplo n.º 13
0
/* Destructively turn slashes into backslashes.  */
static void
unixtodos_filename (char *p)
{
  normalize_filename (p, '\\');
}
Exemplo n.º 14
0
/* Destructively turn backslashes into slashes.  */
#if 0 /* unused */
static void
dostounix_filename (char *p)
{
  normalize_filename (p, '/');
}
Exemplo n.º 15
0
int main (void) {
     const char delimiters[] = "\t";

     char *tmpdir, *write_name, *read_name, *failed_name, *failedpath_name, *trashed_name, *line;
     ssize_t linesize;
     size_t bufsize = 2048;
     char *a1, *a2, *a3, *a4, *tmp;

     tmpdir = getenv("PWIZ_TMPDIR");
     if (tmpdir == NULL || tmpdir[0] == 0) {
	 tmpdir = ".";
     }

     (void) asprintf (&write_name, "%s/filelist_raw.lst", tmpdir);
     (void) asprintf (&read_name, "%s/filelist_read.lst", tmpdir);
     (void) asprintf (&failed_name, "%s/filelist_failed.lst", tmpdir);
     (void) asprintf (&failedpath_name, "%s/filelist_failedpath.lst", tmpdir);
     (void) asprintf (&trashed_name, "%s/filelist_trashed.lst", tmpdir);

     /* FIXME: Error handling. */
     write_file = fopen (write_name, "w");
     read_file = fopen (read_name, "w");
     failed_file = fopen (failed_name, "w");
     failedpath_file = fopen (failedpath_name, "w");
     trashed_file = fopen (trashed_name, "w");
     failedsave_file = failed_file;

     free (write_name);
     free (read_name);
     free (failed_name);
     free (failedpath_name);
     free (trashed_name);

     line = malloc (2048);
     trash_buffer = malloc (2048);
     trash_name = malloc (1);
     strcpy (trash_name, "");

     while ((linesize = getline (&line, &bufsize, stdin)) >= 0) {

	 line[linesize-1] = '\0';
	 tmp = line;

	 a1 = strsep (&tmp, delimiters);
	 if (tmp) {
	     a2 = strsep (&tmp, delimiters);
	     if (tmp) {
		 a3 = strsep (&tmp, delimiters);
		 if (tmp) {
		     a4 = strsep (&tmp, delimiters);
		 }
	     }
	 }

	 if (!strcmp(a2, "read"))
	 {
	     normalize_filename (a3);
	     handle_read (a3, a4);
	 }
	 else
	     if (!strcmp(a2, "open"))
	     {
		 normalize_filename (a3);
		 fprintf (write_file, "%s file\n", a3);
	     }
	     else
		 if (!strcmp(a2, "mkdir"))
		 {
		     normalize_filename (a3);
		     fprintf (write_file, "%s dir\n", a3);
		 }
		 else
		     if (!strcmp(a2, "symlink") || !strcmp(a2, "link"))
		     {
			 normalize_filename (a4);
			 fprintf (write_file, "%s file\n", a4);
		     }

     }

     fclose (write_file);
     fclose (read_file);
     fclose (failed_file);
     fclose (failedpath_file);
     fclose (trashed_file);

     exit(0);
}