From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,5edee74b13d8e50a X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!news.albasani.net!not-for-mail From: "Frank J. Lhota" Newsgroups: comp.lang.ada Subject: Re: The "black magic" of ioctl Date: Sun, 24 Oct 2010 08:41:14 -0400 Organization: albasani.net Message-ID: References: <74b46743-fb81-48cc-a478-ffd069db2fc6@k22g2000yqh.googlegroups.com> <877hh8lkok.fsf@mid.deneb.enyo.de> Reply-To: FrankLho.NOSPAM@rcn.com Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net m6xtvxz7X0vYfwgdvPRsAkTELs/upT9tkzRzrQ3rz0kxRyThwQ1ztAQax+Rw9axjwC+0axVaePrVYmVAjScKIqcN8sMJ1YsCNMtw8bFIKv2E+3zktgFbWY/i/x3yHeIM NNTP-Posting-Date: Sun, 24 Oct 2010 12:41:25 +0000 (UTC) In-Reply-To: <877hh8lkok.fsf@mid.deneb.enyo.de> Cancel-Lock: sha1:e49lKa5YA88iksraBkqozLFTdCk= User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.11) Gecko/20101013 Lightning/1.0b2 Thunderbird/3.1.5 Injection-Info: news.albasani.net; logging-data="OlJB0+rL4WDKu2UTorHDXP5iTdbNvwMT1IfERlUqcaNLwqA12bXA0R93cJ8k+3tvKczHWabI7p7S4+g9Wm5ancWWSIBWcaEFoBVSA294DTH0qKeiofwEilqoTR4RKd1o"; mail-complaints-to="abuse@albasani.net" Xref: g2news1.google.com comp.lang.ada:14716 Date: 2010-10-24T08:41:14-04:00 List-Id: On 10/23/2010 4:26 PM, Florian Weimer wrote: > ioctl is a varargs function. You cannot call C varargs functions > directly from Ada. You need to write a small wrapper with a fixed > number of arguments. > > In addition, the ioctl constants are often difficult to extract from > the header files. The best way to get them seems to be a small C > program which just prints them. > > So writing some C code is unavoidable here. Actually, you can call a varargs function such as ioctl from Ada. Declare each ioctl profile that you need, e.g. -- ioctl for commands with no additional arguments function Ioctl (Fd : in Interfaces.C.Int; Cmd : in Interfaces.C.Int) return Interfaces.C.Int; pragma Import (C, Ioctl, "ioctl"); -- ioctl for commands with an additional argument -- for returning the device status function Ioctl (Fd : in Interfaces.C.Int; Cmd : in Interfaces.C.Int; Status : access Interfaces.C.Int) return Interfaces.C.Int; pragma Import (C, Ioctl, "ioctl"); -- "All things extant in this world, Gods of Heaven, gods of Earth, Let everything be as it should be; Thus shall it be!" - Magical chant from "Magical Shopping Arcade Abenobashi" "Drizzle, Drazzle, Drozzle, Drome, Time for this one to come home!" - Mr. Wizard from "Tooter Turtle"