Imported Debian patch 0.66.1-1
[hcoop/debian/courier-authlib.git] / libs / numlib / numlib.h
CommitLineData
d9898ee8 1#ifndef numlib_h
2#define numlib_h
3
4/*
b0322a85 5** Copyright 1998 - 2010 Double Precision, Inc.
d9898ee8 6** See COPYING for distribution information.
7*/
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
d9898ee8 13
14#if HAVE_CONFIG_H
b0322a85
CE
15#include "numlib/config.h"
16#endif
17
18#if HAVE_STDINT_H
19#include <stdint.h>
d9898ee8 20#endif
21
22#include <sys/types.h>
23#include <time.h>
24
25#define NUMBUFSIZE 60
26
27/* Convert various system types to decimal */
28
29char *libmail_str_time_t(time_t, char *);
30char *libmail_str_off_t(off_t, char *);
b0322a85 31char *libmail_str_int64_t(int64_t, char *);
d9898ee8 32char *libmail_str_pid_t(pid_t, char *);
33char *libmail_str_dev_t(dev_t, char *);
34char *libmail_str_ino_t(ino_t, char *);
35char *libmail_str_uid_t(uid_t, char *);
36char *libmail_str_gid_t(gid_t, char *);
37char *libmail_str_size_t(size_t, char *);
38
39char *libmail_str_sizekb(unsigned long, char *); /* X Kb or X Mb */
40
41/* Convert selected system types to hex */
42
43char *libmail_strh_time_t(time_t, char *);
44char *libmail_strh_pid_t(pid_t, char *);
45char *libmail_strh_ino_t(ino_t, char *);
46char *libmail_strh_dev_t(dev_t, char *);
47
48/* And, now let's do the reverse */
49
50time_t libmail_strtotime_t(const char **);
51time_t libmail_atotime_t(const char *);
52
53uid_t libmail_strtouid_t(const char **);
54uid_t libmail_atouid_t(const char *);
55
56gid_t libmail_strtogid_t(const char **);
57gid_t libmail_atogid_t(const char *);
58
59 /* Common macros: */
60
61#define LIBMAIL_STRIMPL(type, f1, f2) \
62\
63type f1(const char **p)\
64{\
65 type n=0;\
66 while ( **p >= '0' && **p <= '9') n=n*10 + (char)(*(*p)++ - '0');\
67 return n;\
68}\
69\
70type f2(const char *p)\
71{\
72 return f1(&p);\
73}
74
75
76/*
77** The following functions are used by root to reset its user and group id
78** to the authenticated user's. Various functions are provided to handle
79** various situations.
80*/
81
82void libmail_changegroup(gid_t); /* Set the group id only. Also clear any
83 ** auxiliary group ids */
84
85void libmail_changeuidgid(uid_t, gid_t);
86 /* Set both user id and group id. Also clear
87 ** aux group ids */
88
89void libmail_changeusername(const char *, const gid_t *);
90 /*
91 ** Set the userid to the indicate user's. If second argument is
92 ** not null, it points to the groupid to set. If it's null, the
93 ** group id is taken from the passwd file. Auxiliary IDs are set
94 ** to any aux IDs set for the user in the group file. If there are
95 ** no aux group IDs for the user, any AUX ids are cleared.
96 */
97
98#ifdef __cplusplus
99}
100#endif
101#endif