rewrite popen to use posix_spawn instead of fragile vfork hacks
[musl] / src / stdio / ftrylockfile.c
index 67f4b6a..eef4e25 100644 (file)
@@ -1,16 +1,17 @@
 #include "stdio_impl.h"
 #include "pthread_impl.h"
+#include <limits.h>
 
 int ftrylockfile(FILE *f)
 {
        int tid = pthread_self()->tid;
-       if (!libc.lockfile) libc.lockfile = __lockfile;
        if (f->lock == tid) {
-               if (f->lockcount == INT_MAX)
+               if (f->lockcount == LONG_MAX)
                        return -1;
                f->lockcount++;
                return 0;
        }
+       if (f->lock < 0) f->lock = 0;
        if (f->lock || a_cas(&f->lock, 0, tid))
                return -1;
        f->lockcount = 1;