003 File Manager
Current Path:
/usr/src/contrib/sendmail/libsm
usr
/
src
/
contrib
/
sendmail
/
libsm
/
📁
..
📄
Makefile
(346 B)
📄
Makefile.m4
(1.92 KB)
📄
README
(4.42 KB)
📄
assert.c
(4.13 KB)
📄
assert.html
(13.86 KB)
📄
b-strcmp.c
(3.4 KB)
📄
b-strl.c
(5 KB)
📄
cdefs.html
(2.39 KB)
📄
cf.c
(1.97 KB)
📄
clock.c
(13.89 KB)
📄
clrerr.c
(872 B)
📄
config.c
(4.47 KB)
📄
debug.c
(8.91 KB)
📄
debug.html
(7.68 KB)
📄
errstring.c
(6.03 KB)
📄
exc.c
(13.05 KB)
📄
exc.html
(23.27 KB)
📄
fclose.c
(3.13 KB)
📄
feof.c
(961 B)
📄
ferror.c
(932 B)
📄
fflush.c
(3.1 KB)
📄
fget.c
(2.37 KB)
📄
findfp.c
(10.65 KB)
📄
flags.c
(1.27 KB)
📄
fopen.c
(8.3 KB)
📄
fpos.c
(3.12 KB)
📄
fprintf.c
(1.35 KB)
📄
fpurge.c
(1.15 KB)
📄
fput.c
(1.25 KB)
📄
fread.c
(2.28 KB)
📄
fscanf.c
(1.34 KB)
📄
fseek.c
(7.25 KB)
📄
fvwrite.c
(6.24 KB)
📄
fvwrite.h
(740 B)
📄
fwalk.c
(1.41 KB)
📄
fwrite.c
(1.54 KB)
📄
gen.html
(910 B)
📄
get.c
(1.12 KB)
📄
glue.h
(731 B)
📄
heap.c
(17.29 KB)
📄
heap.html
(13.07 KB)
📄
index.html
(5.95 KB)
📄
inet6_ntop.c
(1.1 KB)
📄
io.html
(26.6 KB)
📄
ldap.c
(35.72 KB)
📄
local.h
(9.42 KB)
📄
makebuf.c
(3.36 KB)
📄
match.c
(2.77 KB)
📄
mbdb.c
(16.61 KB)
📄
memstat.c
(5.13 KB)
📄
mpeix.c
(13.84 KB)
📄
niprop.c
(4.64 KB)
📄
notify.c
(3.32 KB)
📄
put.c
(1.61 KB)
📄
refill.c
(7.09 KB)
📄
rewind.c
(1.08 KB)
📄
rpool.c
(11.54 KB)
📄
rpool.html
(6.08 KB)
📄
sem.c
(4.41 KB)
📄
setvbuf.c
(4.2 KB)
📄
shm.c
(2.62 KB)
📄
signal.c
(6.75 KB)
📄
smstdio.c
(6.14 KB)
📄
snprintf.c
(2.29 KB)
📄
sscanf.c
(2.26 KB)
📄
stdio.c
(9.7 KB)
📄
strcasecmp.c
(3.14 KB)
📄
strdup.c
(2.79 KB)
📄
strerror.c
(1.27 KB)
📄
strexit.c
(2.76 KB)
📄
string.c
(1.29 KB)
📄
stringf.c
(1.77 KB)
📄
strio.c
(9.18 KB)
📄
strl.c
(7.52 KB)
📄
strrevcmp.c
(1.61 KB)
📄
strto.c
(5.45 KB)
📄
syslogio.c
(4.11 KB)
📄
t-cf.c
(934 B)
📄
t-event.c
(1.79 KB)
📄
t-exc.c
(2.75 KB)
📄
t-fget.c
(1.71 KB)
📄
t-float.c
(1.78 KB)
📄
t-fopen.c
(875 B)
📄
t-heap.c
(1.3 KB)
📄
t-inet6_ntop.c
(1.4 KB)
📄
t-match.c
(1.1 KB)
📄
t-memstat.c
(2.17 KB)
📄
t-notify.c
(1.81 KB)
📄
t-path.c
(742 B)
📄
t-qic.c
(5.43 KB)
📄
t-rpool.c
(1.5 KB)
📄
t-scanf.c
(1.38 KB)
📄
t-sem.c
(5.85 KB)
📄
t-shm.c
(4.42 KB)
📄
t-smstdio.c
(1.55 KB)
📄
t-string.c
(968 B)
📄
t-strio.c
(775 B)
📄
t-strl.c
(3.53 KB)
📄
t-strrevcmp.c
(994 B)
📄
t-types.c
(2.7 KB)
📄
test.c
(2.73 KB)
📄
ungetc.c
(3.93 KB)
📄
util.c
(4.46 KB)
📄
vasprintf.c
(2.91 KB)
📄
vfprintf.c
(24.09 KB)
📄
vfscanf.c
(18.76 KB)
📄
vprintf.c
(999 B)
📄
vsnprintf.c
(1.87 KB)
📄
wbuf.c
(2.51 KB)
📄
wsetup.c
(1.88 KB)
📄
xtrap.c
(653 B)
Editing: fseek.c
/* * Copyright (c) 2000-2001, 2004 Proofpoint, Inc. and its suppliers. * All rights reserved. * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Chris Torek. * * By using this file, you agree to the terms and conditions set * forth in the LICENSE file which can be found at the top level of * the sendmail distribution. */ #include <sm/gen.h> SM_RCSID("@(#)$Id: fseek.c,v 1.48 2013-11-22 20:51:42 ca Exp $") #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdlib.h> #include <errno.h> #include <setjmp.h> #include <sm/time.h> #include <sm/signal.h> #include <sm/io.h> #include <sm/assert.h> #include <sm/clock.h> #include "local.h" #define POS_ERR (-(off_t)1) static void seekalrm __P((int)); static jmp_buf SeekTimeOut; /* ** SEEKALRM -- handler when timeout activated for sm_io_seek() ** ** Returns flow of control to where setjmp(SeekTimeOut) was set. ** ** Parameters: ** sig -- unused ** ** Returns: ** does not return ** ** Side Effects: ** returns flow of control to setjmp(SeekTimeOut). ** ** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD ** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE ** DOING. */ /* ARGSUSED0 */ static void seekalrm(sig) int sig; { longjmp(SeekTimeOut, 1); } /* ** SM_IO_SEEK -- position the file pointer ** ** Parameters: ** fp -- the file pointer to be seek'd ** timeout -- time to complete seek (milliseconds) ** offset -- seek offset based on 'whence' ** whence -- indicates where seek is relative from. ** One of SM_IO_SEEK_{CUR,SET,END}. ** Returns: ** Failure: returns -1 (minus 1) and sets errno ** Success: returns 0 (zero) */ int sm_io_seek(fp, timeout, offset, whence) register SM_FILE_T *fp; int SM_NONVOLATILE timeout; long SM_NONVOLATILE offset; int SM_NONVOLATILE whence; { bool havepos; off_t target, curoff; size_t n; struct stat st; int ret; SM_EVENT *evt = NULL; register off_t (*seekfn) __P((SM_FILE_T *, off_t, int)); SM_REQUIRE_ISA(fp, SmFileMagic); /* make sure stdio is set up */ if (!Sm_IO_DidInit) sm_init(); /* Have to be able to seek. */ if ((seekfn = fp->f_seek) == NULL) { errno = ESPIPE; /* historic practice */ return -1; } if (timeout == SM_TIME_DEFAULT) timeout = fp->f_timeout; if (timeout == SM_TIME_IMMEDIATE) { /* ** Filling the buffer will take time and we are wanted to ** return immediately. So... */ errno = EAGAIN; return -1; } #define SM_SET_ALARM() \ if (timeout != SM_TIME_FOREVER) \ { \ if (setjmp(SeekTimeOut) != 0) \ { \ errno = EAGAIN; \ return -1; \ } \ evt = sm_seteventm(timeout, seekalrm, 0); \ } /* ** Change any SM_IO_SEEK_CUR to SM_IO_SEEK_SET, and check `whence' ** argument. After this, whence is either SM_IO_SEEK_SET or ** SM_IO_SEEK_END. */ switch (whence) { case SM_IO_SEEK_CUR: /* ** In order to seek relative to the current stream offset, ** we have to first find the current stream offset a la ** ftell (see ftell for details). */ /* may adjust seek offset on append stream */ sm_flush(fp, (int *) &timeout); SM_SET_ALARM(); if (fp->f_flags & SMOFF) curoff = fp->f_lseekoff; else { curoff = (*seekfn)(fp, (off_t) 0, SM_IO_SEEK_CUR); if (curoff == -1L) { ret = -1; goto clean; } } if (fp->f_flags & SMRD) { curoff -= fp->f_r; if (HASUB(fp)) curoff -= fp->f_ur; } else if (fp->f_flags & SMWR && fp->f_p != NULL) curoff += fp->f_p - fp->f_bf.smb_base; offset += curoff; whence = SM_IO_SEEK_SET; havepos = true; break; case SM_IO_SEEK_SET: case SM_IO_SEEK_END: SM_SET_ALARM(); curoff = 0; /* XXX just to keep gcc quiet */ havepos = false; break; default: errno = EINVAL; return -1; } /* ** Can only optimise if: ** reading (and not reading-and-writing); ** not unbuffered; and ** this is a `regular' Unix file (and hence seekfn==sm_stdseek). ** We must check SMNBF first, because it is possible to have SMNBF ** and SMSOPT both set. */ if (fp->f_bf.smb_base == NULL) sm_makebuf(fp); if (fp->f_flags & (SMWR | SMRW | SMNBF | SMNPT)) goto dumb; if ((fp->f_flags & SMOPT) == 0) { if (seekfn != sm_stdseek || fp->f_file < 0 || fstat(fp->f_file, &st) || (st.st_mode & S_IFMT) != S_IFREG) { fp->f_flags |= SMNPT; goto dumb; } fp->f_blksize = st.st_blksize; fp->f_flags |= SMOPT; } /* ** We are reading; we can try to optimise. ** Figure out where we are going and where we are now. */ if (whence == SM_IO_SEEK_SET) target = offset; else { if (fstat(fp->f_file, &st)) goto dumb; target = st.st_size + offset; } if (!havepos) { if (fp->f_flags & SMOFF) curoff = fp->f_lseekoff; else { curoff = (*seekfn)(fp, (off_t) 0, SM_IO_SEEK_CUR); if (curoff == POS_ERR) goto dumb; } curoff -= fp->f_r; if (HASUB(fp)) curoff -= fp->f_ur; } /* ** Compute the number of bytes in the input buffer (pretending ** that any ungetc() input has been discarded). Adjust current ** offset backwards by this count so that it represents the ** file offset for the first byte in the current input buffer. */ if (HASUB(fp)) { curoff += fp->f_r; /* kill off ungetc */ n = fp->f_up - fp->f_bf.smb_base; curoff -= n; n += fp->f_ur; } else { n = fp->f_p - fp->f_bf.smb_base; curoff -= n; n += fp->f_r; } /* ** If the target offset is within the current buffer, ** simply adjust the pointers, clear SMFEOF, undo ungetc(), ** and return. (If the buffer was modified, we have to ** skip this; see getln in fget.c.) */ if (target >= curoff && target < curoff + (off_t) n) { register int o = target - curoff; fp->f_p = fp->f_bf.smb_base + o; fp->f_r = n - o; if (HASUB(fp)) FREEUB(fp); fp->f_flags &= ~SMFEOF; ret = 0; goto clean; } /* ** The place we want to get to is not within the current buffer, ** but we can still be kind to the kernel copyout mechanism. ** By aligning the file offset to a block boundary, we can let ** the kernel use the VM hardware to map pages instead of ** copying bytes laboriously. Using a block boundary also ** ensures that we only read one block, rather than two. */ curoff = target & ~(fp->f_blksize - 1); if ((*seekfn)(fp, curoff, SM_IO_SEEK_SET) == POS_ERR) goto dumb; fp->f_r = 0; fp->f_p = fp->f_bf.smb_base; if (HASUB(fp)) FREEUB(fp); fp->f_flags &= ~SMFEOF; n = target - curoff; if (n) { /* Note: SM_TIME_FOREVER since fn timeout already set */ if (sm_refill(fp, SM_TIME_FOREVER) || fp->f_r < (int) n) goto dumb; fp->f_p += n; fp->f_r -= n; } ret = 0; clean: /* We're back. So undo our timeout and handler */ if (evt != NULL) sm_clrevent(evt); return ret; dumb: /* ** We get here if we cannot optimise the seek ... just ** do it. Allow the seek function to change fp->f_bf.smb_base. */ /* Note: SM_TIME_FOREVER since fn timeout already set */ ret = SM_TIME_FOREVER; if (sm_flush(fp, &ret) != 0 || (*seekfn)(fp, (off_t) offset, whence) == POS_ERR) { ret = -1; goto clean; } /* success: clear SMFEOF indicator and discard ungetc() data */ if (HASUB(fp)) FREEUB(fp); fp->f_p = fp->f_bf.smb_base; fp->f_r = 0; fp->f_flags &= ~SMFEOF; ret = 0; goto clean; }
Upload File
Create Folder