Exemplo n.º 1
0
Source_File *
source_file_lookup_path (const char *path)
{
  Source_File *sf;

  for (sf = first_src_file; sf; sf = sf->next)
    {
      if (FILENAME_CMP (path, sf->name) == 0)
	break;
    }

  if (!sf)
    {
      /* Create a new source file descriptor.  */
      sf = (Source_File *) xmalloc (sizeof (*sf));

      memset (sf, 0, sizeof (*sf));

      sf->name = xstrdup (path);
      sf->next = first_src_file;
      first_src_file = sf;
    }

  return sf;
}
Exemplo n.º 2
0
Source_File *
source_file_lookup_name (const char *filename)
{
  const char *fname;
  Source_File *sf;

  /* The user cannot know exactly how a filename will be stored in
     the debugging info (e.g., ../include/foo.h
     vs. /usr/include/foo.h).  So we simply compare the filename
     component of a path only.  */
  for (sf = first_src_file; sf; sf = sf->next)
    {
      fname = strrchr (sf->name, '/');

      if (fname)
	++fname;
      else
	fname = sf->name;

      if (FILENAME_CMP (filename, fname) == 0)
	break;
    }

  return sf;
}
Exemplo n.º 3
0
static bfd_boolean
is_sysrooted_pathname (const char *name, bfd_boolean notsame)
{
  char * realname = ld_canon_sysroot ? lrealpath (name) : NULL;
  int len;
  bfd_boolean result;

  if (! realname)
    return FALSE;

  len = strlen (realname);

  if (((! notsame && len == ld_canon_sysroot_len)
       || (len >= ld_canon_sysroot_len
	   && IS_DIR_SEPARATOR (realname[ld_canon_sysroot_len])
	   && (realname[ld_canon_sysroot_len] = '\0') == '\0'))
      && FILENAME_CMP (ld_canon_sysroot, realname) == 0)
    result = TRUE;
  else
    result = FALSE;

  if (realname)
    free (realname);

  return result;
}
Exemplo n.º 4
0
static void
add_entry (struct entry **entp, const char *filename, int is_system)
{
  int len;
  struct entry *n;

  n = XNEW (struct entry);
  n->flags = is_system ? FLAG_SYSTEM : 0;
  n->next = NULL;

  len = strlen (filename);

  if (len > 4 && (FILENAME_CMP (filename + len - 4, ".zip") == 0
		  || FILENAME_CMP (filename + len - 4, ".jar") == 0))
    {
      n->flags |= FLAG_ZIP;
      /* If the user uses -classpath then he'll have to include
	 libgcj.jar in the value.  We check for this in a simplistic
	 way.  Symlinks will fool this test.  This is only used for
	 -MM and -MMD, so it probably isn't terribly important.  */
      if (! FILENAME_CMP (filename, LIBGCJ_ZIP_FILE))
	n->flags |= FLAG_SYSTEM;
    }

  /* Note that we add a trailing separator to `.zip' names as well.
     This is a little hack that lets the searching code in jcf-io.c
     work more easily.  Eww.  */
  if (! IS_DIR_SEPARATOR (filename[len - 1]))
    {
      char *f2 = (char *) alloca (len + 2);
      strcpy (f2, filename);
      f2[len] = DIR_SEPARATOR;
      f2[len + 1] = '\0';
      n->name = xstrdup (f2);
      ++len;
    }
  else
    n->name = xstrdup (filename);

  if (len > longest_path)
    longest_path = len;

  append_entry (entp, n);
}
Exemplo n.º 5
0
/* Find the result for having already called info_find_fullpath () with
   FILENAME. */
