Update zoneinfo database.
[dragonfly/netmp.git] / contrib / sendmail / libsm / fpos.c
bloba8083fd86fc0f02ff5687fd6f44da55d043639f2
1 /*
2 * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Chris Torek.
10 * By using this file, you agree to the terms and conditions set
11 * forth in the LICENSE file which can be found at the top level of
12 * the sendmail distribution.
15 #include <sm/gen.h>
16 SM_RCSID("@(#)$Id: fpos.c,v 1.37 2001/09/11 04:04:48 gshapiro Exp $")
17 #include <errno.h>
18 #include <setjmp.h>
19 #include <sys/time.h>
20 #include <sm/heap.h>
21 #include <sm/signal.h>
22 #include <sm/clock.h>
23 #include <sm/io.h>
24 #include <sm/assert.h>
25 #include "local.h"
27 static jmp_buf TellTimeOut;
30 ** TELLALRM -- handler when timeout activated for sm_io_tell()
32 ** Returns flow of control to where setjmp(TellTimeOut) was set.
34 ** Parameters:
35 ** sig -- unused
37 ** Returns:
38 ** does not return
40 ** Side Effects:
41 ** returns flow of control to setjmp(TellTimeOut).
43 ** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
44 ** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
45 ** DOING.
48 /* ARGSUSED0 */
49 static void
50 tellalrm(sig)
51 int sig;
53 longjmp(TellTimeOut, 1);
57 ** SM_IO_TELL -- position the file pointer
59 ** Paramters:
60 ** fp -- the file pointer to get repositioned
61 ** timeout -- time to complete the tell (milliseconds)
63 ** Returns:
64 ** Success -- the repositioned location.
65 ** Failure -- -1 (minus 1) and sets errno
68 long
69 sm_io_tell(fp, timeout)
70 register SM_FILE_T *fp;
71 int SM_NONVOLATILE timeout;
73 register off_t pos;
74 SM_EVENT *evt = NULL;
76 SM_REQUIRE_ISA(fp, SmFileMagic);
77 if (fp->f_seek == NULL)
79 errno = ESPIPE; /* historic practice */
80 return -1L;
83 if (timeout == SM_TIME_DEFAULT)
84 timeout = fp->f_timeout;
85 if (timeout == SM_TIME_IMMEDIATE)
88 ** Filling the buffer will take time and we are wanted to
89 ** return immediately. So...
92 errno = EAGAIN;
93 return -1L;
97 ** Find offset of underlying I/O object, then adjust byte position
98 ** may adjust seek offset on append stream
101 (void) sm_flush(fp, (int *) &timeout);
103 /* This is where we start the timeout */
104 if (timeout != SM_TIME_FOREVER)
106 if (setjmp(TellTimeOut) != 0)
108 errno = EAGAIN;
109 return -1L;
112 evt = sm_seteventm(timeout, tellalrm, 0);
115 if (fp->f_flags & SMOFF)
116 pos = fp->f_lseekoff;
117 else
119 /* XXX only set the timeout here? */
120 pos = (*fp->f_seek)(fp, (off_t) 0, SM_IO_SEEK_CUR);
121 if (pos == -1L)
122 goto clean;
124 if (fp->f_flags & SMRD)
127 ** Reading. Any unread characters (including
128 ** those from ungetc) cause the position to be
129 ** smaller than that in the underlying object.
132 pos -= fp->f_r;
133 if (HASUB(fp))
134 pos -= fp->f_ur;
136 else if (fp->f_flags & SMWR && fp->f_p != NULL)
139 ** Writing. Any buffered characters cause the
140 ** position to be greater than that in the
141 ** underlying object.
144 pos += fp->f_p - fp->f_bf.smb_base;
147 clean:
148 /* We're back. So undo our timeout and handler */
149 if (evt != NULL)
150 sm_clrevent(evt);
151 return pos;