Fix strncmp, fread and fwrite in jerry-libc.
JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
This commit is contained in:
@@ -197,6 +197,12 @@ int
|
|||||||
strncmp (const char *s1, const char *s2, size_t n)
|
strncmp (const char *s1, const char *s2, size_t n)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
|
if (n == 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (s1 == NULL)
|
if (s1 == NULL)
|
||||||
{
|
{
|
||||||
if (s2 != NULL)
|
if (s2 != NULL)
|
||||||
|
|||||||
@@ -322,7 +322,7 @@ ftell (FILE * fp) /**< stream pointer */
|
|||||||
/**
|
/**
|
||||||
* fread
|
* fread
|
||||||
*
|
*
|
||||||
* @return number of bytes read
|
* @return number of elements read
|
||||||
*/
|
*/
|
||||||
size_t
|
size_t
|
||||||
fread (void *ptr, /**< address of buffer to read to */
|
fread (void *ptr, /**< address of buffer to read to */
|
||||||
@@ -333,6 +333,11 @@ fread (void *ptr, /**< address of buffer to read to */
|
|||||||
long int ret;
|
long int ret;
|
||||||
size_t bytes_read = 0;
|
size_t bytes_read = 0;
|
||||||
|
|
||||||
|
if (size == 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
ret = syscall_3 (__NR_read,
|
ret = syscall_3 (__NR_read,
|
||||||
@@ -344,13 +349,13 @@ fread (void *ptr, /**< address of buffer to read to */
|
|||||||
}
|
}
|
||||||
while (bytes_read != size * nmemb && ret != 0);
|
while (bytes_read != size * nmemb && ret != 0);
|
||||||
|
|
||||||
return bytes_read;
|
return bytes_read / size;
|
||||||
} /* fread */
|
} /* fread */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fwrite
|
* fwrite
|
||||||
*
|
*
|
||||||
* @return number of bytes written
|
* @return number of elements written
|
||||||
*/
|
*/
|
||||||
size_t
|
size_t
|
||||||
fwrite (const void *ptr, /**< data to write */
|
fwrite (const void *ptr, /**< data to write */
|
||||||
@@ -360,6 +365,11 @@ fwrite (const void *ptr, /**< data to write */
|
|||||||
{
|
{
|
||||||
size_t bytes_written = 0;
|
size_t bytes_written = 0;
|
||||||
|
|
||||||
|
if (size == 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
long int ret = syscall_3 (__NR_write,
|
long int ret = syscall_3 (__NR_write,
|
||||||
@@ -371,7 +381,7 @@ fwrite (const void *ptr, /**< data to write */
|
|||||||
}
|
}
|
||||||
while (bytes_written != size * nmemb);
|
while (bytes_written != size * nmemb);
|
||||||
|
|
||||||
return bytes_written;
|
return bytes_written / size;
|
||||||
} /* fwrite */
|
} /* fwrite */
|
||||||
|
|
||||||
// FIXME
|
// FIXME
|
||||||
|
|||||||
Reference in New Issue
Block a user