ld/src/ld/debugline.c
/* Return the pathname of the file in S, or NULL on error. 
   The result will have been allocated with malloc.  */
Return the pathname of the file in S, or NULL on error.
The result will have been allocated with malloc.
Return the pathname of the file in S or NULL on error . The result will have been allocated with malloc .
char *
line_file (struct line_reader_data *lnd, uint64_t n)
{
  const uint8_t * prev_pos = lnd->cpos;
  size_t filelen, dirlen;
  uint64_t dir;
  char * result;
  const char * dirpath;
  if (n == 0
      || n > lnd->numfile)
    return NULL;
  filelen = strlen ((const char *)lnd->filenames[n - 1]);
  lnd->cpos = lnd->filenames[n - 1] + filelen + 1;
  dir = read_uleb128 (lnd);
  lnd->cpos = prev_pos;
  if (dir == 0
      || lnd->filenames[n - 1][0] == '/')
    return strdup ((const char *)lnd->filenames[n - 1]);
  else if (dir > lnd->numdir)
    return NULL;
  dirpath = (const char *)lnd->dirnames[dir - 1];
  dirlen = strlen (dirpath);
  if ( dirpath[dirlen-1] == '/' )
    --dirlen;
  if ( (dirpath[dirlen-1] == '.') && (dirpath[dirlen-2] == '/') )
    dirlen -= 2;
  result = malloc (dirlen + filelen + 2);
  memcpy (result, dirpath, dirlen);
  result[dirlen] = '/';
  memcpy (result + dirlen + 1, lnd->filenames[n - 1], filelen);
  result[dirlen + 1 + filelen] = '\0';
  return result;
}
char * line_file ( struct line_reader_data * lnd , uint64_t n ) { const uint8_t * prev_pos = lnd -> cpos ; size_t filelen , dirlen ; uint64_t dir ; char * result ; const char * dirpath ; if ( n == 0 || n > lnd -> numfile ) return NULL ; filelen = strlen ( ( const char * ) lnd -> filenames [ n - 1 ] ) ; lnd -> cpos = lnd -> filenames [ n - 1 ] + filelen + 1 ; dir = read_uleb128 ( lnd ) ; lnd -> cpos = prev_pos ; if ( dir == 0 || lnd -> filenames [ n - 1 ] [ 0 ] == ' ' ) return strdup ( ( const char * ) lnd -> filenames [ n - 1 ] ) ; else if ( dir > lnd -> numdir ) return NULL ; dirpath = ( const char * ) lnd -> dirnames [ dir - 1 ] ; dirlen = strlen ( dirpath ) ; if ( dirpath [ dirlen - 1 ] == ' ' ) -- dirlen ; if ( ( dirpath [ dirlen - 1 ] == ' ' ) && ( dirpath [ dirlen - 2 ] == ' ' ) ) dirlen -= 2 ; result = malloc ( dirlen + filelen + 2 ) ; memcpy ( result , dirpath , dirlen ) ; result [ dirlen ] = ' ' ; memcpy ( result + dirlen + 1 , lnd -> filenames [ n - 1 ] , filelen ) ; result [ dirlen + 1 + filelen ] = ' \0 ' ; return result ; }
Return the pathname of the file in S, or NULL on error.
Return the pathname of the file in S or NULL on error .
/* I'm not sure if this is actually an error.  */