1

I found the problem with my fcntl implementation in js-ctypes. I was using the wrong constant values.

These guys are getting 1 2 3 for rdlck, wrlck, and unlck.

  • However when i run this C code to figure out the constnats on ubuntu its telling me they are 0, 1, and 2 : my constants on ubuntu
muru
  • 197,895
  • 55
  • 485
  • 740
Noitidart
  • 417

2 Answers2

2

I'd say that those constant values are Linux specific, not Ubuntu specific.

In your C file, you're getting fcntl.h from /usr/include/fcntl.h which contains:

/* Get the definitions of O_*, F_*, FD_*: all the
   numbers and flag bits for `open', `fcntl', et al.  */
#include <bits/fcntl.h>

In /usr/include/<your_arch>/bits/fcntl.h you can see the following code:

/* Include generic Linux declarations.  */
#include <bits/fcntl-linux.h>

Finally this /usr/include/<your_arch>/bits/fcntl-linux.h file defines those values as follow:

#ifndef F_RDLCK
/* For posix fcntl() and `l_type' field of a `struct flock' for lockf().  */
# define F_RDLCK        0   /* Read lock.  */
# define F_WRLCK        1   /* Write lock.  */
# define F_UNLCK        2   /* Remove lock.  */
#endif

To confirm that it's not Ubuntu specific, you can check the definitions in the libc source, they are the same.

  • I learned a ton from this post thank you! That's why I accepted this answer. I gave muru an up vote though. I'm very new to C thanks for this basic detail. So libc is used on linux'es right? Mac OS is based on linux but by "linu specific" this excludes mac os right? – Noitidart Sep 24 '14 at 09:16
  • Do you think the same applies for the order of fields in the flock structure? I tried to apply your technique to flock strcuture but not sure if I got it right. From my search flock field order differs on Mac OS based o nhere (https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/fcntl.2.html) but im not sure if all linux have same field order. – Noitidart Sep 24 '14 at 09:18
  • @Noitidart: Sorry I can't confirm for OSX. – Sylvain Pineau Sep 24 '14 at 09:44
  • 1
    @Noitidart What do you mean by order of fields in the structure? The fields have names, the order is irrelevant. As a certified UNIX, OSX should have all the POSIX specified fields, and since Linux doesn't ditch compliance unless necessary, we would have those fields too. – muru Sep 24 '14 at 09:46
  • Thanks muru man! Someone told me HERE that order mattered and it seemed to make a difference because im porting the structure to javascript. :( – Noitidart Sep 24 '14 at 09:51
  • 1
    @Noitidart that is a long chat, and I don't really get what you guys are doing. Are you setting up bindings for some C library in JS? – muru Sep 24 '14 at 23:15
  • Yes sir, it's js-ctypes so I have to define the structure before I can use it. And the structure varies as verified by guy at mozilla HERE. I was wondering if you could help me show me how Sylvian looked up stuff, I would like to look up the constant values and structure for the os's of: freebsd, freebsd, and sunos please. The c libraries are libc.so.7, libc.so.61.0, and libc.so. Should I make seperate topic? – Noitidart Sep 25 '14 at 05:54
1

The value of such constants are always implementation defined, unless the standards specify the value. If you use the values directly instead of the names, that's simply asking for trouble. Nothing in the manpage of fcntl mentions the values, so assume nothing.

muru
  • 197,895
  • 55
  • 485
  • 740
  • Thank you man! I will keep this in mind :) I learned a lot from @Sylvain's post so accepted but definitely definitely appreciate your post and upvoted it :) – Noitidart Sep 24 '14 at 09:16
  • @Noitidart Well, when I saw that answer I was pretty certain which one would get accepted. :D – muru Sep 24 '14 at 09:42