From: "Ara.T.Howard" Date: 2003-12-09T15:57:02+09:00 Subject: Re: RCR - 'struct flock*' wrapper for rb_io_fcntl On Tue, 9 Dec 2003, Yukihiro Matsumoto wrote: > Date: Tue, 9 Dec 2003 13:41:50 +0900 > From: Yukihiro Matsumoto > Newsgroups: comp.lang.ruby > Subject: Re: RCR - 'struct flock*' wrapper for rb_io_fcntl > > Hi, > > In message "RCR - 'struct flock*' wrapper for rb_io_fcntl" > on 03/12/09, "Ara.T.Howard" writes: > > |SYNOPSIS: > | > | ruby's fcntl call is incomplete in that one cannot pass a 'struct flock *' > | arg as fcntl's third arg. because of this, no posix compliant locking is > | available from within ruby. > > You can use pack/unpack for the purpose. > > require 'fcntl' # import constants, perhaps this replaces IO#fcntl... > > f = open('/tmp/foobar', 'w') > flock = [Fcntl::F_RDLCK, 0, 0, 0, 0].pack("ssqqi") is this guaranteed to work: are the offsets always the same as a struct flock* as the compiler lays them out? if so, i am personally o.k with this. (thanks for the pointer!) > p Fcntl::F_RDLCK, Fcntl::F_GETLK > f.fcntl Fcntl::F_GETLK, flock > p flock.unpack("ssqqi") > > But still I would not deny your proposal for the sake of readability > and portability. Maybe there can be functions that work similar to > pack_sockaddr_*() / unpack_sockaddr_*() in the socket extension. > pack_flock() or something. yes that sounds good if anwser to above is 'yes' -a -- ATTN: please update your address books with address below! =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328 | STP :: http://www.ngdc.noaa.gov/stp/ | NGDC :: http://www.ngdc.noaa.gov/ | NESDIS :: http://www.nesdis.noaa.gov/ | NOAA :: http://www.noaa.gov/ | US DOC :: http://www.commerce.gov/ | | The difference between art and science is that science is what we | understand well enough to explain to a computer. | Art is everything else. | -- Donald Knuth, "Discover" | | /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done' ===============================================================================