Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions targets/tizenrt-artik053/apps/jerryscript/jerry_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,75 @@ jerry_port_print_char (char c) /**< the character to print */
printf ("%c", c);
} /* jerry_port_print_char */

#ifndef CONFIG_DISABLE_ES2015_MODULE_SYSTEM
/**
* Determines the size of the given file.
* @return size of the file
*/
static size_t
jerry_port_get_file_size (FILE *file_p) /**< opened file */
{
fseek (file_p, 0, SEEK_END);
long size = ftell (file_p);
fseek (file_p, 0, SEEK_SET);

return (size_t) size;
} /* jerry_port_get_file_size */

/**
* Opens file with the given path and reads its source.
* @return the source of the file
*/
uint8_t *
jerry_port_read_source (const char *file_name_p, /**< file name */
size_t *out_size_p) /**< [out] read bytes */
{
FILE *file_p = fopen (file_name_p, "rb");

if (file_p == NULL)
{
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: failed to open file: %s\n", file_name_p);
return NULL;
}

size_t file_size = jerry_port_get_file_size (file_p);
uint8_t *buffer_p = (uint8_t *) malloc (file_size);

if (buffer_p == NULL)
{
fclose (file_p);

jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: failed to allocate memory for module");
return NULL;
}

size_t bytes_read = fread (buffer_p, 1u, file_size, file_p);

if (!bytes_read)
{
fclose (file_p);
free (buffer_p);

jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: failed to read file: %s\n", file_name_p);
return NULL;
}

fclose (file_p);
*out_size_p = bytes_read;

return buffer_p;
} /* jerry_port_read_source */

/**
* Release the previously opened file's content.
*/
void
jerry_port_release_source (uint8_t *buffer_p) /**< buffer to free */
{
free (buffer_p);
} /* jerry_port_release_source */
#endif /* !CONFIG_DISABLE_ES2015_MODULE_SYSTEM */

/**
* Main program.
*
Expand Down