static char *
lookup_info_filename (char *filename)
{
  if (filename && names_and_files)
    {
      register int i;
      for (i = 0; names_and_files[i]; i++)
        {
          if (FILENAME_CMP (names_and_files[i]->filename, filename) == 0)
            return names_and_files[i]->expansion;
        }
    }
  return NULL;
}
Exemplo n.º 6
0
static void
map_over_list (bfd *arch, void (*function) (bfd *, bfd *), struct list *list)
{
  bfd *head;

  if (list == NULL)
    {
      bfd *next;

      head = arch->archive_next;
      while (head != NULL)
	{
	  next = head->archive_next;
	  function (head, (bfd *) NULL);
	  head = next;
	}
    }
  else
    {
      struct list *ptr;

      /* This may appear to be a baroque way of accomplishing what we
	 want.  however we have to iterate over the filenames in order
	 to notice where a filename is requested but does not exist in
	 the archive.  Ditto mapping over each file each time -- we
	 want to hack multiple references.  */
      for (ptr = list; ptr; ptr = ptr->next)
	{
	  bfd_boolean found = FALSE;
	  bfd *prev = arch;

	  for (head = arch->archive_next; head; head = head->archive_next)
	    {
	      if (head->filename != NULL
		  && FILENAME_CMP (ptr->name, head->filename) == 0)
		{
		  found = TRUE;
		  function (head, prev);
		}
	      prev = head;
	    }
	  if (! found)
	    fprintf (stderr, _("No entry %s in archive.\n"), ptr->name);
	}
    }
}
Exemplo n.º 7
0
/*
 * Look for the file in our directory structure.  Return 1 if successful,
 * 0 if not found.  Fill in the size and starting position.
 */
