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