Beispiel #1
0
            /*-------------------------------------------------
            *   buffer - return a pointer to the file buffer;
            *   if it doesn't yet exist, load the file into
            *   RAM first
            *  -------------------------------------------------*/
            public override MemoryU8 buffer()  //void const *buffer()
            {
                // if we already have data, just return it
                if (!is_loaded() && length() != 0)
                {
                    // allocate some memory
                    MemoryU8 buf = allocate();  //void *const buf = allocate();
                    if (buf == null)
                    {
                        return(null);
                    }

                    // read the file
                    uint64_t  bytes_read = 0;
                    uint64_t  remaining  = length();
                    PointerU8 ptr        = new PointerU8(buf); //std::uint8_t *ptr = reinterpret_cast<std::uint8_t *>(buf);
                    while (remaining != 0)
                    {
                        uint32_t            chunk = std.min(uint32_t.MaxValue, (uint32_t)remaining); //std::uint32_t const chunk = std::min<std::common_type_t<std::uint32_t, std::size_t> >(std::numeric_limits<std::uint32_t>::max(), remaining);
                        uint32_t            read_length;
                        std.error_condition filerr = m_file.read(ptr, bytes_read, chunk, out read_length);
                        if (filerr || read_length == 0)
                        {
                            purge();
                            return(base.buffer());
                        }

                        bytes_read += read_length;
                        remaining  -= read_length;
                        ptr        += read_length;
                    }

                    m_file.Dispose();  //m_file.reset(); // close the file because we don't need it anymore
                    m_file = null;
                }

                return(base.buffer());
            }
Beispiel #2
0
 public static void set_osdfile(osd_file osdfile)
 {
     m_osdfile = osdfile;
 }
Beispiel #3
0
 /// \brief Create a new pseudo-terminal (PTY) pair
 ///
 /// \param [out] file Receives the handle of the master side of the
 ///   pseudo-terminal if the operation succeeds.  Not valid if the
 ///   operation fails.
 /// \param [out] name Receives the name of the slave side of the
 ///   pseudo-terminal if the operation succeeds.  Not valid if the
 ///   operation fails.
 /// \return Result of the operation.
 protected abstract std.error_condition openpty(out osd_file file, out string name);  //static std::error_condition openpty(ptr &file, std::string &name);
Beispiel #4
0
        /// \brief Smart pointer to a file handle
        //typedef std::unique_ptr<osd_file> ptr;


        /// \brief Open a new file handle
        ///
        /// This function is called by core_fopen and several other places
        /// in the core to access files. These functions will construct
        /// paths by concatenating various search paths held in the
        /// options.c options database with partial paths specified by the
        /// core.  The core assumes that the path separator is the first
        /// character of the string PATH_SEPARATOR, but does not interpret
        /// any path separators in the search paths, so if you use a
        /// different path separator in a search path, you may get a mixture
        /// of PATH_SEPARATORs (from the core) and alternate path separators
        /// (specified by users and placed into the options database).
        /// \param [in] path Path to the file to open.
        /// \param [in] openflags Combination of #OPEN_FLAG_READ,
        ///   #OPEN_FLAG_WRITE, #OPEN_FLAG_CREATE and
        ///   #OPEN_FLAG_CREATE_PATHS specifying the requested access mode
        ///   and open behaviour.
        /// \param [out] file Receives the file handle if the operation
        ///   succeeds.  Not valid if the operation fails.
        /// \param [out] filesize Receives the size of the opened file if
        ///   the operation succeeded.  Not valid if the operation failed.
        ///   Will be zero for stream-like objects (e.g. TCP sockets or
        ///   named pipes).
        /// \return Result of the operation.
        public abstract std.error_condition open(string path, uint32_t openflags, out osd_file file, out uint64_t filesize);
Beispiel #5
0
 /*-----------------------------------------------------------------------------
 *   osd_file::openpty: create a new PTY pair
 *
 *   Parameters:
 *
 *       file - reference to an osd_file::ptr to receive the handle of the master
 *           side of the newly-created PTY; this is only valid if the function
 *           returns FILERR_NONE
 *
 *       name - reference to string where slave filename will be stored
 *
 *   Return value:
 *
 *       a file_error describing any error that occurred while creating the
 *       PTY, or FILERR_NONE if no error occurred
 *  -----------------------------------------------------------------------------*/
 protected abstract error openpty(out osd_file file, out string name);