static boolean
find_file(const char *name, library ** lib, long *startp, long *sizep)
{
    int i, j;
    library *lp;

    for (i = 0; i < MAX_LIBS && dlb_libs[i].fdata; i++) {
        lp = &dlb_libs[i];
        for (j = 0; j < lp->nentries; j++) {
            if (FILENAME_CMP(name, lp->dir[j].fname) == 0) {
                *lib = lp;
                *startp = lp->dir[j].foffset;
                *sizep = lp->dir[j].fsize;
                return TRUE;
            }
        }
    }
    *lib = NULL;
    *startp = *sizep = 0;
    return FALSE;
}
Exemplo n.º 8
0
static bfd_boolean
is_sysrooted_pathname (const char *name)
{
  char *realname;
  int len;
  bfd_boolean result;

  if (ld_canon_sysroot == NULL)
    return FALSE;

  realname = lrealpath (name);
  len = strlen (realname);
  result = FALSE;
  if (len > ld_canon_sysroot_len
      && IS_DIR_SEPARATOR (realname[ld_canon_sysroot_len]))
    {
      realname[ld_canon_sysroot_len] = '\0';
      result = FILENAME_CMP (ld_canon_sysroot, realname) == 0;
    }

  free (realname);
  return result;
}
Exemplo n.º 9
0
int main(int argc, char *argv[])
{
    int i, r;
    int ap=2;				/* argument pointer */
    int cp;				/* command pointer */
    int iseen=0, fseen=0, verbose=0;	/* flags */
    char action=' ';
    library lib;

    if (argc > 0 && argv[0] && *argv[0]) progname = argv[0];

    if (argc<2) {
	usage();
	/* doesn't return */
    }

    for (cp=0; argv[1][cp]; cp++){
	switch(argv[1][cp]){
	    default:
		usage();	/* doesn't return */
	    case '-':	/* silently ignore */
		break;
	    case '?':
	    case 'h':
		verbose_help();
		break;
	    case 'I':
		if (ap == argc) usage();
		list_file=argv[ap++];
		if (iseen)
		    printf("Warning: multiple I options.  Previous ignored.\n");
		iseen=1;
		break;
	    case 'f':
		if (ap == argc) usage();
		library_file=argv[ap++];
		if (fseen)
		    printf("Warning: multiple f options.  Previous ignored.\n");
		fseen=1;
		break;
	    case 'C':
		if (ap == argc) usage();
		if (chdir(argv[ap++])){
		    printf("Can't chdir to %s\n",argv[--ap]);
		    xexit(EXIT_FAILURE);
		}
		break;
	    case 'v':
		verbose=1;
		break;
	    case 't':
	    case 'c':
	    case 'x':
		if (action != ' '){
		    printf("Only one of t,x,c may be specified.\n");
		    usage();
		}
		action=argv[1][cp];
		break;
	}
    }

    if (argv[ap] && iseen){
	printf("Too many arguments.\n");
	xexit(EXIT_FAILURE);
    }

    switch(action){
    default:
	printf("Internal error - action.\n");
	xexit(EXIT_FAILURE);
	break;
    case 't':			/* list archive */
	if (!open_library(library_file, &lib)) {
	    printf("Can't open dlb file\n");
	    xexit(EXIT_FAILURE);
	}

	for (i = 0; i < lib.nentries; i++) {
	    if (verbose)
		printf("%-14s %6ld %6ld\n",
		    lib.dir[i].fname, lib.dir[i].foffset, lib.dir[i].fsize);
	    else
		printf("%s\n", lib.dir[i].fname);
	}

	if (verbose)
	    printf("Revision:%ld  File count:%ld  String size:%ld\n",
		lib.rev, lib.nentries, lib.strsize);

	close_library(&lib);
	xexit(EXIT_SUCCESS);

    case 'x': {			/* extract archive contents */
	int f, n;
	long remainder, total_read;
	char buf[BUFSIZ];

	if (!open_library(library_file, &lib)) {
	    printf("Can't open dlb file\n");
	    xexit(EXIT_FAILURE);
	}

	for (i = 0; i < lib.nentries; i++) {
	    if (argv[ap]) {
		/* if files are listed, see if current is wanted */
		int c;
		for (c = ap; c < argc; c++)
		    if (!FILENAME_CMP(lib.dir[i].fname, argv[c])) break;
		if (c == argc) continue;	/* skip */
	    } else if (!FILENAME_CMP(lib.dir[i].fname, DLB_DIRECTORY)) {
		/*
		 * Don't extract the directory unless the user
		 * specifically asks for it.
		 *
		 * Perhaps we should never extract the directory???
		 */
		continue;
	    }
	    fseek(lib.fdata, lib.dir[i].foffset, SEEK_SET);

	    f = open(lib.dir[i].fname, O_WRONLY|O_TRUNC|O_BINARY|O_CREAT, 0640);
	    if (f < 0) {
		printf("Can't create '%s'\n", lib.dir[i].fname);
		xexit(EXIT_FAILURE);
	    }

	    /* read chunks from library and write them out */
	    total_read = 0;
	    do {
		remainder = lib.dir[i].fsize - total_read;
		if (remainder > (long) sizeof(buf))
		    r = (int) sizeof(buf);
		else
		    r = remainder;

		n = fread(buf, 1, r, lib.fdata);
		if (n != r) {
		    printf("Read Error in '%s'\n", lib.dir[i].fname);
		    xexit(EXIT_FAILURE);
		}
		if (write(f, buf, n) != n) {
		    printf("Write Error in '%s'\n", lib.dir[i].fname);
		    xexit(EXIT_FAILURE);
		}

		total_read += n;
	    } while (total_read != lib.dir[i].fsize);

	    close(f);

	    if (verbose) printf("x %s\n", lib.dir[i].fname);
	}

	close_library(&lib);
	xexit(EXIT_SUCCESS);
	}

    case 'c':			/* create archive */
	{
	libdir ld[MAX_DLB_FILES];
	char buf[BUFSIZ];
	int fd, out, nfiles = 0;
	long dir_size, slen, flen, fsiz;
	boolean rewrite_directory = FALSE;

	/*
	 * Get names from either/both an argv list and a file
	 * list.  This does not do any duplicate checking
	 */

	/* get file name in argv list */
	if (argv[ap]) {
	    for ( ; ap < argc; ap++, nfiles++) {
		if (nfiles >= MAX_DLB_FILES) {
		    printf("Too many dlb files!  Stopping at %d.\n",
								MAX_DLB_FILES);
		    xexit(EXIT_FAILURE);
		}
		ld[nfiles].fname = malloc(strlen(argv[ap]) + 1);
		strcpy(ld[nfiles].fname, argv[ap]);
	    }
	}

	if (iseen) {
	    /* want to do a list file */
	    FILE *list = fopen(list_file, "r");
	    if (!list) {
		printf("Can't open %s\n",list_file);
		xexit(EXIT_FAILURE);
	    }

	    /* get file names, one per line */
	    for ( ; fgets(buf, sizeof(buf), list); nfiles++) {
		if (nfiles >= MAX_DLB_FILES) {
		    printf("Too many dlb files!  Stopping at %d.\n",
								MAX_DLB_FILES);
		    xexit(EXIT_FAILURE);
		}
		*(eos(buf)-1) = '\0';	/* strip newline */
		ld[nfiles].fname = malloc(strlen(buf) + 1);
		strcpy(ld[nfiles].fname, buf);
	    }
	    fclose(list);
	}

	if (nfiles == 0) {
	    printf("No files to archive\n");
	    xexit(EXIT_FAILURE);
	}


	/*
	 * Get file sizes and name string length.  Don't include
	 * the directory information yet.
	 */
	for (i = 0, slen = 0, flen = 0; i < nfiles; i++) {
	    fd = open(ld[i].fname, O_RDONLY|O_BINARY, 0);
	    if (fd < 0) {
		printf("Can't open %s\n", ld[i].fname);
		xexit(EXIT_FAILURE);
	    }
	    ld[i].fsize = lseek(fd, 0, SEEK_END);
	    ld[i].foffset = flen;

	    slen += strlen(ld[i].fname);	/* don't add null (yet) */
	    flen += ld[i].fsize;
	    close(fd);
	}

	/* open output file */
	out = open(library_file, O_RDWR|O_TRUNC|O_BINARY|O_CREAT, FCMASK);
	if (out < 0) {
	    printf("Can't open %s for output\n", library_file);
	    xexit(EXIT_FAILURE);
	}

	/* caculate directory size */
	dir_size = 40			/* header line (see below) */
		   + ((nfiles+1)*11)	/* handling+file offset+SP+newline */
		   + slen+strlen(DLB_DIRECTORY); /* file names */

	/* write directory */
	write_dlb_directory(out, nfiles, ld, slen, dir_size, flen);

	flen = 0L;
	/* write each file */
	for (i = 0; i < nfiles; i++) {
	    fd = open(ld[i].fname, O_RDONLY|O_BINARY, 0);
	    if (fd < 0) {
		printf("Can't open input file '%s'\n", ld[i].fname);
		xexit(EXIT_FAILURE);
	    }
	    if (verbose) printf("%s\n",ld[i].fname);

	    fsiz = 0L;
	    while ((r = read(fd, buf, sizeof buf)) != 0) {
		if (r == -1) {
		    printf("Read Error in '%s'\n", ld[i].fname);
		    xexit(EXIT_FAILURE);
		}
		if (write(out, buf, r) != r) {
		    printf("Write Error in '%s'\n", ld[i].fname);
		    xexit(EXIT_FAILURE);
		}
		fsiz += r;
	    }
	    close(fd);
	    if (fsiz != ld[i].fsize) rewrite_directory = TRUE;
	    /* in case directory rewrite is needed */
	    ld[i].fsize = fsiz;
	    ld[i].foffset = flen;
	    flen += fsiz;
	}

	if (rewrite_directory) {
	    if (verbose) printf("(rewriting dlb directory info)\n");
	    lseek(out, 0, SEEK_SET);	/* rewind */
	    write_dlb_directory(out, nfiles, ld, slen, dir_size, flen);
	}

	for (i = 0; i < nfiles; i++)
	    free(ld[i].fname),  ld[i].fname = 0;

	close(out);
	xexit(EXIT_SUCCESS);
	}
    }

    xexit(EXIT_SUCCESS);
    /*NOTREACHED*/
    return 0;
}