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: fopen.c
/* * Copyright (c) 2000-2002, 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: fopen.c,v 1.63 2013-11-22 20:51:42 ca Exp $") #include <errno.h> #include <setjmp.h> #include <sm/time.h> #include <sm/heap.h> #include <sm/signal.h> #include <sm/assert.h> #include <sm/io.h> #include <sm/clock.h> #include "local.h" static void openalrm __P((int)); static void reopenalrm __P((int)); extern int sm_io_fclose __P((SM_FILE_T *)); static jmp_buf OpenTimeOut, ReopenTimeOut; /* ** OPENALRM -- handler when timeout activated for sm_io_open() ** ** Returns flow of control to where setjmp(OpenTimeOut) was set. ** ** Parameters: ** sig -- unused ** ** Returns: ** does not return ** ** Side Effects: ** returns flow of control to setjmp(OpenTimeOut). ** ** 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 openalrm(sig) int sig; { longjmp(OpenTimeOut, 1); } /* ** REOPENALRM -- handler when timeout activated for sm_io_reopen() ** ** Returns flow of control to where setjmp(ReopenTimeOut) was set. ** ** Parameters: ** sig -- unused ** ** Returns: ** does not return ** ** Side Effects: ** returns flow of control to setjmp(ReopenTimeOut). ** ** 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 reopenalrm(sig) int sig; { longjmp(ReopenTimeOut, 1); } /* ** SM_IO_OPEN -- open a file of a specific type ** ** Parameters: ** type -- type of file to open ** timeout -- time to complete the open ** info -- info describing what is to be opened (type dependent) ** flags -- user selected flags ** rpool -- pointer to rpool to be used for this open ** ** Returns: ** Raises exception on heap exhaustion. ** Aborts if type is invalid. ** Returns NULL and sets errno ** - when the type specific open fails ** - when open vector errors ** - when flags not set or invalid ** Success returns a file pointer to the opened file type. */ SM_FILE_T * sm_io_open(type, timeout, info, flags, rpool) const SM_FILE_T *type; int SM_NONVOLATILE timeout; /* this is not the file type timeout */ const void *info; int flags; const void *rpool; { register SM_FILE_T *fp; int ioflags; SM_EVENT *evt = NULL; ioflags = sm_flags(flags); if (ioflags == 0) { /* must give some indication/intent */ errno = EINVAL; return NULL; } if (timeout == SM_TIME_DEFAULT) timeout = SM_TIME_FOREVER; if (timeout == SM_TIME_IMMEDIATE) { errno = EAGAIN; return NULL; } fp = sm_fp(type, ioflags, NULL); /* Okay, this is where we set the timeout. */ if (timeout != SM_TIME_FOREVER) { if (setjmp(OpenTimeOut) != 0) { errno = EAGAIN; return NULL; } evt = sm_seteventm(timeout, openalrm, 0); } if ((*fp->f_open)(fp, info, flags, rpool) < 0) { fp->f_flags = 0; /* release */ fp->sm_magic = NULL; /* release */ return NULL; } /* We're back. So undo our timeout and handler */ if (evt != NULL) sm_clrevent(evt); #if SM_RPOOL if (rpool != NULL) sm_rpool_attach_x(rpool, sm_io_fclose, fp); #endif return fp; } /* ** SM_IO_DUP -- duplicate a file pointer ** ** Parameters: ** fp -- file pointer to duplicate ** ** Returns: ** Success - the duplicated file pointer ** Failure - NULL (was an invalid file pointer or too many open) ** ** Increments the duplicate counter (dup_cnt) for the open file pointer. ** The counter counts the number of duplicates. When the duplicate ** counter is 0 (zero) then the file pointer is the only one left ** (no duplicates, it is the only one). */ SM_FILE_T * sm_io_dup(fp) SM_FILE_T *fp; { SM_REQUIRE_ISA(fp, SmFileMagic); if (fp->sm_magic != SmFileMagic) { errno = EBADF; return NULL; } if (fp->f_dup_cnt >= INT_MAX - 1) { /* Can't let f_dup_cnt wrap! */ errno = EMFILE; return NULL; } fp->f_dup_cnt++; return fp; } /* ** SM_IO_REOPEN -- open a new file using the old file pointer ** ** Parameters: ** type -- file type to be opened ** timeout -- time to complete the reopen ** info -- information about what is to be "re-opened" (type dep.) ** flags -- user flags to map to internal flags ** rpool -- rpool file to be associated with ** fp -- the file pointer to reuse ** ** Returns: ** Raises an exception on heap exhaustion. ** Aborts if type is invalid. ** Failure: returns NULL ** Success: returns "reopened" file pointer */ SM_FILE_T * sm_io_reopen(type, timeout, info, flags, rpool, fp) const SM_FILE_T *type; int SM_NONVOLATILE timeout; const void *info; int flags; const void *rpool; SM_FILE_T *fp; { int ioflags, ret; SM_FILE_T *fp2; SM_EVENT *evt = NULL; if ((ioflags = sm_flags(flags)) == 0) { (void) sm_io_close(fp, timeout); return NULL; } if (!Sm_IO_DidInit) sm_init(); if (timeout == SM_TIME_DEFAULT) timeout = SM_TIME_FOREVER; if (timeout == SM_TIME_IMMEDIATE) { /* ** Filling the buffer will take time and we are wanted to ** return immediately. So... */ errno = EAGAIN; return NULL; } /* Okay, this is where we set the timeout. */ if (timeout != SM_TIME_FOREVER) { if (setjmp(ReopenTimeOut) != 0) { errno = EAGAIN; return NULL; } evt = sm_seteventm(timeout, reopenalrm, 0); } /* ** There are actually programs that depend on being able to "reopen" ** descriptors that weren't originally open. Keep this from breaking. ** Remember whether the stream was open to begin with, and which file ** descriptor (if any) was associated with it. If it was attached to ** a descriptor, defer closing it; reopen("/dev/stdin", "r", stdin) ** should work. This is unnecessary if it was not a Unix file. */ if (fp != NULL) { if (fp->sm_magic != SmFileMagic) fp->f_flags = SMFEOF; /* hold on to it */ else { /* flush the stream; ANSI doesn't require this. */ (void) sm_io_flush(fp, SM_TIME_FOREVER); (void) sm_io_close(fp, SM_TIME_FOREVER); } } fp2 = sm_fp(type, ioflags, fp); ret = (*fp2->f_open)(fp2, info, flags, rpool); /* We're back. So undo our timeout and handler */ if (evt != NULL) sm_clrevent(evt); if (ret < 0) { fp2->f_flags = 0; /* release */ fp2->sm_magic = NULL; /* release */ return NULL; } /* ** We're not preserving this logic (below) for sm_io because it is now ** abstracted at least one "layer" away. By closing and reopening ** the 1st fd used should be the just released one (when Unix ** behavior followed). Old comment:: ** If reopening something that was open before on a real file, try ** to maintain the descriptor. Various C library routines (perror) ** assume stderr is always fd STDERR_FILENO, even if being reopen'd. */ #if SM_RPOOL if (rpool != NULL) sm_rpool_attach_x(rpool, sm_io_close, fp2); #endif return fp2; } /* ** SM_IO_AUTOFLUSH -- link another file to this for auto-flushing ** ** When a read occurs on fp, fp2 will be flushed iff there is no ** data waiting on fp. ** ** Parameters: ** fp -- the file opened for reading. ** fp2 -- the file opened for writing. ** ** Returns: ** The old flush file pointer. */ SM_FILE_T * sm_io_autoflush(fp, fp2) SM_FILE_T *fp; SM_FILE_T *fp2; { SM_FILE_T *savefp; SM_REQUIRE_ISA(fp, SmFileMagic); if (fp2 != NULL) SM_REQUIRE_ISA(fp2, SmFileMagic); savefp = fp->f_flushfp; fp->f_flushfp = fp2; return savefp; } /* ** SM_IO_AUTOMODE -- link another file to this for auto-moding ** ** When the mode (blocking or non-blocking) changes for fp1 then ** update fp2's mode at the same time. This is to be used when ** a system dup() has generated a second file descriptor for ** another sm_io_open() by file descriptor. The modes have been ** linked in the system and this formalizes it for sm_io internally. ** ** Parameters: ** fp1 -- the first file ** fp2 -- the second file ** ** Returns: ** nothing */ void sm_io_automode(fp1, fp2) SM_FILE_T *fp1; SM_FILE_T *fp2; { SM_REQUIRE_ISA(fp1, SmFileMagic); SM_REQUIRE_ISA(fp2, SmFileMagic); fp1->f_modefp = fp2; fp2->f_modefp = fp1; }
Upload File
Create Folder