Add config-check for unlocked I/O..
[s-mailx.git] / def.h
blob9db737ce12f361597105c2818b2919fbcca96d8c
1 /*
2 * S-nail - a mail user agent derived from Berkeley Mail.
4 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
5 * Copyright (c) 2012 Steffen "Daode" Nurpmeso.
6 */
7 /*
8 * Copyright (c) 1980, 1993
9 * The Regents of the University of California. All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
41 * Mail -- a mail program
43 * Author: Kurt Shoens (UCB) March 25, 1978
46 #if !defined (NI_MAXHOST) || (NI_MAXHOST) < 1025
47 #undef NI_MAXHOST
48 #define NI_MAXHOST 1025
49 #endif
51 #define APPEND /* New mail goes to end of mailbox */
53 /* Is *C* a quoting character (for *quote-fold* compression) */
54 #define ISQUOTE(C) ((C) == '>' || (C) == '|')
56 #define ESCAPE '~' /* Default escape for sending */
57 #ifndef MAXPATHLEN
58 #ifdef PATH_MAX
59 #define MAXPATHLEN PATH_MAX
60 #else
61 #define MAXPATHLEN 1024
62 #endif
63 #endif
64 #ifndef PATHSIZE
65 #define PATHSIZE MAXPATHLEN /* Size of pathnames throughout */
66 #endif
67 #define HSHSIZE 59 /* Hash size for aliases and vars */
68 #define LINESIZE 2560 /* max readable line width */
69 #define STRINGSIZE ((unsigned) 128)/* Dynamic allocation units */
70 #define MAXARGC 1024 /* Maximum list of raw strings */
71 #define MAXEXP 25 /* Maximum expansion of aliases */
73 #define equal(a, b) (strcmp(a,b)==0)/* A nice function to string compare */
75 #undef tr
76 #ifdef HAVE_CATGETS
77 # define CATSET 1
78 # define tr(c, d) catgets(catd, CATSET, c, d)
79 #else
80 # define catgets(a, b, c, d) (d)
81 # define tr(c, d) (d)
82 #endif
84 typedef void (*sighandler_type)(int);
86 enum okay {
87 STOP = 0,
88 OKAY = 1
91 enum mimeenc {
92 MIME_NONE, /* message is not in MIME format */
93 MIME_BIN, /* message is in binary encoding */
94 MIME_8B, /* message is in 8bit encoding */
95 MIME_7B, /* message is in 7bit encoding */
96 MIME_QP, /* message is quoted-printable */
97 MIME_B64 /* message is in base64 encoding */
100 enum conversion {
101 CONV_NONE, /* no conversion */
102 CONV_7BIT, /* no conversion, is 7bit */
103 CONV_FROMQP, /* convert from quoted-printable */
104 CONV_TOQP, /* convert to quoted-printable */
105 CONV_8BIT, /* convert to 8bit (iconv) */
106 CONV_FROMB64, /* convert from base64 */
107 CONV_FROMB64_T, /* convert from base64/text */
108 CONV_TOB64, /* convert to base64 */
109 CONV_FROMHDR, /* convert from RFC1522 format */
110 CONV_TOHDR, /* convert to RFC1522 format */
111 CONV_TOHDR_A /* convert addresses for header */
114 enum sendaction {
115 SEND_MBOX, /* no conversion to perform */
116 SEND_RFC822, /* no conversion, no From_ line */
117 SEND_TODISP, /* convert to displayable form */
118 SEND_TODISP_ALL, /* same, include all MIME parts */
119 SEND_SHOW, /* convert to 'show' command form */
120 SEND_TOSRCH, /* convert for IMAP SEARCH */
121 SEND_TOFLTR, /* convert for junk mail filtering */
122 SEND_TOFILE, /* convert for saving body to a file */
123 SEND_TOPIPE, /* convert for pipe-content/subc. */
124 SEND_QUOTE, /* convert for quoting */
125 SEND_QUOTE_ALL, /* same, include all MIME parts */
126 SEND_DECRYPT /* decrypt */
129 enum mimecontent {
130 MIME_UNKNOWN, /* unknown content */
131 MIME_SUBHDR, /* inside a multipart subheader */
132 MIME_822, /* message/rfc822 content */
133 MIME_MESSAGE, /* other message/ content */
134 MIME_TEXT_PLAIN, /* text/plain content */
135 MIME_TEXT_HTML, /* text/html content */
136 MIME_TEXT, /* other text/ content */
137 MIME_ALTERNATIVE, /* multipart/alternative content */
138 MIME_DIGEST, /* multipart/digest content */
139 MIME_MULTI, /* other multipart/ content */
140 MIME_PKCS7, /* PKCS7 content */
141 MIME_DISCARD /* content is discarded */
144 enum mimeclean {
145 MIME_CLEAN = 000, /* plain RFC 2822 message */
146 MIME_HIGHBIT = 001, /* characters >= 0200 */
147 MIME_LONGLINES = 002, /* has lines too long for RFC 2822 */
148 MIME_CTRLCHAR = 004, /* contains control characters */
149 MIME_HASNUL = 010, /* contains \0 characters */
150 MIME_NOTERMNL = 020 /* lacks a terminating newline */
153 enum tdflags {
154 TD_NONE = 0, /* no display conversion */
155 TD_ISPR = 01, /* use isprint() checks */
156 TD_ICONV = 02, /* use iconv() */
157 TD_DELCTRL = 04 /* delete control characters */
160 struct str {
161 char *s; /* the string's content */
162 size_t l; /* the stings's length */
165 enum protocol {
166 PROTO_FILE, /* refers to a local file */
167 PROTO_POP3, /* is a pop3 server string */
168 PROTO_IMAP, /* is an imap server string */
169 PROTO_MAILDIR, /* refers to a maildir folder */
170 PROTO_UNKNOWN /* unknown protocol */
173 struct sock { /* data associated with a socket */
174 int s_fd; /* file descriptor */
175 #ifdef USE_SSL
176 int s_use_ssl; /* SSL is used */
177 #if defined (USE_NSS)
178 void *s_prfd; /* NSPR file descriptor */
179 #elif defined (USE_OPENSSL)
180 void *s_ssl; /* SSL object */
181 void *s_ctx; /* SSL context object */
182 #endif /* SSL library specific */
183 #endif /* USE_SSL */
184 char *s_wbuf; /* for buffered writes */
185 int s_wbufsize; /* allocated size of s_buf */
186 int s_wbufpos; /* position of first empty data byte */
187 char s_rbuf[LINESIZE+1]; /* for buffered reads */
188 char *s_rbufptr; /* read pointer to s_rbuf */
189 int s_rsz; /* size of last read in s_rbuf */
190 char *s_desc; /* description of error messages */
191 void (*s_onclose)(void); /* execute on close */
194 struct mailbox {
195 struct sock mb_sock; /* socket structure */
196 enum {
197 MB_NONE = 000, /* no reply expected */
198 MB_COMD = 001, /* command reply expected */
199 MB_MULT = 002, /* multiline reply expected */
200 MB_PREAUTH = 004, /* not in authenticated state */
201 MB_BYE = 010 /* may accept a BYE state */
202 } mb_active;
203 FILE *mb_itf; /* temp file with messages, read open */
204 FILE *mb_otf; /* same, write open */
205 char *mb_sorted; /* sort method */
206 enum {
207 MB_VOID, /* no type (e. g. connection failed) */
208 MB_FILE, /* local file */
209 MB_POP3, /* POP3 mailbox */
210 MB_IMAP, /* IMAP mailbox */
211 MB_MAILDIR, /* maildir folder */
212 MB_CACHE /* cached mailbox */
213 } mb_type; /* type of mailbox */
214 enum {
215 MB_DELE = 01, /* may delete messages in mailbox */
216 MB_EDIT = 02 /* may edit messages in mailbox */
217 } mb_perm;
218 int mb_compressed; /* is a compressed mbox file */
219 int mb_threaded; /* mailbox has been threaded */
220 enum mbflags {
221 MB_NOFLAGS = 000,
222 MB_UIDPLUS = 001 /* supports IMAP UIDPLUS */
223 } mb_flags;
224 unsigned long mb_uidvalidity; /* IMAP unique identifier validity */
225 char *mb_imap_account; /* name of current IMAP account */
226 char *mb_imap_mailbox; /* name of current IMAP mailbox */
227 char *mb_cache_directory; /* name of cache directory */
230 enum needspec {
231 NEED_UNSPEC, /* unspecified need, don't fetch */
232 NEED_HEADER, /* need the header of a message */
233 NEED_BODY /* need header and body of a message */
236 enum havespec {
237 HAVE_NOTHING = 0, /* nothing downloaded yet */
238 HAVE_HEADER = 01, /* header is downloaded */
239 HAVE_BODY = 02 /* entire message is downloaded */
243 * flag bits. Attention: Flags that are used in cache.c may not change.
245 enum mflag {
246 MUSED = (1<<0), /* entry is used, but this bit isn't */
247 MDELETED = (1<<1), /* entry has been deleted */
248 MSAVED = (1<<2), /* entry has been saved */
249 MTOUCH = (1<<3), /* entry has been noticed */
250 MPRESERVE = (1<<4), /* keep entry in sys mailbox */
251 MMARK = (1<<5), /* message is marked! */
252 MODIFY = (1<<6), /* message has been modified */
253 MNEW = (1<<7), /* message has never been seen */
254 MREAD = (1<<8), /* message has been read sometime. */
255 MSTATUS = (1<<9), /* message status has changed */
256 MBOX = (1<<10), /* Send this to mbox, regardless */
257 MNOFROM = (1<<11), /* no From line */
258 MHIDDEN = (1<<12), /* message is hidden to user */
259 MFULLYCACHED = (1<<13), /* message is completely cached */
260 MBOXED = (1<<14), /* message has been sent to mbox */
261 MUNLINKED = (1<<15), /* message was unlinked from cache */
262 MNEWEST = (1<<16), /* message is very new (newmail) */
263 MFLAG = (1<<17), /* message has been flagged recently */
264 MUNFLAG = (1<<18), /* message has been unflagged */
265 MFLAGGED = (1<<19), /* message is `flagged' */
266 MANSWER = (1<<20), /* message has been answered recently */
267 MUNANSWER = (1<<21), /* message has been unanswered */
268 MANSWERED = (1<<22), /* message is `answered' */
269 MDRAFT = (1<<23), /* message has been drafted recently */
270 MUNDRAFT = (1<<24), /* message has been undrafted */
271 MDRAFTED = (1<<25), /* message is marked as `draft' */
272 MKILL = (1<<26), /* message has been killed */
273 MOLDMARK = (1<<27), /* messages was marked previously */
274 MJUNK = (1<<28) /* message is classified as junk */
277 struct mimepart {
278 enum mflag m_flag; /* flags */
279 enum havespec m_have; /* downloaded parts of the part */
280 int m_block; /* block number of this part */
281 size_t m_offset; /* offset in block of part */
282 size_t m_size; /* Bytes in the part */
283 size_t m_xsize; /* Bytes in the full part */
284 long m_lines; /* Lines in the message */
285 long m_xlines; /* Lines in the full message */
286 time_t m_time; /* time the message was sent */
287 char *m_from; /* message sender */
288 struct mimepart *m_nextpart; /* next part at same level */
289 struct mimepart *m_multipart; /* parts of multipart */
290 struct mimepart *m_parent; /* enclosing multipart part */
291 char *m_ct_type; /* content-type */
292 char *m_ct_type_plain; /* content-type without specs */
293 enum mimecontent m_mimecontent; /* same in enum */
294 char *m_charset; /* charset */
295 char *m_ct_transfer_enc; /* content-transfer-encoding */
296 enum mimeenc m_mimeenc; /* same in enum */
297 char *m_partstring; /* part level string */
298 char *m_filename; /* attachment filename */
301 struct message {
302 enum mflag m_flag; /* flags */
303 enum havespec m_have; /* downloaded parts of the message */
304 int m_block; /* block number of this message */
305 size_t m_offset; /* offset in block of message */
306 size_t m_size; /* Bytes in the message */
307 size_t m_xsize; /* Bytes in the full message */
308 long m_lines; /* Lines in the message */
309 long m_xlines; /* Lines in the full message */
310 time_t m_time; /* time the message was sent */
311 time_t m_date; /* time in the 'Date' field */
312 unsigned m_idhash; /* hash on Message-ID for threads */
313 unsigned long m_uid; /* IMAP unique identifier */
314 struct message *m_child; /* first child of this message */
315 struct message *m_younger; /* younger brother of this message */
316 struct message *m_elder; /* elder brother of this message */
317 struct message *m_parent; /* parent of this message */
318 unsigned m_level; /* thread level of message */
319 long m_threadpos; /* position in threaded display */
320 float m_score; /* score of message */
321 char *m_maildir_file; /* original maildir file of msg */
322 unsigned m_maildir_hash; /* hash of file name in maildir sub */
323 int m_collapsed; /* collapsed thread information */
327 * Given a file address, determine the block number it represents.
329 #define mailx_blockof(off) ((int) ((off) / 4096))
330 #define mailx_offsetof(off) ((int) ((off) % 4096))
331 #define mailx_positionof(block, offset) ((off_t)(block) * 4096 + (offset))
334 * Argument types.
336 enum argtype {
337 MSGLIST = 0, /* Message list type */
338 STRLIST = 1, /* A pure string */
339 RAWLIST = 2, /* Shell string list */
340 NOLIST = 3, /* Just plain 0 */
341 NDMLIST = 4, /* Message list, no defaults */
342 ECHOLIST= 5, /* Like raw list, but keep quote chars */
343 P = 040, /* Autoprint dot after command */
344 I = 0100, /* Interactive command bit */
345 M = 0200, /* Legal from send mode bit */
346 W = 0400, /* Illegal when read only bit */
347 F = 01000, /* Is a conditional command */
348 T = 02000, /* Is a transparent command */
349 R = 04000, /* Cannot be called from collect */
350 A = 010000 /* Needs an active mailbox */
354 * Oft-used mask values
357 #define MMNORM (MDELETED|MSAVED|MHIDDEN)/* Look at both save and delete bits */
358 #define MMNDEL (MDELETED|MHIDDEN) /* Look only at deleted bit */
361 * Format of the command description table.
362 * The actual table is declared and initialized
363 * in lex.c
365 struct cmd {
366 char *c_name; /* Name of command */
367 int (*c_func)(void *); /* Implementor of the command */
368 enum argtype c_argtype; /* Type of arglist (see below) */
369 short c_msgflag; /* Required flags of messages */
370 short c_msgmask; /* Relevant flags of messages */
373 /* Yechh, can't initialize unions */
375 #define c_minargs c_msgflag /* Minimum argcount for RAWLIST */
376 #define c_maxargs c_msgmask /* Max argcount for RAWLIST */
379 * Structure used to return a break down of a head
380 * line (hats off to Bill Joy!)
383 struct headline {
384 char *l_from; /* The name of the sender */
385 char *l_tty; /* His tty string (if any) */
386 char *l_date; /* The entire date string */
389 enum gfield {
390 GTO = 1, /* Grab To: line */
391 GSUBJECT= 2, /* Likewise, Subject: line */
392 GCC = 4, /* And the Cc: line */
393 GBCC = 8, /* And also the Bcc: line */
395 GNL = 16, /* Print blank line after */
396 GDEL = 32, /* Entity removed from list */
397 GCOMMA = 64, /* detract puts in commas */
398 GUA = 128, /* User-Agent field */
399 GMIME = 256, /* MIME 1.0 fields */
400 GMSGID = 512, /* a Message-ID */
401 /* 1024 */ /* unused */
402 GIDENT = 2048, /* From:, Reply-To: and Organization: field */
403 GREF = 4096, /* References: field */
404 GDATE = 8192, /* Date: field */
405 GFULL = 16384, /* include full names */
406 GSKIN = 32768, /* skin names */
407 GEXTRA = 65536, /* extra fields */
408 GFILES = 131072 /* include filename addresses */
411 #define GMASK (GTO|GSUBJECT|GCC|GBCC) /* Mask of places from whence */
413 #define visible(mp) (((mp)->m_flag & (MDELETED|MHIDDEN|MKILL)) == 0 || \
414 (dot == (mp) && (mp)->m_flag & MKILL))
417 * Structure used to pass about the current
418 * state of the user-typed message header.
421 struct header {
422 struct name *h_to; /* Dynamic "To:" string */
423 char *h_subject; /* Subject string */
424 struct name *h_cc; /* Carbon copies string */
425 struct name *h_bcc; /* Blind carbon copies */
426 struct name *h_ref; /* References */
427 struct name *h_smopts; /* Sendmail options */
428 struct attachment *h_attach; /* MIME attachments */
429 char *h_charset; /* preferred charset */
430 struct name *h_from; /* overridden "From:" field */
431 struct name *h_replyto; /* overridden "Reply-To:" field */
432 struct name *h_sender; /* overridden "Sender:" field */
433 char *h_organization; /* overridden "Organization:" field */
437 * Structure of namelist nodes used in processing
438 * the recipients of mail and aliases and all that
439 * kind of stuff.
442 enum nameflags {
443 NAME_MIME_CHECKED = 1<<0, /* mime_name_invalid() yet checked.. */
444 NAME_MIME_INVALID = 1<<1, /* ..and it was invalid */
445 NAME_IDNA_REQUIRED = 1<<2, /* IDNA convertion desired.. */
446 NAME_IDNA_APPLIED = 1<<3 /* ..and is applied to name.n_name */
449 struct name {
450 struct name *n_flink; /* Forward link in list. */
451 struct name *n_blink; /* Backward list link */
452 enum gfield n_type; /* From which list it came */
453 int n_flags; /* enum nameflags */
454 char *n_name; /* This fella's name */
455 char *n_fullname; /* Sometimes, name including comment */
459 * Structure of a MIME attachment.
462 struct attachment {
463 struct attachment *a_flink; /* Forward link in list. */
464 struct attachment *a_blink; /* Backward list link */
465 char *a_name; /* file name */
466 char *a_content_type; /* content type */
467 char *a_content_disposition; /* content disposition */
468 char *a_content_id; /* content id */
469 char *a_content_description; /* content description */
470 char *a_charset; /* character set */
471 int a_msgno; /* message number */
475 * Structure of a variable node. All variables are
476 * kept on a singly-linked list of these, rooted by
477 * "variables"
480 struct var {
481 struct var *v_link; /* Forward link to next variable */
482 char *v_name; /* The variable's name */
483 char *v_value; /* And it's current value */
486 struct group {
487 struct group *ge_link; /* Next person in this group */
488 char *ge_name; /* This person's user name */
491 struct grouphead {
492 struct grouphead *g_link; /* Next grouphead in list */
493 char *g_name; /* Name of this group */
494 struct group *g_list; /* Users in group. */
498 * Structure of the hash table of ignored header fields
500 struct ignoretab {
501 int i_count; /* Number of entries */
502 struct ignore {
503 struct ignore *i_link; /* Next ignored field in bucket */
504 char *i_field; /* This ignored field */
505 } *i_head[HSHSIZE];
509 * Token values returned by the scanner used for argument lists.
510 * Also, sizes of scanner-related things.
512 enum ltoken {
513 TEOL = 0, /* End of the command line */
514 TNUMBER = 1, /* A message number */
515 TDASH = 2, /* A simple dash */
516 TSTRING = 3, /* A string (possibly containing -) */
517 TDOT = 4, /* A "." */
518 TUP = 5, /* An "^" */
519 TDOLLAR = 6, /* A "$" */
520 TSTAR = 7, /* A "*" */
521 TOPEN = 8, /* An '(' */
522 TCLOSE = 9, /* A ')' */
523 TPLUS = 10, /* A '+' */
524 TERROR = 11, /* A lexical error */
525 TCOMMA = 12, /* A ',' */
526 TSEMI = 13, /* A ';' */
527 TBACK = 14 /* A '`' */
530 #define REGDEP 2 /* Maximum regret depth. */
533 * Constants for conditional commands. These describe whether
534 * we should be executing stuff or not.
536 enum condition {
537 CANY = 0, /* Execute in send or receive mode */
538 CRCV = 1, /* Execute in receive mode only */
539 CSEND = 2, /* Execute in send mode only */
540 CTERM = 3, /* Execute only if stdin is a tty */
541 CNONTERM= 4 /* Execute only if stdin not tty */
545 * For the 'shortcut' and 'unshortcut' functionality.
547 struct shortcut {
548 struct shortcut *sh_next; /* next shortcut in list */
549 char *sh_short; /* shortcut string */
550 char *sh_long; /* expanded form */
554 * Kludges to handle the change from setexit / reset to setjmp / longjmp
557 #define setexit() sigsetjmp(srbuf, 1)
558 #define reset(x) siglongjmp(srbuf, x)
561 * Locale-independent character classes.
563 enum {
564 C_CNTRL = 0000,
565 C_BLANK = 0001,
566 C_WHITE = 0002,
567 C_SPACE = 0004,
568 C_PUNCT = 0010,
569 C_OCTAL = 0020,
570 C_DIGIT = 0040,
571 C_UPPER = 0100,
572 C_LOWER = 0200
575 extern const unsigned char class_char[];
577 #define __ischarof(C, FLAGS) (asciichar(C) && class_char[(size_t)C] & (FLAGS))
578 #define __ischareq(C, FLAGS) (asciichar(C) && class_char[(size_t)C] == (FLAGS))
580 #define asciichar(c) ((size_t)(c) <= 0177)
581 #define alnumchar(c) __ischarof(c, C_DIGIT|C_OCTAL|C_UPPER|C_LOWER)
582 #define alphachar(c) __ischarof(c, C_UPPER|C_LOWER)
583 #define blankchar(c) __ischarof(c, C_BLANK)
584 #define blankspacechar(c) __ischarof(c, C_BLANK|C_SPACE)
585 #define cntrlchar(c) __ischareq(c, C_CNTRL)
586 #define digitchar(c) __ischarof(c, C_DIGIT|C_OCTAL)
587 #define lowerchar(c) __ischarof(c, C_LOWER)
588 #define punctchar(c) __ischarof(c, C_PUNCT)
589 #define spacechar(c) __ischarof(c, C_BLANK|C_SPACE|C_WHITE)
590 #define upperchar(c) __ischarof(c, C_UPPER)
591 #define whitechar(c) __ischarof(c, C_BLANK|C_WHITE)
592 #define octalchar(c) __ischarof(c, C_OCTAL)
594 #define upperconv(c) (lowerchar(c) ? (c)-'a'+'A' : (c))
595 #define lowerconv(c) (upperchar(c) ? (c)-'A'+'a' : (c))
596 /* RFC 822, 3.2. */
597 #define fieldnamechar(c) (asciichar(c)&&(c)>040&&(c)!=0177&&(c)!=':')
600 * Truncate a file to the last character written. This is
601 * useful just before closing an old file that was opened
602 * for read/write.
604 #define trunc(stream) { \
605 fflush(stream); \
606 ftruncate(fileno(stream), (off_t)ftell(stream)); \
610 * Use either alloca() or smalloc()/free(). ac_alloc can be used to
611 * allocate space within a function. ac_free must be called when the
612 * space is no longer needed, but expands to nothing if using alloca().
614 #ifdef HAVE_ALLOCA
615 #define ac_alloc(n) alloca(n)
616 #define ac_free(n) do {} while (0)
617 #else /* !HAVE_ALLOCA */
618 #define ac_alloc(n) smalloc(n)
619 #define ac_free(n) free(n)
620 #endif /* !HAVE_ALLOCA */
623 * Single-threaded, use unlocked I/O.
625 #ifdef HAVE_PUTC_UNLOCKED
626 # undef getc
627 # define getc(c) getc_unlocked(c)
628 # undef putc
629 # define putc(c, f) putc_unlocked(c, f)
630 # undef putchar
631 # define putchar(c) putc_unlocked((c), stdout)
632 #endif
634 #define CBAD (-15555)
636 #define smin(a, b) ((a) < (b) ? (a) : (b))
637 #define smax(a, b) ((a) < (b) ? (b) : (a))
640 * For saving the current directory and later returning.
642 #ifdef HAVE_FCHDIR
643 struct cw {
644 int cw_fd;
646 #else /* !HAVE_FCHDIR */
647 struct cw {
648 char cw_wd[PATHSIZE];
650 #endif /* !HAVE_FCHDIR */
652 #ifdef USE_SSL
653 enum ssl_vrfy_level {
654 VRFY_IGNORE,
655 VRFY_WARN,
656 VRFY_ASK,
657 VRFY_STRICT
659 #endif /* USE_SSL */