Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22031

Using flock() on Solaris 5.10

$
0
0

I'm writing a C utility for Solaris 5.10 that uses flock() for file synchronization. My goal is to interoperate with an existing legacy system that also invokes flock() under the hood. According to man pages on my box, it is supported in BSD compatibility mode — the legacy system was compiled somehow, after all! (Unfortunately, I only have access to the binary now.)

The problem is, when I try to compile my code, it fails with the following errors:

main.c: In function `main':
main.c:11: warning: implicit declaration of function `flock'
main.c:11: error: `LOCK_EX' undeclared (first use in this function)
main.c:11: error: (Each undeclared identifier is reported only once
main.c:11: error: for each function it appears in.)
main.c:11: error: `LOCK_NB' undeclared (first use in this function)

Here's a short reproducible example (well, reproducible if you have 5.10 at hand...):

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <fcntl.h>
#include <stdio.h>

int main(int argc, char** argv) {
  int fd;
  if ((fd = open("file.txt", O_CREAT | O_RDWR, 0644) == -1))
    return 1;
  if (flock(fd, LOCK_EX | LOCK_NB) == -1)
    return 1;

  puts("File locked!");
  return 0;
}

I'm using gcc 3.4.3 with the following arguments: -o test -std=gnu99 -Wall main.c. The error messages seem to suggest that I'm including the wrong header files, but the man page for flock() doesn't mention anything besides the standard #include <sys/file.h>.

What compiler flags do I need to specify to get a program using flock() to work on Solaris 5.10?


Viewing all articles
Browse latest Browse all 22031

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>