Guest User

Untitled

a guest
Sep 26th, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.35 KB | None | 0 0
  1. diff --git a/libc/stdio/_stdio.h b/libc/stdio/_stdio.h
  2. index 85464fa..4512622 100644
  3. --- a/libc/stdio/_stdio.h
  4. +++ b/libc/stdio/_stdio.h
  5. @@ -22,9 +22,20 @@
  6.  #ifdef __UCLIBC_HAS_WCHAR__
  7.  #include <wchar.h>
  8.  #endif
  9. +#ifdef __UCLIBC_HAS_THREADS__
  10. +#include "pthreadP.h"
  11. +#endif
  12.  
  13.  #include <bits/uClibc_mutex.h>
  14.  
  15. +#ifdef __UCLIBC_HAS_THREADS__
  16. +       #define DISABLE_CANCELLABILITY(oldstate) __pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &(oldstate))
  17. +       #define RESTORE_CANCELLABILITY(oldstate) __pthread_setcancelstate(oldstate, NULL)
  18. +#else
  19. +       #define DISABLE_CANCELLABILITY(oldstate) ((void)0)
  20. +       #define RESTORE_CANCELLABILITY(oldstate) ((void)0)
  21. +#endif
  22. +
  23.  #define __STDIO_THREADLOCK_OPENLIST_ADD                        \
  24.          __UCLIBC_IO_MUTEX_LOCK(_stdio_openlist_add_lock)
  25.  
  26. @@ -149,9 +160,16 @@ static inline ssize_t __READ(FILE *stream, char *buf, size_t bufsize)
  27.  
  28.  static inline ssize_t __WRITE(FILE *stream, const char *buf, size_t bufsize)
  29.  {
  30. +       ssize_t ret;
  31. +#ifdef __UCLIBC_HAS_THREADS__
  32. +       int oldstate;
  33. +#endif
  34. +       DISABLE_CANCELLABILITY(oldstate);
  35.         __STDIO_STREAM_CUSTOM_WRITE_FUNC(stream, buf, bufsize);
  36.  
  37. -       return write(stream->__filedes, buf, bufsize);
  38. +       ret = write(stream->__filedes, buf, bufsize);
  39. +       RESTORE_CANCELLABILITY(oldstate);
  40. +       return ret;
  41.  }
Advertisement
Add Comment
Please, Sign In to add comment