diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2011-12-13 12:56:53 +0000 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2011-12-13 12:56:53 +0000 |
commit | b98d399f3c4f7fc19a80a7f12503f0b4226c59dc (patch) | |
tree | 82a06feb8b1ac21527aee2be7c7c3cd37a7e70b9 /cpukit/posix/src/semaphorecreatesupp.c | |
parent | 2011-12-13 Ralf Corsépius <ralf.corsepius@rtems.org> (diff) | |
download | rtems-b98d399f3c4f7fc19a80a7f12503f0b4226c59dc.tar.bz2 |
2011-12-13 Sebastian Huber <sebastian.huber@embedded-brains.de>
* posix/src/mqueuenametoid.c,
posix/src/semaphorenametoid.c: Removed files.
* posix/src/psxnametoid.c: New file.
* posix/Makefile.am: Reflect changes above.
* posix/include/rtems/posix/config.h: Fixed integer types.
* posix/include/rtems/posix/posixapi.h: Declare _POSIX_Name_to_id().
* posix/include/rtems/posix/mqueue.h,
posix/inline/rtems/posix/mqueue.inl: Changed parameter of
_POSIX_Message_queue_Create_support().
_POSIX_Message_queue_Name_to_id() is now inline.
* posix/include/rtems/posix/semaphore.h,
posix/inline/rtems/posix/semaphore.inl: Changed parameter of
_POSIX_Semaphore_Create_support(). _POSIX_Semaphore_Name_to_id() is
now inline.
* posix/src/mqueuecreatesupp.c, posix/src/semaphorecreatesupp.c: Use
_Workspace_String_duplicate().
* posix/src/mqueuesendsupp.c, posix/src/mqueueopen.c,
posix/src/mqueueunlink.c, posix/src/seminit.c, posix/src/semopen.c,
posix/src/semunlink.c: Update due to API changes.
Diffstat (limited to 'cpukit/posix/src/semaphorecreatesupp.c')
-rw-r--r-- | cpukit/posix/src/semaphorecreatesupp.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/cpukit/posix/src/semaphorecreatesupp.c b/cpukit/posix/src/semaphorecreatesupp.c index 42e530bf07..7673b51752 100644 --- a/cpukit/posix/src/semaphorecreatesupp.c +++ b/cpukit/posix/src/semaphorecreatesupp.c @@ -24,13 +24,11 @@ #include <rtems/system.h> #include <rtems/score/object.h> +#include <rtems/score/wkspace.h> #include <rtems/posix/semaphore.h> #include <rtems/posix/time.h> #include <rtems/seterr.h> -/* pure ANSI mode does not have this prototype */ -size_t strnlen(const char *, size_t); - /* * _POSIX_Semaphore_Create_support * @@ -39,7 +37,8 @@ size_t strnlen(const char *, size_t); * sem_open. */ int _POSIX_Semaphore_Create_support( - const char *name, + const char *name_arg, + size_t name_len, int pshared, unsigned int value, POSIX_Semaphore_Control **the_sem @@ -47,26 +46,35 @@ int _POSIX_Semaphore_Create_support( { POSIX_Semaphore_Control *the_semaphore; CORE_semaphore_Attributes *the_sem_attr; - char *name_p = (char *)name; + char *name; /* Sharing semaphores among processes is not currently supported */ if (pshared != 0) rtems_set_errno_and_return_minus_one( ENOSYS ); - if ( name ) { - if ( strnlen( name, NAME_MAX ) >= NAME_MAX ) - rtems_set_errno_and_return_minus_one( ENAMETOOLONG ); - } - _Thread_Disable_dispatch(); the_semaphore = _POSIX_Semaphore_Allocate(); - if ( !the_semaphore ) { _Thread_Enable_dispatch(); rtems_set_errno_and_return_minus_one( ENOSPC ); } + /* + * Make a copy of the user's string for name just in case it was + * dynamically constructed. + */ + if ( name_arg != NULL ) { + name = _Workspace_String_duplicate( name_arg, name_len ); + if ( !name ) { + _POSIX_Semaphore_Free( the_semaphore ); + _Thread_Enable_dispatch(); + rtems_set_errno_and_return_minus_one( ENOMEM ); + } + } else { + name = NULL; + } + the_semaphore->process_shared = pshared; if ( name ) { @@ -103,7 +111,7 @@ int _POSIX_Semaphore_Create_support( _Objects_Open_string( &_POSIX_Semaphore_Information, &the_semaphore->Object, - name_p + name ); *the_sem = the_semaphore; |