mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-10-06 10:59:48 +08:00
cpukit/libcsupport: reformat src with clang-format
excludes cfmakeraw.c, cfmakesane.c, realpath.c Updates #3860. Closes #5355.
This commit is contained in:
committed by
Kinsey Moore
parent
d68ce7ca80
commit
72dd54eaa8
@@ -40,7 +40,7 @@
|
||||
#include <rtems/bspIo.h>
|
||||
#include <rtems.h>
|
||||
|
||||
#if defined(RTEMS_NEWLIB) && !defined(HAVE___ASSERT_FUNC)
|
||||
#if defined( RTEMS_NEWLIB ) && !defined( HAVE___ASSERT_FUNC )
|
||||
#include <assert.h>
|
||||
|
||||
/**
|
||||
@@ -61,12 +61,13 @@ void __assert_func(
|
||||
.failed_expression = failedexpr
|
||||
};
|
||||
|
||||
printk("assertion \"%s\" failed: file \"%s\", line %d%s%s\n",
|
||||
printk(
|
||||
"assertion \"%s\" failed: file \"%s\", line %d%s%s\n",
|
||||
failedexpr,
|
||||
file,
|
||||
line,
|
||||
(func) ? ", function: " : "",
|
||||
(func) ? func : ""
|
||||
( func ) ? ", function: " : "",
|
||||
( func ) ? func : ""
|
||||
);
|
||||
rtems_fatal( RTEMS_FATAL_SOURCE_ASSERT, (rtems_fatal_code) &assert_context );
|
||||
}
|
||||
|
||||
@@ -42,13 +42,13 @@
|
||||
/*
|
||||
* Prototype to avoid warning
|
||||
*/
|
||||
pid_t __getpid(void);
|
||||
pid_t __getpid( void );
|
||||
|
||||
/**
|
||||
* Some C Libraries reference this routine since they think getpid is
|
||||
* a real system call.
|
||||
*/
|
||||
pid_t __getpid(void)
|
||||
pid_t __getpid( void )
|
||||
{
|
||||
return getpid();
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#if defined(RTEMS_NEWLIB)
|
||||
#if defined( RTEMS_NEWLIB )
|
||||
/*
|
||||
* Needed to get the prototype for the newlib helper method
|
||||
*/
|
||||
@@ -49,7 +49,7 @@
|
||||
#include <rtems/score/todimpl.h>
|
||||
#include <rtems/seterr.h>
|
||||
|
||||
#if defined(RTEMS_NEWLIB) && !defined(HAVE_GETTIMEOFDAY)
|
||||
#if defined( RTEMS_NEWLIB ) && !defined( HAVE_GETTIMEOFDAY )
|
||||
|
||||
/**
|
||||
* SVR4 and BSD4.3 extension required by Newlib
|
||||
@@ -62,8 +62,9 @@ int gettimeofday(
|
||||
)
|
||||
{
|
||||
/* struct timezone* tzp = (struct timezone*) __tz; */
|
||||
if ( !tp )
|
||||
if ( !tp ) {
|
||||
rtems_set_errno_and_return_minus_one( EFAULT );
|
||||
}
|
||||
|
||||
/*
|
||||
* POSIX does not seem to allow for not having a TOD so we just
|
||||
@@ -81,7 +82,7 @@ int gettimeofday(
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(RTEMS_NEWLIB) && !defined(HAVE__GETTIMEOFDAY_R)
|
||||
#if defined( RTEMS_NEWLIB ) && !defined( HAVE__GETTIMEOFDAY_R )
|
||||
|
||||
#include <sys/reent.h>
|
||||
|
||||
@@ -89,9 +90,9 @@ int gettimeofday(
|
||||
* "Reentrant" version
|
||||
*/
|
||||
int _gettimeofday_r(
|
||||
struct _reent *ignored_reentrancy_stuff RTEMS_UNUSED,
|
||||
struct timeval *tp,
|
||||
void *__tz
|
||||
struct _reent *ignored_reentrancy_stuff RTEMS_UNUSED,
|
||||
struct timeval *tp,
|
||||
void *__tz
|
||||
)
|
||||
{
|
||||
struct timezone *tzp = __tz;
|
||||
|
||||
@@ -58,24 +58,23 @@
|
||||
/**
|
||||
* POSIX 1003.1b 4.5.2 - Get Process Times
|
||||
*/
|
||||
clock_t _times(
|
||||
struct tms *ptms
|
||||
)
|
||||
clock_t _times( struct tms *ptms )
|
||||
{
|
||||
uint32_t tick_interval;
|
||||
sbintime_t uptime;
|
||||
sbintime_t cpu_time_used;
|
||||
|
||||
if ( !ptms )
|
||||
if ( !ptms ) {
|
||||
rtems_set_errno_and_return_minus_one( EFAULT );
|
||||
}
|
||||
|
||||
tick_interval = (uint32_t)
|
||||
(SBT_1US * rtems_configuration_get_microseconds_per_tick());
|
||||
tick_interval =
|
||||
(uint32_t) ( SBT_1US * rtems_configuration_get_microseconds_per_tick() );
|
||||
|
||||
ptms = memset( ptms, 0, sizeof( *ptms ) );
|
||||
|
||||
_TOD_Get_zero_based_uptime( &uptime );
|
||||
ptms->tms_stime = ((clock_t) uptime) / tick_interval;
|
||||
ptms->tms_stime = ( (clock_t) uptime ) / tick_interval;
|
||||
|
||||
/*
|
||||
* RTEMS technically has no notion of system versus user time
|
||||
@@ -84,9 +83,10 @@ clock_t _times(
|
||||
* of ticks since boot and the number of ticks executed by this
|
||||
* this thread.
|
||||
*/
|
||||
cpu_time_used =
|
||||
_Thread_Get_CPU_time_used_after_last_reset( _Thread_Get_executing() );
|
||||
ptms->tms_utime = ((clock_t) cpu_time_used) / tick_interval;
|
||||
cpu_time_used = _Thread_Get_CPU_time_used_after_last_reset(
|
||||
_Thread_Get_executing()
|
||||
);
|
||||
ptms->tms_utime = ( (clock_t) cpu_time_used ) / tick_interval;
|
||||
|
||||
return ptms->tms_stime;
|
||||
}
|
||||
@@ -94,24 +94,19 @@ clock_t _times(
|
||||
/**
|
||||
* times() system call wrapper for _times() above.
|
||||
*/
|
||||
clock_t times(
|
||||
struct tms *ptms
|
||||
)
|
||||
clock_t times( struct tms *ptms )
|
||||
{
|
||||
return _times( ptms );
|
||||
}
|
||||
|
||||
#if defined(RTEMS_NEWLIB)
|
||||
#if defined( RTEMS_NEWLIB )
|
||||
|
||||
#include <reent.h>
|
||||
|
||||
/**
|
||||
* This is the Newlib dependent reentrant version of times().
|
||||
*/
|
||||
clock_t _times_r(
|
||||
struct _reent *ptr RTEMS_UNUSED,
|
||||
struct tms *ptms
|
||||
)
|
||||
clock_t _times_r( struct _reent *ptr RTEMS_UNUSED, struct tms *ptms )
|
||||
{
|
||||
return _times( ptms );
|
||||
}
|
||||
|
||||
@@ -47,9 +47,9 @@
|
||||
|
||||
static int null_handler_open(
|
||||
rtems_libio_t *iop,
|
||||
const char *path,
|
||||
int oflag,
|
||||
mode_t mode
|
||||
const char *path,
|
||||
int oflag,
|
||||
mode_t mode
|
||||
)
|
||||
{
|
||||
(void) iop;
|
||||
@@ -62,7 +62,7 @@ static int null_handler_open(
|
||||
|
||||
static int null_handler_fstat(
|
||||
const rtems_filesystem_location_info_t *pathloc,
|
||||
struct stat *buf
|
||||
struct stat *buf
|
||||
)
|
||||
{
|
||||
(void) pathloc;
|
||||
@@ -101,10 +101,10 @@ static void null_op_lock_or_unlock(
|
||||
|
||||
static int null_op_mknod(
|
||||
const rtems_filesystem_location_info_t *parentloc,
|
||||
const char *name,
|
||||
size_t namelen,
|
||||
mode_t mode,
|
||||
dev_t dev
|
||||
const char *name,
|
||||
size_t namelen,
|
||||
mode_t mode,
|
||||
dev_t dev
|
||||
)
|
||||
{
|
||||
(void) parentloc;
|
||||
@@ -130,8 +130,8 @@ static int null_op_rmnod(
|
||||
static int null_op_link(
|
||||
const rtems_filesystem_location_info_t *parentloc,
|
||||
const rtems_filesystem_location_info_t *targetloc,
|
||||
const char *name,
|
||||
size_t namelen
|
||||
const char *name,
|
||||
size_t namelen
|
||||
)
|
||||
{
|
||||
(void) parentloc;
|
||||
@@ -144,7 +144,7 @@ static int null_op_link(
|
||||
|
||||
static int null_op_fchmod(
|
||||
const rtems_filesystem_location_info_t *pathloc,
|
||||
mode_t mode
|
||||
mode_t mode
|
||||
)
|
||||
{
|
||||
(void) pathloc;
|
||||
@@ -155,8 +155,8 @@ static int null_op_fchmod(
|
||||
|
||||
static int null_op_chown(
|
||||
const rtems_filesystem_location_info_t *loc,
|
||||
uid_t owner,
|
||||
gid_t group
|
||||
uid_t owner,
|
||||
gid_t group
|
||||
)
|
||||
{
|
||||
(void) loc;
|
||||
@@ -166,9 +166,7 @@ static int null_op_chown(
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int null_op_clonenode(
|
||||
rtems_filesystem_location_info_t *loc
|
||||
)
|
||||
static int null_op_clonenode( rtems_filesystem_location_info_t *loc )
|
||||
{
|
||||
(void) loc;
|
||||
|
||||
@@ -177,7 +175,7 @@ static int null_op_clonenode(
|
||||
|
||||
static int null_op_mount(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
const void *data
|
||||
const void *data
|
||||
)
|
||||
{
|
||||
(void) mt_entry;
|
||||
@@ -186,9 +184,7 @@ static int null_op_mount(
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int null_op_unmount(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry
|
||||
)
|
||||
static int null_op_unmount( rtems_filesystem_mount_table_entry_t *mt_entry )
|
||||
{
|
||||
(void) mt_entry;
|
||||
|
||||
@@ -206,7 +202,7 @@ static void null_op_fsunmount_me(
|
||||
|
||||
static int null_op_utimens(
|
||||
const rtems_filesystem_location_info_t *loc,
|
||||
struct timespec times[2]
|
||||
struct timespec times[ 2 ]
|
||||
)
|
||||
{
|
||||
(void) loc;
|
||||
@@ -217,9 +213,9 @@ static int null_op_utimens(
|
||||
|
||||
static int null_op_symlink(
|
||||
const rtems_filesystem_location_info_t *parentloc,
|
||||
const char *name,
|
||||
size_t namelen,
|
||||
const char *target
|
||||
const char *name,
|
||||
size_t namelen,
|
||||
const char *target
|
||||
)
|
||||
{
|
||||
(void) parentloc;
|
||||
@@ -232,8 +228,8 @@ static int null_op_symlink(
|
||||
|
||||
static ssize_t null_op_readlink(
|
||||
const rtems_filesystem_location_info_t *loc,
|
||||
char *buf,
|
||||
size_t bufsize
|
||||
char *buf,
|
||||
size_t bufsize
|
||||
)
|
||||
{
|
||||
(void) loc;
|
||||
@@ -247,8 +243,8 @@ static int null_op_rename(
|
||||
const rtems_filesystem_location_info_t *oldparentloc,
|
||||
const rtems_filesystem_location_info_t *oldloc,
|
||||
const rtems_filesystem_location_info_t *newparentloc,
|
||||
const char *name,
|
||||
size_t namelen
|
||||
const char *name,
|
||||
size_t namelen
|
||||
)
|
||||
{
|
||||
(void) oldparentloc;
|
||||
@@ -306,13 +302,12 @@ rtems_filesystem_mount_table_entry_t rtems_filesystem_null_mt_entry = {
|
||||
};
|
||||
|
||||
rtems_filesystem_global_location_t rtems_filesystem_global_location_null = {
|
||||
.location = {
|
||||
.mt_entry_node = RTEMS_CHAIN_NODE_INITIALIZER_ONE_NODE_CHAIN(
|
||||
&rtems_filesystem_null_mt_entry.location_chain
|
||||
),
|
||||
.handlers = &rtems_filesystem_null_handlers,
|
||||
.mt_entry = &rtems_filesystem_null_mt_entry
|
||||
},
|
||||
.location =
|
||||
{ .mt_entry_node = RTEMS_CHAIN_NODE_INITIALIZER_ONE_NODE_CHAIN(
|
||||
&rtems_filesystem_null_mt_entry.location_chain
|
||||
),
|
||||
.handlers = &rtems_filesystem_null_handlers,
|
||||
.mt_entry = &rtems_filesystem_null_mt_entry },
|
||||
|
||||
/*
|
||||
* The initial reference count accounts for the following references
|
||||
@@ -330,12 +325,12 @@ rtems_user_env_t rtems_global_user_env = {
|
||||
.umask = S_IWGRP | S_IWOTH
|
||||
};
|
||||
|
||||
rtems_user_env_t *rtems_current_user_env_get(void)
|
||||
rtems_user_env_t *rtems_current_user_env_get( void )
|
||||
{
|
||||
Thread_Control *executing = _Thread_Get_executing();
|
||||
Thread_Control *executing = _Thread_Get_executing();
|
||||
rtems_user_env_t *env = executing->user_environment;
|
||||
|
||||
if (env == NULL) {
|
||||
if ( env == NULL ) {
|
||||
return &rtems_global_user_env;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,15 +37,11 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#if defined(RTEMS_NEWLIB) && !defined(HAVE__CALLOC_R)
|
||||
#if defined( RTEMS_NEWLIB ) && !defined( HAVE__CALLOC_R )
|
||||
#include <sys/reent.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void *_calloc_r(
|
||||
struct _reent *ignored,
|
||||
size_t elements,
|
||||
size_t size
|
||||
)
|
||||
void *_calloc_r( struct _reent *ignored, size_t elements, size_t size )
|
||||
{
|
||||
(void) ignored;
|
||||
return calloc( elements, size );
|
||||
|
||||
@@ -37,14 +37,11 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#if defined(RTEMS_NEWLIB) && !defined(HAVE__FREE_R)
|
||||
#if defined( RTEMS_NEWLIB ) && !defined( HAVE__FREE_R )
|
||||
#include <sys/reent.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void _free_r(
|
||||
struct _reent *ignored,
|
||||
void *ptr
|
||||
)
|
||||
void _free_r( struct _reent *ignored, void *ptr )
|
||||
{
|
||||
(void) ignored;
|
||||
free( ptr );
|
||||
|
||||
@@ -32,14 +32,11 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#if defined(RTEMS_NEWLIB) && !defined(HAVE__MALLOC_R)
|
||||
#if defined( RTEMS_NEWLIB ) && !defined( HAVE__MALLOC_R )
|
||||
#include <sys/reent.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void *_malloc_r(
|
||||
struct _reent *ignored,
|
||||
size_t size
|
||||
)
|
||||
void *_malloc_r( struct _reent *ignored, size_t size )
|
||||
{
|
||||
(void) ignored;
|
||||
return malloc( size );
|
||||
|
||||
@@ -38,15 +38,11 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#if defined(RTEMS_NEWLIB) && !defined(HAVE__REALLOC_R)
|
||||
#if defined( RTEMS_NEWLIB ) && !defined( HAVE__REALLOC_R )
|
||||
#include <sys/reent.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void *_realloc_r(
|
||||
struct _reent *ignored,
|
||||
void *ptr,
|
||||
size_t size
|
||||
)
|
||||
void *_realloc_r( struct _reent *ignored, void *ptr, size_t size )
|
||||
{
|
||||
(void) ignored;
|
||||
return realloc( ptr, size );
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#if defined(RTEMS_NEWLIB) && !defined(HAVE__RENAME_R)
|
||||
#if defined( RTEMS_NEWLIB ) && !defined( HAVE__RENAME_R )
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -51,18 +51,17 @@
|
||||
*/
|
||||
int _rename_r(
|
||||
struct _reent *ptr RTEMS_UNUSED,
|
||||
const char *old,
|
||||
const char *new
|
||||
const char *old,
|
||||
const char *new
|
||||
)
|
||||
{
|
||||
int rv = 0;
|
||||
int rv = 0;
|
||||
rtems_filesystem_eval_path_context_t old_ctx;
|
||||
int old_eval_flags = 0;
|
||||
rtems_filesystem_location_info_t old_parentloc;
|
||||
int old_parent_eval_flags = RTEMS_FS_PERMS_WRITE
|
||||
| RTEMS_FS_FOLLOW_HARD_LINK;
|
||||
const rtems_filesystem_location_info_t *old_currentloc =
|
||||
rtems_filesystem_eval_path_start_with_parent(
|
||||
int old_eval_flags = 0;
|
||||
rtems_filesystem_location_info_t old_parentloc;
|
||||
int old_parent_eval_flags = RTEMS_FS_PERMS_WRITE | RTEMS_FS_FOLLOW_HARD_LINK;
|
||||
const rtems_filesystem_location_info_t
|
||||
*old_currentloc = rtems_filesystem_eval_path_start_with_parent(
|
||||
&old_ctx,
|
||||
old,
|
||||
old_eval_flags,
|
||||
@@ -72,9 +71,8 @@ int _rename_r(
|
||||
rtems_filesystem_eval_path_context_t new_ctx;
|
||||
|
||||
/* FIXME: This is not POSIX conform */
|
||||
int new_eval_flags = RTEMS_FS_FOLLOW_HARD_LINK
|
||||
| RTEMS_FS_MAKE
|
||||
| RTEMS_FS_EXCLUSIVE;
|
||||
int new_eval_flags = RTEMS_FS_FOLLOW_HARD_LINK | RTEMS_FS_MAKE |
|
||||
RTEMS_FS_EXCLUSIVE;
|
||||
|
||||
const rtems_filesystem_location_info_t *new_currentloc =
|
||||
rtems_filesystem_eval_path_start( &new_ctx, new, new_eval_flags );
|
||||
@@ -84,7 +82,7 @@ int _rename_r(
|
||||
new_currentloc
|
||||
);
|
||||
if ( rv == 0 ) {
|
||||
rv = (*new_currentloc->mt_entry->ops->rename_h)(
|
||||
rv = ( *new_currentloc->mt_entry->ops->rename_h )(
|
||||
&old_parentloc,
|
||||
old_currentloc,
|
||||
new_currentloc,
|
||||
|
||||
@@ -42,29 +42,30 @@
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
int access(
|
||||
const char *path,
|
||||
int amode
|
||||
)
|
||||
int access( const char *path, int amode )
|
||||
{
|
||||
struct stat statbuf;
|
||||
|
||||
if ( stat(path, &statbuf) )
|
||||
if ( stat( path, &statbuf ) ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( amode & R_OK ) {
|
||||
if (!( statbuf.st_mode & S_IREAD ))
|
||||
if ( !( statbuf.st_mode & S_IREAD ) ) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if ( amode & W_OK ) {
|
||||
if ( !( statbuf.st_mode & S_IWRITE ) )
|
||||
if ( !( statbuf.st_mode & S_IWRITE ) ) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if ( amode & X_OK ) {
|
||||
if ( !( statbuf.st_mode & S_IEXEC ) )
|
||||
if ( !( statbuf.st_mode & S_IEXEC ) ) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -42,6 +42,7 @@ void *aligned_alloc( size_t alignment, size_t size )
|
||||
return rtems_heap_allocate_aligned_with_boundary( size, alignment, 0 );
|
||||
}
|
||||
|
||||
void *memalign( size_t, size_t ) RTEMS_ALIAS( aligned_alloc ) __malloc_like
|
||||
__alloc_align(1) __alloc_size(2) __result_use_check
|
||||
__attribute__((__nothrow__));
|
||||
void *memalign( size_t, size_t ) RTEMS_ALIAS(
|
||||
aligned_alloc
|
||||
) __malloc_like __alloc_align( 1 ) __alloc_size( 2 ) __result_use_check
|
||||
__attribute__(( __nothrow__ ));
|
||||
|
||||
@@ -58,7 +58,7 @@ size_t rtems_assoc_32_to_string(
|
||||
|
||||
len = 0;
|
||||
|
||||
for ( i = 0; i < pair_count ; ++i ) {
|
||||
for ( i = 0; i < pair_count; ++i ) {
|
||||
const rtems_assoc_32_pair *p;
|
||||
|
||||
p = &pairs[ i ];
|
||||
|
||||
@@ -43,18 +43,16 @@
|
||||
#include <rtems.h>
|
||||
#include <rtems/assoc.h>
|
||||
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
|
||||
uint32_t rtems_assoc_local_by_name(
|
||||
const rtems_assoc_t *ap,
|
||||
const char *name
|
||||
)
|
||||
uint32_t rtems_assoc_local_by_name( const rtems_assoc_t *ap, const char *name )
|
||||
{
|
||||
const rtems_assoc_t *nap;
|
||||
|
||||
nap = rtems_assoc_ptr_by_name(ap, name);
|
||||
if (nap)
|
||||
nap = rtems_assoc_ptr_by_name( ap, name );
|
||||
if ( nap ) {
|
||||
return nap->local_value;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
#include <rtems.h>
|
||||
#include <rtems/assoc.h>
|
||||
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
|
||||
uint32_t rtems_assoc_local_by_remote(
|
||||
const rtems_assoc_t *ap,
|
||||
@@ -51,9 +51,10 @@ uint32_t rtems_assoc_local_by_remote(
|
||||
{
|
||||
const rtems_assoc_t *nap;
|
||||
|
||||
nap = rtems_assoc_ptr_by_remote(ap, remote_value);
|
||||
if (nap)
|
||||
nap = rtems_assoc_ptr_by_remote( ap, remote_value );
|
||||
if ( nap ) {
|
||||
return nap->local_value;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -42,20 +42,20 @@
|
||||
#include <rtems.h>
|
||||
#include <rtems/assoc.h>
|
||||
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
|
||||
|
||||
uint32_t rtems_assoc_local_by_remote_bitfield(
|
||||
const rtems_assoc_t *ap,
|
||||
uint32_t remote_value
|
||||
uint32_t rtems_assoc_local_by_remote_bitfield(
|
||||
const rtems_assoc_t *ap,
|
||||
uint32_t remote_value
|
||||
)
|
||||
{
|
||||
uint32_t b;
|
||||
uint32_t local_value = 0;
|
||||
uint32_t b;
|
||||
uint32_t local_value = 0;
|
||||
|
||||
for (b = 1; b; b <<= 1) {
|
||||
if (b & remote_value)
|
||||
local_value |= rtems_assoc_local_by_remote(ap, b);
|
||||
for ( b = 1; b; b <<= 1 ) {
|
||||
if ( b & remote_value ) {
|
||||
local_value |= rtems_assoc_local_by_remote( ap, b );
|
||||
}
|
||||
}
|
||||
|
||||
return local_value;
|
||||
|
||||
@@ -43,23 +43,27 @@
|
||||
#include <rtems/assoc.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h> /* sprintf */
|
||||
#include <stdio.h> /* sprintf */
|
||||
|
||||
const char *
|
||||
rtems_assoc_name_bad(
|
||||
const char *rtems_assoc_name_bad(
|
||||
#ifdef RTEMS_DEBUG
|
||||
uint32_t bad_value
|
||||
uint32_t bad_value
|
||||
#else
|
||||
uint32_t bad_value RTEMS_UNUSED
|
||||
uint32_t bad_value RTEMS_UNUSED
|
||||
#endif
|
||||
)
|
||||
{
|
||||
#ifdef RTEMS_DEBUG
|
||||
static char bad_buffer[32];
|
||||
static char bad_buffer[ 32 ];
|
||||
|
||||
sprintf(bad_buffer, "< %" PRId32 "[0x%" PRIx32 " ] >", bad_value, bad_value);
|
||||
sprintf(
|
||||
bad_buffer,
|
||||
"< %" PRId32 "[0x%" PRIx32 " ] >",
|
||||
bad_value,
|
||||
bad_value
|
||||
);
|
||||
#else
|
||||
static char bad_buffer[40] = "<assocnamebad.c: : BAD NAME>";
|
||||
static char bad_buffer[ 40 ] = "<assocnamebad.c: : BAD NAME>";
|
||||
#endif
|
||||
return bad_buffer;
|
||||
return bad_buffer;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
#include <rtems.h>
|
||||
#include <rtems/assoc.h>
|
||||
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
|
||||
const char *rtems_assoc_name_by_local(
|
||||
const rtems_assoc_t *ap,
|
||||
@@ -51,9 +51,10 @@ const char *rtems_assoc_name_by_local(
|
||||
{
|
||||
const rtems_assoc_t *nap;
|
||||
|
||||
nap = rtems_assoc_ptr_by_local(ap, local_value);
|
||||
if (nap)
|
||||
nap = rtems_assoc_ptr_by_local( ap, local_value );
|
||||
if ( nap ) {
|
||||
return nap->name;
|
||||
}
|
||||
|
||||
return rtems_assoc_name_bad(local_value);
|
||||
return rtems_assoc_name_bad( local_value );
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
#include <rtems.h>
|
||||
#include <rtems/assoc.h>
|
||||
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
|
||||
char *rtems_assoc_name_by_local_bitfield(
|
||||
const rtems_assoc_t *ap,
|
||||
@@ -50,15 +50,16 @@ char *rtems_assoc_name_by_local_bitfield(
|
||||
char *buffer
|
||||
)
|
||||
{
|
||||
uint32_t b;
|
||||
uint32_t b;
|
||||
|
||||
*buffer = 0;
|
||||
|
||||
for (b = 1; b; b <<= 1) {
|
||||
if (b & value) {
|
||||
if (*buffer)
|
||||
strcat(buffer, " ");
|
||||
strcat(buffer, rtems_assoc_name_by_local(ap, b));
|
||||
for ( b = 1; b; b <<= 1 ) {
|
||||
if ( b & value ) {
|
||||
if ( *buffer ) {
|
||||
strcat( buffer, " " );
|
||||
}
|
||||
strcat( buffer, rtems_assoc_name_by_local( ap, b ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,8 +42,7 @@
|
||||
#include <rtems.h>
|
||||
#include <rtems/assoc.h>
|
||||
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
|
||||
const char *rtems_assoc_name_by_remote(
|
||||
const rtems_assoc_t *ap,
|
||||
@@ -51,10 +50,11 @@ const char *rtems_assoc_name_by_remote(
|
||||
)
|
||||
{
|
||||
const rtems_assoc_t *nap;
|
||||
nap = rtems_assoc_ptr_by_remote(ap, remote_value);
|
||||
nap = rtems_assoc_ptr_by_remote( ap, remote_value );
|
||||
|
||||
if (nap)
|
||||
if ( nap ) {
|
||||
return nap->name;
|
||||
}
|
||||
|
||||
return rtems_assoc_name_bad(remote_value);
|
||||
return rtems_assoc_name_bad( remote_value );
|
||||
}
|
||||
|
||||
@@ -42,8 +42,7 @@
|
||||
#include <rtems.h>
|
||||
#include <rtems/assoc.h>
|
||||
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
|
||||
char *rtems_assoc_name_by_remote_bitfield(
|
||||
const rtems_assoc_t *ap,
|
||||
@@ -51,15 +50,16 @@ char *rtems_assoc_name_by_remote_bitfield(
|
||||
char *buffer
|
||||
)
|
||||
{
|
||||
uint32_t b;
|
||||
uint32_t b;
|
||||
|
||||
*buffer = 0;
|
||||
|
||||
for (b = 1; b; b <<= 1) {
|
||||
if (b & value) {
|
||||
if (*buffer)
|
||||
strcat(buffer, " ");
|
||||
strcat(buffer, rtems_assoc_name_by_remote(ap, b));
|
||||
for ( b = 1; b; b <<= 1 ) {
|
||||
if ( b & value ) {
|
||||
if ( *buffer ) {
|
||||
strcat( buffer, " " );
|
||||
}
|
||||
strcat( buffer, rtems_assoc_name_by_remote( ap, b ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
#include <rtems.h>
|
||||
#include <rtems/assoc.h>
|
||||
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
|
||||
const rtems_assoc_t *rtems_assoc_ptr_by_local(
|
||||
const rtems_assoc_t *ap,
|
||||
@@ -51,12 +51,15 @@ const rtems_assoc_t *rtems_assoc_ptr_by_local(
|
||||
{
|
||||
const rtems_assoc_t *default_ap = 0;
|
||||
|
||||
if (rtems_assoc_is_default(ap))
|
||||
if ( rtems_assoc_is_default( ap ) ) {
|
||||
default_ap = ap++;
|
||||
}
|
||||
|
||||
for ( ; ap->name; ap++)
|
||||
if (ap->local_value == local_value)
|
||||
for ( ; ap->name; ap++ ) {
|
||||
if ( ap->local_value == local_value ) {
|
||||
return ap;
|
||||
}
|
||||
}
|
||||
|
||||
return default_ap;
|
||||
}
|
||||
|
||||
@@ -42,8 +42,7 @@
|
||||
#include <rtems.h>
|
||||
#include <rtems/assoc.h>
|
||||
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
|
||||
const rtems_assoc_t *rtems_assoc_ptr_by_name(
|
||||
const rtems_assoc_t *ap,
|
||||
@@ -52,12 +51,15 @@ const rtems_assoc_t *rtems_assoc_ptr_by_name(
|
||||
{
|
||||
const rtems_assoc_t *default_ap = 0;
|
||||
|
||||
if (rtems_assoc_is_default(ap))
|
||||
if ( rtems_assoc_is_default( ap ) ) {
|
||||
default_ap = ap++;
|
||||
}
|
||||
|
||||
for ( ; ap->name; ap++)
|
||||
if (strcmp(ap->name, name) == 0)
|
||||
return ap;
|
||||
for ( ; ap->name; ap++ ) {
|
||||
if ( strcmp( ap->name, name ) == 0 ) {
|
||||
return ap;
|
||||
}
|
||||
}
|
||||
|
||||
return default_ap;
|
||||
}
|
||||
|
||||
@@ -42,21 +42,24 @@
|
||||
#include <rtems.h>
|
||||
#include <rtems/assoc.h>
|
||||
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
|
||||
const rtems_assoc_t *rtems_assoc_ptr_by_remote(
|
||||
const rtems_assoc_t *ap,
|
||||
uint32_t remote_value
|
||||
uint32_t remote_value
|
||||
)
|
||||
{
|
||||
const rtems_assoc_t *default_ap = 0;
|
||||
|
||||
if (rtems_assoc_is_default(ap))
|
||||
if ( rtems_assoc_is_default( ap ) ) {
|
||||
default_ap = ap++;
|
||||
}
|
||||
|
||||
for ( ; ap->name; ap++)
|
||||
if (ap->remote_value == remote_value)
|
||||
for ( ; ap->name; ap++ ) {
|
||||
if ( ap->remote_value == remote_value ) {
|
||||
return ap;
|
||||
}
|
||||
}
|
||||
|
||||
return default_ap;
|
||||
}
|
||||
|
||||
@@ -42,18 +42,19 @@
|
||||
#include <rtems.h>
|
||||
#include <rtems/assoc.h>
|
||||
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
|
||||
uint32_t rtems_assoc_remote_by_local(
|
||||
const rtems_assoc_t *ap,
|
||||
uint32_t local_value
|
||||
uint32_t local_value
|
||||
)
|
||||
{
|
||||
const rtems_assoc_t *nap;
|
||||
|
||||
nap = rtems_assoc_ptr_by_local(ap, local_value);
|
||||
if (nap)
|
||||
nap = rtems_assoc_ptr_by_local( ap, local_value );
|
||||
if ( nap ) {
|
||||
return nap->remote_value;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -43,20 +43,21 @@
|
||||
#include <rtems.h>
|
||||
#include <rtems/assoc.h>
|
||||
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
|
||||
|
||||
uint32_t rtems_assoc_remote_by_local_bitfield(
|
||||
const rtems_assoc_t *ap,
|
||||
uint32_t local_value
|
||||
uint32_t rtems_assoc_remote_by_local_bitfield(
|
||||
const rtems_assoc_t *ap,
|
||||
uint32_t local_value
|
||||
)
|
||||
{
|
||||
uint32_t b;
|
||||
uint32_t remote_value = 0;
|
||||
uint32_t b;
|
||||
uint32_t remote_value = 0;
|
||||
|
||||
for (b = 1; b; b <<= 1)
|
||||
if (b & local_value)
|
||||
remote_value |= rtems_assoc_remote_by_local(ap, b);
|
||||
for ( b = 1; b; b <<= 1 ) {
|
||||
if ( b & local_value ) {
|
||||
remote_value |= rtems_assoc_remote_by_local( ap, b );
|
||||
}
|
||||
}
|
||||
|
||||
return remote_value;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
#include <rtems.h>
|
||||
#include <rtems/assoc.h>
|
||||
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
#include <string.h> /* strcat, strcmp */
|
||||
|
||||
uint32_t rtems_assoc_remote_by_name(
|
||||
const rtems_assoc_t *ap,
|
||||
@@ -51,9 +51,10 @@ uint32_t rtems_assoc_remote_by_name(
|
||||
{
|
||||
const rtems_assoc_t *nap;
|
||||
|
||||
nap = rtems_assoc_ptr_by_name(ap, name);
|
||||
if (nap)
|
||||
nap = rtems_assoc_ptr_by_name( ap, name );
|
||||
if ( nap ) {
|
||||
return nap->remote_value;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -33,35 +33,35 @@
|
||||
#include <rtems/score/statesimpl.h>
|
||||
|
||||
static const rtems_assoc_32_pair state_pairs[] = {
|
||||
{ STATES_WAITING_FOR_MUTEX, "MTX" },
|
||||
{ STATES_WAITING_FOR_SEMAPHORE, "SEM" },
|
||||
{ STATES_WAITING_FOR_EVENT, "EV" },
|
||||
{ STATES_WAITING_FOR_SYSTEM_EVENT, "SYSEV" },
|
||||
{ STATES_WAITING_FOR_MESSAGE, "MSG" },
|
||||
{ STATES_WAITING_FOR_MUTEX, "MTX" },
|
||||
{ STATES_WAITING_FOR_SEMAPHORE, "SEM" },
|
||||
{ STATES_WAITING_FOR_EVENT, "EV" },
|
||||
{ STATES_WAITING_FOR_SYSTEM_EVENT, "SYSEV" },
|
||||
{ STATES_WAITING_FOR_MESSAGE, "MSG" },
|
||||
{ STATES_WAITING_FOR_CONDITION_VARIABLE, "CV" },
|
||||
{ STATES_WAITING_FOR_FUTEX, "FTX" },
|
||||
{ STATES_WAITING_FOR_BSD_WAKEUP, "WK" },
|
||||
{ STATES_WAITING_FOR_TIME, "TIME" },
|
||||
{ STATES_WAITING_FOR_PERIOD, "PER" },
|
||||
{ STATES_WAITING_FOR_SIGNAL, "SIG" },
|
||||
{ STATES_WAITING_FOR_BARRIER, "BAR" },
|
||||
{ STATES_WAITING_FOR_RWLOCK, "RW" },
|
||||
{ STATES_WAITING_FOR_JOIN_AT_EXIT, "JATX" },
|
||||
{ STATES_WAITING_FOR_JOIN, "JOIN" },
|
||||
{ STATES_SUSPENDED, "SUSP" },
|
||||
{ STATES_WAITING_FOR_SEGMENT, "SEG" },
|
||||
{ STATES_LIFE_IS_CHANGING, "LIFE" },
|
||||
{ STATES_DEBUGGER, "DBG" },
|
||||
{ STATES_INTERRUPTIBLE_BY_SIGNAL, "IS" },
|
||||
{ STATES_WAITING_FOR_RPC_REPLY, "RPC" },
|
||||
{ STATES_ZOMBIE, "ZOMBI" },
|
||||
{ STATES_DORMANT, "DORM" }
|
||||
{ STATES_WAITING_FOR_FUTEX, "FTX" },
|
||||
{ STATES_WAITING_FOR_BSD_WAKEUP, "WK" },
|
||||
{ STATES_WAITING_FOR_TIME, "TIME" },
|
||||
{ STATES_WAITING_FOR_PERIOD, "PER" },
|
||||
{ STATES_WAITING_FOR_SIGNAL, "SIG" },
|
||||
{ STATES_WAITING_FOR_BARRIER, "BAR" },
|
||||
{ STATES_WAITING_FOR_RWLOCK, "RW" },
|
||||
{ STATES_WAITING_FOR_JOIN_AT_EXIT, "JATX" },
|
||||
{ STATES_WAITING_FOR_JOIN, "JOIN" },
|
||||
{ STATES_SUSPENDED, "SUSP" },
|
||||
{ STATES_WAITING_FOR_SEGMENT, "SEG" },
|
||||
{ STATES_LIFE_IS_CHANGING, "LIFE" },
|
||||
{ STATES_DEBUGGER, "DBG" },
|
||||
{ STATES_INTERRUPTIBLE_BY_SIGNAL, "IS" },
|
||||
{ STATES_WAITING_FOR_RPC_REPLY, "RPC" },
|
||||
{ STATES_ZOMBIE, "ZOMBI" },
|
||||
{ STATES_DORMANT, "DORM" }
|
||||
};
|
||||
|
||||
size_t rtems_assoc_thread_states_to_string(
|
||||
uint32_t states,
|
||||
char *buffer,
|
||||
size_t buffer_size
|
||||
uint32_t states,
|
||||
char *buffer,
|
||||
size_t buffer_size
|
||||
)
|
||||
{
|
||||
return rtems_assoc_32_to_string(
|
||||
|
||||
@@ -51,8 +51,8 @@
|
||||
void rtems_filesystem_initialize( void )
|
||||
{
|
||||
int rv = 0;
|
||||
const rtems_filesystem_mount_configuration *root_config =
|
||||
&rtems_filesystem_root_configuration;
|
||||
const rtems_filesystem_mount_configuration
|
||||
*root_config = &rtems_filesystem_root_configuration;
|
||||
|
||||
rv = mount(
|
||||
root_config->source,
|
||||
@@ -61,8 +61,9 @@ void rtems_filesystem_initialize( void )
|
||||
root_config->options,
|
||||
root_config->data
|
||||
);
|
||||
if ( rv != 0 )
|
||||
if ( rv != 0 ) {
|
||||
rtems_fatal_error_occurred( 0xABCD0002 );
|
||||
}
|
||||
|
||||
/*
|
||||
* Traditionally RTEMS devices are under "/dev" so install this directory.
|
||||
@@ -71,8 +72,9 @@ void rtems_filesystem_initialize( void )
|
||||
*/
|
||||
|
||||
rv = mkdir( "/dev", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH );
|
||||
if ( rv != 0 )
|
||||
if ( rv != 0 ) {
|
||||
rtems_fatal_error_occurred( 0xABCD0003 );
|
||||
}
|
||||
|
||||
/*
|
||||
* You can't mount another filesystem properly until the mount point
|
||||
|
||||
@@ -42,7 +42,7 @@ void *rtems_cache_aligned_malloc( size_t nbytes )
|
||||
/* Assume that the cache line size is a power of two */
|
||||
size_t m = line_size - 1;
|
||||
|
||||
nbytes = (nbytes + m) & ~m;
|
||||
nbytes = ( nbytes + m ) & ~m;
|
||||
}
|
||||
|
||||
return rtems_heap_allocate_aligned_with_boundary( nbytes, line_size, 0 );
|
||||
|
||||
@@ -46,12 +46,12 @@ static Heap_Control cache_coherent_heap_instance;
|
||||
static Heap_Control *cache_coherent_heap;
|
||||
|
||||
void *rtems_cache_coherent_allocate(
|
||||
size_t size,
|
||||
size_t size,
|
||||
uintptr_t alignment,
|
||||
uintptr_t boundary
|
||||
)
|
||||
{
|
||||
void *ptr;
|
||||
void *ptr;
|
||||
Heap_Control *heap;
|
||||
|
||||
_RTEMS_Lock_allocator();
|
||||
@@ -97,10 +97,7 @@ void rtems_cache_coherent_free( void *ptr )
|
||||
_RTEMS_Unlock_allocator();
|
||||
}
|
||||
|
||||
static rtems_status_code add_area(
|
||||
void *area_begin,
|
||||
uintptr_t area_size
|
||||
)
|
||||
static rtems_status_code add_area( void *area_begin, uintptr_t area_size )
|
||||
{
|
||||
Heap_Control *heap = cache_coherent_heap;
|
||||
|
||||
@@ -112,7 +109,7 @@ static rtems_status_code add_area(
|
||||
}
|
||||
cache_coherent_heap = heap;
|
||||
} else {
|
||||
if (_Heap_Extend( heap, area_begin, area_size, 0 ) == 0) {
|
||||
if ( _Heap_Extend( heap, area_begin, area_size, 0 ) == 0 ) {
|
||||
return RTEMS_UNSATISFIED;
|
||||
}
|
||||
}
|
||||
@@ -120,12 +117,12 @@ static rtems_status_code add_area(
|
||||
}
|
||||
|
||||
rtems_status_code rtems_cache_coherent_add_area(
|
||||
void *area_begin,
|
||||
void *area_begin,
|
||||
uintptr_t area_size
|
||||
)
|
||||
{
|
||||
rtems_status_code sc;
|
||||
bool needs_locking = _System_state_Is_up( _System_state_Get());
|
||||
bool needs_locking = _System_state_Is_up( _System_state_Get() );
|
||||
|
||||
if ( needs_locking ) {
|
||||
_RTEMS_Lock_allocator();
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#if defined(RTEMS_NEWLIB) && !defined(HAVE_CALLOC)
|
||||
#if defined( RTEMS_NEWLIB ) && !defined( HAVE_CALLOC )
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <errno.h>
|
||||
@@ -45,13 +45,10 @@
|
||||
|
||||
#include <rtems/score/basedefs.h>
|
||||
|
||||
void *calloc(
|
||||
size_t nelem,
|
||||
size_t elsize
|
||||
)
|
||||
void *calloc( size_t nelem, size_t elsize )
|
||||
{
|
||||
void *cptr;
|
||||
size_t length;
|
||||
void *cptr;
|
||||
size_t length;
|
||||
|
||||
if ( nelem == 0 ) {
|
||||
return NULL;
|
||||
|
||||
@@ -38,16 +38,14 @@
|
||||
#endif
|
||||
|
||||
#include <rtems.h>
|
||||
#if defined(RTEMS_NEWLIB)
|
||||
#if defined( RTEMS_NEWLIB )
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <termios.h>
|
||||
|
||||
speed_t cfgetispeed(
|
||||
const struct termios *tp
|
||||
)
|
||||
speed_t cfgetispeed( const struct termios *tp )
|
||||
{
|
||||
return tp->c_ispeed;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
#endif
|
||||
|
||||
#include <rtems.h>
|
||||
#if defined(RTEMS_NEWLIB)
|
||||
#if defined( RTEMS_NEWLIB )
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -48,9 +48,7 @@
|
||||
/**
|
||||
* POSIX 1003.1b 7.1.3 - Baud Rate Functions
|
||||
*/
|
||||
speed_t cfgetospeed(
|
||||
const struct termios *tp
|
||||
)
|
||||
speed_t cfgetospeed( const struct termios *tp )
|
||||
{
|
||||
return tp->c_ospeed;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
#endif
|
||||
|
||||
#include <rtems.h>
|
||||
#if defined(RTEMS_NEWLIB)
|
||||
#if defined( RTEMS_NEWLIB )
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -50,13 +50,11 @@
|
||||
/**
|
||||
* POSIX 1003.1b 7.1.3 - Baud Rate Functions
|
||||
*/
|
||||
int cfsetispeed(
|
||||
struct termios *tp,
|
||||
speed_t speed
|
||||
)
|
||||
int cfsetispeed( struct termios *tp, speed_t speed )
|
||||
{
|
||||
if ( rtems_termios_baud_to_index( speed ) == -1 )
|
||||
if ( rtems_termios_baud_to_index( speed ) == -1 ) {
|
||||
rtems_set_errno_and_return_minus_one( EINVAL );
|
||||
}
|
||||
|
||||
tp->c_ispeed = speed;
|
||||
return 0;
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
#endif
|
||||
|
||||
#include <rtems.h>
|
||||
#if defined(RTEMS_NEWLIB)
|
||||
#if defined( RTEMS_NEWLIB )
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -50,13 +50,11 @@
|
||||
/**
|
||||
* POSIX 1003.1b 7.1.3 - Baud Rate Functions
|
||||
*/
|
||||
int cfsetospeed(
|
||||
struct termios *tp,
|
||||
speed_t speed
|
||||
)
|
||||
int cfsetospeed( struct termios *tp, speed_t speed )
|
||||
{
|
||||
if ( rtems_termios_baud_to_index( speed ) == -1 )
|
||||
if ( rtems_termios_baud_to_index( speed ) == -1 ) {
|
||||
rtems_set_errno_and_return_minus_one( EINVAL );
|
||||
}
|
||||
|
||||
tp->c_ospeed = speed;
|
||||
return 0;
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#endif
|
||||
|
||||
#include <rtems.h>
|
||||
#if defined(RTEMS_NEWLIB)
|
||||
#if defined( RTEMS_NEWLIB )
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -46,13 +46,11 @@
|
||||
#include <rtems/termiostypes.h>
|
||||
#include <rtems/seterr.h>
|
||||
|
||||
int cfsetspeed(
|
||||
struct termios *tp,
|
||||
speed_t speed
|
||||
)
|
||||
int cfsetspeed( struct termios *tp, speed_t speed )
|
||||
{
|
||||
if ( rtems_termios_baud_to_index( speed ) == -1 )
|
||||
if ( rtems_termios_baud_to_index( speed ) == -1 ) {
|
||||
rtems_set_errno_and_return_minus_one( EINVAL );
|
||||
}
|
||||
|
||||
cfsetispeed( tp, speed );
|
||||
cfsetospeed( tp, speed );
|
||||
|
||||
@@ -48,8 +48,8 @@
|
||||
int rtems_filesystem_chdir( rtems_filesystem_location_info_t *loc )
|
||||
{
|
||||
int rv = 0;
|
||||
rtems_filesystem_global_location_t *global_loc =
|
||||
rtems_filesystem_location_transform_to_global( loc );
|
||||
rtems_filesystem_global_location_t
|
||||
*global_loc = rtems_filesystem_location_transform_to_global( loc );
|
||||
mode_t type = rtems_filesystem_location_type( &global_loc->location );
|
||||
|
||||
if ( S_ISDIR( type ) ) {
|
||||
@@ -68,10 +68,9 @@ int rtems_filesystem_chdir( rtems_filesystem_location_info_t *loc )
|
||||
|
||||
int chdir( const char *path )
|
||||
{
|
||||
int rv = 0;
|
||||
int rv = 0;
|
||||
rtems_filesystem_eval_path_context_t ctx;
|
||||
int eval_flags = RTEMS_FS_PERMS_EXEC
|
||||
| RTEMS_FS_FOLLOW_LINK;
|
||||
int eval_flags = RTEMS_FS_PERMS_EXEC | RTEMS_FS_FOLLOW_LINK;
|
||||
rtems_filesystem_location_info_t pathloc;
|
||||
|
||||
rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
|
||||
|
||||
@@ -46,11 +46,11 @@
|
||||
*/
|
||||
int chmod( const char *path, mode_t mode )
|
||||
{
|
||||
int rv = 0;
|
||||
int rv = 0;
|
||||
rtems_filesystem_eval_path_context_t ctx;
|
||||
int eval_flags = RTEMS_FS_FOLLOW_LINK;
|
||||
const rtems_filesystem_location_info_t *currentloc =
|
||||
rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
|
||||
int eval_flags = RTEMS_FS_FOLLOW_LINK;
|
||||
const rtems_filesystem_location_info_t
|
||||
*currentloc = rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
|
||||
|
||||
rv = rtems_filesystem_chmod( currentloc, mode );
|
||||
|
||||
|
||||
@@ -49,11 +49,11 @@
|
||||
*/
|
||||
int chown( const char *path, uid_t owner, gid_t group )
|
||||
{
|
||||
int rv;
|
||||
int rv;
|
||||
rtems_filesystem_eval_path_context_t ctx;
|
||||
int eval_flags = RTEMS_FS_FOLLOW_LINK;
|
||||
const rtems_filesystem_location_info_t *currentloc =
|
||||
rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
|
||||
int eval_flags = RTEMS_FS_FOLLOW_LINK;
|
||||
const rtems_filesystem_location_info_t
|
||||
*currentloc = rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
|
||||
|
||||
rv = rtems_filesystem_chown( currentloc, owner, group );
|
||||
|
||||
|
||||
@@ -50,12 +50,11 @@
|
||||
|
||||
int chroot( const char *path )
|
||||
{
|
||||
int rv = 0;
|
||||
rtems_status_code sc = RTEMS_SUCCESSFUL;
|
||||
int rv = 0;
|
||||
rtems_status_code sc = RTEMS_SUCCESSFUL;
|
||||
rtems_filesystem_eval_path_context_t ctx;
|
||||
int eval_flags = RTEMS_FS_PERMS_EXEC
|
||||
| RTEMS_FS_FOLLOW_LINK;
|
||||
rtems_filesystem_location_info_t loc;
|
||||
int eval_flags = RTEMS_FS_PERMS_EXEC | RTEMS_FS_FOLLOW_LINK;
|
||||
rtems_filesystem_location_info_t loc;
|
||||
rtems_filesystem_global_location_t *new_current_loc;
|
||||
|
||||
/*
|
||||
@@ -80,7 +79,7 @@ int chroot( const char *path )
|
||||
|
||||
if ( S_ISDIR( type ) ) {
|
||||
sc = rtems_libio_set_private_env();
|
||||
if (sc == RTEMS_SUCCESSFUL) {
|
||||
if ( sc == RTEMS_SUCCESSFUL ) {
|
||||
rtems_filesystem_global_location_assign(
|
||||
&rtems_filesystem_root,
|
||||
new_root_loc
|
||||
@@ -90,7 +89,7 @@ int chroot( const char *path )
|
||||
new_current_loc
|
||||
);
|
||||
} else {
|
||||
if (sc != RTEMS_UNSATISFIED) {
|
||||
if ( sc != RTEMS_UNSATISFIED ) {
|
||||
errno = ENOMEM;
|
||||
}
|
||||
rv = -1;
|
||||
|
||||
@@ -42,5 +42,5 @@ clock_t clock( void )
|
||||
|
||||
_Timecounter_Microuptime( &tv );
|
||||
|
||||
return (clock_t) (tv.tv_sec - 1) * CLOCKS_PER_SEC + tv.tv_usec;
|
||||
return (clock_t) ( tv.tv_sec - 1 ) * CLOCKS_PER_SEC + tv.tv_usec;
|
||||
}
|
||||
|
||||
@@ -39,14 +39,14 @@
|
||||
#include <rtems/libio_.h>
|
||||
|
||||
void rtems_filesystem_location_clone(
|
||||
rtems_filesystem_location_info_t *clone,
|
||||
rtems_filesystem_location_info_t *clone,
|
||||
const rtems_filesystem_location_info_t *master
|
||||
)
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
clone = rtems_filesystem_location_copy( clone, master );
|
||||
rv = (*clone->mt_entry->ops->clonenod_h)( clone );
|
||||
rv = ( *clone->mt_entry->ops->clonenod_h )( clone );
|
||||
if ( rv != 0 ) {
|
||||
rtems_filesystem_location_remove_from_mt_entry( clone );
|
||||
rtems_filesystem_location_initialize_to_null( clone );
|
||||
|
||||
@@ -40,9 +40,7 @@
|
||||
|
||||
#include <rtems/libio_.h>
|
||||
|
||||
int close(
|
||||
int fd
|
||||
)
|
||||
int close( int fd )
|
||||
{
|
||||
rtems_libio_t *iop;
|
||||
int rc;
|
||||
@@ -54,7 +52,7 @@ int close(
|
||||
LIBIO_GET_IOP( fd, iop );
|
||||
|
||||
while ( true ) {
|
||||
unsigned int flags;
|
||||
unsigned int flags;
|
||||
unsigned int desired;
|
||||
bool success;
|
||||
flags = rtems_libio_iop_flags( iop );
|
||||
@@ -87,13 +85,15 @@ int close(
|
||||
break;
|
||||
}
|
||||
|
||||
if ( ( flags & LIBIO_FLAGS_REFERENCE_MASK ) != LIBIO_FLAGS_REFERENCE_INC ) {
|
||||
if (
|
||||
( flags & LIBIO_FLAGS_REFERENCE_MASK ) != LIBIO_FLAGS_REFERENCE_INC
|
||||
) {
|
||||
rtems_libio_iop_drop( iop );
|
||||
rtems_set_errno_and_return_minus_one( EBUSY );
|
||||
}
|
||||
}
|
||||
|
||||
rc = (*iop->pathinfo.handlers->close_h)( iop );
|
||||
rc = ( *iop->pathinfo.handlers->close_h )( iop );
|
||||
|
||||
rtems_libio_iop_drop( iop );
|
||||
|
||||
@@ -106,14 +106,11 @@ int close(
|
||||
* This is the Newlib dependent reentrant version of close().
|
||||
*/
|
||||
|
||||
#if defined(RTEMS_NEWLIB) && !defined(HAVE__CLOSE_R)
|
||||
#if defined( RTEMS_NEWLIB ) && !defined( HAVE__CLOSE_R )
|
||||
|
||||
#include <reent.h>
|
||||
|
||||
int _close_r(
|
||||
struct _reent *ptr RTEMS_UNUSED,
|
||||
int fd
|
||||
)
|
||||
int _close_r( struct _reent *ptr RTEMS_UNUSED, int fd )
|
||||
{
|
||||
return close( fd );
|
||||
}
|
||||
|
||||
@@ -75,11 +75,11 @@ static const rtems_filesystem_file_handlers_r _Console_simple_Handlers = {
|
||||
};
|
||||
|
||||
static const IMFS_node_control
|
||||
_Console_simple_Node_control = IMFS_NODE_CONTROL_INITIALIZER(
|
||||
&_Console_simple_Handlers,
|
||||
IMFS_node_initialize_default,
|
||||
IMFS_do_nothing_destroy
|
||||
);
|
||||
_Console_simple_Node_control = IMFS_NODE_CONTROL_INITIALIZER(
|
||||
&_Console_simple_Handlers,
|
||||
IMFS_node_initialize_default,
|
||||
IMFS_do_nothing_destroy
|
||||
);
|
||||
|
||||
static const char _Console_simple_Name[] = "console";
|
||||
|
||||
|
||||
@@ -25,8 +25,4 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
ssize_t _Console_simple_Read(
|
||||
rtems_libio_t *iop,
|
||||
void *buffer,
|
||||
size_t count
|
||||
);
|
||||
ssize_t _Console_simple_Read( rtems_libio_t *iop, void *buffer, size_t count );
|
||||
|
||||
@@ -30,17 +30,13 @@
|
||||
|
||||
#include "consolesimple.h"
|
||||
|
||||
ssize_t _Console_simple_Read(
|
||||
rtems_libio_t *iop,
|
||||
void *buffer,
|
||||
size_t count
|
||||
)
|
||||
ssize_t _Console_simple_Read( rtems_libio_t *iop, void *buffer, size_t count )
|
||||
{
|
||||
(void) iop;
|
||||
|
||||
char *buf;
|
||||
ssize_t i;
|
||||
ssize_t n;
|
||||
char *buf;
|
||||
ssize_t i;
|
||||
ssize_t n;
|
||||
|
||||
buf = buffer;
|
||||
n = (ssize_t) count;
|
||||
|
||||
@@ -44,10 +44,10 @@ typedef struct {
|
||||
IMFS_jnode_t Node;
|
||||
RTEMS_INTERRUPT_LOCK_MEMBER( buf_lock )
|
||||
rtems_mutex output_mutex;
|
||||
rtems_id task;
|
||||
size_t head;
|
||||
size_t tail;
|
||||
char buf[ CONSOLE_SIMPLE_TASK_BUFFER_SIZE ];
|
||||
rtems_id task;
|
||||
size_t head;
|
||||
size_t tail;
|
||||
char buf[ CONSOLE_SIMPLE_TASK_BUFFER_SIZE ];
|
||||
} Console_simple_task_Control;
|
||||
|
||||
static Console_simple_task_Control _Console_simple_task_Instance;
|
||||
@@ -144,7 +144,7 @@ static void _Console_simple_task_Put_chars( Console_simple_task_Control *cons )
|
||||
|
||||
rtems_interrupt_lock_release( &cons->buf_lock, &lock_context );
|
||||
|
||||
for ( i = 0; i < available; ++i) {
|
||||
for ( i = 0; i < available; ++i ) {
|
||||
rtems_putc( cons->buf[ tail ] );
|
||||
tail = ( tail + 1 ) % CONSOLE_SIMPLE_TASK_BUFFER_SIZE;
|
||||
}
|
||||
@@ -186,11 +186,11 @@ static const rtems_filesystem_file_handlers_r _Console_simple_task_Handlers = {
|
||||
};
|
||||
|
||||
static const IMFS_node_control
|
||||
_Console_simple_task_Node_control = IMFS_NODE_CONTROL_INITIALIZER(
|
||||
&_Console_simple_task_Handlers,
|
||||
IMFS_node_initialize_default,
|
||||
IMFS_do_nothing_destroy
|
||||
);
|
||||
_Console_simple_task_Node_control = IMFS_NODE_CONTROL_INITIALIZER(
|
||||
&_Console_simple_task_Handlers,
|
||||
IMFS_node_initialize_default,
|
||||
IMFS_do_nothing_destroy
|
||||
);
|
||||
|
||||
static void _Console_simple_task_Task( rtems_task_argument arg )
|
||||
{
|
||||
@@ -217,7 +217,7 @@ static const char _Console_simple_task_Name[] = "console";
|
||||
void _Console_simple_task_Initialize( void )
|
||||
{
|
||||
Console_simple_task_Control *cons;
|
||||
rtems_status_code status;
|
||||
rtems_status_code status;
|
||||
|
||||
cons = &_Console_simple_task_Instance;
|
||||
|
||||
@@ -235,19 +235,19 @@ void _Console_simple_task_Initialize( void )
|
||||
IMFS_add_node( "/dev", &cons->Node, NULL );
|
||||
|
||||
status = rtems_task_create(
|
||||
rtems_build_name('C', 'O', 'N', 'S'),
|
||||
rtems_build_name( 'C', 'O', 'N', 'S' ),
|
||||
RTEMS_MAXIMUM_PRIORITY - 1,
|
||||
RTEMS_MINIMUM_STACK_SIZE,
|
||||
RTEMS_DEFAULT_ATTRIBUTES,
|
||||
RTEMS_DEFAULT_MODES,
|
||||
&cons->task
|
||||
);
|
||||
_Assert_Unused_variable_equals(status, RTEMS_SUCCESSFUL);
|
||||
_Assert_Unused_variable_equals( status, RTEMS_SUCCESSFUL );
|
||||
|
||||
status = rtems_task_start(
|
||||
cons->task,
|
||||
_Console_simple_task_Task,
|
||||
(rtems_task_argument) cons
|
||||
);
|
||||
_Assert_Unused_variable_equals(status, RTEMS_SUCCESSFUL);
|
||||
_Assert_Unused_variable_equals( status, RTEMS_SUCCESSFUL );
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
#endif
|
||||
|
||||
#include <rtems.h>
|
||||
#if defined(RTEMS_NEWLIB)
|
||||
#if defined( RTEMS_NEWLIB )
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -49,12 +49,11 @@ static char *ctermid_name = "/dev/console";
|
||||
/**
|
||||
* ctermid() - POSIX 1003.1b 4.7.1 - Generate Terminal Pathname
|
||||
*/
|
||||
char *ctermid(
|
||||
char *s
|
||||
)
|
||||
char *ctermid( char *s )
|
||||
{
|
||||
if ( !s )
|
||||
if ( !s ) {
|
||||
return ctermid_name;
|
||||
}
|
||||
|
||||
/*
|
||||
* We have no way of knowing the length of the user provided buffer.
|
||||
|
||||
@@ -41,9 +41,7 @@
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
int dup(
|
||||
int fildes
|
||||
)
|
||||
int dup( int fildes )
|
||||
{
|
||||
return fcntl( fildes, F_DUPFD, 0 );
|
||||
}
|
||||
|
||||
@@ -45,29 +45,28 @@
|
||||
/**
|
||||
* POSIX 1003.1b 6.2.1 Duplicate an Open File Descriptor
|
||||
*/
|
||||
int dup2(
|
||||
int fildes,
|
||||
int fildes2
|
||||
)
|
||||
int dup2( int fildes, int fildes2 )
|
||||
{
|
||||
int status;
|
||||
struct stat buf;
|
||||
int status;
|
||||
struct stat buf;
|
||||
|
||||
/*
|
||||
* If fildes is not valid, then fildes2 should not be closed.
|
||||
*/
|
||||
|
||||
status = fstat( fildes, &buf );
|
||||
if ( status == -1 )
|
||||
if ( status == -1 ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* If fildes2 is not valid, then we should not do anything either.
|
||||
*/
|
||||
|
||||
status = fstat( fildes2, &buf );
|
||||
if ( status == -1 )
|
||||
if ( status == -1 ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* This fcntl handles everything else.
|
||||
|
||||
@@ -46,79 +46,92 @@
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h> /* _exit() */
|
||||
#include <unistd.h> /* _exit() */
|
||||
|
||||
int rtems_panic_in_progress;
|
||||
int rtems_panic_in_progress;
|
||||
|
||||
int rtems_verror(
|
||||
rtems_error_code_t error_flag,
|
||||
const char *printf_format,
|
||||
va_list arglist
|
||||
rtems_error_code_t error_flag,
|
||||
const char *printf_format,
|
||||
va_list arglist
|
||||
)
|
||||
{
|
||||
int local_errno = 0;
|
||||
int chars_written = 0;
|
||||
rtems_status_code status;
|
||||
|
||||
if (error_flag & RTEMS_ERROR_PANIC) {
|
||||
if (rtems_panic_in_progress++)
|
||||
_Thread_Dispatch_disable(); /* disable task switches */
|
||||
if ( error_flag & RTEMS_ERROR_PANIC ) {
|
||||
if ( rtems_panic_in_progress++ ) {
|
||||
_Thread_Dispatch_disable(); /* disable task switches */
|
||||
}
|
||||
|
||||
/* don't aggravate things */
|
||||
if (rtems_panic_in_progress > 2)
|
||||
if ( rtems_panic_in_progress > 2 ) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
(void) fflush(stdout); /* in case stdout/stderr same */
|
||||
(void) fflush( stdout ); /* in case stdout/stderr same */
|
||||
|
||||
status = error_flag & ~RTEMS_ERROR_MASK;
|
||||
if (error_flag & RTEMS_ERROR_ERRNO) /* include errno? */
|
||||
if ( error_flag & RTEMS_ERROR_ERRNO ) { /* include errno? */
|
||||
local_errno = errno;
|
||||
|
||||
#if defined(RTEMS_MULTIPROCESSING)
|
||||
if (_System_state_Is_multiprocessing)
|
||||
fprintf(stderr, "[%" PRIu16 "] ", rtems_object_get_local_node());
|
||||
#endif
|
||||
|
||||
chars_written += vfprintf(stderr, printf_format, arglist);
|
||||
|
||||
if (status)
|
||||
chars_written +=
|
||||
fprintf(stderr, " (status: %s)", rtems_status_text(status));
|
||||
|
||||
if (local_errno) {
|
||||
if ((local_errno > 0) && *strerror(local_errno))
|
||||
chars_written += fprintf(stderr, " (errno: %s)", strerror(local_errno));
|
||||
else
|
||||
chars_written += fprintf(stderr, " (unknown errno=%d)", local_errno);
|
||||
}
|
||||
|
||||
chars_written += fprintf(stderr, "\n");
|
||||
#if defined( RTEMS_MULTIPROCESSING )
|
||||
if ( _System_state_Is_multiprocessing ) {
|
||||
fprintf( stderr, "[%" PRIu16 "] ", rtems_object_get_local_node() );
|
||||
}
|
||||
#endif
|
||||
|
||||
(void) fflush(stderr);
|
||||
chars_written += vfprintf( stderr, printf_format, arglist );
|
||||
|
||||
if ( status ) {
|
||||
chars_written += fprintf(
|
||||
stderr,
|
||||
" (status: %s)",
|
||||
rtems_status_text( status )
|
||||
);
|
||||
}
|
||||
|
||||
if ( local_errno ) {
|
||||
if ( ( local_errno > 0 ) && *strerror( local_errno ) ) {
|
||||
chars_written += fprintf(
|
||||
stderr,
|
||||
" (errno: %s)",
|
||||
strerror( local_errno )
|
||||
);
|
||||
} else {
|
||||
chars_written += fprintf( stderr, " (unknown errno=%d)", local_errno );
|
||||
}
|
||||
}
|
||||
|
||||
chars_written += fprintf( stderr, "\n" );
|
||||
|
||||
(void) fflush( stderr );
|
||||
|
||||
return chars_written;
|
||||
}
|
||||
|
||||
int rtems_error(
|
||||
rtems_error_code_t error_flag,
|
||||
const char *printf_format,
|
||||
const char *printf_format,
|
||||
...
|
||||
)
|
||||
{
|
||||
va_list arglist;
|
||||
int chars_written;
|
||||
int chars_written;
|
||||
|
||||
va_start(arglist, printf_format);
|
||||
chars_written = rtems_verror(error_flag, printf_format, arglist);
|
||||
va_end(arglist);
|
||||
va_start( arglist, printf_format );
|
||||
chars_written = rtems_verror( error_flag, printf_format, arglist );
|
||||
va_end( arglist );
|
||||
|
||||
if (error_flag & RTEMS_ERROR_PANIC) {
|
||||
rtems_error(0, "fatal error, exiting");
|
||||
_exit(errno);
|
||||
if ( error_flag & RTEMS_ERROR_PANIC ) {
|
||||
rtems_error( 0, "fatal error, exiting" );
|
||||
_exit( errno );
|
||||
}
|
||||
if (error_flag & RTEMS_ERROR_ABORT) {
|
||||
rtems_error(0, "fatal error, aborting");
|
||||
if ( error_flag & RTEMS_ERROR_ABORT ) {
|
||||
rtems_error( 0, "fatal error, aborting" );
|
||||
abort();
|
||||
}
|
||||
|
||||
|
||||
@@ -49,9 +49,9 @@
|
||||
*/
|
||||
int fchdir( int fd )
|
||||
{
|
||||
int rv = 0;
|
||||
rtems_libio_t *iop;
|
||||
struct stat st;
|
||||
int rv = 0;
|
||||
rtems_libio_t *iop;
|
||||
struct stat st;
|
||||
rtems_filesystem_location_info_t loc;
|
||||
|
||||
st.st_mode = 0;
|
||||
@@ -61,7 +61,7 @@ int fchdir( int fd )
|
||||
LIBIO_GET_IOP( fd, iop );
|
||||
|
||||
rtems_filesystem_instance_lock( &iop->pathinfo );
|
||||
rv = (*iop->pathinfo.handlers->fstat_h)( &iop->pathinfo, &st );
|
||||
rv = ( *iop->pathinfo.handlers->fstat_h )( &iop->pathinfo, &st );
|
||||
if ( rv == 0 ) {
|
||||
bool access_ok = rtems_filesystem_check_access(
|
||||
RTEMS_FS_PERMS_EXEC,
|
||||
|
||||
@@ -44,27 +44,28 @@
|
||||
|
||||
int rtems_filesystem_chmod(
|
||||
const rtems_filesystem_location_info_t *loc,
|
||||
mode_t mode
|
||||
mode_t mode
|
||||
)
|
||||
{
|
||||
const rtems_filesystem_mount_table_entry_t *mt_entry = loc->mt_entry;
|
||||
int rv;
|
||||
int rv;
|
||||
|
||||
if ( mt_entry->writeable || rtems_filesystem_location_is_null( loc ) ) {
|
||||
struct stat st;
|
||||
|
||||
memset( &st, 0, sizeof(st) );
|
||||
memset( &st, 0, sizeof( st ) );
|
||||
|
||||
rv = (*loc->handlers->fstat_h)( loc, &st );
|
||||
rv = ( *loc->handlers->fstat_h )( loc, &st );
|
||||
if ( rv == 0 ) {
|
||||
uid_t uid = geteuid();
|
||||
|
||||
if ( uid == 0 || st.st_uid == uid ) {
|
||||
mode_t mask = S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX;
|
||||
mode_t mask = S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID |
|
||||
S_ISVTX;
|
||||
|
||||
mode = (st.st_mode & ~mask) | (mode & mask);
|
||||
mode = ( st.st_mode & ~mask ) | ( mode & mask );
|
||||
|
||||
rv = (*mt_entry->ops->fchmod_h)( loc, mode );
|
||||
rv = ( *mt_entry->ops->fchmod_h )( loc, mode );
|
||||
} else {
|
||||
errno = EPERM;
|
||||
rv = -1;
|
||||
@@ -83,7 +84,7 @@ int rtems_filesystem_chmod(
|
||||
*/
|
||||
int fchmod( int fd, mode_t mode )
|
||||
{
|
||||
int rv;
|
||||
int rv;
|
||||
rtems_libio_t *iop;
|
||||
|
||||
LIBIO_GET_IOP( fd, iop );
|
||||
|
||||
@@ -44,24 +44,24 @@
|
||||
|
||||
int rtems_filesystem_chown(
|
||||
const rtems_filesystem_location_info_t *loc,
|
||||
uid_t owner,
|
||||
gid_t group
|
||||
uid_t owner,
|
||||
gid_t group
|
||||
)
|
||||
{
|
||||
const rtems_filesystem_mount_table_entry_t *mt_entry = loc->mt_entry;
|
||||
int rv;
|
||||
int rv;
|
||||
|
||||
if ( mt_entry->writeable || rtems_filesystem_location_is_null( loc ) ) {
|
||||
struct stat st;
|
||||
|
||||
memset( &st, 0, sizeof(st) );
|
||||
memset( &st, 0, sizeof( st ) );
|
||||
|
||||
rv = (*loc->handlers->fstat_h)( loc, &st );
|
||||
rv = ( *loc->handlers->fstat_h )( loc, &st );
|
||||
if ( rv == 0 ) {
|
||||
uid_t uid = geteuid();
|
||||
|
||||
if ( uid == 0 || st.st_uid == uid ) {
|
||||
rv = (*mt_entry->ops->chown_h)( loc, owner, group );
|
||||
rv = ( *mt_entry->ops->chown_h )( loc, owner, group );
|
||||
} else {
|
||||
errno = EPERM;
|
||||
rv = -1;
|
||||
@@ -80,7 +80,7 @@ int rtems_filesystem_chown(
|
||||
*/
|
||||
int fchown( int fd, uid_t owner, gid_t group )
|
||||
{
|
||||
int rv;
|
||||
int rv;
|
||||
rtems_libio_t *iop;
|
||||
|
||||
LIBIO_GET_IOP( fd, iop );
|
||||
|
||||
@@ -53,7 +53,7 @@ static int duplicate_iop( rtems_libio_t *iop )
|
||||
oflag = rtems_libio_to_fcntl_flags( rtems_libio_iop_flags( iop ) );
|
||||
diop = rtems_libio_allocate();
|
||||
|
||||
if (diop != NULL) {
|
||||
if ( diop != NULL ) {
|
||||
rtems_filesystem_instance_lock( &iop->pathinfo );
|
||||
rtems_filesystem_location_clone( &diop->pathinfo, &iop->pathinfo );
|
||||
rtems_filesystem_instance_unlock( &iop->pathinfo );
|
||||
@@ -64,7 +64,7 @@ static int duplicate_iop( rtems_libio_t *iop )
|
||||
*
|
||||
* FIXME: What to do with the path?
|
||||
*/
|
||||
rv = (*diop->pathinfo.handlers->open_h)( diop, NULL, oflag, 0 );
|
||||
rv = ( *diop->pathinfo.handlers->open_h )( diop, NULL, oflag, 0 );
|
||||
if ( rv == 0 ) {
|
||||
rtems_libio_iop_flags_set( diop, LIBIO_FLAGS_OPEN );
|
||||
rv = rtems_libio_iop_to_descriptor( diop );
|
||||
@@ -89,15 +89,14 @@ static int duplicate2_iop( rtems_libio_t *iop, int fd2 )
|
||||
|
||||
iop2 = rtems_libio_iop( fd2 );
|
||||
|
||||
if (iop != iop2)
|
||||
{
|
||||
if ( iop != iop2 ) {
|
||||
int oflag;
|
||||
|
||||
if ((rtems_libio_iop_flags( iop2 ) & LIBIO_FLAGS_OPEN) != 0) {
|
||||
rv = (*iop2->pathinfo.handlers->close_h)( iop2 );
|
||||
if ( ( rtems_libio_iop_flags( iop2 ) & LIBIO_FLAGS_OPEN ) != 0 ) {
|
||||
rv = ( *iop2->pathinfo.handlers->close_h )( iop2 );
|
||||
}
|
||||
|
||||
if (rv == 0) {
|
||||
if ( rv == 0 ) {
|
||||
oflag = rtems_libio_to_fcntl_flags( rtems_libio_iop_flags( iop ) );
|
||||
rtems_libio_iop_flags_set( iop2, rtems_libio_from_fcntl_flags( oflag ) );
|
||||
|
||||
@@ -111,7 +110,7 @@ static int duplicate2_iop( rtems_libio_t *iop, int fd2 )
|
||||
*
|
||||
* FIXME: What to do with the path?
|
||||
*/
|
||||
rv = (*iop2->pathinfo.handlers->open_h)( iop2, NULL, oflag, 0 );
|
||||
rv = ( *iop2->pathinfo.handlers->open_h )( iop2, NULL, oflag, 0 );
|
||||
if ( rv == 0 ) {
|
||||
rv = fd2;
|
||||
}
|
||||
@@ -121,11 +120,7 @@ static int duplicate2_iop( rtems_libio_t *iop, int fd2 )
|
||||
return rv;
|
||||
}
|
||||
|
||||
static int vfcntl(
|
||||
int fd,
|
||||
int cmd,
|
||||
va_list ap
|
||||
)
|
||||
static int vfcntl( int fd, int cmd, va_list ap )
|
||||
{
|
||||
rtems_libio_t *iop;
|
||||
int fd2;
|
||||
@@ -144,20 +139,21 @@ static int vfcntl(
|
||||
*/
|
||||
|
||||
switch ( cmd ) {
|
||||
case F_DUPFD: /* dup */
|
||||
case F_DUPFD: /* dup */
|
||||
ret = duplicate_iop( iop );
|
||||
break;
|
||||
|
||||
case F_DUP2FD: /* dup2 */
|
||||
case F_DUP2FD: /* dup2 */
|
||||
fd2 = va_arg( ap, int );
|
||||
ret = duplicate2_iop( iop, fd2 );
|
||||
break;
|
||||
|
||||
case F_GETFD: /* get f_flags */
|
||||
ret = ((rtems_libio_iop_flags(iop) & LIBIO_FLAGS_CLOSE_ON_EXEC) != 0);
|
||||
case F_GETFD: /* get f_flags */
|
||||
ret =
|
||||
( ( rtems_libio_iop_flags( iop ) & LIBIO_FLAGS_CLOSE_ON_EXEC ) != 0 );
|
||||
break;
|
||||
|
||||
case F_SETFD: /* set f_flags */
|
||||
case F_SETFD: /* set f_flags */
|
||||
/*
|
||||
* Interpret the third argument as the "close on exec()" flag.
|
||||
* If this argument is 1, then the file descriptor is to be closed
|
||||
@@ -166,13 +162,14 @@ static int vfcntl(
|
||||
* F_GETFD work.
|
||||
*/
|
||||
|
||||
if ( va_arg( ap, int ) )
|
||||
if ( va_arg( ap, int ) ) {
|
||||
rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_CLOSE_ON_EXEC );
|
||||
else
|
||||
} else {
|
||||
rtems_libio_iop_flags_clear( iop, LIBIO_FLAGS_CLOSE_ON_EXEC );
|
||||
}
|
||||
break;
|
||||
|
||||
case F_GETFL: /* more flags (cloexec) */
|
||||
case F_GETFL: /* more flags (cloexec) */
|
||||
ret = rtems_libio_to_fcntl_flags( rtems_libio_iop_flags( iop ) );
|
||||
break;
|
||||
|
||||
@@ -203,12 +200,12 @@ static int vfcntl(
|
||||
ret = -1;
|
||||
break;
|
||||
|
||||
case F_SETOWN: /* for sockets. */
|
||||
case F_SETOWN: /* for sockets. */
|
||||
errno = ENOTSUP;
|
||||
ret = -1;
|
||||
break;
|
||||
|
||||
case F_GETOWN: /* for sockets. */
|
||||
case F_GETOWN: /* for sockets. */
|
||||
errno = ENOTSUP;
|
||||
ret = -1;
|
||||
break;
|
||||
@@ -224,12 +221,12 @@ static int vfcntl(
|
||||
* filesystem specific handler a chance to process this.
|
||||
*/
|
||||
|
||||
if (ret >= 0) {
|
||||
int err = (*iop->pathinfo.handlers->fcntl_h)( iop, cmd );
|
||||
if (err == 0 && !rtems_libio_iop_is_open( iop ) ) {
|
||||
if ( ret >= 0 ) {
|
||||
int err = ( *iop->pathinfo.handlers->fcntl_h )( iop, cmd );
|
||||
if ( err == 0 && !rtems_libio_iop_is_open( iop ) ) {
|
||||
err = EBADF;
|
||||
}
|
||||
if (err != 0) {
|
||||
if ( err != 0 ) {
|
||||
errno = err;
|
||||
ret = -1;
|
||||
}
|
||||
@@ -239,37 +236,27 @@ static int vfcntl(
|
||||
return ret;
|
||||
}
|
||||
|
||||
int fcntl(
|
||||
int fd,
|
||||
int cmd,
|
||||
...
|
||||
)
|
||||
int fcntl( int fd, int cmd, ... )
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
int ret;
|
||||
va_list ap;
|
||||
va_start( ap, cmd );
|
||||
ret = vfcntl(fd,cmd,ap);
|
||||
va_end(ap);
|
||||
ret = vfcntl( fd, cmd, ap );
|
||||
va_end( ap );
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* _fcntl_r
|
||||
*
|
||||
* This is the Newlib dependent reentrant version of fcntl().
|
||||
*/
|
||||
|
||||
#if defined(RTEMS_NEWLIB) && !defined(HAVE_FCNTL_R)
|
||||
#if defined( RTEMS_NEWLIB ) && !defined( HAVE_FCNTL_R )
|
||||
|
||||
#include <reent.h>
|
||||
|
||||
int _fcntl_r(
|
||||
struct _reent *ptr RTEMS_UNUSED,
|
||||
int fd,
|
||||
int cmd,
|
||||
int arg
|
||||
)
|
||||
int _fcntl_r( struct _reent *ptr RTEMS_UNUSED, int fd, int cmd, int arg )
|
||||
{
|
||||
return fcntl( fd, cmd, arg );
|
||||
}
|
||||
|
||||
@@ -43,9 +43,7 @@
|
||||
#include <rtems/libio_.h>
|
||||
#include <rtems/seterr.h>
|
||||
|
||||
int fdatasync(
|
||||
int fd
|
||||
)
|
||||
int fdatasync( int fd )
|
||||
{
|
||||
rtems_libio_t *iop;
|
||||
int rv;
|
||||
@@ -56,7 +54,7 @@ int fdatasync(
|
||||
* Now process the fdatasync().
|
||||
*/
|
||||
|
||||
rv = (*iop->pathinfo.handlers->fdatasync_h)( iop );
|
||||
rv = ( *iop->pathinfo.handlers->fdatasync_h )( iop );
|
||||
rtems_libio_iop_drop( iop );
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#if defined(RTEMS_NEWLIB) && !defined(HAVE_FLOCKFILE)
|
||||
#if defined( RTEMS_NEWLIB ) && !defined( HAVE_FLOCKFILE )
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/**
|
||||
* This is a non-functional stub
|
||||
*/
|
||||
void flockfile(FILE* file)
|
||||
void flockfile( FILE *file )
|
||||
{
|
||||
(void) file;
|
||||
}
|
||||
|
||||
@@ -46,13 +46,10 @@
|
||||
/**
|
||||
* POSIX 1003.1b - 5.7.1 - Configurable Pathname Varables
|
||||
*/
|
||||
long fpathconf(
|
||||
int fd,
|
||||
int name
|
||||
)
|
||||
long fpathconf( int fd, int name )
|
||||
{
|
||||
long return_value;
|
||||
rtems_libio_t *iop;
|
||||
long return_value;
|
||||
rtems_libio_t *iop;
|
||||
const rtems_filesystem_limits_and_options_t *the_limits;
|
||||
|
||||
LIBIO_GET_IOP( fd, iop );
|
||||
|
||||
@@ -51,7 +51,7 @@ RTEMS_INTERRUPT_LOCK_DEFINE( static, _Malloc_GC_lock, "Malloc GC" )
|
||||
static void *_Malloc_Get_deferred_free( void )
|
||||
{
|
||||
rtems_interrupt_lock_context lock_context;
|
||||
void *p;
|
||||
void *p;
|
||||
|
||||
rtems_interrupt_lock_acquire( &_Malloc_GC_lock, &lock_context );
|
||||
p = rtems_chain_get_unprotected( &_Malloc_GC_list );
|
||||
@@ -75,7 +75,7 @@ void _Malloc_Process_deferred_frees( void )
|
||||
static void _Malloc_Deferred_free( void *p )
|
||||
{
|
||||
rtems_interrupt_lock_context lock_context;
|
||||
rtems_chain_node *node;
|
||||
rtems_chain_node *node;
|
||||
|
||||
node = (rtems_chain_node *) p;
|
||||
|
||||
@@ -85,23 +85,25 @@ static void _Malloc_Deferred_free( void *p )
|
||||
rtems_interrupt_lock_release( &_Malloc_GC_lock, &lock_context );
|
||||
}
|
||||
|
||||
void free(
|
||||
void *ptr
|
||||
)
|
||||
void free( void *ptr )
|
||||
{
|
||||
if ( !ptr )
|
||||
if ( !ptr ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Do not attempt to free memory if in a critical section or ISR.
|
||||
*/
|
||||
if ( _Malloc_System_state() != MALLOC_SYSTEM_STATE_NORMAL ) {
|
||||
_Malloc_Deferred_free(ptr);
|
||||
return;
|
||||
_Malloc_Deferred_free( ptr );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !_Protected_heap_Free( RTEMS_Malloc_Heap, ptr ) ) {
|
||||
rtems_fatal( RTEMS_FATAL_SOURCE_INVALID_HEAP_FREE, (rtems_fatal_code) ptr );
|
||||
rtems_fatal(
|
||||
RTEMS_FATAL_SOURCE_INVALID_HEAP_FREE,
|
||||
(rtems_fatal_code) ptr
|
||||
);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -45,7 +45,7 @@ void rtems_filesystem_location_free( rtems_filesystem_location_info_t *loc )
|
||||
{
|
||||
if ( loc->mt_entry != NULL ) {
|
||||
rtems_filesystem_instance_lock( loc );
|
||||
(*loc->mt_entry->ops->freenod_h)( loc );
|
||||
( *loc->mt_entry->ops->freenod_h )( loc );
|
||||
rtems_filesystem_instance_unlock( loc );
|
||||
rtems_filesystem_location_remove_from_mt_entry( loc );
|
||||
}
|
||||
|
||||
@@ -39,10 +39,7 @@
|
||||
#include <rtems/libio_.h>
|
||||
#include <rtems/seterr.h>
|
||||
|
||||
int fstat(
|
||||
int fd,
|
||||
struct stat *sbuf
|
||||
)
|
||||
int fstat( int fd, struct stat *sbuf )
|
||||
{
|
||||
rtems_libio_t *iop;
|
||||
int rv;
|
||||
@@ -50,8 +47,9 @@ int fstat(
|
||||
/*
|
||||
* Check to see if we were passed a valid pointer.
|
||||
*/
|
||||
if ( !sbuf )
|
||||
if ( !sbuf ) {
|
||||
rtems_set_errno_and_return_minus_one( EFAULT );
|
||||
}
|
||||
|
||||
/*
|
||||
* Now process the stat() request.
|
||||
@@ -62,10 +60,10 @@ int fstat(
|
||||
* Zero out the stat structure so the various support
|
||||
* versions of stat don't have to.
|
||||
*/
|
||||
memset( sbuf, 0, sizeof(struct stat) );
|
||||
memset( sbuf, 0, sizeof( struct stat ) );
|
||||
|
||||
rv = (*iop->pathinfo.handlers->fstat_h)( &iop->pathinfo, sbuf );
|
||||
if (rv == 0 && !rtems_libio_iop_is_open( iop ) ) {
|
||||
rv = ( *iop->pathinfo.handlers->fstat_h )( &iop->pathinfo, sbuf );
|
||||
if ( rv == 0 && !rtems_libio_iop_is_open( iop ) ) {
|
||||
errno = EBADF;
|
||||
rv = -1;
|
||||
}
|
||||
@@ -79,15 +77,11 @@ int fstat(
|
||||
* This is the Newlib dependent reentrant version of fstat().
|
||||
*/
|
||||
|
||||
#if defined(RTEMS_NEWLIB) && !defined(HAVE_FSTAT_R)
|
||||
#if defined( RTEMS_NEWLIB ) && !defined( HAVE_FSTAT_R )
|
||||
|
||||
#include <reent.h>
|
||||
|
||||
int _fstat_r(
|
||||
struct _reent *ptr RTEMS_UNUSED,
|
||||
int fd,
|
||||
struct stat *buf
|
||||
)
|
||||
int _fstat_r( struct _reent *ptr RTEMS_UNUSED, int fd, struct stat *buf )
|
||||
{
|
||||
return fstat( fd, buf );
|
||||
}
|
||||
|
||||
@@ -45,9 +45,7 @@
|
||||
/**
|
||||
* POSIX 1003.1b 6.6.1 - Synchronize the State of a File
|
||||
*/
|
||||
int fsync(
|
||||
int fd
|
||||
)
|
||||
int fsync( int fd )
|
||||
{
|
||||
rtems_libio_t *iop;
|
||||
int rv;
|
||||
@@ -58,7 +56,7 @@ int fsync(
|
||||
* Now process the fsync().
|
||||
*/
|
||||
|
||||
rv = (*iop->pathinfo.handlers->fsync_h)( iop );
|
||||
rv = ( *iop->pathinfo.handlers->fsync_h )( iop );
|
||||
rtems_libio_iop_drop( iop );
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ int ftruncate( int fd, off_t length )
|
||||
|
||||
LIBIO_GET_IOP_WITH_ACCESS( fd, iop, LIBIO_FLAGS_WRITE, EINVAL );
|
||||
|
||||
rv = (*iop->pathinfo.handlers->ftruncate_h)( iop, length );
|
||||
rv = ( *iop->pathinfo.handlers->ftruncate_h )( iop, length );
|
||||
rtems_libio_iop_drop( iop );
|
||||
} else {
|
||||
errno = EINVAL;
|
||||
|
||||
@@ -10,14 +10,14 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#if defined(RTEMS_NEWLIB) && !defined(HAVE_FTRYLOCKFILE)
|
||||
#if defined( RTEMS_NEWLIB ) && !defined( HAVE_FTRYLOCKFILE )
|
||||
|
||||
#include <stdio.h>
|
||||
#include <rtems/seterr.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* This is a non-functional stub */
|
||||
int ftrylockfile(FILE* file)
|
||||
int ftrylockfile( FILE *file )
|
||||
{
|
||||
(void) file;
|
||||
rtems_set_errno_and_return_minus_one( ENOTSUP );
|
||||
|
||||
@@ -17,14 +17,14 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#if defined(RTEMS_NEWLIB) && !defined(HAVE_FUNLOCKFILE)
|
||||
#if defined( RTEMS_NEWLIB ) && !defined( HAVE_FUNLOCKFILE )
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/**
|
||||
* This is a non-functional stub
|
||||
*/
|
||||
void funlockfile(FILE* file)
|
||||
void funlockfile( FILE *file )
|
||||
{
|
||||
(void) file;
|
||||
}
|
||||
|
||||
@@ -49,14 +49,11 @@
|
||||
*
|
||||
* Set file access and modification times
|
||||
*/
|
||||
int futimens(
|
||||
int fd,
|
||||
const struct timespec times[2]
|
||||
)
|
||||
int futimens( int fd, const struct timespec times[ 2 ] )
|
||||
{
|
||||
int rv;
|
||||
rtems_libio_t *iop;
|
||||
struct timespec new_times[2];
|
||||
int rv;
|
||||
rtems_libio_t *iop;
|
||||
struct timespec new_times[ 2 ];
|
||||
const rtems_filesystem_location_info_t *currentloc = NULL;
|
||||
|
||||
LIBIO_GET_IOP_WITH_ACCESS( fd, iop, LIBIO_FLAGS_READ, EBADF );
|
||||
@@ -75,10 +72,7 @@ int futimens(
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = (*currentloc->mt_entry->ops->utimens_h)(
|
||||
currentloc,
|
||||
new_times
|
||||
);
|
||||
rv = ( *currentloc->mt_entry->ops->utimens_h )( currentloc, new_times );
|
||||
|
||||
rtems_libio_iop_drop( iop );
|
||||
|
||||
|
||||
@@ -46,11 +46,7 @@
|
||||
/*
|
||||
* Prototypes to avoid warnings
|
||||
*/
|
||||
int getdents(
|
||||
int dd_fd,
|
||||
char *dd_buf,
|
||||
int dd_len
|
||||
);
|
||||
int getdents( int dd_fd, char *dd_buf, int dd_len );
|
||||
|
||||
/**
|
||||
* SVR4 and SVID extension required by Newlib readdir() family.
|
||||
@@ -59,15 +55,11 @@ int getdents(
|
||||
* the current directory position index. These entries will be placed in
|
||||
* character array pointed to by -dd_buf-
|
||||
*/
|
||||
int getdents(
|
||||
int dd_fd,
|
||||
char *dd_buf,
|
||||
int dd_len
|
||||
)
|
||||
int getdents( int dd_fd, char *dd_buf, int dd_len )
|
||||
{
|
||||
rtems_libio_t *iop;
|
||||
mode_t type;
|
||||
int result;
|
||||
mode_t type;
|
||||
int result;
|
||||
|
||||
/*
|
||||
* Get the file control block structure associated with the file descriptor
|
||||
@@ -87,7 +79,7 @@ int getdents(
|
||||
* Return the number of bytes that were actually transfered as a result
|
||||
* of the read attempt.
|
||||
*/
|
||||
result = (*iop->pathinfo.handlers->read_h)( iop, dd_buf, dd_len );
|
||||
result = ( *iop->pathinfo.handlers->read_h )( iop, dd_buf, dd_len );
|
||||
rtems_libio_iop_drop( iop );
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@
|
||||
#include <rtems/score/assert.h>
|
||||
|
||||
typedef struct {
|
||||
FILE *fp;
|
||||
char buf[256];
|
||||
FILE *fp;
|
||||
char buf[ 256 ];
|
||||
struct group grp;
|
||||
} grp_context;
|
||||
|
||||
@@ -40,48 +40,57 @@ static pthread_once_t grp_once = PTHREAD_ONCE_INIT;
|
||||
|
||||
static pthread_key_t grp_key;
|
||||
|
||||
static void grp_init(void)
|
||||
static void grp_init( void )
|
||||
{
|
||||
pthread_key_create(&grp_key, free);
|
||||
pthread_key_create( &grp_key, free );
|
||||
}
|
||||
|
||||
static grp_context *grp_get_context(void)
|
||||
static grp_context *grp_get_context( void )
|
||||
{
|
||||
pthread_once(&grp_once, grp_init);
|
||||
pthread_once( &grp_once, grp_init );
|
||||
|
||||
return pthread_getspecific(grp_key);
|
||||
return pthread_getspecific( grp_key );
|
||||
}
|
||||
|
||||
struct group *getgrent(void)
|
||||
struct group *getgrent( void )
|
||||
{
|
||||
grp_context *ctx = grp_get_context();
|
||||
|
||||
if (ctx == NULL)
|
||||
if ( ctx == NULL ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ctx->fp == NULL)
|
||||
if ( ctx->fp == NULL ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!_libcsupport_scangr(ctx->fp, &ctx->grp, ctx->buf, sizeof(ctx->buf)))
|
||||
if ( !_libcsupport_scangr(
|
||||
ctx->fp,
|
||||
&ctx->grp,
|
||||
ctx->buf,
|
||||
sizeof( ctx->buf )
|
||||
) ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &ctx->grp;
|
||||
}
|
||||
|
||||
void setgrent(void)
|
||||
void setgrent( void )
|
||||
{
|
||||
grp_context *ctx = grp_get_context();
|
||||
|
||||
if (ctx == NULL) {
|
||||
if ( ctx == NULL ) {
|
||||
int eno;
|
||||
|
||||
ctx = calloc(1, sizeof(*ctx));
|
||||
if (ctx == NULL)
|
||||
ctx = calloc( 1, sizeof( *ctx ) );
|
||||
if ( ctx == NULL ) {
|
||||
return;
|
||||
}
|
||||
|
||||
eno = pthread_setspecific(grp_key, ctx);
|
||||
if (eno != 0) {
|
||||
free(ctx);
|
||||
eno = pthread_setspecific( grp_key, ctx );
|
||||
if ( eno != 0 ) {
|
||||
free( ctx );
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -89,25 +98,27 @@ void setgrent(void)
|
||||
|
||||
_libcsupport_pwdgrp_init();
|
||||
|
||||
if (ctx->fp != NULL)
|
||||
fclose(ctx->fp);
|
||||
if ( ctx->fp != NULL ) {
|
||||
fclose( ctx->fp );
|
||||
}
|
||||
|
||||
ctx->fp = fopen("/etc/group", "r");
|
||||
ctx->fp = fopen( "/etc/group", "r" );
|
||||
}
|
||||
|
||||
void endgrent(void)
|
||||
void endgrent( void )
|
||||
{
|
||||
grp_context *ctx = grp_get_context();
|
||||
int sc;
|
||||
|
||||
if (ctx == NULL)
|
||||
if ( ctx == NULL ) {
|
||||
return;
|
||||
|
||||
if (ctx->fp != NULL) {
|
||||
fclose(ctx->fp);
|
||||
}
|
||||
|
||||
free(ctx);
|
||||
sc = pthread_setspecific(grp_key, NULL);
|
||||
_Assert_Unused_variable_equals(sc, 0);
|
||||
if ( ctx->fp != NULL ) {
|
||||
fclose( ctx->fp );
|
||||
}
|
||||
|
||||
free( ctx );
|
||||
sc = pthread_setspecific( grp_key, NULL );
|
||||
_Assert_Unused_variable_equals( sc, 0 );
|
||||
}
|
||||
|
||||
@@ -29,27 +29,25 @@
|
||||
/*
|
||||
* Static, thread-unsafe, buffers
|
||||
*/
|
||||
static char grbuf[200];
|
||||
static char grbuf[ 200 ];
|
||||
static struct group grent;
|
||||
|
||||
struct group *getgrnam(
|
||||
const char *name
|
||||
)
|
||||
struct group *getgrnam( const char *name )
|
||||
{
|
||||
struct group *p;
|
||||
|
||||
if(getgrnam_r(name, &grent, grbuf, sizeof grbuf, &p))
|
||||
if ( getgrnam_r( name, &grent, grbuf, sizeof grbuf, &p ) ) {
|
||||
return NULL;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
struct group *getgrgid(
|
||||
gid_t gid
|
||||
)
|
||||
struct group *getgrgid( gid_t gid )
|
||||
{
|
||||
struct group *p;
|
||||
|
||||
if(getgrgid_r(gid, &grent, grbuf, sizeof grbuf, &p))
|
||||
if ( getgrgid_r( gid, &grent, grbuf, sizeof grbuf, &p ) ) {
|
||||
return NULL;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -48,21 +48,18 @@
|
||||
/**
|
||||
* 4.2.3 Get Supplementary IDs, P1003.1b-1993, p. 86
|
||||
*/
|
||||
int getgroups(
|
||||
int gidsetsize,
|
||||
gid_t grouplist[]
|
||||
)
|
||||
int getgroups( int gidsetsize, gid_t grouplist[] )
|
||||
{
|
||||
int rv;
|
||||
struct passwd pwd;
|
||||
int rv;
|
||||
struct passwd pwd;
|
||||
struct passwd *pwd_res;
|
||||
char buf[256];
|
||||
gid_t gid;
|
||||
const char *user;
|
||||
struct group *grp;
|
||||
char buf[ 256 ];
|
||||
gid_t gid;
|
||||
const char *user;
|
||||
struct group *grp;
|
||||
|
||||
rv = getpwuid_r(getuid(), &pwd, &buf[0], sizeof(buf), &pwd_res);
|
||||
if (rv != 0) {
|
||||
rv = getpwuid_r( getuid(), &pwd, &buf[ 0 ], sizeof( buf ), &pwd_res );
|
||||
if ( rv != 0 ) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -71,17 +68,17 @@ int getgroups(
|
||||
|
||||
setgrent();
|
||||
|
||||
while ((grp = getgrent()) != NULL) {
|
||||
char **mem = &grp->gr_mem[0];
|
||||
while ( ( grp = getgrent() ) != NULL ) {
|
||||
char **mem = &grp->gr_mem[ 0 ];
|
||||
|
||||
if (grp->gr_gid == gid) {
|
||||
if ( grp->gr_gid == gid ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
while (*mem != NULL) {
|
||||
if (strcmp(*mem, user) == 0) {
|
||||
if (rv < gidsetsize) {
|
||||
grouplist[rv] = grp->gr_gid;
|
||||
while ( *mem != NULL ) {
|
||||
if ( strcmp( *mem, user ) == 0 ) {
|
||||
if ( rv < gidsetsize ) {
|
||||
grouplist[ rv ] = grp->gr_gid;
|
||||
}
|
||||
|
||||
++rv;
|
||||
@@ -95,9 +92,9 @@ int getgroups(
|
||||
|
||||
endgrent();
|
||||
|
||||
if (gidsetsize == 0 || rv <= gidsetsize) {
|
||||
if ( gidsetsize == 0 || rv <= gidsetsize ) {
|
||||
return rv;
|
||||
} else {
|
||||
rtems_set_errno_and_return_minus_one(EINVAL);
|
||||
rtems_set_errno_and_return_minus_one( EINVAL );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,26 +64,26 @@ char *getlogin( void )
|
||||
*
|
||||
* @note P1003.1c/D10, p. 49 adds getlogin_r().
|
||||
*/
|
||||
int getlogin_r(
|
||||
char *name,
|
||||
size_t namesize
|
||||
)
|
||||
int getlogin_r( char *name, size_t namesize )
|
||||
{
|
||||
struct passwd *pw;
|
||||
char *pname;
|
||||
|
||||
if ( !name )
|
||||
if ( !name ) {
|
||||
return EFAULT;
|
||||
}
|
||||
|
||||
if ( namesize < LOGIN_NAME_MAX )
|
||||
if ( namesize < LOGIN_NAME_MAX ) {
|
||||
return ERANGE;
|
||||
}
|
||||
|
||||
/* Set the pointer to a default name */
|
||||
pname = "";
|
||||
|
||||
pw = getpwuid(getuid());
|
||||
if ( pw )
|
||||
pname = pw->pw_name;
|
||||
pw = getpwuid( getuid() );
|
||||
if ( pw ) {
|
||||
pname = pw->pw_name;
|
||||
}
|
||||
|
||||
strncpy( name, pname, LOGIN_NAME_MAX );
|
||||
return 0;
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
* gcc 2.8.1 plus gnat 3.13p and gcc 3.0.1 require it to be there and
|
||||
* return a reasonable value.
|
||||
*/
|
||||
int getpagesize(void)
|
||||
int getpagesize( void )
|
||||
{
|
||||
return PAGE_SIZE;
|
||||
}
|
||||
|
||||
@@ -49,16 +49,14 @@ pid_t getpid( void )
|
||||
return rtems_object_get_local_node();
|
||||
}
|
||||
|
||||
#if defined(RTEMS_NEWLIB) && !defined(HAVE__GETPID_R)
|
||||
#if defined( RTEMS_NEWLIB ) && !defined( HAVE__GETPID_R )
|
||||
|
||||
#include <reent.h>
|
||||
|
||||
/**
|
||||
* This is the Newlib dependent reentrant version of getpid().
|
||||
*/
|
||||
pid_t _getpid_r(
|
||||
struct _reent *ptr RTEMS_UNUSED
|
||||
)
|
||||
pid_t _getpid_r( struct _reent *ptr RTEMS_UNUSED )
|
||||
{
|
||||
return getpid();
|
||||
}
|
||||
|
||||
@@ -29,52 +29,54 @@
|
||||
/*
|
||||
* Static, thread-unsafe, buffers
|
||||
*/
|
||||
static FILE *passwd_fp;
|
||||
static char pwbuf[200];
|
||||
static FILE *passwd_fp;
|
||||
static char pwbuf[ 200 ];
|
||||
static struct passwd pwent;
|
||||
|
||||
struct passwd *getpwnam(
|
||||
const char *name
|
||||
)
|
||||
struct passwd *getpwnam( const char *name )
|
||||
{
|
||||
struct passwd *p;
|
||||
|
||||
if(getpwnam_r(name, &pwent, pwbuf, sizeof pwbuf, &p))
|
||||
if ( getpwnam_r( name, &pwent, pwbuf, sizeof pwbuf, &p ) ) {
|
||||
return NULL;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
struct passwd *getpwuid(
|
||||
uid_t uid
|
||||
)
|
||||
struct passwd *getpwuid( uid_t uid )
|
||||
{
|
||||
struct passwd *p;
|
||||
|
||||
if(getpwuid_r(uid, &pwent, pwbuf, sizeof pwbuf, &p))
|
||||
if ( getpwuid_r( uid, &pwent, pwbuf, sizeof pwbuf, &p ) ) {
|
||||
return NULL;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
struct passwd *getpwent(void)
|
||||
struct passwd *getpwent( void )
|
||||
{
|
||||
if (passwd_fp == NULL)
|
||||
if ( passwd_fp == NULL ) {
|
||||
return NULL;
|
||||
if (!_libcsupport_scanpw(passwd_fp, &pwent, pwbuf, sizeof pwbuf))
|
||||
}
|
||||
if ( !_libcsupport_scanpw( passwd_fp, &pwent, pwbuf, sizeof pwbuf ) ) {
|
||||
return NULL;
|
||||
}
|
||||
return &pwent;
|
||||
}
|
||||
|
||||
void setpwent(void)
|
||||
void setpwent( void )
|
||||
{
|
||||
_libcsupport_pwdgrp_init();
|
||||
|
||||
if (passwd_fp != NULL)
|
||||
fclose(passwd_fp);
|
||||
passwd_fp = fopen("/etc/passwd", "r");
|
||||
if ( passwd_fp != NULL ) {
|
||||
fclose( passwd_fp );
|
||||
}
|
||||
passwd_fp = fopen( "/etc/passwd", "r" );
|
||||
}
|
||||
|
||||
void endpwent(void)
|
||||
void endpwent( void )
|
||||
{
|
||||
if (passwd_fp != NULL)
|
||||
fclose(passwd_fp);
|
||||
if ( passwd_fp != NULL ) {
|
||||
fclose( passwd_fp );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,11 +12,11 @@
|
||||
|
||||
#include <rtems.h>
|
||||
|
||||
#if defined(RTEMS_NEWLIB)
|
||||
#if defined( RTEMS_NEWLIB )
|
||||
#include <sys/reent.h>
|
||||
|
||||
#ifndef _REENT_THREAD_LOCAL
|
||||
struct _reent *__getreent(void)
|
||||
struct _reent *__getreent( void )
|
||||
{
|
||||
return _GLOBAL_REENT;
|
||||
}
|
||||
|
||||
@@ -61,9 +61,7 @@ static bool usage_visitor( Thread_Control *the_thread, void *arg )
|
||||
return false;
|
||||
}
|
||||
|
||||
static int getrusage_RUSAGE_SELF(
|
||||
struct rusage *usage
|
||||
)
|
||||
static int getrusage_RUSAGE_SELF( struct rusage *usage )
|
||||
{
|
||||
/*
|
||||
* RTEMS only has a single process so there are no children. The
|
||||
@@ -84,13 +82,11 @@ static int getrusage_RUSAGE_SELF(
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int getrusage_RUSAGE_THREAD(
|
||||
struct rusage *usage
|
||||
)
|
||||
static int getrusage_RUSAGE_THREAD( struct rusage *usage )
|
||||
{
|
||||
Thread_Control *the_thread;
|
||||
ISR_lock_Context lock_context;
|
||||
Timestamp_Control used;
|
||||
Thread_Control *the_thread;
|
||||
ISR_lock_Context lock_context;
|
||||
Timestamp_Control used;
|
||||
the_thread = _Thread_Get( OBJECTS_ID_OF_SELF, &lock_context );
|
||||
used = _Thread_Get_CPU_time_used( the_thread );
|
||||
_ISR_lock_ISR_enable( &lock_context );
|
||||
@@ -100,22 +96,21 @@ static int getrusage_RUSAGE_THREAD(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getrusage(
|
||||
int who, struct rusage *usage
|
||||
)
|
||||
int getrusage( int who, struct rusage *usage )
|
||||
{
|
||||
if ( !usage )
|
||||
if ( !usage ) {
|
||||
rtems_set_errno_and_return_minus_one( EFAULT );
|
||||
}
|
||||
|
||||
switch ( who ) {
|
||||
case RUSAGE_SELF:
|
||||
return getrusage_RUSAGE_SELF( usage );
|
||||
case RUSAGE_THREAD:
|
||||
return getrusage_RUSAGE_THREAD( usage );
|
||||
case RUSAGE_CHILDREN:
|
||||
rtems_set_errno_and_return_minus_one( ENOSYS );
|
||||
default:
|
||||
break;
|
||||
case RUSAGE_SELF:
|
||||
return getrusage_RUSAGE_SELF( usage );
|
||||
case RUSAGE_THREAD:
|
||||
return getrusage_RUSAGE_THREAD( usage );
|
||||
case RUSAGE_CHILDREN:
|
||||
rtems_set_errno_and_return_minus_one( ENOSYS );
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
rtems_set_errno_and_return_minus_one( EINVAL );
|
||||
|
||||
@@ -49,4 +49,3 @@ uid_t getuid( void )
|
||||
{
|
||||
return _POSIX_types_Uid;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,27 +48,23 @@
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
int ioctl(
|
||||
int fd,
|
||||
ioctl_command_t command,
|
||||
...
|
||||
)
|
||||
int ioctl( int fd, ioctl_command_t command, ... )
|
||||
{
|
||||
va_list ap;
|
||||
int rc;
|
||||
rtems_libio_t *iop;
|
||||
void *buffer;
|
||||
va_list ap;
|
||||
int rc;
|
||||
rtems_libio_t *iop;
|
||||
void *buffer;
|
||||
|
||||
LIBIO_GET_IOP( fd, iop );
|
||||
|
||||
va_start(ap, command);
|
||||
va_start( ap, command );
|
||||
|
||||
buffer = va_arg(ap, void *);
|
||||
buffer = va_arg( ap, void * );
|
||||
|
||||
/*
|
||||
* Now process the ioctl().
|
||||
*/
|
||||
rc = (*iop->pathinfo.handlers->ioctl_h)( iop, command, buffer );
|
||||
rc = ( *iop->pathinfo.handlers->ioctl_h )( iop, command, buffer );
|
||||
|
||||
va_end( ap );
|
||||
rtems_libio_iop_drop( iop );
|
||||
|
||||
@@ -37,18 +37,15 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#if defined(RTEMS_NEWLIB) && !defined(HAVE__ISATTY_R)
|
||||
#if defined( RTEMS_NEWLIB ) && !defined( HAVE__ISATTY_R )
|
||||
|
||||
/**
|
||||
/**
|
||||
* This is the Newlib dependent reentrant version of isatty().
|
||||
*/
|
||||
#include <unistd.h>
|
||||
#include <reent.h>
|
||||
|
||||
int _isatty_r(
|
||||
struct _reent *ptr,
|
||||
int fd
|
||||
)
|
||||
int _isatty_r( struct _reent *ptr, int fd )
|
||||
{
|
||||
(void) ptr;
|
||||
return isatty( fd );
|
||||
|
||||
@@ -37,17 +37,17 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#if defined(RTEMS_NEWLIB) && !defined(HAVE_ISSETUGID)
|
||||
#if defined( RTEMS_NEWLIB ) && !defined( HAVE_ISSETUGID )
|
||||
|
||||
/*
|
||||
* Prototype to avoid warnings
|
||||
*/
|
||||
int issetugid (void);
|
||||
int issetugid( void );
|
||||
|
||||
/**
|
||||
* Dummy version of BSD routine
|
||||
*/
|
||||
int issetugid (void)
|
||||
int issetugid( void )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
* These are directly supported (and completely correct) in the posix api.
|
||||
*/
|
||||
|
||||
#if !defined(RTEMS_POSIX_API)
|
||||
#if !defined( RTEMS_POSIX_API )
|
||||
int kill( pid_t pid, int sig )
|
||||
{
|
||||
(void) pid;
|
||||
@@ -42,7 +42,7 @@ int kill( pid_t pid, int sig )
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(RTEMS_NEWLIB)
|
||||
#if defined( RTEMS_NEWLIB )
|
||||
#include <reent.h>
|
||||
|
||||
int _kill_r( struct _reent *ptr, pid_t pid, int sig )
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
|
||||
int lchown( const char *path, uid_t owner, gid_t group )
|
||||
{
|
||||
int rv;
|
||||
int rv;
|
||||
rtems_filesystem_eval_path_context_t ctx;
|
||||
int eval_flags = RTEMS_FS_FOLLOW_HARD_LINK;
|
||||
const rtems_filesystem_location_info_t *currentloc =
|
||||
rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
|
||||
int eval_flags = RTEMS_FS_FOLLOW_HARD_LINK;
|
||||
const rtems_filesystem_location_info_t
|
||||
*currentloc = rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
|
||||
|
||||
rv = rtems_filesystem_chown( currentloc, owner, group );
|
||||
|
||||
|
||||
@@ -62,31 +62,31 @@
|
||||
#undef ACCEPT_O_NDELAY_ALIAS
|
||||
|
||||
static const rtems_assoc_t access_modes_assoc[] = {
|
||||
{ "READ", LIBIO_FLAGS_READ, O_RDONLY },
|
||||
{ "WRITE", LIBIO_FLAGS_WRITE, O_WRONLY },
|
||||
{ "READ", LIBIO_FLAGS_READ, O_RDONLY },
|
||||
{ "WRITE", LIBIO_FLAGS_WRITE, O_WRONLY },
|
||||
{ "READ/WRITE", LIBIO_FLAGS_READ_WRITE, O_RDWR },
|
||||
{ 0, 0, 0 },
|
||||
};
|
||||
|
||||
static const rtems_assoc_t status_flags_assoc[] = {
|
||||
#ifdef ACCEPT_O_NDELAY_ALIAS
|
||||
{ "NO DELAY", LIBIO_FLAGS_NO_DELAY, O_NDELAY },
|
||||
{ "NO DELAY", LIBIO_FLAGS_NO_DELAY, O_NDELAY },
|
||||
#endif
|
||||
{ "NONBLOCK", LIBIO_FLAGS_NO_DELAY, O_NONBLOCK },
|
||||
{ "APPEND", LIBIO_FLAGS_APPEND, O_APPEND },
|
||||
{ "NONBLOCK", LIBIO_FLAGS_NO_DELAY, O_NONBLOCK },
|
||||
{ "APPEND", LIBIO_FLAGS_APPEND, O_APPEND },
|
||||
{ 0, 0, 0 },
|
||||
};
|
||||
|
||||
unsigned int rtems_libio_from_fcntl_flags( int fcntl_flags )
|
||||
{
|
||||
unsigned int flags = 0;
|
||||
uint32_t access_modes;
|
||||
unsigned int flags = 0;
|
||||
uint32_t access_modes;
|
||||
|
||||
/*
|
||||
* Access mode is a small integer
|
||||
*/
|
||||
|
||||
access_modes = (unsigned int) (fcntl_flags & O_ACCMODE);
|
||||
access_modes = (unsigned int) ( fcntl_flags & O_ACCMODE );
|
||||
fcntl_flags &= ~O_ACCMODE;
|
||||
flags = rtems_assoc_local_by_remote( access_modes_assoc, access_modes );
|
||||
|
||||
@@ -94,7 +94,7 @@ unsigned int rtems_libio_from_fcntl_flags( int fcntl_flags )
|
||||
* Everything else is single bits
|
||||
*/
|
||||
|
||||
flags |= (unsigned int ) rtems_assoc_local_by_remote_bitfield(
|
||||
flags |= (unsigned int) rtems_assoc_local_by_remote_bitfield(
|
||||
status_flags_assoc,
|
||||
(uint32_t) fcntl_flags
|
||||
);
|
||||
@@ -106,19 +106,19 @@ int rtems_libio_to_fcntl_flags( unsigned int flags )
|
||||
{
|
||||
int fcntl_flags = 0;
|
||||
|
||||
if ( (flags & LIBIO_FLAGS_READ_WRITE) == LIBIO_FLAGS_READ_WRITE ) {
|
||||
if ( ( flags & LIBIO_FLAGS_READ_WRITE ) == LIBIO_FLAGS_READ_WRITE ) {
|
||||
fcntl_flags |= O_RDWR;
|
||||
} else if ( (flags & LIBIO_FLAGS_READ) == LIBIO_FLAGS_READ) {
|
||||
} else if ( ( flags & LIBIO_FLAGS_READ ) == LIBIO_FLAGS_READ ) {
|
||||
fcntl_flags |= O_RDONLY;
|
||||
} else if ( (flags & LIBIO_FLAGS_WRITE) == LIBIO_FLAGS_WRITE) {
|
||||
} else if ( ( flags & LIBIO_FLAGS_WRITE ) == LIBIO_FLAGS_WRITE ) {
|
||||
fcntl_flags |= O_WRONLY;
|
||||
}
|
||||
|
||||
if ( (flags & LIBIO_FLAGS_NO_DELAY) == LIBIO_FLAGS_NO_DELAY ) {
|
||||
if ( ( flags & LIBIO_FLAGS_NO_DELAY ) == LIBIO_FLAGS_NO_DELAY ) {
|
||||
fcntl_flags |= O_NONBLOCK;
|
||||
}
|
||||
|
||||
if ( (flags & LIBIO_FLAGS_APPEND) == LIBIO_FLAGS_APPEND ) {
|
||||
if ( ( flags & LIBIO_FLAGS_APPEND ) == LIBIO_FLAGS_APPEND ) {
|
||||
fcntl_flags |= O_APPEND;
|
||||
}
|
||||
|
||||
@@ -151,9 +151,7 @@ rtems_libio_t *rtems_libio_allocate( void )
|
||||
return iop;
|
||||
}
|
||||
|
||||
void rtems_libio_free_iop(
|
||||
rtems_libio_t *iop
|
||||
)
|
||||
void rtems_libio_free_iop( rtems_libio_t *iop )
|
||||
{
|
||||
size_t zero;
|
||||
|
||||
@@ -181,18 +179,16 @@ void rtems_libio_free_iop(
|
||||
rtems_libio_unlock();
|
||||
}
|
||||
|
||||
int rtems_libio_count_open_iops(
|
||||
void
|
||||
)
|
||||
int rtems_libio_count_open_iops( void )
|
||||
{
|
||||
int open = 0;
|
||||
uint32_t i;
|
||||
/*
|
||||
* No locking needed to count the open iops
|
||||
*/
|
||||
for (i = 0; i < rtems_libio_number_iops; ++i) {
|
||||
for ( i = 0; i < rtems_libio_number_iops; ++i ) {
|
||||
const rtems_libio_t *iop = &rtems_libio_iops[ i ];
|
||||
if (( rtems_libio_iop_flags( iop ) & LIBIO_FLAGS_OPEN ) != 0 ) {
|
||||
if ( ( rtems_libio_iop_flags( iop ) & LIBIO_FLAGS_OPEN ) != 0 ) {
|
||||
++open;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,9 +39,9 @@
|
||||
|
||||
#include <rtems/libio.h>
|
||||
|
||||
void rtems_libio_exit(void)
|
||||
void rtems_libio_exit( void )
|
||||
{
|
||||
(void)close(0);
|
||||
(void)close(1);
|
||||
(void)close(2);
|
||||
(void) close( 0 );
|
||||
(void) close( 1 );
|
||||
(void) close( 2 );
|
||||
}
|
||||
|
||||
@@ -66,19 +66,18 @@ void **rtems_libio_iop_free_tail = &rtems_libio_iop_free_head;
|
||||
|
||||
static void rtems_libio_init( void )
|
||||
{
|
||||
uint32_t i;
|
||||
rtems_libio_t *iop;
|
||||
uint32_t i;
|
||||
rtems_libio_t *iop;
|
||||
|
||||
if (rtems_libio_number_iops > 0)
|
||||
{
|
||||
iop = rtems_libio_iop_free_head = &rtems_libio_iops[0];
|
||||
for (i = 0 ; (i + 1) < rtems_libio_number_iops ; i++, iop++) {
|
||||
rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_FREE );
|
||||
iop->data1 = iop + 1;
|
||||
}
|
||||
iop->data1 = NULL;
|
||||
rtems_libio_iop_free_tail = &iop->data1;
|
||||
if ( rtems_libio_number_iops > 0 ) {
|
||||
iop = rtems_libio_iop_free_head = &rtems_libio_iops[ 0 ];
|
||||
for ( i = 0; ( i + 1 ) < rtems_libio_number_iops; i++, iop++ ) {
|
||||
rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_FREE );
|
||||
iop->data1 = iop + 1;
|
||||
}
|
||||
iop->data1 = NULL;
|
||||
rtems_libio_iop_free_tail = &iop->data1;
|
||||
}
|
||||
}
|
||||
|
||||
RTEMS_SYSINIT_ITEM(
|
||||
|
||||
@@ -46,13 +46,11 @@
|
||||
*/
|
||||
int link( const char *path1, const char *path2 )
|
||||
{
|
||||
int rv = 0;
|
||||
int rv = 0;
|
||||
rtems_filesystem_eval_path_context_t ctx_1;
|
||||
rtems_filesystem_eval_path_context_t ctx_2;
|
||||
int eval_flags_1 = RTEMS_FS_FOLLOW_LINK;
|
||||
int eval_flags_2 = RTEMS_FS_FOLLOW_LINK
|
||||
| RTEMS_FS_MAKE
|
||||
| RTEMS_FS_EXCLUSIVE;
|
||||
int eval_flags_1 = RTEMS_FS_FOLLOW_LINK;
|
||||
int eval_flags_2 = RTEMS_FS_FOLLOW_LINK | RTEMS_FS_MAKE | RTEMS_FS_EXCLUSIVE;
|
||||
const rtems_filesystem_location_info_t *currentloc_1 =
|
||||
rtems_filesystem_eval_path_start( &ctx_1, path1, eval_flags_1 );
|
||||
const rtems_filesystem_location_info_t *currentloc_2 =
|
||||
@@ -63,7 +61,7 @@ int link( const char *path1, const char *path2 )
|
||||
currentloc_2
|
||||
);
|
||||
if ( rv == 0 ) {
|
||||
rv = (*currentloc_2->mt_entry->ops->link_h)(
|
||||
rv = ( *currentloc_2->mt_entry->ops->link_h )(
|
||||
currentloc_2,
|
||||
currentloc_1,
|
||||
rtems_filesystem_eval_path_get_token( &ctx_2 ),
|
||||
@@ -77,7 +75,7 @@ int link( const char *path1, const char *path2 )
|
||||
return rv;
|
||||
}
|
||||
|
||||
#if defined(RTEMS_NEWLIB)
|
||||
#if defined( RTEMS_NEWLIB )
|
||||
|
||||
#include <reent.h>
|
||||
|
||||
@@ -86,8 +84,8 @@ int link( const char *path1, const char *path2 )
|
||||
*/
|
||||
int _link_r(
|
||||
struct _reent *ptr RTEMS_UNUSED,
|
||||
const char *path1,
|
||||
const char *path2
|
||||
const char *path1,
|
||||
const char *path2
|
||||
)
|
||||
{
|
||||
return link( path1, path2 );
|
||||
|
||||
@@ -46,7 +46,7 @@ off_t lseek( int fd, off_t offset, int whence )
|
||||
|
||||
LIBIO_GET_IOP( fd, iop );
|
||||
|
||||
rv = (*iop->pathinfo.handlers->lseek_h)( iop, offset, whence );
|
||||
rv = ( *iop->pathinfo.handlers->lseek_h )( iop, offset, whence );
|
||||
rtems_libio_iop_drop( iop );
|
||||
return rv;
|
||||
}
|
||||
@@ -57,15 +57,15 @@ off_t lseek( int fd, off_t offset, int whence )
|
||||
* This is the Newlib dependent reentrant version of lseek().
|
||||
*/
|
||||
|
||||
#if defined(RTEMS_NEWLIB) && !defined(HAVE__LSEEK_R)
|
||||
#if defined( RTEMS_NEWLIB ) && !defined( HAVE__LSEEK_R )
|
||||
|
||||
#include <reent.h>
|
||||
|
||||
off_t _lseek_r(
|
||||
struct _reent *ptr RTEMS_UNUSED,
|
||||
int fd,
|
||||
off_t offset,
|
||||
int whence
|
||||
int fd,
|
||||
off_t offset,
|
||||
int whence
|
||||
)
|
||||
{
|
||||
return lseek( fd, offset, whence );
|
||||
|
||||
@@ -44,11 +44,9 @@
|
||||
|
||||
#include "malloc_p.h"
|
||||
|
||||
void *malloc(
|
||||
size_t size
|
||||
)
|
||||
void *malloc( size_t size )
|
||||
{
|
||||
void *return_this;
|
||||
void *return_this;
|
||||
|
||||
if ( size == 0 ) {
|
||||
return NULL;
|
||||
@@ -63,13 +61,11 @@ void *malloc(
|
||||
return return_this;
|
||||
}
|
||||
|
||||
size_t malloc_usable_size(
|
||||
void *area
|
||||
)
|
||||
size_t malloc_usable_size( void *area )
|
||||
{
|
||||
Heap_Block* block = NULL;
|
||||
size_t size = 0;
|
||||
bool needs_lock;
|
||||
Heap_Block *block = NULL;
|
||||
size_t size = 0;
|
||||
bool needs_lock;
|
||||
|
||||
if ( area == NULL ) {
|
||||
return 0;
|
||||
@@ -82,12 +78,12 @@ size_t malloc_usable_size(
|
||||
}
|
||||
|
||||
block = _Heap_Block_of_alloc_area(
|
||||
(uintptr_t)area,
|
||||
(uintptr_t) area,
|
||||
RTEMS_Malloc_Heap->page_size
|
||||
);
|
||||
|
||||
if (block) {
|
||||
size = _Heap_Block_size(block);
|
||||
if ( block ) {
|
||||
size = _Heap_Block_size( block );
|
||||
}
|
||||
|
||||
if ( needs_lock ) {
|
||||
|
||||
@@ -81,7 +81,7 @@ void *rtems_heap_allocate_aligned_with_boundary(
|
||||
)
|
||||
{
|
||||
Heap_Control *heap = RTEMS_Malloc_Heap;
|
||||
void *p;
|
||||
void *p;
|
||||
|
||||
switch ( _Malloc_System_state() ) {
|
||||
case MALLOC_SYSTEM_STATE_NORMAL:
|
||||
@@ -111,14 +111,15 @@ void *rtems_heap_allocate_aligned_with_boundary(
|
||||
}
|
||||
|
||||
if ( p == NULL && alignment == 0 && boundary == 0 ) {
|
||||
p = (*rtems_malloc_extend_handler)( heap, size );
|
||||
p = ( *rtems_malloc_extend_handler )( heap, size );
|
||||
}
|
||||
|
||||
/*
|
||||
* If the user wants us to dirty the allocated memory, then do it.
|
||||
*/
|
||||
if ( p != NULL && rtems_malloc_dirty_helper != NULL )
|
||||
(*rtems_malloc_dirty_helper)( p, size );
|
||||
if ( p != NULL && rtems_malloc_dirty_helper != NULL ) {
|
||||
( *rtems_malloc_dirty_helper )( p, size );
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -44,10 +44,7 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
void rtems_malloc_dirty_memory(
|
||||
void *start,
|
||||
size_t size
|
||||
)
|
||||
void rtems_malloc_dirty_memory( void *start, size_t size )
|
||||
{
|
||||
(void) memset(start, 0xCF, size);
|
||||
(void) memset( start, 0xCF, size );
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
bool malloc_walk(int source, bool printf_enabled)
|
||||
bool malloc_walk( int source, bool printf_enabled )
|
||||
{
|
||||
return _Protected_heap_Walk( RTEMS_Malloc_Heap, source, printf_enabled );
|
||||
}
|
||||
|
||||
@@ -31,5 +31,5 @@
|
||||
|
||||
#include <rtems/malloc.h>
|
||||
|
||||
const rtems_heap_extend_handler rtems_malloc_extend_handler =
|
||||
rtems_heap_null_extend;
|
||||
const rtems_heap_extend_handler
|
||||
rtems_malloc_extend_handler = rtems_heap_null_extend;
|
||||
|
||||
@@ -40,12 +40,11 @@
|
||||
#include <rtems/malloc.h>
|
||||
#include <rtems/score/protectedheap.h>
|
||||
|
||||
int malloc_info(
|
||||
Heap_Information_block *the_info
|
||||
)
|
||||
int malloc_info( Heap_Information_block *the_info )
|
||||
{
|
||||
if ( !the_info )
|
||||
if ( !the_info ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
_Protected_heap_Get_information( RTEMS_Malloc_Heap, the_info );
|
||||
return 0;
|
||||
|
||||
@@ -41,9 +41,7 @@
|
||||
#include <rtems/libcsupport.h>
|
||||
#include "malloc_p.h"
|
||||
|
||||
void malloc_set_heap_pointer(
|
||||
Heap_Control *new_heap
|
||||
)
|
||||
void malloc_set_heap_pointer( Heap_Control *new_heap )
|
||||
{
|
||||
RTEMS_Malloc_Heap = new_heap;
|
||||
}
|
||||
|
||||
@@ -46,10 +46,7 @@
|
||||
/**
|
||||
* POSIX 1003.1b 5.4.1 - Make a Directory
|
||||
*/
|
||||
int mkdir(
|
||||
const char *pathname,
|
||||
mode_t mode
|
||||
)
|
||||
int mkdir( const char *pathname, mode_t mode )
|
||||
{
|
||||
return mknod( pathname, mode | S_IFDIR, 0LL);
|
||||
return mknod( pathname, mode | S_IFDIR, 0LL );
|
||||
}
|
||||
|
||||
@@ -44,10 +44,7 @@
|
||||
/**
|
||||
* POSIX 1003.1b 5.4.1 - Make a FIFO Special File
|
||||
*/
|
||||
int mkfifo(
|
||||
const char *path,
|
||||
mode_t mode
|
||||
)
|
||||
int mkfifo( const char *path, mode_t mode )
|
||||
{
|
||||
return mknod( path, mode | S_IFIFO, 0LL );
|
||||
}
|
||||
|
||||
@@ -43,17 +43,17 @@
|
||||
|
||||
int rtems_filesystem_mknod(
|
||||
const rtems_filesystem_location_info_t *parentloc,
|
||||
const char *name,
|
||||
size_t namelen,
|
||||
mode_t mode,
|
||||
dev_t dev
|
||||
const char *name,
|
||||
size_t namelen,
|
||||
mode_t mode,
|
||||
dev_t dev
|
||||
)
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
mode &= ~rtems_filesystem_umask;
|
||||
|
||||
switch (mode & S_IFMT) {
|
||||
switch ( mode & S_IFMT ) {
|
||||
case S_IFBLK:
|
||||
case S_IFCHR:
|
||||
case S_IFDIR:
|
||||
@@ -65,11 +65,11 @@ int rtems_filesystem_mknod(
|
||||
rv = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if ( rv == 0 ) {
|
||||
const rtems_filesystem_operations_table *ops = parentloc->mt_entry->ops;
|
||||
|
||||
rv = (*ops->mknod_h)( parentloc, name, namelen, mode, dev );
|
||||
rv = ( *ops->mknod_h )( parentloc, name, namelen, mode, dev );
|
||||
}
|
||||
|
||||
return rv;
|
||||
@@ -82,14 +82,13 @@ int rtems_filesystem_mknod(
|
||||
*/
|
||||
int mknod( const char *path, mode_t mode, dev_t dev )
|
||||
{
|
||||
int rv = 0;
|
||||
int rv = 0;
|
||||
rtems_filesystem_eval_path_context_t ctx;
|
||||
int eval_flags = RTEMS_FS_FOLLOW_LINK
|
||||
| RTEMS_FS_MAKE
|
||||
| RTEMS_FS_EXCLUSIVE
|
||||
| (S_ISDIR(mode) ? RTEMS_FS_ACCEPT_RESIDUAL_DELIMITERS : 0);
|
||||
const rtems_filesystem_location_info_t *currentloc =
|
||||
rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
|
||||
int eval_flags = RTEMS_FS_FOLLOW_LINK | RTEMS_FS_MAKE | RTEMS_FS_EXCLUSIVE |
|
||||
( S_ISDIR( mode ) ? RTEMS_FS_ACCEPT_RESIDUAL_DELIMITERS
|
||||
: 0 );
|
||||
const rtems_filesystem_location_info_t
|
||||
*currentloc = rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
|
||||
|
||||
rv = rtems_filesystem_mknod(
|
||||
currentloc,
|
||||
|
||||
@@ -49,24 +49,24 @@
|
||||
#include <rtems/libio_.h>
|
||||
|
||||
typedef struct {
|
||||
rtems_chain_node node;
|
||||
rtems_chain_node node;
|
||||
rtems_filesystem_table_t entry;
|
||||
} filesystem_node;
|
||||
|
||||
static RTEMS_CHAIN_DEFINE_EMPTY(filesystem_chain);
|
||||
static RTEMS_CHAIN_DEFINE_EMPTY( filesystem_chain );
|
||||
|
||||
bool rtems_filesystem_iterate(
|
||||
rtems_per_filesystem_routine routine,
|
||||
void *routine_arg
|
||||
void *routine_arg
|
||||
)
|
||||
{
|
||||
rtems_chain_control *chain = &filesystem_chain;
|
||||
const rtems_filesystem_table_t *table_entry = &rtems_filesystem_table [0];
|
||||
rtems_chain_node *node = NULL;
|
||||
bool stop = false;
|
||||
rtems_chain_control *chain = &filesystem_chain;
|
||||
const rtems_filesystem_table_t *table_entry = &rtems_filesystem_table[ 0 ];
|
||||
rtems_chain_node *node = NULL;
|
||||
bool stop = false;
|
||||
|
||||
while ( table_entry->type && !stop ) {
|
||||
stop = (*routine)( table_entry, routine_arg );
|
||||
stop = ( *routine )( table_entry, routine_arg );
|
||||
++table_entry;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ bool rtems_filesystem_iterate(
|
||||
) {
|
||||
const filesystem_node *fsn = (filesystem_node *) node;
|
||||
|
||||
stop = (*routine)( &fsn->entry, routine_arg );
|
||||
stop = ( *routine )( &fsn->entry, routine_arg );
|
||||
}
|
||||
rtems_libio_unlock();
|
||||
}
|
||||
@@ -88,11 +88,11 @@ bool rtems_filesystem_iterate(
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
const char *type;
|
||||
const char *type;
|
||||
rtems_filesystem_mount_t mount_h;
|
||||
} find_arg;
|
||||
|
||||
static bool find_handler(const rtems_filesystem_table_t *entry, void *arg)
|
||||
static bool find_handler( const rtems_filesystem_table_t *entry, void *arg )
|
||||
{
|
||||
find_arg *fa = arg;
|
||||
|
||||
@@ -105,15 +105,9 @@ static bool find_handler(const rtems_filesystem_table_t *entry, void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
rtems_filesystem_mount_t
|
||||
rtems_filesystem_get_mount_handler(
|
||||
const char *type
|
||||
)
|
||||
rtems_filesystem_mount_t rtems_filesystem_get_mount_handler( const char *type )
|
||||
{
|
||||
find_arg fa = {
|
||||
.type = type,
|
||||
.mount_h = NULL
|
||||
};
|
||||
find_arg fa = { .type = type, .mount_h = NULL };
|
||||
|
||||
if ( type != NULL ) {
|
||||
rtems_filesystem_iterate( find_handler, &fa );
|
||||
@@ -122,22 +116,22 @@ rtems_filesystem_get_mount_handler(
|
||||
return fa.mount_h;
|
||||
}
|
||||
|
||||
int
|
||||
rtems_filesystem_register(
|
||||
const char *type,
|
||||
rtems_filesystem_mount_t mount_h
|
||||
int rtems_filesystem_register(
|
||||
const char *type,
|
||||
rtems_filesystem_mount_t mount_h
|
||||
)
|
||||
{
|
||||
rtems_chain_control *chain = &filesystem_chain;
|
||||
size_t type_size = strlen(type) + 1;
|
||||
size_t fsn_size = sizeof( filesystem_node ) + type_size;
|
||||
filesystem_node *fsn = malloc( fsn_size );
|
||||
char *type_storage = (char *) fsn + sizeof( *fsn );
|
||||
size_t type_size = strlen( type ) + 1;
|
||||
size_t fsn_size = sizeof( filesystem_node ) + type_size;
|
||||
filesystem_node *fsn = malloc( fsn_size );
|
||||
char *type_storage = (char *) fsn + sizeof( *fsn );
|
||||
|
||||
if ( fsn == NULL )
|
||||
if ( fsn == NULL ) {
|
||||
rtems_set_errno_and_return_minus_one( ENOMEM );
|
||||
}
|
||||
|
||||
memcpy(type_storage, type, type_size);
|
||||
memcpy( type_storage, type, type_size );
|
||||
fsn->entry.type = type_storage;
|
||||
fsn->entry.mount_h = mount_h;
|
||||
|
||||
@@ -156,13 +150,10 @@ rtems_filesystem_register(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
rtems_filesystem_unregister(
|
||||
const char *type
|
||||
)
|
||||
int rtems_filesystem_unregister( const char *type )
|
||||
{
|
||||
rtems_chain_control *chain = &filesystem_chain;
|
||||
rtems_chain_node *node = NULL;
|
||||
rtems_chain_node *node = NULL;
|
||||
|
||||
if ( type == NULL ) {
|
||||
rtems_set_errno_and_return_minus_one( EINVAL );
|
||||
@@ -170,8 +161,7 @@ rtems_filesystem_unregister(
|
||||
|
||||
rtems_libio_lock();
|
||||
for (
|
||||
node = rtems_chain_first( chain );
|
||||
!rtems_chain_is_tail( chain, node );
|
||||
node = rtems_chain_first( chain ); !rtems_chain_is_tail( chain, node );
|
||||
node = rtems_chain_next( node )
|
||||
) {
|
||||
filesystem_node *fsn = (filesystem_node *) node;
|
||||
|
||||
@@ -42,25 +42,19 @@
|
||||
#include <rtems/libio.h>
|
||||
|
||||
int mount_and_make_target_path(
|
||||
const char *source,
|
||||
const char *target,
|
||||
const char *filesystemtype,
|
||||
const char *source,
|
||||
const char *target,
|
||||
const char *filesystemtype,
|
||||
rtems_filesystem_options_t options,
|
||||
const void *data
|
||||
const void *data
|
||||
)
|
||||
{
|
||||
int rv = -1;
|
||||
|
||||
if (target != NULL) {
|
||||
rv = rtems_mkdir(target, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
if (rv == 0) {
|
||||
rv = mount(
|
||||
source,
|
||||
target,
|
||||
filesystemtype,
|
||||
options,
|
||||
data
|
||||
);
|
||||
if ( target != NULL ) {
|
||||
rv = rtems_mkdir( target, S_IRWXU | S_IRWXG | S_IRWXO );
|
||||
if ( rv == 0 ) {
|
||||
rv = mount( source, target, filesystemtype, options, data );
|
||||
}
|
||||
} else {
|
||||
errno = EINVAL;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user