fix formatting in rc/libruntime/target/linux/jerry-libc.c

This commit is contained in:
e.gavrin
2014-08-11 11:33:42 +04:00
parent 3a388b07a1
commit 4b651ab427
2 changed files with 102 additions and 91 deletions
+1 -1
View File
@@ -365,7 +365,7 @@ $(JERRY_TARGETS):
@rm -rf $(TARGET_DIR) @rm -rf $(TARGET_DIR)
@cppcheck $(DEFINES_JERRY) $(SOURCES_JERRY_C) $(INCLUDES_JERRY) $(INCLUDES_THIRDPARTY) \ @cppcheck $(DEFINES_JERRY) $(SOURCES_JERRY_C) $(INCLUDES_JERRY) $(INCLUDES_THIRDPARTY) \
--error-exitcode=1 --std=c99 --enable=all --suppress=missingIncludeSystem --suppress=unusedFunction 1>/dev/null --error-exitcode=1 --std=c99 --enable=all --suppress=missingIncludeSystem --suppress=unusedFunction 1>/dev/null
@vera++ -r ./tools/vera++ -p jerry $(SOURCES_JERRY_C) $(SOURCES_JERRY_H) -e @vera++ -r ./tools/vera++ -p jerry $(SOURCES_JERRY_C) $(SOURCES_JERRY_H) -e --summary 1>/dev/null
@mkdir -p $(TARGET_DIR) @mkdir -p $(TARGET_DIR)
@mkdir -p $(TARGET_DIR)/obj @mkdir -p $(TARGET_DIR)/obj
@source_index=0; \ @source_index=0; \
+101 -90
View File
@@ -26,11 +26,11 @@
#ifdef __TARGET_HOST_x64 #ifdef __TARGET_HOST_x64
# include "asm_x64.h" # include "asm_x64.h"
#elif defined(__TARGET_HOST_x86) #elif defined (__TARGET_HOST_x86)
# include "asm_x86.h" # include "asm_x86.h"
#endif /* !__TARGET_HOST_x64 && TARGET_HOST_x86 */ #endif /* !__TARGET_HOST_x64 && TARGET_HOST_x86 */
FIXME( Rename __unused ) FIXME (Rename __unused)
#undef __unused #undef __unused
#include <unistd.h> #include <unistd.h>
@@ -42,15 +42,16 @@ FIXME( Rename __unused )
/** /**
* Exit program with ERR_SYSCALL if syscall_ret_val is negative * Exit program with ERR_SYSCALL if syscall_ret_val is negative
*/ */
#define LIBC_EXIT_ON_ERROR( syscall_ret_val) \ #define LIBC_EXIT_ON_ERROR (syscall_ret_val) \
if ( unlikely( ( syscall_ret_val ) < 0 ) ) \ if (unlikely ((syscall_ret_val) < 0)) \
{ \ { \
__exit( -ERR_SYSCALL); \ __exit (-ERR_SYSCALL); \
} }
static long int syscall_1( long int syscall_no, long int arg1); static long int syscall_1 (long int syscall_no, long int arg1);
static long int syscall_2( long int syscall_no, long int arg1, long int arg2); static long int syscall_2 (long int syscall_no, long int arg1, long int arg2);
static long int syscall_3( long int syscall_no, long int arg1, long int arg2, long int arg3); static long int syscall_3 (long int syscall_no, long int arg1,
long int arg2, long int arg3);
/** /**
* System call with one argument. * System call with one argument.
@@ -58,14 +59,14 @@ static long int syscall_3( long int syscall_no, long int arg1, long int arg2, lo
* @return syscall's return value * @return syscall's return value
*/ */
static long int static long int
syscall_1( long int syscall_no, /**< syscall number */ syscall_1 (long int syscall_no, /**< syscall number */
long int arg1) /**< argument */ long int arg1) /**< argument */
{ {
long int ret; long int ret;
SYSCALL_1( syscall_no, arg1, ret); SYSCALL_1 (syscall_no, arg1, ret);
LIBC_EXIT_ON_ERROR( ret ); LIBC_EXIT_ON_ERROR (ret);
return ret; return ret;
} /* syscall_1 */ } /* syscall_1 */
@@ -76,15 +77,15 @@ syscall_1( long int syscall_no, /**< syscall number */
* @return syscall's return value * @return syscall's return value
*/ */
static long int static long int
syscall_2( long int syscall_no, /**< syscall number */ syscall_2 (long int syscall_no, /**< syscall number */
long int arg1, /**< first argument */ long int arg1, /**< first argument */
long int arg2) /**< second argument */ long int arg2) /**< second argument */
{ {
long int ret; long int ret;
SYSCALL_2( syscall_no, arg1, arg2, ret); SYSCALL_2 (syscall_no, arg1, arg2, ret);
LIBC_EXIT_ON_ERROR( ret ); LIBC_EXIT_ON_ERROR (ret);
return ret; return ret;
} /* syscall_2 */ } /* syscall_2 */
@@ -95,25 +96,27 @@ syscall_2( long int syscall_no, /**< syscall number */
* @return syscall's return value * @return syscall's return value
*/ */
static long int static long int
syscall_3( long int syscall_no, /**< syscall number */ syscall_3 (long int syscall_no, /**< syscall number */
long int arg1, /**< first argument */ long int arg1, /**< first argument */
long int arg2, /**< second argument */ long int arg2, /**< second argument */
long int arg3) /**< third argument */ long int arg3) /**< third argument */
{ {
long int ret; long int ret;
SYSCALL_3( syscall_no, arg1, arg2, arg3, ret); SYSCALL_3 (syscall_no, arg1, arg2, arg3, ret);
LIBC_EXIT_ON_ERROR( ret ); LIBC_EXIT_ON_ERROR (ret);
return ret; return ret;
} /* syscall_3 */ } /* syscall_3 */
/** Output of character. Writes the character c, cast to an unsigned char, to stdout. */ /**
* Output of character. Writes the character c, cast to an unsigned char,
* to stdout. */
int int
__putchar (int c) __putchar (int c)
{ {
__fwrite( &c, 1, sizeof(char), LIBC_STDOUT); __fwrite (&c, 1, sizeof (char), LIBC_STDOUT);
return c; return c;
} /* __putchar */ } /* __putchar */
@@ -124,13 +127,13 @@ __putchar (int c)
void __noreturn void __noreturn
__exit (int status) /**< status code */ __exit (int status) /**< status code */
{ {
syscall_1( __NR_close, (long int)LIBC_STDIN); syscall_1 (__NR_close, (long int)LIBC_STDIN);
syscall_1( __NR_close, (long int)LIBC_STDOUT); syscall_1 (__NR_close, (long int)LIBC_STDOUT);
syscall_1( __NR_close, (long int)LIBC_STDERR); syscall_1 (__NR_close, (long int)LIBC_STDERR);
syscall_1( __NR_exit_group, status); syscall_1 (__NR_exit_group, status);
while ( true ) while (true)
{ {
/* unreachable */ /* unreachable */
} }
@@ -143,8 +146,8 @@ __exit (int status) /**< status code */
* NULL - otherwise * NULL - otherwise
*/ */
_FILE* _FILE*
__fopen(const char *path, /**< file path */ __fopen (const char *path, /**< file path */
const char *mode) /**< file open mode */ const char *mode) /**< file open mode */
{ {
bool may_read = false, bool may_read = false,
may_write = false, may_write = false,
@@ -152,10 +155,10 @@ __fopen(const char *path, /**< file path */
create_if_not_exist = false, create_if_not_exist = false,
position_at_end = false; position_at_end = false;
JERRY_ASSERT( path != NULL && mode != NULL ); JERRY_ASSERT (path != NULL && mode != NULL);
JERRY_ASSERT( mode[1] == '+' || mode[1] == '\0' ); JERRY_ASSERT (mode[1] == '+' || mode[1] == '\0');
switch( mode[0] ) switch (mode[0])
{ {
case 'r': case 'r':
may_read = true; may_read = true;
@@ -171,60 +174,60 @@ __fopen(const char *path, /**< file path */
may_write = true; may_write = true;
position_at_end = true; position_at_end = true;
create_if_not_exist = true; create_if_not_exist = true;
if ( mode[1] == '+' ) if (mode[1] == '+')
{ {
JERRY_UNIMPLEMENTED(); JERRY_UNIMPLEMENTED ();
} }
break; break;
default: default:
JERRY_UNREACHABLE(); JERRY_UNREACHABLE ();
} }
int flags = 0; int flags = 0;
int access = S_IRUSR | S_IWUSR; int access = S_IRUSR | S_IWUSR;
if ( may_read && !may_write ) if (may_read && !may_write)
{ {
flags = O_RDONLY; flags = O_RDONLY;
} }
else if ( !may_read && may_write ) else if (!may_read && may_write)
{ {
flags = O_WRONLY; flags = O_WRONLY;
} }
else else
{ {
JERRY_ASSERT( may_read && may_write ); JERRY_ASSERT (may_read && may_write);
flags = O_RDWR; flags = O_RDWR;
} }
if ( truncate ) if (truncate)
{ {
flags |= O_TRUNC; flags |= O_TRUNC;
} }
if ( create_if_not_exist ) if (create_if_not_exist)
{ {
flags |= O_CREAT; flags |= O_CREAT;
} }
if ( position_at_end ) if (position_at_end)
{ {
flags |= O_APPEND; flags |= O_APPEND;
} }
long int ret = syscall_3( __NR_open, (long int)path, flags, access); long int ret = syscall_3 (__NR_open, (long int)path, flags, access);
return (void*)(uintptr_t)(ret); return (void*)(uintptr_t) (ret);
} /* __fopen */ } /* __fopen */
/** /**
* The rewind() function sets the file position indicator * The rewind () function sets the file position indicator
* for the stream pointed to by STREAM to the beginning of the file. * for the stream pointed to by STREAM to the beginning of the file.
*/ */
void void
__rewind (_FILE *stream) /**< stream pointer */ __rewind (_FILE *stream) /**< stream pointer */
{ {
syscall_3( __NR_lseek, (long int)stream, 0, SEEK_SET); syscall_3 (__NR_lseek, (long int)stream, 0, SEEK_SET);
} /* __rewind */ } /* __rewind */
/** /**
@@ -234,9 +237,9 @@ __rewind (_FILE *stream) /**< stream pointer */
* non-zero value - otherwise. * non-zero value - otherwise.
*/ */
int int
__fclose(_FILE *fp) /**< stream pointer */ __fclose (_FILE *fp) /**< stream pointer */
{ {
syscall_2( __NR_close, (long int)fp, 0); syscall_2 (__NR_close, (long int)fp, 0);
return 0; return 0;
} /* __fclose */ } /* __fclose */
@@ -245,13 +248,13 @@ __fclose(_FILE *fp) /**< stream pointer */
* fseek * fseek
*/ */
int int
__fseek(_FILE * fp, /**< stream pointer */ __fseek (_FILE * fp, /**< stream pointer */
long offset, /**< offset */ long offset, /**< offset */
_whence_t whence) /**< specifies position type _whence_t whence) /**< specifies position type
to add offset to */ to add offset to */
{ {
int whence_real = SEEK_CUR; int whence_real = SEEK_CUR;
switch ( whence ) switch (whence)
{ {
case __SEEK_SET: case __SEEK_SET:
whence_real = SEEK_SET; whence_real = SEEK_SET;
@@ -264,7 +267,7 @@ __fseek(_FILE * fp, /**< stream pointer */
break; break;
} }
syscall_3( __NR_lseek, (long int)fp, offset, whence_real); syscall_3 (__NR_lseek, (long int)fp, offset, whence_real);
return 0; return 0;
} /* __fseek */ } /* __fseek */
@@ -273,9 +276,9 @@ __fseek(_FILE * fp, /**< stream pointer */
* ftell * ftell
*/ */
long long
__ftell(_FILE * fp) /**< stream pointer */ __ftell (_FILE * fp) /**< stream pointer */
{ {
long int ret = syscall_3( __NR_lseek, (long int)fp, 0, SEEK_CUR); long int ret = syscall_3 (__NR_lseek, (long int)fp, 0, SEEK_CUR);
return ret; return ret;
} /* __ftell */ } /* __ftell */
@@ -286,17 +289,20 @@ __ftell(_FILE * fp) /**< stream pointer */
* @return number of bytes read * @return number of bytes read
*/ */
size_t size_t
__fread(void *ptr, /**< address of buffer to read to */ __fread (void *ptr, /**< address of buffer to read to */
size_t size, /**< size of elements to read */ size_t size, /**< size of elements to read */
size_t nmemb, /**< number of elements to read */ size_t nmemb, /**< number of elements to read */
_FILE *stream) /**< stream pointer */ _FILE *stream) /**< stream pointer */
{ {
long int ret; long int ret;
size_t bytes_read = 0; size_t bytes_read = 0;
do do
{ {
ret = syscall_3( __NR_read, (long int)stream, (long int) ((uint8_t*)ptr + bytes_read), (long int) (size * nmemb - bytes_read)); ret = syscall_3 (
__NR_read,
(long int)stream, (long int) ((uint8_t*)ptr + bytes_read),
(long int) (size * nmemb - bytes_read));
bytes_read += (size_t)ret; bytes_read += (size_t)ret;
} while (bytes_read != size * nmemb && ret != 0); } while (bytes_read != size * nmemb && ret != 0);
@@ -310,16 +316,19 @@ __fread(void *ptr, /**< address of buffer to read to */
* @return number of bytes written * @return number of bytes written
*/ */
size_t size_t
__fwrite(const void *ptr, /**< data to write */ __fwrite (const void *ptr, /**< data to write */
size_t size, /**< size of elements to write */ size_t size, /**< size of elements to write */
size_t nmemb, /**< number of elements */ size_t nmemb, /**< number of elements */
_FILE *stream) /**< stream pointer */ _FILE *stream) /**< stream pointer */
{ {
size_t bytes_written = 0; size_t bytes_written = 0;
do do
{ {
long int ret = syscall_3( __NR_write, (long int)stream, (long int) ((uint8_t*)ptr + bytes_written), (long int) (size * nmemb - bytes_written)); long int ret = syscall_3 (
__NR_write, (long int)stream,
(long int) ((uint8_t*)ptr + bytes_written),
(long int) (size * nmemb - bytes_written));
bytes_written += (size_t)ret; bytes_written += (size_t)ret;
} while (bytes_written != size * nmemb); } while (bytes_written != size * nmemb);
@@ -327,7 +336,7 @@ __fwrite(const void *ptr, /**< data to write */
return bytes_written; return bytes_written;
} /* __fwrite */ } /* __fwrite */
#elif defined(LIBC_MUSL) #elif defined (LIBC_MUSL)
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -336,18 +345,20 @@ const _FILE **libc_stdin = (void*)&stdin;
const _FILE **libc_stdout = (void*)&stdout; const _FILE **libc_stdout = (void*)&stdout;
const _FILE **libc_stderr = (void*)&stderr; const _FILE **libc_stderr = (void*)&stderr;
/** Output of character. Writes the character c, cast to an unsigned char, to stdout. */ /**
* Output of character. Writes the character c, cast to an unsigned char,
* to stdout. */
int int
__putchar (int c) __putchar (int c)
{ {
return putchar( c); return putchar (c);
} /* __putchar */ } /* __putchar */
/** exit - cause normal process termination */ /** exit - cause normal process termination */
void __noreturn void __noreturn
__exit (int status) __exit (int status)
{ {
exit( status); exit (status);
} /* __exit */ } /* __exit */
/** /**
@@ -357,14 +368,14 @@ __exit (int status)
* NULL - otherwise * NULL - otherwise
*/ */
_FILE* _FILE*
__fopen(const char *path, /**< file path */ __fopen (const char *path, /**< file path */
const char *mode) /**< file open mode */ const char *mode) /**< file open mode */
{ {
return fopen( path, mode); return fopen (path, mode);
} /* __fopen */ } /* __fopen */
/** The rewind() function sets the file position /** The rewind () function sets the file position
indicator for the stream pointed to by STREAM to the beginning of the file. */ indicator for the stream pointed to by STREAM to the beginning of the file. */
void void
__rewind (_FILE *stream) __rewind (_FILE *stream)
{ {
@@ -378,22 +389,22 @@ __rewind (_FILE *stream)
* non-zero value - otherwise. * non-zero value - otherwise.
*/ */
int int
__fclose(_FILE *fp) /**< stream pointer */ __fclose (_FILE *fp) /**< stream pointer */
{ {
return fclose( fp); return fclose (fp);
} /* __fclose */ } /* __fclose */
/** /**
* fseek * fseek
*/ */
int int
__fseek(_FILE * fp, /**< stream pointer */ __fseek (_FILE * fp, /**< stream pointer */
long offset, /**< offset */ long offset, /**< offset */
_whence_t whence) /**< specifies position type _whence_t whence) /**< specifies position type
to add offset to */ to add offset to */
{ {
int whence_real = SEEK_CUR; int whence_real = SEEK_CUR;
switch ( whence ) switch (whence)
{ {
case __SEEK_SET: case __SEEK_SET:
whence_real = SEEK_SET; whence_real = SEEK_SET;
@@ -406,16 +417,16 @@ __fseek(_FILE * fp, /**< stream pointer */
break; break;
} }
return fseek( fp, offset, whence_real); return fseek (fp, offset, whence_real);
} /* __fseek */ } /* __fseek */
/** /**
* ftell * ftell
*/ */
long long
__ftell(_FILE * fp) /**< stream pointer */ __ftell (_FILE * fp) /**< stream pointer */
{ {
return ftell( fp); return ftell (fp);
} /* __ftell */ } /* __ftell */
/** /**
@@ -424,12 +435,12 @@ __ftell(_FILE * fp) /**< stream pointer */
* @return number of bytes read * @return number of bytes read
*/ */
size_t size_t
__fread(void *ptr, /**< address of buffer to read to */ __fread (void *ptr, /**< address of buffer to read to */
size_t size, /**< size of elements to read */ size_t size, /**< size of elements to read */
size_t nmemb, /**< number of elements to read */ size_t nmemb, /**< number of elements to read */
_FILE *stream) /**< stream pointer */ _FILE *stream) /**< stream pointer */
{ {
return fread(ptr, size, nmemb, stream); return fread (ptr, size, nmemb, stream);
} /* __fread */ } /* __fread */
/** /**
@@ -438,12 +449,12 @@ __fread(void *ptr, /**< address of buffer to read to */
* @return number of bytes written * @return number of bytes written
*/ */
size_t size_t
__fwrite(const void *ptr, /**< data to write */ __fwrite (const void *ptr, /**< data to write */
size_t size, /**< size of elements to write */ size_t size, /**< size of elements to write */
size_t nmemb, /**< number of elements */ size_t nmemb, /**< number of elements */
_FILE *stream) /**< stream pointer */ _FILE *stream) /**< stream pointer */
{ {
return fwrite(ptr, size, nmemb, stream); return fwrite (ptr, size, nmemb, stream);
} /* __fwrite */ } /* __fwrite */
#else /* !LIBC_RAW && !LIBC_MUSL */ #else /* !LIBC_RAW && !LIBC_MUSL */