17#include <stdlib.h> 18#include <unistd.h> 19#include <sys/param.h> 20#include <errno.h> 21#include <string.h> 22#include <syslog.h> 23#include <sm/io.h> 24#include <sm/assert.h> 25#include <sm/heap.h> 26#include <sm/string.h> 27#include <sm/conf.h> 28#include "local.h" 29#include "glue.h" 30 31bool Sm_IO_DidInit; /* IO system has been initialized? */ 32 33const char SmFileMagic[] = "sm_file"; 34 35/* An open type to map to fopen()-like behavior */ 36SM_FILE_T SmFtStdio_def = 37 {SmFileMagic, 0, 0, 0, (SMRW|SMFBF), -1, {0, 0}, 0, 0, 0, 38 sm_stdclose, sm_stdread, sm_stdseek, sm_stdwrite, 39 sm_stdopen, sm_stdsetinfo, sm_stdgetinfo, SM_TIME_FOREVER, 40 SM_TIME_BLOCK, "stdio" }; 41 42/* An open type to map to fdopen()-like behavior */ 43SM_FILE_T SmFtStdiofd_def = 44 {SmFileMagic, 0, 0, 0, (SMRW|SMFBF), -1, {0, 0}, 0, 0, 0, 45 sm_stdclose, sm_stdread, sm_stdseek, sm_stdwrite, 46 sm_stdfdopen, sm_stdsetinfo, sm_stdgetinfo, SM_TIME_FOREVER, 47 SM_TIME_BLOCK, "stdiofd" }; 48 49/* A string file type */
| 17#include <stdlib.h> 18#include <unistd.h> 19#include <sys/param.h> 20#include <errno.h> 21#include <string.h> 22#include <syslog.h> 23#include <sm/io.h> 24#include <sm/assert.h> 25#include <sm/heap.h> 26#include <sm/string.h> 27#include <sm/conf.h> 28#include "local.h" 29#include "glue.h" 30 31bool Sm_IO_DidInit; /* IO system has been initialized? */ 32 33const char SmFileMagic[] = "sm_file"; 34 35/* An open type to map to fopen()-like behavior */ 36SM_FILE_T SmFtStdio_def = 37 {SmFileMagic, 0, 0, 0, (SMRW|SMFBF), -1, {0, 0}, 0, 0, 0, 38 sm_stdclose, sm_stdread, sm_stdseek, sm_stdwrite, 39 sm_stdopen, sm_stdsetinfo, sm_stdgetinfo, SM_TIME_FOREVER, 40 SM_TIME_BLOCK, "stdio" }; 41 42/* An open type to map to fdopen()-like behavior */ 43SM_FILE_T SmFtStdiofd_def = 44 {SmFileMagic, 0, 0, 0, (SMRW|SMFBF), -1, {0, 0}, 0, 0, 0, 45 sm_stdclose, sm_stdread, sm_stdseek, sm_stdwrite, 46 sm_stdfdopen, sm_stdsetinfo, sm_stdgetinfo, SM_TIME_FOREVER, 47 SM_TIME_BLOCK, "stdiofd" }; 48 49/* A string file type */
|
51 {SmFileMagic, 0, 0, 0, (SMRW|SMNBF), -1, {0, 0}, 0, 0, 0, 52 sm_strclose, sm_strread, sm_strseek, sm_strwrite, 53 sm_stropen, sm_strsetinfo, sm_strgetinfo, SM_TIME_FOREVER, 54 SM_TIME_BLOCK, "string" }; 55 56#if 0 57/* A file type for syslog communications */ 58SM_FILE_T SmFtSyslog_def = 59 {SmFileMagic, 0, 0, 0, (SMRW|SMNBF), -1, {0, 0}, 0, 0, 0, 60 sm_syslogclose, sm_syslogread, sm_syslogseek, sm_syslogwrite, 61 sm_syslogopen, sm_syslogsetinfo, sm_sysloggetinfo, SM_TIME_FOREVER, 62 SM_TIME_BLOCK, "syslog" }; 63#endif /* 0 */ 64 65#define NDYNAMIC 10 /* add ten more whenever necessary */ 66 67#define smio(flags, file, name) \ 68 {SmFileMagic, 0, 0, 0, flags, file, {0}, 0, SmIoF+file, 0, \ 69 sm_stdclose, sm_stdread, sm_stdseek, sm_stdwrite, \ 70 sm_stdopen, sm_stdsetinfo, sm_stdgetinfo, SM_TIME_FOREVER, \ 71 SM_TIME_BLOCK, name} 72 73/* sm_magic p r w flags file bf lbfsize cookie ival */ 74#define smstd(flags, file, name) \ 75 {SmFileMagic, 0, 0, 0, flags, -1, {0}, 0, 0, file, \ 76 sm_stdioclose, sm_stdioread, sm_stdioseek, sm_stdiowrite, \ 77 sm_stdioopen, sm_stdiosetinfo, sm_stdiogetinfo, SM_TIME_FOREVER,\ 78 SM_TIME_BLOCK, name} 79 80/* A file type for interfacing to stdio FILE* streams. */ 81SM_FILE_T SmFtRealStdio_def = smstd(SMRW|SMNBF, -1, "realstdio"); 82 83 /* the usual - (stdin + stdout + stderr) */ 84static SM_FILE_T usual[SM_IO_OPEN_MAX - 3]; 85static struct sm_glue smuglue = { 0, SM_IO_OPEN_MAX - 3, usual }; 86 87/* List of builtin automagically already open file pointers */ 88SM_FILE_T SmIoF[6] = 89{ 90 smio(SMRD|SMLBF, SMIOIN_FILENO, "smioin"), /* smioin */ 91 smio(SMWR|SMLBF, SMIOOUT_FILENO, "smioout"), /* smioout */ 92 smio(SMWR|SMNBF, SMIOERR_FILENO, "smioerr"), /* smioerr */ 93 smstd(SMRD|SMNBF, SMIOIN_FILENO, "smiostdin"), /* smiostdin */ 94 smstd(SMWR|SMNBF, SMIOOUT_FILENO, "smiostdout"),/* smiostdout */ 95 smstd(SMWR|SMNBF, SMIOERR_FILENO, "smiostderr") /* smiostderr */ 96}; 97 98/* Structure containing list of currently open file pointers */ 99struct sm_glue smglue = { &smuglue, 3, SmIoF }; 100 101/* 102** SM_MOREGLUE -- adds more space for open file pointers 103** 104** Parameters: 105** n -- number of new spaces for file pointers 106** 107** Returns: 108** Raises an exception if no more memory. 109** Otherwise, returns a pointer to new spaces. 110*/ 111 112static struct sm_glue *sm_moreglue_x __P((int)); 113static SM_FILE_T empty; 114 115static struct sm_glue * 116sm_moreglue_x(n) 117 register int n; 118{ 119 register struct sm_glue *g; 120 register SM_FILE_T *p; 121
| 51 {SmFileMagic, 0, 0, 0, (SMRW|SMNBF), -1, {0, 0}, 0, 0, 0, 52 sm_strclose, sm_strread, sm_strseek, sm_strwrite, 53 sm_stropen, sm_strsetinfo, sm_strgetinfo, SM_TIME_FOREVER, 54 SM_TIME_BLOCK, "string" }; 55 56#if 0 57/* A file type for syslog communications */ 58SM_FILE_T SmFtSyslog_def = 59 {SmFileMagic, 0, 0, 0, (SMRW|SMNBF), -1, {0, 0}, 0, 0, 0, 60 sm_syslogclose, sm_syslogread, sm_syslogseek, sm_syslogwrite, 61 sm_syslogopen, sm_syslogsetinfo, sm_sysloggetinfo, SM_TIME_FOREVER, 62 SM_TIME_BLOCK, "syslog" }; 63#endif /* 0 */ 64 65#define NDYNAMIC 10 /* add ten more whenever necessary */ 66 67#define smio(flags, file, name) \ 68 {SmFileMagic, 0, 0, 0, flags, file, {0}, 0, SmIoF+file, 0, \ 69 sm_stdclose, sm_stdread, sm_stdseek, sm_stdwrite, \ 70 sm_stdopen, sm_stdsetinfo, sm_stdgetinfo, SM_TIME_FOREVER, \ 71 SM_TIME_BLOCK, name} 72 73/* sm_magic p r w flags file bf lbfsize cookie ival */ 74#define smstd(flags, file, name) \ 75 {SmFileMagic, 0, 0, 0, flags, -1, {0}, 0, 0, file, \ 76 sm_stdioclose, sm_stdioread, sm_stdioseek, sm_stdiowrite, \ 77 sm_stdioopen, sm_stdiosetinfo, sm_stdiogetinfo, SM_TIME_FOREVER,\ 78 SM_TIME_BLOCK, name} 79 80/* A file type for interfacing to stdio FILE* streams. */ 81SM_FILE_T SmFtRealStdio_def = smstd(SMRW|SMNBF, -1, "realstdio"); 82 83 /* the usual - (stdin + stdout + stderr) */ 84static SM_FILE_T usual[SM_IO_OPEN_MAX - 3]; 85static struct sm_glue smuglue = { 0, SM_IO_OPEN_MAX - 3, usual }; 86 87/* List of builtin automagically already open file pointers */ 88SM_FILE_T SmIoF[6] = 89{ 90 smio(SMRD|SMLBF, SMIOIN_FILENO, "smioin"), /* smioin */ 91 smio(SMWR|SMLBF, SMIOOUT_FILENO, "smioout"), /* smioout */ 92 smio(SMWR|SMNBF, SMIOERR_FILENO, "smioerr"), /* smioerr */ 93 smstd(SMRD|SMNBF, SMIOIN_FILENO, "smiostdin"), /* smiostdin */ 94 smstd(SMWR|SMNBF, SMIOOUT_FILENO, "smiostdout"),/* smiostdout */ 95 smstd(SMWR|SMNBF, SMIOERR_FILENO, "smiostderr") /* smiostderr */ 96}; 97 98/* Structure containing list of currently open file pointers */ 99struct sm_glue smglue = { &smuglue, 3, SmIoF }; 100 101/* 102** SM_MOREGLUE -- adds more space for open file pointers 103** 104** Parameters: 105** n -- number of new spaces for file pointers 106** 107** Returns: 108** Raises an exception if no more memory. 109** Otherwise, returns a pointer to new spaces. 110*/ 111 112static struct sm_glue *sm_moreglue_x __P((int)); 113static SM_FILE_T empty; 114 115static struct sm_glue * 116sm_moreglue_x(n) 117 register int n; 118{ 119 register struct sm_glue *g; 120 register SM_FILE_T *p; 121
|