blob: 7b268e2765826d75fdb68243036187a33b34559e [file] [log] [blame]
Denis Vlasenko83ea6432006-11-16 02:27:24 +00001/*
2Copyright (c) 2001-2006, Gerrit Pape
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, 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
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
Denis Vlasenko83ea6432006-11-16 02:27:24 +000028/*** byte.h ***/
29
30extern unsigned byte_chr(char *s,unsigned n,int c);
31
32
33/*** coe.h ***/
34
35extern int coe(int);
36
37
38/*** direntry.h ***/
39
40#define direntry struct dirent
41
42
43/*** fd.h ***/
44
45extern int fd_copy(int,int);
46extern int fd_move(int,int);
47
48
Denis Vlasenko83ea6432006-11-16 02:27:24 +000049/*** tai.h ***/
50
51struct tai {
52 uint64_t x;
Denis Vlasenko8c783952007-01-27 22:21:52 +000053};
Denis Vlasenko83ea6432006-11-16 02:27:24 +000054
55#define tai_unix(t,u) ((void) ((t)->x = 4611686018427387914ULL + (uint64_t) (u)))
56
Denis Vlasenko83ea6432006-11-16 02:27:24 +000057#define TAI_PACK 8
Denis Vlasenko8c783952007-01-27 22:21:52 +000058//extern void tai_pack(char *,const struct tai *);
Denis Vlasenko83ea6432006-11-16 02:27:24 +000059extern void tai_unpack(const char *,struct tai *);
60
61extern void tai_uint(struct tai *,unsigned);
62
63
64/*** taia.h ***/
65
66struct taia {
67 struct tai sec;
68 unsigned long nano; /* 0...999999999 */
69 unsigned long atto; /* 0...999999999 */
Denis Vlasenko8c783952007-01-27 22:21:52 +000070};
Denis Vlasenko83ea6432006-11-16 02:27:24 +000071
Denis Vlasenko8c783952007-01-27 22:21:52 +000072//extern void taia_tai(const struct taia *,struct tai *);
Denis Vlasenko83ea6432006-11-16 02:27:24 +000073
74extern void taia_now(struct taia *);
75
Denis Vlasenko83ea6432006-11-16 02:27:24 +000076extern void taia_add(struct taia *,const struct taia *,const struct taia *);
77extern void taia_addsec(struct taia *,const struct taia *,int);
78extern void taia_sub(struct taia *,const struct taia *,const struct taia *);
79extern void taia_half(struct taia *,const struct taia *);
80extern int taia_less(const struct taia *,const struct taia *);
81
82#define TAIA_PACK 16
83extern void taia_pack(char *,const struct taia *);
Denis Vlasenko8c783952007-01-27 22:21:52 +000084//extern void taia_unpack(const char *,struct taia *);
Denis Vlasenko83ea6432006-11-16 02:27:24 +000085
Denis Vlasenko8c783952007-01-27 22:21:52 +000086//#define TAIA_FMTFRAC 19
87//extern unsigned taia_fmtfrac(char *,const struct taia *);
Denis Vlasenko83ea6432006-11-16 02:27:24 +000088
89extern void taia_uint(struct taia *,unsigned);
90
91
92/*** fmt_ptime.h ***/
93
94#define FMT_PTIME 30
95
Denis Vlasenko8c783952007-01-27 22:21:52 +000096/* NUL terminated */
97extern void fmt_ptime30nul(char *, struct taia *);
98/* NOT terminated! */
99extern unsigned fmt_taia25(char *, struct taia *);
Denis Vlasenko83ea6432006-11-16 02:27:24 +0000100
101
Denis Vlasenko83ea6432006-11-16 02:27:24 +0000102/*** iopause.h ***/
103
104typedef struct pollfd iopause_fd;
105#define IOPAUSE_READ POLLIN
106#define IOPAUSE_WRITE POLLOUT
107
108extern void iopause(iopause_fd *,unsigned,struct taia *,struct taia *);
109
110
111/*** lock.h ***/
112
113extern int lock_ex(int);
114extern int lock_un(int);
115extern int lock_exnb(int);
116
117
Denis Vlasenko83ea6432006-11-16 02:27:24 +0000118/*** open.h ***/
119
120extern int open_read(const char *);
121extern int open_excl(const char *);
122extern int open_append(const char *);
123extern int open_trunc(const char *);
124extern int open_write(const char *);
125
126
Denis Vlasenko83ea6432006-11-16 02:27:24 +0000127/*** pmatch.h ***/
128
129extern unsigned pmatch(const char *, const char *, unsigned);
130
131
Denis Vlasenko83ea6432006-11-16 02:27:24 +0000132/*** sig.h ***/
133
Denis Vlasenko83ea6432006-11-16 02:27:24 +0000134extern void sig_catch(int,void (*)(int));
Denis Vlasenkoe2473f82007-01-27 22:22:17 +0000135#define sig_ignore(s) (sig_catch((s), SIG_IGN))
136#define sig_uncatch(s) (sig_catch((s), SIG_DFL))
Denis Vlasenko83ea6432006-11-16 02:27:24 +0000137
138extern void sig_block(int);
139extern void sig_unblock(int);
140extern void sig_blocknone(void);
141extern void sig_pause(void);
142
Denis Vlasenko83ea6432006-11-16 02:27:24 +0000143
144/*** str.h ***/
145
146extern unsigned str_chr(const char *,int); /* never returns NULL */
147
Denis Vlasenkoe2473f82007-01-27 22:22:17 +0000148#define str_diff(s,t) strcmp((s), (t))
149#define str_equal(s,t) (!strcmp((s), (t)))
Denis Vlasenko83ea6432006-11-16 02:27:24 +0000150
151
152/*** wait.h ***/
153
154extern int wait_pid(int *wstat, int pid);
155extern 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)