Back to index

courier  0.68.2
numlib.h
Go to the documentation of this file.
00001 #ifndef       numlib_h
00002 #define       numlib_h
00003 
00004 /*
00005 ** Copyright 1998 - 2010 Double Precision, Inc.
00006 ** See COPYING for distribution information.
00007 */
00008 
00009 #ifdef __cplusplus
00010 extern "C" {
00011 #endif
00012 
00013 
00014 #if    HAVE_CONFIG_H
00015 #include      "../numlib/config.h" /* VPATH build */
00016 #endif
00017 
00018 #if    HAVE_STDINT_H
00019 #include      <stdint.h>
00020 #endif
00021 
00022 #include      <sys/types.h>
00023 #include      <time.h>
00024 
00025 #define       NUMBUFSIZE    60
00026 
00027 /* Convert various system types to decimal */
00028 
00029 char   *libmail_str_time_t(time_t, char *);
00030 char   *libmail_str_off_t(off_t, char *);
00031 char   *libmail_str_int64_t(int64_t, char *);
00032 char   *libmail_str_pid_t(pid_t, char *);
00033 char   *libmail_str_dev_t(dev_t, char *);
00034 char   *libmail_str_ino_t(ino_t, char *);
00035 char   *libmail_str_uid_t(uid_t, char *);
00036 char   *libmail_str_gid_t(gid_t, char *);
00037 char   *libmail_str_size_t(size_t, char *);
00038 
00039 char   *libmail_str_sizekb(unsigned long, char *);      /* X Kb or X Mb */
00040 
00041 /* Convert selected system types to hex */
00042 
00043 char   *libmail_strh_time_t(time_t, char *);
00044 char   *libmail_strh_pid_t(pid_t, char *);
00045 char   *libmail_strh_ino_t(ino_t, char *);
00046 char   *libmail_strh_dev_t(dev_t, char *);
00047 
00048 /* And, now let's do the reverse */
00049 
00050 time_t libmail_strtotime_t(const char **);
00051 time_t libmail_atotime_t(const char *);
00052 
00053 uid_t libmail_strtouid_t(const char **);
00054 uid_t libmail_atouid_t(const char *);
00055 
00056 gid_t libmail_strtogid_t(const char **);
00057 gid_t libmail_atogid_t(const char *);
00058 
00059        /* Common macros: */
00060 
00061 #define LIBMAIL_STRIMPL(type, f1, f2) \
00062 \
00063 type f1(const char **p)\
00064 {\
00065        type n=0;\
00066        while ( **p >= '0' && **p <= '9') n=n*10 + (char)(*(*p)++ - '0');\
00067        return n;\
00068 }\
00069 \
00070 type f2(const char *p)\
00071 {\
00072        return f1(&p);\
00073 }
00074 
00075 
00076 /*
00077 ** The following functions are used by root to reset its user and group id
00078 ** to the authenticated user's.  Various functions are provided to handle
00079 ** various situations.
00080 */
00081 
00082 void libmail_changegroup(gid_t);   /* Set the group id only.  Also clear any
00083                             ** auxiliary group ids */
00084 
00085 void libmail_changeuidgid(uid_t, gid_t);
00086                             /* Set both user id and group id.  Also clear
00087                             ** aux group ids */
00088 
00089 void libmail_changeusername(const char *, const gid_t *);
00090        /*
00091        ** Set the userid to the indicate user's.  If second argument is
00092        ** not null, it points to the groupid to set.  If it's null, the
00093        ** group id is taken from the passwd file.  Auxiliary IDs are set
00094        ** to any aux IDs set for the user in the group file.  If there are
00095        ** no aux group IDs for the user, any AUX ids are cleared.
00096        */
00097 
00098 #ifdef __cplusplus
00099 }
00100 #endif
00101 #endif