summaryrefslogtreecommitdiff
path: root/clients/xzwrite/util.c
blob: 38c7f130aabd270d679bc67446027e142bc162e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <stdio.h>
#include <varargs.h>
#include <pwd.h>

#include "xzwrite.h"

/*VARARGS*/
void Warning(first, va_alist)
   char	*first;
   va_dcl
{
     va_list	vp;
     char	*s;
     
     fputs(first, stderr);

     va_start(vp);
     while ((s = va_arg(vp, char *)) != NULL)
	  fputs(s, stderr);
     va_end(vp);
     putc('\n', stderr);
}

/*VARARGS*/
void Error(first, va_alist)
   char *first;
   va_dcl
{
     va_list	vp;
     char	*s;
     
     fputs(first, stderr);

     va_start(vp);
     while ((s = va_arg(vp, char *)) != NULL)
	  fputs(s, stderr);
     va_end(vp);
     putc('\n', stderr);

     exit(1);
}

/*VARARGS*/
char *Malloc(n, va_alist)
   int	n;
   va_dcl
{
     va_list	vp;
     char	*ptr, *s;

     ptr = (char *) malloc((unsigned) n);
     if (ptr)
	  return ptr;

     fputs("Out of memory: ", stderr);

     va_start(vp);
     while ((s = va_arg(vp, char *)) != NULL)
	  fputs(s, stderr);
     va_end(vp);
     putc('\n', stderr);

     exit(1);
}

char *get_username()
{
     struct passwd *pwuid;
     static char *u = NULL;

     if (u) return u;

     if (u = (char *) getenv("USER")) return u;

     pwuid = getpwuid(getuid());
     if (pwuid)
       return u = pwuid->pw_name;
     else
       return NULL;
}