pinentry-dmenu

a pinentry program based on dmenu
git clone anongit@rnpnr.xyz:pinentry-dmenu.git
Log | Files | Refs | Feed | README | LICENSE

util.h (2095B)


      1 /* Quintuple Agent utilities
      2  * Copyright (C) 1999 Robert Bihlmeyer <robbe@orcus.priv.at>
      3  * Copyright (C) 2003 g10 Code GmbH
      4  *
      5  *  This program is free software; you can redistribute it and/or modify
      6  *  it under the terms of the GNU General Public License as published by
      7  *  the Free Software Foundation; either version 2 of the License, or
      8  *  (at your option) any later version.
      9  *
     10  *  This program is distributed in the hope that it will be useful,
     11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13  *  GNU General Public License for more details.
     14  *
     15  *  You should have received a copy of the GNU General Public License
     16  *  along with this program; if not, write to the Free Software
     17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     18  */
     19 
     20 #ifndef _UTIL_H
     21 #define _UTIL_H
     22 
     23 #include <sys/types.h>
     24 
     25 #ifndef HAVE_BYTE_TYPEDEF
     26 # undef byte	   
     27 # ifdef __riscos__
     28     /* Norcroft treats char == unsigned char but char* != unsigned char*  */
     29     typedef char byte;
     30 # else 
     31     typedef unsigned char byte;
     32 # endif 
     33 # define HAVE_BYTE_TYPEDEF
     34 #endif
     35 
     36 #ifndef HAVE_ULONG_TYPEDEF
     37 # undef ulong	   
     38   typedef unsigned long ulong;
     39 # define HAVE_ULONG_TYPEDEF
     40 #endif
     41 
     42 
     43 ssize_t xwrite(int, const void *, size_t); /* write until finished */
     44 int debugmsg(const char *, ...); /* output a debug message if debugging==on */
     45 void drop_privs(void);		/* finally drop privileges */
     46 
     47 
     48 /* To avoid that a compiler optimizes certain memset calls away, these
     49    macros may be used instead. */
     50 #define wipememory2(_ptr,_set,_len) do { \
     51               volatile char *_vptr=(volatile char *)(_ptr); \
     52               size_t _vlen=(_len); \
     53               while(_vlen) { *_vptr=(_set); _vptr++; _vlen--; } \
     54                   } while(0)
     55 #define wipememory(_ptr,_len) wipememory2(_ptr,0,_len)
     56 #define wipe(_ptr,_len)       wipememory2(_ptr,0,_len)
     57 
     58 
     59 
     60 
     61 #define xtoi_1(p)   (*(p) <= '9'? (*(p)- '0'): \
     62                      *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10))
     63 #define xtoi_2(p)   ((xtoi_1(p) * 16) + xtoi_1((p)+1))
     64 
     65 
     66 #endif