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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ba2f8edf6a585206 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-04-20 02:11:31 PST Path: archiver1.google.com!news1.google.com!news.glorb.com!news.cs.univ-paris8.fr!proxad.net!news.tiscali.fr!foorum!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: File_Type Date: 20 Apr 2004 08:08:26 GMT Message-ID: <2004420-10826-784447b@foorum> References: <61f665c0.0404180417.72855af4@posting.google.com> NNTP-Posting-Host: 212.190.145.10 NNTP-Posting-Date: 20 Apr 2004 08:08:26 GMT X-Complaints-To: abuse@foorum.fr X-POSTER: foorum.com X-Foorum_user_id: X-Foorum_user_tmp_id: 2004415-143819-705548-212.190.145.10-club-internet X-Originating-User: 212.190.145.10 X-Newsreader: Foorum Xref: archiver1.google.com comp.lang.ada:7354 Date: 2004-04-20T08:08:26+00:00 List-Id: Jorge Suarez-Solis Rivaya asked: > Is there anyway to use an Integer Type like a File_Type?, > Is there anyway to asign a File_Type the value 3? Yes, there is, on Unix and Unix-like operating systems; perhaps also on others as well. The way to achieve this is to write a thin binding to the operating system's file management functions, like so: package Low_Level_IO is type File_Type is new Integer; File_Error : exception; function Open (File_Name : in String) return File_Type; procedure Write (Into : in File_Type; What : in String); end Low_Level_IO; package body Low_Level_IO is function Open (File_Name : in String) return File_Type is function Internal (File_Name : in String, Flags : in Integer) return File_Type; pragma Import (C, Internal, "open"); Result : File_Type := Internal (File_Name & ASCII.NUL, 12); begin if Result = 0 then raise File_Error; end if; return Result; end Open; procedure Write (Into : in File_Type; What : in String) is function Internal (Into : in File_Type; What : in String; Size : in Integer) return Integer; pragma Import (C, Internal, "write"); Result : Integer := Internal (Into, What, What'Length); begin if Result /= What'Length then raise File_Error; end if; end Write; end Low_Level_IO; But, you have to ask yourself exactly why you are trying to use such low-level code. This is platform-dependent and error-prone. I encourage you to consider using Ada's IO libraries, or GNAT.OS_Lib, which provide most of what you want in a portable manner. Indeed, if you look at the implementation of GNAT.OS_Lib, you will find something roughly equivalent to what I wrote above. You should try to avoid messing around with file descriptors if you can. It is better to use high-level abstractions; they are much safer. -- Ludovic Brenta. -- Ce message a ete poste via la plateforme Web club-Internet.fr This message has been posted by the Web platform club-Internet.fr http://forums.club-internet.fr/