Beispiel #6
0
        //typedef std::unique_ptr<osd_file> ptr;


        /*-----------------------------------------------------------------------------
        *   osd_file::open: open a new file.
        *
        *   Parameters:
        *
        *       path - path to the file to open
        *
        *       openflags - some combination of:
        *
        *           OPEN_FLAG_READ - open the file for read access
        *           OPEN_FLAG_WRITE - open the file for write access
        *           OPEN_FLAG_CREATE - create/truncate the file when opening
        *           OPEN_FLAG_CREATE_PATHS - specifies that non-existant paths
        *                   should be created if necessary
        *
        *       file - reference to an osd_file::ptr to receive the newly-opened file
        *           handle; this is only valid if the function returns FILERR_NONE
        *
        *       filesize - reference to a UINT64 to receive the size of the opened
        *           file; this is only valid if the function returns FILERR_NONE
        *
        *   Return value:
        *
        *       a file_error describing any error that occurred while opening
        *       the file, or FILERR_NONE if no error occurred
        *
        *   Notes:
        *
        *       This function is called by core_fopen and several other places in
        *       the core to access files. These functions will construct paths by
        *       concatenating various search paths held in the options.c options
        *       database with partial paths specified by the core. The core assumes
        *       that the path separator is the first character of the string
        *       PATH_SEPARATOR, but does not interpret any path separators in the
        *       search paths, so if you use a different path separator in a search
        *       path, you may get a mixture of PATH_SEPARATORs (from the core) and
        *       alternate path separators (specified by users and placed into the
        *       options database).
        *  -----------------------------------------------------------------------------*/
        public abstract error open(string path, uint32_t openflags, out osd_file file, out uint64_t filesize);
Beispiel #7
0
        // osd_file read/write implementation
        //class osd_file_read_write_adapter : public osd_file_read_adapter, public random_read_write


        //random_read::ptr ram_read(void const *data, std::size_t size) noexcept;
        //random_read::ptr ram_read(void const *data, std::size_t size, std::uint8_t filler) noexcept;
        //random_read::ptr ram_read_copy(void const *data, std::size_t size) noexcept;
        //random_read::ptr ram_read_copy(void const *data, std::size_t size, std::uint8_t filler) noexcept;

        //random_read::ptr stdio_read(FILE *file) noexcept;
        //random_read::ptr stdio_read(FILE *file, std::uint8_t filler) noexcept;
        //random_read::ptr stdio_read_noclose(FILE *file) noexcept;
        //random_read::ptr stdio_read_noclose(FILE *file, std::uint8_t filler) noexcept;

        //random_read_write::ptr stdio_read_write(FILE *file) noexcept;
        //random_read_write::ptr stdio_read_write(FILE *file, std::uint8_t filler) noexcept;
        //random_read_write::ptr stdio_read_write_noclose(FILE *file) noexcept;
        //random_read_write::ptr stdio_read_write_noclose(FILE *file, std::uint8_t filler) noexcept;


        // creating osd_file read adapters

        //random_read::ptr osd_file_read(std::unique_ptr<osd_file> &&file) noexcept;

        public static random_read osd_file_read(osd_file file) //random_read::ptr osd_file_read(osd_file &file) noexcept;
        {
            return(new osd_file_read_adapter(file));           //return random_read::ptr(new (std::nothrow) osd_file_read_adapter(file));
        }
Beispiel #8
0
            //osd_file_read_adapter(osd_file::ptr &&file) noexcept : osd_file_adapter_base(std::move(file))
            //{
            //}

            public osd_file_read_adapter(osd_file file) : base(file)
            {
            }
Beispiel #9
0
            bool m_close;    //bool const m_close;


            //osd_file_adapter_base(osd_file::ptr &&file) noexcept : m_file(file.release()), m_close(true)
            //{
            //    assert(m_file);
            //}

            protected osd_file_adapter_base(osd_file file)
            {
                m_file  = file;
                m_close = false;
            }
Beispiel #10
0
            MemoryU8 m_buffer      = new MemoryU8(FILE_BUFFER_SIZE, true); //std::uint8_t    m_buffer[FILE_BUFFER_SIZE]; // buffer data


            public core_osd_file(uint32_t openmode, osd_file file, uint64_t length)
                : base(openmode, length)
            {
                m_file = file;
            }