Lines Matching +full:s +full:- +full:mode

2  * Copyright (c) 2000-2002, 2004, 2005 Proofpoint, Inc. and its suppliers.
16 SM_IDSTR(id, "@(#)$Id: strio.c,v 1.45 2013-11-22 20:51:43 ca Exp $")
48 ** SM_STRGROW -- increase storage space for string
51 ** s -- current cookie
52 ** size -- new storage size request
61 sm_strgrow(s, size) in sm_strgrow() argument
62 SM_STR_OBJ_T *s; in sm_strgrow()
67 if (s->strio_size >= size)
69 p = sm_realloc(s->strio_base, size);
72 s->strio_base = p;
73 s->strio_end = s->strio_base + size;
74 s->strio_size = size;
79 ** SM_STRREAD -- read a portion of the string
82 ** fp -- the file pointer
83 ** buf -- location to place read data
84 ** n -- number of bytes to read
87 ** Failure: -1 and sets errno
97 register SM_STR_OBJ_T *s = fp->f_cookie; local
100 if (!(s->strio_flags & SMRD) && !(s->strio_flags & SMRW))
103 return -1;
105 len = SM_MIN(s->strio_size - s->strio_offset, n);
106 (void) memmove(buf, s->strio_base + s->strio_offset, len);
107 s->strio_offset += len;
112 ** SM_STRWRITE -- write a portion of the string
115 ** fp -- the file pointer
116 ** buf -- location of data for writing
117 ** n -- number of bytes to write
120 ** Failure: -1 and sets errno
130 register SM_STR_OBJ_T *s = fp->f_cookie; local
132 if (!(s->strio_flags & SMWR) && !(s->strio_flags & SMRW))
135 return -1;
137 if (n + s->strio_offset > s->strio_size)
139 if (!sm_strgrow(s, n + s->strio_offset))
142 (void) memmove(s->strio_base + s->strio_offset, buf, n);
143 s->strio_offset += n;
148 ** SM_STRSEEK -- position the offset pointer for the string
154 ** fp -- the file pointer
155 ** offset -- number of bytes offset from "base"
156 ** whence -- determines "base" for 'offset'
159 ** Failure: -1 and sets errno
170 register SM_STR_OBJ_T *s = fp->f_cookie; local
179 ret = s->strio_offset + offset;
182 ret = s->strio_size;
186 return -1;
188 if (ret < 0 || ret > (off_t)(size_t)(-1)) /* XXX ugly */
189 return -1;
190 if ((size_t) ret > s->strio_size)
192 if (sm_strgrow(s, (size_t)ret))
196 return -1;
198 s->strio_offset = (size_t) ret;
203 ** SM_STROPEN -- open a string file type
206 ** fp -- file pointer open to be associated with
207 ** info -- initial contents (NULL for none)
208 ** flags -- flags for methods of access (was mode)
209 ** rpool -- resource pool to use memory from (if applicable)
213 ** Failure: -1 and sets errno
223 register SM_STR_OBJ_T *s; local
226 s = sm_rpool_malloc_x(rpool, sizeof(SM_STR_OBJ_T));
228 s = sm_malloc(sizeof(SM_STR_OBJ_T));
229 if (s == NULL)
230 return -1;
233 fp->f_cookie = s;
234 s->strio_rpool = rpool;
235 s->strio_offset = 0;
236 s->strio_size = 0;
237 s->strio_base = NULL;
238 s->strio_end = NULL;
243 s->strio_flags = SMRW;
246 s->strio_flags = SMRD;
249 s->strio_flags = SMWR;
252 if (s->strio_rpool == NULL)
253 sm_free(s);
255 return -1;
257 if (s->strio_rpool == NULL)
258 sm_free(s);
260 return -1;
265 s->strio_base = sm_strdup_x(info);
266 if (s->strio_base == NULL)
270 if (s->strio_rpool == NULL)
271 sm_free(s);
273 return -1;
275 s->strio_size = strlen(info);
276 s->strio_end = s->strio_base + s->strio_size;
282 ** SM_STRCLOSE -- close the string file type and free resources
285 ** fp -- file pointer
295 SM_STR_OBJ_T *s = fp->f_cookie; local
298 sm_free(s->strio_base);
299 s->strio_base = NULL;
305 ** SM_STRSETMODE -- set mode info for the file
307 ** Note: changing the mode can be a safe way to have the "parent"
311 ** fp -- the file pointer
312 ** mode -- location of new mode to set
316 ** Failure: -1 and sets errno
320 sm_strsetmode(fp, mode) in sm_strsetmode() argument
322 const int *mode;
324 register SM_STR_OBJ_T *s = fp->f_cookie; local
327 switch (*mode)
340 return -1;
343 return -1;
345 s->strio_flags &= ~SMMODEMASK;
346 s->strio_flags |= flags;
351 ** SM_STRGETMODE -- get mode info for the file
354 ** fp -- the file pointer
355 ** mode -- location to store current mode
359 ** Failure: -1 and sets errno
363 sm_strgetmode(fp, mode) in sm_strgetmode() argument
365 int *mode;
367 register SM_STR_OBJ_T *s = fp->f_cookie; local
369 switch (s->strio_flags & SMMODEMASK)
372 *mode = SM_IO_RDWR;
375 *mode = SM_IO_RDONLY;
378 *mode = SM_IO_WRONLY;
382 return -1;
388 ** SM_STRSETINFO -- set info for the file
393 ** fp -- the file pointer
394 ** what -- type of information to set
395 ** valp -- location to data for doing set
398 ** Failure: -1 and sets errno
414 return -1;
419 ** SM_STRGETINFO -- get info for the file
424 ** fp -- the file pointer
425 ** what -- type of information requested
426 ** valp -- location to return information in
429 ** Failure: -1 and sets errno
445 return -1;
450 ** SM_STRIO_INIT -- initializes a write-only string type
453 ** The same functionality can be done by changing the mode of the file.
454 ** ------------
455 ** sm_strio_init initializes an SM_FILE_T structure as a write-only file
457 ** - Use sm_io_putc, sm_io_fprintf, etc, to write into the buffer.
458 ** Attempts to write more than size-1 characters into the buffer will fail
460 ** - Use sm_io_fflush to nul terminate the string in the buffer
465 ** fp -- file pointer
466 ** buf -- memory location for stored data
467 ** size -- size of 'buf'
479 fp->sm_magic = SmFileMagic;
480 fp->f_flags = SMWR | SMSTR;
481 fp->f_file = -1;
482 fp->f_bf.smb_base = fp->f_p = (unsigned char *) buf;
483 fp->f_bf.smb_size = fp->f_w = (size ? size - 1 : 0);
484 fp->f_lbfsize = 0;
485 fp->f_r = 0;
486 fp->f_read = NULL;
487 fp->f_seek = NULL;
488 fp->f_getinfo = NULL;
489 fp->f_setinfo = NULL;