1N/A * Copyright (c) 1999-2002, 2004, 2006 Sendmail, Inc. and its suppliers. 1N/A * All rights reserved. 1N/A * By using this file, you agree to the terms and conditions set 1N/A * forth in the LICENSE file which can be found at the top level of 1N/A * the sendmail distribution. 1N/A#
pragma ident "%Z%%M% %I% %E% SMI" 1N/A** This is in transition. Changed from the original bf_torek.c code 1N/A** to use sm_io function calls directly rather than through stdio 1N/A** translation layer. Will be made a built-in file type of libsm 1N/A** next (once safeopen() linkable from libsm). 1N/A/* bf io functions */ 1N/A** Data structure for storing information about each buffered file 1N/A#
else /* BF_STANDALONE */ 1N/A#
endif /* BF_STANDALONE */ 1N/A** SM_BFOPEN -- the "base" open function called by sm_io_open() for the 1N/A** internal, file-type-specific info setup. 1N/A** fp -- file pointer being filled-in for file being open'd 1N/A** info -- information about file being opened 1N/A** rpool -- ignored (currently) 1N/A** Failure: -1 and sets errno 1N/A /* Empty filename string */ 1N/A /* File already exists on disk */ 1N/A /* Allocate memory */ 1N/A /* Assign data buffer */ 1N/A /* A zero bsize is valid, just don't allocate memory */ 1N/A /* Nearly home free, just set all the parameters now */ 1N/A** BFOPEN -- create a new buffered file 1N/A** filename -- the file's name 1N/A** fmode -- what mode the file should be created as 1N/A** bsize -- amount of buffer space to allocate (may be 0) 1N/A** flags -- if running under sendmail, passed directly to safeopen 1N/A** a SM_FILE_T * which may then be used with stdio functions, 1N/A** or NULL on failure. SM_FILE_T * is opened for writing 1N/A** "SM_IO_WHAT_VECTORS"). 1N/A** any value of errno specified by sm_io_setinfo_type() 1N/A** any value of errno specified by sm_io_open() 1N/A** any value of errno specified by sm_io_setinfo() 1N/A** XXX This is a temporary hack since MODE_T on HP-UX 10.x is short. 1N/A** If we use K&R here, the compiler will complain about 1N/A** Inconsistent parameter list declaration 1N/A** due to the change from short to int. 1N/A#
endif /* __STDC__ */ 1N/A ** Apply current umask to fmode as it may change by the time 1N/A ** the file is actually created. fmode becomes the true 1N/A ** permissions of the file, which OPEN() must obey. 1N/A** SM_BFGETINFO -- returns info about an open file pointer 1N/A** fp -- file pointer to get info about 1N/A** what -- type of info to obtain 1N/A** valp -- thing to return the info in 1N/A** SM_BFCLOSE -- close a buffered file 1N/A** fp -- cookie of file to close 1N/A** 0 to indicate success 1N/A** deletes backing file, sm_frees memory. 1N/A /* Cast cookie back to correct type */ 1N/A /* Need to clean up the file */ 1N/A /* Need to sm_free the buffer */ 1N/A /* Finally, sm_free the structure */ 1N/A** SM_BFREAD -- read a buffered file 1N/A** cookie -- cookie of file to read 1N/A** buf -- buffer to fill 1N/A** nbytes -- how many bytes to read 1N/A** number of bytes read or -1 indicate failure 1N/A /* Cast cookie back to correct type */ 1N/A /* Need to grab some from buffer */ 1N/A /* Need to grab some from file */ 1N/A /* Oops, the file doesn't exist. EOF. */ 1N/A /* Catch a read() on an earlier failed write to disk */ 1N/A ** stdio won't be expecting these 1N/A ** errnos from read()! Change them 1N/A ** into something it can understand. 1N/A /* errno is set implicitly by read() */ 1N/A** SM_BFSEEK -- seek to a position in a buffered file 1N/A** fp -- fp of file to seek 1N/A** offset -- position to seek to 1N/A** whence -- how to seek 1N/A** new file offset or -1 indicate failure 1N/A /* Cast cookie back to correct type */ 1N/A** SM_BFWRITE -- write to a buffered file 1N/A** fp -- fp of file to write 1N/A** buf -- data buffer 1N/A** nbytes -- how many bytes to write 1N/A** number of bytes written or -1 indicate failure 1N/A** may create backing file if over memory limit for file. 1N/A /* Cast cookie back to correct type */ 1N/A /* If committed, go straight to disk */ 1N/A ** stdio won't be expecting these 1N/A ** errnos from write()! Change them 1N/A ** into something it can understand. 1N/A /* errno is set implicitly by write() */ 1N/A /* Need to put some in buffer */ 1N/A /* Need to put some in file */ 1N/A /* Clear umask as bf_filemode are the true perms */ 1N/A /* Couldn't create file: failure */ 1N/A ** stdio may not be expecting these 1N/A ** errnos from write()! Change to 1N/A ** something which it can understand. 1N/A ** Note that ENOSPC and EDQUOT are saved 1N/A ** because they are actually valid for 1N/A /* Catch a write() on an earlier failed write to disk */ 1N/A ** stdio won't be expecting these 1N/A ** errnos from write()! Change them into 1N/A ** something which it can understand. 1N/A /* errno is set implicitly by write() */ 1N/A** BFREWIND -- rewinds the SM_FILE_T * 1N/A** fp -- SM_FILE_T * to rewind 1N/A** 0 on success, -1 on error 1N/A** rewinds the SM_FILE_T * and puts it into read mode. Normally 1N/A** one would bfopen() a file, write to it, then bfrewind() and 1N/A** fread(). If fp is not a buffered file, this is equivalent to 1N/A** any value of errno specified by sm_io_rewind() 1N/A** SM_BFCOMMIT -- "commits" the buffered file 1N/A** fp -- SM_FILE_T * to commit to disk 1N/A** 0 on success, -1 on error 1N/A** Forces the given SM_FILE_T * to be written to disk if it is not 1N/A** already, and ensures that it will be kept after closing. If 1N/A** fp is not a buffered file, this is a no-op. 1N/A** any value of errno specified by open() 1N/A** any value of errno specified by write() 1N/A** any value of errno specified by lseek() 1N/A /* Get associated bf structure */ 1N/A /* If already committed, noop */ 1N/A /* Do we need to open a file? */ 1N/A /* Clear umask as bf_filemode are the true perms */ 1N/A /* Couldn't create file: failure */ 1N/A /* errno is set implicitly by open() */ 1N/A /* Write out the contents of our buffer, if we have any */ 1N/A /* errno is set implicitly by lseek() */ 1N/A /* errno is set implicitly by write() */ 1N/A /* Invalidate buf; all goes to file now */ 1N/A /* Don't need buffer anymore; free it */ 1N/A** SM_BFTRUNCATE -- rewinds and truncates the SM_FILE_T * 1N/A** fp -- SM_FILE_T * to truncate 1N/A** 0 on success, -1 on error 1N/A** rewinds the SM_FILE_T *, truncates it to zero length, and puts 1N/A** it into write mode. 1N/A** any value of errno specified by fseek() 1N/A** any value of errno specified by ftruncate() 1N/A /* Get bf structure */ 1N/A /* Need to zero the buffer */ 1N/A /* XXX: Not much we can do except rewind it */ 1N/A#
else /* NOFTRUNCATE */ 1N/A#
endif /* NOFTRUNCATE */ 1N/A** fp -- file pointer to get info about 1N/A /* Get bf structure */ 1N/A /* A zero bsize is valid, just don't allocate memory */ 1N/A return 1;
/* always */