Skip to content

[R-pkg-devel] header file for "flockfile" function under windows

2 messages · Carmen M. Livi, Dirk Eddelbuettel

#
Hi all,

I am using file-locking functions in C that can be found in the 
<stdio.h> in Unix

extern void flockfile (FILE *__stream) __THROW;
extern int ftrylockfile (FILE *__stream) __THROW __wur;
extern void funlockfile (FILE *__stream) __THROW;

When submitting to CRAN I have troubles with the win-builder.

<stdio.h> in windows does not contain those functions. But I found them 
in the <pthread_unistd.h>.
But even when including all possible header files for pthread like:*
*

*#include <windows.h>**#include <sys/locking.h>*
*#include <pthread_unistd.h>****#include <pthread.h>****#include <pthread_compat.h>****#include <pthread_signal.h>****#include <pthread_time.h>*

I am aways getting the same error from win-builder:

bed2vector.cpp:2667:19: error: 'flockfile' was not declared in this scope
    flockfile(stream);
                    ^
bed2vector.cpp:2670:46: error: 'getc_unlocked' was not declared in this scope
    for (int ch = 0; (ch = getc_unlocked(stream)) != EOF;) {
                                               ^
bed2vector.cpp:2678:27: error: 'funlockfile' was not declared in this scope
          funlockfile(stream);
                            ^
bed2vector.cpp:2694:21: error: 'funlockfile' was not declared in this scope
    funlockfile(stream);
                      ^

So the header files are there, but the functions are not defined. I am 
not an expert in C, but
have to submit a package that uses C-code. Does someone have more 
experience with this?

Thanks,
Carmen
On 19/02/2018 15:22, Mauro Donadello wrote:

  
  
#
On 20 February 2018 at 20:56, Carmen M. Livi wrote:
| I am using file-locking functions in C that can be found in the 
| <stdio.h> in Unix
| 
| extern void flockfile (FILE *__stream) __THROW;
| extern int ftrylockfile (FILE *__stream) __THROW __wur;
| extern void funlockfile (FILE *__stream) __THROW;
| 
| When submitting to CRAN I have troubles with the win-builder.

lockfile operations are rather OS-dependent. You can't just assume they exist
under Windows.  There are reasons many of us hate the non-POSIX compliance of
Windows with a reason---this is one of them.

But you may be in luck as Gabor recently released a package with a _portable_
lockfile implementation, maybe give it a try:

    https://cran.r-project.org/package=filelock

Dirk