----------------------------------------------------------------------------- -- -- Onions Network Streams Library -- -- O N I O N S . O S -- -- B o d y -- -- Copyright (C) 1997-1998 Regents of the University of California -- -- Onions is free software; you can redistribute it and/or modify it under -- the terms of the GNU General Public License as published by the Free -- Software Foundation, with or without the single exception listed below; -- either version 2, or (at your option) any later version. Onions is -- distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; -- without even the implied warranty of MERCHANTABILITY or FITNESS FOR A -- PARTICULAR PURPOSE. See the GNU General Public License for more details. -- You should have received a copy of the GNU General Public License -- distributed with Onions; see the file COPYING. If not, write to the -- Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- 02111-1307, USA. -- -- As a special exception, if other files instantiate generics from this -- library, or you link this library with other files to produce an -- executable, this library does not by itself cause the resulting -- executable to be covered by the GNU General Public License. This -- exception does not however invalidate any other reasons why the -- executable file might be covered by the GNU General Public License. -- -- Portions of this unit have been derived from version 1.02 of the Garlic -- library of GLADE, the Ada95 Distributed Systems Annex for GNAT. GLADE -- is maintained by ACT Europe (see ). -- -- GLADE is Copyright (C) 1996,1997 Free Software Foundation, Inc. -- All source code that is shared by both GLADE version 1.02 and -- this unit remains under the FSF copyright. -- -- Rewritten for Onions in 1997 by Roy T. Fielding ----------------------------------------------------------------------------- -- -- The OS package provides a slightly thicker binding to some -- operating system-dependent routines. The package spec is -- generated by configure, so portability problems should be -- fixed via hooks within this package. -- with Ada.Exceptions; with Interfaces.C.Strings; with Onions.Constants; use Onions.Constants; with Onions.Thin; use Onions.Thin; package body Onions.OS is use C.Strings; use type C.int; -- Raise_Error patches together a meaningful error message to -- go along with a raised exception. If Errno is non-zero, suffix -- the Message with the system error string [strerror(errno)]. -- procedure Raise_Error (Ex_ID : in Ada.Exceptions.Exception_Id; Errno : in C.Int; Message : in String) is Sys_Msg : chars_ptr; begin if Errno /= 0 then Sys_Msg := C_strerror (Errno); if Sys_Msg /= C.Strings.Null_Ptr then Ada.Exceptions.Raise_Exception (Ex_ID, Message & ": " & Value (Sys_Msg)); end if; end if; Ada.Exceptions.Raise_Exception (Ex_ID, Message); end Raise_Error; -- Return the value of the environment variable Name or an empty -- string if this variable doesn't exist. -- function Getenv (Name : String) return String is C_Name : chars_ptr := New_String (Name); C_Result : constant chars_ptr := C_getenv (C_Name); begin Free (C_Name); if C_Result = Null_Ptr then return ""; else return Value (C_Result); end if; end Getenv; -- Set the open file descriptor to non-blocking mode -- and return Failure or Success. -- function Set_Non_Blocking (Filedes : Descriptor) return C.int is Status : C.int; Flags : Int_Flags; begin Status := C_fcntl (Filedes, F_GETFL); if Status = Failure then return Failure; end if; Flags := Int_Flags (Status); if (Flags and O_NONBLOCK) = 0 then Status := C.int (Flags or O_NONBLOCK); if C_fcntl (Filedes, F_SETFL, Status) = Failure then return Failure; end if; end if; return Success; end Set_Non_Blocking; end Onions.OS;