Almroth.com
Home Software Projects Documents Links Photos Contact us

gpgerror.adb

------------------------------------------------------------------------------
-- --
-- GPGError --
-- --
-- Binding Body --
-- --
-- --
-- Copyright (C) 2003 Andreas Almroth --
-- --
-- GPGError is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the Free --
-- Software Foundation; either version 2, or (at your option) any later --
-- version. GPGError is distributed in the hope that it will be useful, --
-- but WITH OUT 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 GPGError; see 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 --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit 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 Public License. --
-- --
------------------------------------------------------------------------------
--
-- This is an Ada95 thin binding to GPG-error
-- !!! This version is synchronised to 1.0 !!!
--
-- The original GPGError library is copyrighted by;
-- Copyright (C) 2003,2004 g10 Code GmbH
------------------------------------------------------------------------------
-- $Author: Andreas Almroth $
-- $Date: 005-03-28 11:01 $
-- $Workfile: gpgerror.adb $
-- $Revision: 5 $
-- $State: Unstable $
--
-- HISTORY:
--
-- Revision 5: No changes, version update.
-- 2005-03-28
--
-- Revision 4: Changes to reflect 0.5 of C API
-- 03-10-10 01:44
--
-- Revision 3: Version upgrade only
--
-- Revision 2: Minor updates to constants
--
-- Revision 1: Initial release
--

package body Gpgerror is
--------------------------------------------------------------------------
--
--------------------------------------------------------------------------
function Gpg_Err_Make(Source : Gpg_Err_Source_T;
Code : Gpg_Err_Code_T)
return Gpg_Error_T is
begin
if Code /= GPG_ERR_NO_ERROR then
return Shift_Left((Source and GPG_ERR_SOURCE_MASK),
Integer(GPG_ERR_SOURCE_SHIFT))
or (code and GPG_ERR_CODE_MASK);
end if;

return GPG_ERR_NO_ERROR;
end Gpg_Err_Make;

--------------------------------------------------------------------------
--
--------------------------------------------------------------------------
function Gpg_Error (Code : Gpg_Err_Code_T) return Gpg_Error_T is
begin
return Gpg_Err_Make(GPG_ERR_SOURCE_DEFAULT,Code);
end Gpg_Error;


--------------------------------------------------------------------------
-- Retrieve the error code from an error value.
--------------------------------------------------------------------------
function Gpg_Err_Code(Err : Gpg_Error_T) return Gpg_Err_Code_T is
begin
return err and GPG_ERR_CODE_MASK;
end Gpg_Err_Code;


--------------------------------------------------------------------------
-- Retrieve the error source from an error value.
--------------------------------------------------------------------------
function Gpg_Err_Source(Err : Gpg_Error_T) return Gpg_Err_Source_T is
begin
return Shift_Right(Err,Integer(GPG_ERR_SOURCE_SHIFT))
and GPG_ERR_SOURCE_MASK;
end Gpg_Err_Source;

--------------------------------------------------------------------------
-- Self-documenting convenience functions.
--------------------------------------------------------------------------

--------------------------------------------------------------------------
--
--------------------------------------------------------------------------
function Gpg_Err_Make_From_Errno (Source : Gpg_Err_Source_T;
Err : Interfaces.C.int)
return Gpg_Error_T is
begin
return Gpg_Err_Make(source,Gpg_Err_Code_From_Errno(Err));
end Gpg_Err_Make_From_Errno;


--------------------------------------------------------------------------
--
--------------------------------------------------------------------------
function Gpg_Error_From_Errno(Err : Interfaces.C.Int)
return Gpg_Error_T is
begin
return Gpg_Error(Gpg_Err_Code_From_Errno(Err));
end Gpg_Error_From_Errno;

end Gpgerror;




© 2005 Andreas Almroth