f3s_ram_page()

In the socket services page() function, we first check that the given offset doesn't exceed the bounds of the allocated memory, and then assign the window size if required. The function returns the offset address modulo the window size.

/*
** File: f3s_ram_page.c
**
** Description:
**
** This file contains the page function for the ram library
**
*/
#include "f3s_ram.h"

uint8_t *f3s_ram_page(f3s_socket_t *socket,
                      uint32_t flags,
                      uint32_t offset,
                      int32_t *size)
{
   /* check if offset does not fit in array */
   if (offset >= socket->window_size)
   {
      errno = ERANGE;
      return (NULL);
   }

   /* select proper page */
   socket->window_offset = offset & ~(socket->window_size - 1);

   /* set size properly */
   *size = min((offset & ~(socket->window_size - 1)) +
               socket->window_size - offset, *size);

   /* return memory pointer */
   return (socket->memory + offset);
}


The socket services status() and close() don't do anything interesting in this driver.