1/************************************************************************ 2 * Some routine common to procmail, formail and lockfile * 3 * * 4 * Copyright (c) 1993-1997, S.R. van den Berg, The Netherlands * 5 * Copyright (c) 1999-2001, Philip Guenther, The United States * 6 * of America * 7 * #include "../README" * 8 ************************************************************************/ 9#ifdef RCS 10static /*const*/char rcsid[]= 11 "$Id: acommon.c,v 1.12 2001/08/04 07:14:59 guenther Exp $"; 12#endif 13#include "includes.h" 14#include "acommon.h" 15#include "robust.h" 16#include "shell.h" 17 18const char*hostname P((void)) 19{ 20#ifdef NOuname 21#ifndef MAXHOSTNAMELEN 22#define MAXHOSTNAMELEN 64 23#endif 24 static char name[MAXHOSTNAMELEN]=""; 25 if(!name[0]) 26 gethostname(name,MAXHOSTNAMELEN),name[MAXHOSTNAMELEN-1]='\0'; 27#else 28 static char*name=0; 29 if(!name) 30 { struct utsname names; 31 Uname(&names); 32 if(!(name=malloc(strlen(names.nodename)+1))) 33 return ""; /* can happen when called from within lockfile */ 34 strcpy(name,names.nodename); 35 } 36#endif 37 return name; 38} 39 40char*ultoan(val,dest)unsigned long val;char*dest; /* convert to a number */ 41{ register int i; /* within the set [A-Za-z0-9-_] */ 42 do 43 { i=val&0x3f; /* collating sequence dependency! */ 44 *dest++=i+(i<26?'A':i<26+26?'a'-26:i<26+26+10?'0'-26-26: 45 i==26+26+10?'-'-26-26-10:'_'-26-26-11); 46 } 47 while(val>>=6); 48 *dest='\0'; 49 return dest; 50} 51 52char*ultstr(minwidth,val,dest)int minwidth;unsigned long val;char*dest; 53{ int i;unsigned long j;char*ret; 54 j=val;i=0; /* a beauty, isn't it :-) */ 55 do i++; /* determine needed width */ 56 while(j/=10); 57 while(--minwidth>=i) /* fill up any excess width */ 58 *dest++=' '; 59 *(ret=dest+=i)='\0'; 60 do *--dest='0'+val%10; /* display value backwards */ 61 while(val/=10); 62 return ret; 63} 64