Changeset fe19d06 in rtems-tools


Ignore:
Timestamp:
Nov 20, 2012, 11:40:01 PM (7 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
4.10, 4.11, master
Children:
a1d4930
Parents:
fd8a2c5
Message:

Fix archive GNU extension and make image read/write follow POSIX.

Fix the finding of a file name in the GNU extension for long names
in GNU archives so the correct location is referenced.

Made the image read and write routines keep reading if not all the
requested data is read or written due to possible signals.

Location:
linkers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • linkers/rld-files.cpp

    rfd8a2c5 rfe19d06  
    403403
    404404    ssize_t
    405     image::read (uint8_t* buffer, size_t size)
    406     {
    407       ssize_t rsize = ::read (fd (), buffer, size);
    408       if (rsize < 0)
    409         throw rld::error (strerror (errno), "read:" + name ().path ());
    410       return rsize;
     405    image::read (void* buffer_, size_t size)
     406    {
     407      uint8_t* buffer = static_cast <uint8_t*> (buffer_);
     408      size_t   have_read = 0;
     409      size_t   to_read = size;
     410      while (have_read < size)
     411      {
     412        ssize_t rsize = ::read (fd (), buffer, to_read);
     413        if (rsize < 0)
     414          throw rld::error (strerror (errno), "read:" + name ().path ());
     415        if (rsize == 0)
     416          break;
     417        have_read += rsize;
     418        to_read -= rsize;
     419        buffer += rsize;
     420      }
     421      return have_read;
    411422    }
    412423
    413424    ssize_t
    414     image::write (const void* buffer, size_t size)
    415     {
    416       ssize_t wsize = ::write (fd (), buffer, size);
    417       if (wsize < 0)
    418         throw rld::error (strerror (errno), "write:" + name ().path ());
    419       return wsize;
     425    image::write (const void* buffer_, size_t size)
     426    {
     427      const uint8_t* buffer = static_cast <const uint8_t*>  (buffer_);
     428      size_t         have_written = 0;
     429      size_t         to_write = size;
     430      while (have_written < size)
     431      {
     432        ssize_t wsize = ::write (fd (), buffer, to_write);
     433        if (wsize < 0)
     434          throw rld::error (strerror (errno), "write:" + name ().path ());
     435        have_written += wsize;
     436        to_write -= wsize;
     437        buffer += wsize;
     438      }
     439      return have_written;
    420440    }
    421441
     
    488508      #define COPY_FILE_BUFFER_SIZE (8 * 1024)
    489509      uint8_t* buffer = 0;
     510
     511      if (size == 0)
     512        size = in.name ().size ();
     513
    490514      try
    491515      {
     
    793817    archive::create (object_list& objects)
    794818    {
     819      if (rld::verbose () >= RLD_VERBOSE_INFO)
     820        std::cout << "archive::create: " << name ().full ()
     821                  << ", objects: " << objects.size () << std::endl;
     822
    795823      open (true);
    796824
     
    839867            if (oname.length () > rld_archive_fname_size)
    840868            {
    841               size_t pos = extended_file_names.find_first_of (oname + '\n');
     869              size_t pos = extended_file_names.find (oname + '\n');
    842870              if (pos == std::string::npos)
    843871                throw rld_error_at ("extended file name not found");
     
    849877            write_header (oname, 0, 0, 0, 0666, obj.name ().size ());
    850878            obj.seek (0);
    851             copy_file (obj, *this, obj.name ().size ());
     879            copy_file (obj, *this);
    852880          }
    853881          catch (...)
     
    10521080      return archive_;
    10531081    }
    1054 
    1055 #if 0
    1056     int
    1057     object::sections () const
    1058     {
    1059       return ehdr.e_shnum;
    1060     }
    1061 
    1062     int
    1063     object::section_strings () const
    1064     {
    1065       return ehdr.e_shstrndx;
    1066     }
    1067 #endif
    10681082
    10691083    rld::symbols::table&
  • linkers/rld-files.h

    rfd8a2c5 rfe19d06  
    241241
    242242      /**
    243        * The object's offset in the archive.
     243       * The object's offset in the archive or on disk.
    244244       */
    245245      off_t offset () const;
     
    254254      std::string oname_;  //< The object name.
    255255      off_t       offset_; //< The object's offset in the archive.
    256       size_t      size_;   //< The object's size in teh archive.
     256      size_t      size_;   //< The object's size in the archive or on disk.
    257257    };
    258258
     
    309309       * Read a block from the file.
    310310       */
    311       virtual ssize_t read (uint8_t* buffer, size_t size);
     311      virtual ssize_t read (void* buffer, size_t size);
    312312
    313313      /**
     
    781781
    782782    /**
     783     * Copy the in file to the out file.
     784     *
     785     * @param in The input file.
     786     * @param out The output file.
     787     * @param size The amount to copy. If 0 the whole on in is copied.
     788     */
     789    void copy_file (image& in, image& out, size_t size = 0);
     790
     791    /**
    783792     * Find the libraries given the list of libraries as bare name which
    784793     * have 'lib' and '.a' added.
Note: See TracChangeset for help on using the changeset viewer.