static int memfile_ftruncate( rtems_libio_t *iop, off_t length ) { IMFS_memfile_t *memfile = IMFS_iop_to_memfile( iop ); /* * POSIX 1003.1b does not specify what happens if you truncate a file * and the new length is greater than the current size. We treat this * as an extend operation. */ if ( length > memfile->File.size ) return IMFS_memfile_extend( memfile, true, length ); /* * The in-memory files do not currently reclaim memory until the file is * deleted. So we leave the previously allocated blocks in place for * future use and just set the length. */ memfile->File.size = length; IMFS_mtime_ctime_update( &memfile->File.Node ); return 0; }
static ssize_t memfile_write( rtems_libio_t *iop, const void *buffer, size_t count ) { IMFS_memfile_t *memfile = IMFS_iop_to_memfile( iop ); ssize_t status; if (rtems_libio_iop_is_append(iop)) iop->offset = memfile->File.size; status = IMFS_memfile_write( memfile, iop->offset, buffer, count ); if ( status > 0 ) iop->offset += status; return status; }
static ssize_t memfile_write( rtems_libio_t *iop, const void *buffer, size_t count ) { IMFS_memfile_t *memfile = IMFS_iop_to_memfile( iop ); ssize_t status; if ((iop->flags & LIBIO_FLAGS_APPEND) != 0) iop->offset = memfile->File.size; status = IMFS_memfile_write( memfile, iop->offset, buffer, count ); if ( status > 0 ) iop->offset += status; return status; }