X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdio%2Fftrylockfile.c;fp=functions%2Fstdio%2Fftrylockfile.c;h=cb8147abd12b591b5a0f291c0dbe7c824c26ff24;hb=026148e2e90368c0b23192f506e15aa6197105aa;hp=0000000000000000000000000000000000000000;hpb=e70d680319ea23460b891e14259f2f6b3a568291;p=pdclib diff --git a/functions/stdio/ftrylockfile.c b/functions/stdio/ftrylockfile.c new file mode 100644 index 0000000..cb8147a --- /dev/null +++ b/functions/stdio/ftrylockfile.c @@ -0,0 +1,39 @@ +/* ftrylockfile(FILE * ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include +#include + +#ifndef REGTEST +#include +#include + +int ftrylockfile( FILE * file ) +{ + int res = mtx_trylock( &file->lock ); + switch(res) { + case thrd_success: + return 0; + case thrd_busy: + return 1; + + default: + abort(); + } +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + // Not tested here - tested by other stdio test drivers + return TEST_RESULTS; +} + +#endif