@@ -3962,7 +3962,21 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
39623962 {
39633963 if (cond == NULL )
39643964 return BAD_FUNC_ARG ;
3965- #if defined(__OS2__ )
3965+ #if defined(__MACH__ )
3966+ cond -> cond = dispatch_semaphore_create (0 );
3967+ if (cond -> cond == NULL )
3968+ return MEMORY_E ;
3969+
3970+ /* dispatch_release() fails hard, with Trace/BPT trap signal, if the
3971+ * sem's internal count is less than the value passed in with
3972+ * dispatch_semaphore_create(). work around this by initializing
3973+ * with 0, then incrementing it afterwards.
3974+ */
3975+ if (dispatch_semaphore_signal (s -> sem ) < 0 ) {
3976+ dispatch_release (s -> sem );
3977+ return return MEMORY_E ;
3978+ }
3979+ #elif defined(__OS2__ )
39663980 DosCreateMutexSem ( NULL , & cond -> mutex , 0 , FALSE );
39673981 DosCreateEventSem ( NULL , & cond -> cond , DCE_POSTONE , FALSE );
39683982 #elif defined(__NT__ )
@@ -3993,7 +4007,9 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
39934007 {
39944008 if (cond == NULL )
39954009 return BAD_FUNC_ARG ;
3996- #if defined(__OS2__ )
4010+ #if defined(__MACH__ )
4011+ dispatch_release (cond -> cond );
4012+ #elif defined(__OS2__ )
39974013 DosCloseMutexSem (cond -> mutex );
39984014 DosCloseEventSem (cond -> cond );
39994015 #elif defined(__NT__ )
@@ -4013,7 +4029,8 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
40134029 {
40144030 if (cond == NULL )
40154031 return BAD_FUNC_ARG ;
4016- #if defined(__OS2__ )
4032+ #if defined(__MACH__ )
4033+ #elif defined(__OS2__ )
40174034 #elif defined(__NT__ )
40184035 if (wc_LockMutex (& cond -> mutex ) != 0 )
40194036 return BAD_MUTEX_E ;
@@ -4028,7 +4045,9 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
40284045 {
40294046 if (cond == NULL )
40304047 return BAD_FUNC_ARG ;
4031- #if defined(__OS2__ )
4048+ #if defined(__MACH__ )
4049+ dispatch_semaphore_signal (cond -> cond );
4050+ #elif defined(__OS2__ )
40324051 #elif defined(__NT__ )
40334052 if (wc_UnLockMutex (& cond -> mutex ) != 0 )
40344053 return BAD_MUTEX_E ;
@@ -4049,7 +4068,9 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
40494068 {
40504069 if (cond == NULL )
40514070 return BAD_FUNC_ARG ;
4052- #if defined(__OS2__ )
4071+ #if defined(__MACH__ )
4072+ dispatch_semaphore_wait (cond -> cond , DISPATCH_TIME_FOREVER );
4073+ #elif defined(__OS2__ )
40534074 #elif defined(__NT__ )
40544075 if (wc_UnLockMutex (& cond -> mutex ) != 0 )
40554076 return BAD_MUTEX_E ;
0 commit comments