From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mike Gran Newsgroups: gmane.lisp.guile.user Subject: Re: (fcntl fd F_GETLK ...) from Guile Date: Sat, 1 Sep 2007 20:34:52 -0700 (PDT) Message-ID: <493012.28697.qm@web37913.mail.mud.yahoo.com> References: <87zm07c136.fsf@doganov.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="0-1862918085-1188704092=:28697" Content-Transfer-Encoding: 8bit X-Trace: sea.gmane.org 1188704112 21080 80.91.229.12 (2 Sep 2007 03:35:12 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 2 Sep 2007 03:35:12 +0000 (UTC) To: Kaloian Doganov , guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Sep 02 05:35:11 2007 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IRgEt-0006qv-Mg for guile-user@m.gmane.org; Sun, 02 Sep 2007 05:35:08 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IRgEs-0003hY-LC for guile-user@m.gmane.org; Sat, 01 Sep 2007 23:35:06 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IRgEi-0003YO-LH for guile-user@gnu.org; Sat, 01 Sep 2007 23:34:56 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IRgEg-0003V2-Dn for guile-user@gnu.org; Sat, 01 Sep 2007 23:34:56 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IRgEg-0003Up-8h for guile-user@gnu.org; Sat, 01 Sep 2007 23:34:54 -0400 Original-Received: from web37913.mail.mud.yahoo.com ([209.191.91.175]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1IRgEf-0004nT-Qa for guile-user@gnu.org; Sat, 01 Sep 2007 23:34:54 -0400 Original-Received: (qmail 29088 invoked by uid 60001); 2 Sep 2007 03:34:52 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=dIsuFeuzKc31rUGDlrrqvUvT+l/PvkPLwRedehhaEr3Mr31cBi5aqIejBo7PvoKxwUaQ42vDBNjmIcMt0b/gDfZo5wY9+Co4YqpdZx0FSiCRQ9B3cL6WUIzqL+CLH1/zg1baeOJnx8oo/uRf4J0eZyHCWEzQIXPdr5bEe+TiJPI=; X-YMail-OSG: MN5Bd6gVM1l84nyps73vVQyCuS1JRQErnrNcrN.U1iYG.Kg_A2jHBuUqNqqCDk0t1cBUOrxjVm6d_1XxFZg1P4cuwwehPfXcDsASwZF3LEv71UcpGOY- Original-Received: from [4.232.135.233] by web37913.mail.mud.yahoo.com via HTTP; Sat, 01 Sep 2007 20:34:52 PDT In-Reply-To: <87zm07c136.fsf@doganov.org> X-Detected-Kernel: FreeBSD 4.7-5.2 (or MacOS X 10.2-10.4) (2) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:6124 Archived-At: --0-1862918085-1188704092=:28697 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Content-Id: Content-Disposition: inline Kaloian- --- Kaloian Doganov wrote: > Is there a way to use fcntl's F_GETLK command from Guile? According > to the docs [1], only the following commands are available: > I put together something. I've attached the more important source files here for reference, but, the buildable files are in http://lonelycactus.com/getlk-0.0.tar.gz For me, it does "./configure && make && make install" on Linux, but fails on Cygwin. Cygwin fails because I don't know how to do DLLs. Here's what it does on my machine. Your mileage may vary. bash-3.1$ guile guile> (use-modules (getlk)) guile> (define fd (open-output-file "blammo")) guile> (define lk (fcntl-lk fd F_SETLKW (list F_WRLCK SEEK_SET 0 0 (getpid)))) guile> lk (1 0 0 0 11415) guile> (set! lk (fcntl-lk fd F_SETLK (list F_UNLCK SEEK_SET 0 0 (getpid)))) guile> lk (2 0 0 0 11415) guile> Good luck. -- Mike Gran --0-1862918085-1188704092=:28697 Content-Type: text/plain; name="getlk.c" Content-Description: 1659791818-getlk.c Content-Disposition: inline; filename="getlk.c" #include #include #include #include #include #ifdef DLL_EXPORT #define API __attribute__ ((dllexport, cdecl)) #else #define API #endif SCM getlk_fcntl_lk_fdes (SCM s_fdes, SCM s_cmd, SCM s_list) API; void getlk_init_getlk (void) API; SCM s_f_getlk; SCM s_f_setlk; SCM s_f_setlkw; SCM s_f_rdlck; SCM s_f_wrlck; SCM s_f_unlck; SCM getlk_fcntl_lk_fdes(SCM s_fdes, SCM s_cmd, SCM s_list) { int rv; int fdes; struct flock lock; SCM l_type; SCM l_whence; SCM l_start; SCM l_len; SCM l_pid; SCM_ASSERT (scm_is_integer(s_fdes), s_fdes, SCM_ARG1, "fcntl-lk-fdes"); SCM_ASSERT ( scm_is_integer (s_cmd), s_cmd, SCM_ARG2, "fcntl-lk-fdes"); SCM_ASSERT ( scm_is_true (scm_list_p (s_list)), s_list, SCM_ARG3, "fcntl-lk-fdes"); fdes = scm_to_int (s_fdes); l_type = scm_list_ref (s_list, scm_from_int (0)); l_whence = scm_list_ref (s_list, scm_from_int (1)); l_start = scm_list_ref (s_list, scm_from_int (2)); l_len = scm_list_ref (s_list, scm_from_int (3)); l_pid = scm_list_ref (s_list, scm_from_int (4)); lock.l_type = scm_to_short (l_type); lock.l_whence = scm_to_short (l_whence); if (SIZEOF_OFF_T == 4) { lock.l_start = scm_to_int32 (l_start); lock.l_len = scm_to_int32 (l_len); } else if (SIZEOF_OFF_T == 8) { lock.l_start = scm_to_int64 (l_start); lock.l_len = scm_to_int64 (l_len); } else abort (); if (SIZEOF_PID_T == 4) { lock.l_pid = scm_to_int32 (l_pid); } else abort (); rv = fcntl (fdes, scm_to_int (s_cmd), &lock); if (rv == -1) { scm_syserror ("fcntl-lk-fdes"); } l_type = scm_from_short (lock.l_type); l_whence = scm_from_short (lock.l_whence); if (SIZEOF_OFF_T == 4) { l_start = scm_from_int32 (lock.l_start); l_len = scm_from_int32 (lock.l_len); } else if (SIZEOF_OFF_T == 8) { l_start = scm_from_int64 (lock.l_start); l_len = scm_from_int64 (lock.l_len); } else { printf ("aborting at %s %d", __FILE__, __LINE__); abort (); } if (SIZEOF_PID_T == 4) { l_pid = scm_from_int32 (lock.l_pid); } else { printf ("aborting at %s %d", __FILE__, __LINE__); abort (); } return scm_list_5 (l_type, l_whence, l_start, l_len, l_pid); } void getlk_init_getlk () { scm_c_define_gsubr ("fcntl-lk-fdes", 3, 0, 0, getlk_fcntl_lk_fdes); s_f_getlk = scm_permanent_object (scm_c_define ("F_GETLK", scm_from_int (F_GETLK))); s_f_setlk = scm_permanent_object (scm_c_define ("F_SETLK", scm_from_int (F_SETLK))); s_f_setlkw = scm_permanent_object (scm_c_define ("F_SETLKW", scm_from_int (F_SETLKW))); s_f_rdlck = scm_permanent_object (scm_c_define ("F_RDLCK", scm_from_int (F_RDLCK))); s_f_wrlck = scm_permanent_object (scm_c_define ("F_WRLCK", scm_from_int (F_WRLCK))); s_f_unlck = scm_permanent_object (scm_c_define ("F_UNLCK", scm_from_int (F_UNLCK))); } --0-1862918085-1188704092=:28697 Content-Type: application/octet-stream; name="getlk.scm.in" Content-Transfer-Encoding: base64 Content-Description: 1271041479-getlk.scm.in Content-Disposition: attachment; filename="getlk.scm.in" OzsgLSotIE1vZGU6IHNjaGVtZSAtKi0KCihkZWZpbmUtbW9kdWxlIChnZXRs aykKICAjOmV4cG9ydCAoZmNudGwtbGsKCSAgICBGX0dFVExLCgkgICAgRl9T RVRMSwoJICAgIEZfU0VUTEtXCgkgICAgRl9SRExDSwoJICAgIEZfV1JMQ0sK CSAgICBGX1VOTENLKSkKCgooZGVmaW5lIChmY250bC1sayBmZGVzIGNtZCBs aXN0KQogIChpZiAocG9ydD8gZmRlcykKICAgICAgKGZjbnRsLWxrLWZkZXMg KHBvcnQtPmZkZXMgZmRlcykgY21kIGxpc3QpCiAgICAgIChmY250bC1say1m ZGVzIGZkZXMgY21kIGxpc3QpKSkKCgoobG9hZC1leHRlbnNpb24gIlhYbGli ZGlyWFgvbGliZ3VpbGUtZ2V0bGsiICJnZXRsa19pbml0X2dldGxrIik= --0-1862918085-1188704092=:28697 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user --0-1862918085-1188704092=:28697--