Denis Vlasenko | 83ea643 | 2006-11-16 02:27:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright (c) 2001-2006, Gerrit Pape |
| 3 | All rights reserved. |
| 4 | |
| 5 | Redistribution and use in source and binary forms, with or without |
| 6 | modification, are permitted provided that the following conditions are met: |
| 7 | |
| 8 | 1. Redistributions of source code must retain the above copyright notice, |
| 9 | this list of conditions and the following disclaimer. |
| 10 | 2. Redistributions in binary form must reproduce the above copyright |
| 11 | notice, this list of conditions and the following disclaimer in the |
| 12 | documentation and/or other materials provided with the distribution. |
| 13 | 3. The name of the author may not be used to endorse or promote products |
| 14 | derived from this software without specific prior written permission. |
| 15 | |
| 16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
Denis Vlasenko | 83ea643 | 2006-11-16 02:27:24 +0000 | [diff] [blame] | 28 | /*** byte.h ***/ |
| 29 | |
| 30 | extern unsigned byte_chr(char *s,unsigned n,int c); |
| 31 | |
| 32 | |
| 33 | /*** coe.h ***/ |
| 34 | |
| 35 | extern int coe(int); |
| 36 | |
| 37 | |
| 38 | /*** direntry.h ***/ |
| 39 | |
| 40 | #define direntry struct dirent |
| 41 | |
| 42 | |
| 43 | /*** fd.h ***/ |
| 44 | |
| 45 | extern int fd_copy(int,int); |
| 46 | extern int fd_move(int,int); |
| 47 | |
| 48 | |
Denis Vlasenko | 83ea643 | 2006-11-16 02:27:24 +0000 | [diff] [blame] | 49 | /*** tai.h ***/ |
| 50 | |
| 51 | struct tai { |
| 52 | uint64_t x; |
Denis Vlasenko | 8c78395 | 2007-01-27 22:21:52 +0000 | [diff] [blame] | 53 | }; |
Denis Vlasenko | 83ea643 | 2006-11-16 02:27:24 +0000 | [diff] [blame] | 54 | |
| 55 | #define tai_unix(t,u) ((void) ((t)->x = 4611686018427387914ULL + (uint64_t) (u))) |
| 56 | |
Denis Vlasenko | 83ea643 | 2006-11-16 02:27:24 +0000 | [diff] [blame] | 57 | #define TAI_PACK 8 |
Denis Vlasenko | 8c78395 | 2007-01-27 22:21:52 +0000 | [diff] [blame] | 58 | //extern void tai_pack(char *,const struct tai *); |
Denis Vlasenko | 83ea643 | 2006-11-16 02:27:24 +0000 | [diff] [blame] | 59 | extern void tai_unpack(const char *,struct tai *); |
| 60 | |
| 61 | extern void tai_uint(struct tai *,unsigned); |
| 62 | |
| 63 | |
| 64 | /*** taia.h ***/ |
| 65 | |
| 66 | struct taia { |
| 67 | struct tai sec; |
| 68 | unsigned long nano; /* 0...999999999 */ |
| 69 | unsigned long atto; /* 0...999999999 */ |
Denis Vlasenko | 8c78395 | 2007-01-27 22:21:52 +0000 | [diff] [blame] | 70 | }; |
Denis Vlasenko | 83ea643 | 2006-11-16 02:27:24 +0000 | [diff] [blame] | 71 | |
Denis Vlasenko | 8c78395 | 2007-01-27 22:21:52 +0000 | [diff] [blame] | 72 | //extern void taia_tai(const struct taia *,struct tai *); |
Denis Vlasenko | 83ea643 | 2006-11-16 02:27:24 +0000 | [diff] [blame] | 73 | |
| 74 | extern void taia_now(struct taia *); |
| 75 | |
Denis Vlasenko | 83ea643 | 2006-11-16 02:27:24 +0000 | [diff] [blame] | 76 | extern void taia_add(struct taia *,const struct taia *,const struct taia *); |
| 77 | extern void taia_addsec(struct taia *,const struct taia *,int); |
| 78 | extern void taia_sub(struct taia *,const struct taia *,const struct taia *); |
| 79 | extern void taia_half(struct taia *,const struct taia *); |
| 80 | extern int taia_less(const struct taia *,const struct taia *); |
| 81 | |
| 82 | #define TAIA_PACK 16 |
| 83 | extern void taia_pack(char *,const struct taia *); |
Denis Vlasenko | 8c78395 | 2007-01-27 22:21:52 +0000 | [diff] [blame] | 84 | //extern void taia_unpack(const char *,struct taia *); |
Denis Vlasenko | 83ea643 | 2006-11-16 02:27:24 +0000 | [diff] [blame] | 85 | |
Denis Vlasenko | 8c78395 | 2007-01-27 22:21:52 +0000 | [diff] [blame] | 86 | //#define TAIA_FMTFRAC 19 |
| 87 | //extern unsigned taia_fmtfrac(char *,const struct taia *); |
Denis Vlasenko | 83ea643 | 2006-11-16 02:27:24 +0000 | [diff] [blame] | 88 | |
| 89 | extern void taia_uint(struct taia *,unsigned); |
| 90 | |
| 91 | |
| 92 | /*** fmt_ptime.h ***/ |
| 93 | |
| 94 | #define FMT_PTIME 30 |
| 95 | |
Denis Vlasenko | 8c78395 | 2007-01-27 22:21:52 +0000 | [diff] [blame] | 96 | /* NUL terminated */ |
| 97 | extern void fmt_ptime30nul(char *, struct taia *); |
| 98 | /* NOT terminated! */ |
| 99 | extern unsigned fmt_taia25(char *, struct taia *); |
Denis Vlasenko | 83ea643 | 2006-11-16 02:27:24 +0000 | [diff] [blame] | 100 | |
| 101 | |
Denis Vlasenko | 83ea643 | 2006-11-16 02:27:24 +0000 | [diff] [blame] | 102 | /*** iopause.h ***/ |
| 103 | |
| 104 | typedef struct pollfd iopause_fd; |
| 105 | #define IOPAUSE_READ POLLIN |
| 106 | #define IOPAUSE_WRITE POLLOUT |
| 107 | |
| 108 | extern void iopause(iopause_fd *,unsigned,struct taia *,struct taia *); |
| 109 | |
| 110 | |
| 111 | /*** lock.h ***/ |
| 112 | |
| 113 | extern int lock_ex(int); |
| 114 | extern int lock_un(int); |
| 115 | extern int lock_exnb(int); |
| 116 | |
| 117 | |
Denis Vlasenko | 83ea643 | 2006-11-16 02:27:24 +0000 | [diff] [blame] | 118 | /*** open.h ***/ |
| 119 | |
| 120 | extern int open_read(const char *); |
| 121 | extern int open_excl(const char *); |
| 122 | extern int open_append(const char *); |
| 123 | extern int open_trunc(const char *); |
| 124 | extern int open_write(const char *); |
| 125 | |
| 126 | |
Denis Vlasenko | 83ea643 | 2006-11-16 02:27:24 +0000 | [diff] [blame] | 127 | /*** pmatch.h ***/ |
| 128 | |
| 129 | extern unsigned pmatch(const char *, const char *, unsigned); |
| 130 | |
| 131 | |
Denis Vlasenko | 83ea643 | 2006-11-16 02:27:24 +0000 | [diff] [blame] | 132 | /*** sig.h ***/ |
| 133 | |
Denis Vlasenko | 83ea643 | 2006-11-16 02:27:24 +0000 | [diff] [blame] | 134 | extern void sig_catch(int,void (*)(int)); |
Denis Vlasenko | e2473f8 | 2007-01-27 22:22:17 +0000 | [diff] [blame] | 135 | #define sig_ignore(s) (sig_catch((s), SIG_IGN)) |
| 136 | #define sig_uncatch(s) (sig_catch((s), SIG_DFL)) |
Denis Vlasenko | 83ea643 | 2006-11-16 02:27:24 +0000 | [diff] [blame] | 137 | |
| 138 | extern void sig_block(int); |
| 139 | extern void sig_unblock(int); |
| 140 | extern void sig_blocknone(void); |
| 141 | extern void sig_pause(void); |
| 142 | |
Denis Vlasenko | 83ea643 | 2006-11-16 02:27:24 +0000 | [diff] [blame] | 143 | |
| 144 | /*** str.h ***/ |
| 145 | |
| 146 | extern unsigned str_chr(const char *,int); /* never returns NULL */ |
| 147 | |
Denis Vlasenko | e2473f8 | 2007-01-27 22:22:17 +0000 | [diff] [blame] | 148 | #define str_diff(s,t) strcmp((s), (t)) |
| 149 | #define str_equal(s,t) (!strcmp((s), (t))) |
Denis Vlasenko | 83ea643 | 2006-11-16 02:27:24 +0000 | [diff] [blame] | 150 | |
| 151 | |
| 152 | /*** wait.h ***/ |
| 153 | |
| 154 | extern int wait_pid(int *wstat, int pid); |
| 155 | extern int wait_nohang(int *wstat); |
| 156 | |
| 157 | #define wait_crashed(w) ((w) & 127) |
| 158 | #define wait_exitcode(w) ((w) >> 8) |
| 159 | #define wait_stopsig(w) ((w) >> 8) |
| 160 | #define wait_stopped(w) (((w) & 127) == 127) |