home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / c / cbase.zoo / lseq101.zoo / lsputrf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-20  |  2.5 KB  |  104 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)lsputrf.c    1.4 - 90/06/20" */
  5.  
  6. /* ansi headers */
  7. #include <errno.h>
  8. /*#include <stddef.h>*/
  9. /*#include <string.h>*/
  10.  
  11. /* library headers */
  12. #include <blkio.h>
  13.  
  14. /* local headers */
  15. #include "lseq_.h"
  16.  
  17. /*man---------------------------------------------------------------------------
  18. NAME
  19.      lsputrf - put field to current lseq record
  20.  
  21. SYNOPSIS
  22.      #include <lseq.h>
  23.  
  24.      int lsputrf(lsp, offset, buf, bufsize)
  25.      lseq_t *lsp;
  26.      size_t offset;
  27.      const void *buf;
  28.      size_t bufsize;
  29.  
  30. DESCRIPTION
  31.      The lsputrf function writes the contents of buf into a field in
  32.      the current record in lseq lsp.  The field begins offset
  33.      characters from the beginning of the record and is bufsize
  34.      characters long.  buf must point to a storage area at least
  35.      bufsize characters long.
  36.  
  37.      lsputrf will fail if one or more of the following is true:
  38.  
  39.      [EINVAL]       lsp is not a valid lseq pointer.
  40.      [EINVAL]       buf is the NULL pointer.
  41.      [EINVAL]       bufsize is 0.
  42.      [LSEBOUND]     offset + bufsize extends beyond the end
  43.                     of the record.
  44.      [LSELOCK]      lsp is not write locked.
  45.      [LSENOPEN]     lsp is not open.
  46.      [LSENREC]      The cursor is null.
  47.  
  48. SEE ALSO
  49.      lscursor, lsgetrf, lsputr.
  50.  
  51. DIAGNOSTICS
  52.      Upon successful completion, a value of 0 is returned.  Otherwise,
  53.      a value of -1 is returned, and errno set to indicate the error.
  54.  
  55. ------------------------------------------------------------------------------*/
  56. int lsputrf(lsp, offset, buf, bufsize)
  57. lseq_t *lsp;
  58. size_t offset;
  59. const void *buf;
  60. size_t bufsize;
  61. {
  62.     /* validate arguments */
  63.     if (!ls_valid(lsp) || buf == NULL || bufsize < 1) {
  64.         errno = EINVAL;
  65.         return -1;
  66.     }
  67.  
  68.     /* check if not open */
  69.     if (!(lsp->flags & LSOPEN)) {
  70.         errno = EINVAL;
  71.         return -1;
  72.     }
  73.  
  74.     /* check if not write locked */
  75.     if (!(lsp->flags & LSWRLCK)) {
  76.         errno = LSELOCK;
  77.         return -1;
  78.     }
  79.  
  80.     /* check if over record boundary */
  81.     if (offset + bufsize > lsp->lshdr.recsize) {
  82.         errno = LSEBOUND;
  83.         return -1;
  84.     }
  85.  
  86.     /* check if cursor is null */
  87.     if (lsp->clspos == NIL) {
  88.         errno = LSENREC;
  89.         return -1;
  90.     }
  91.  
  92.     /* copy field to current record */
  93.     memcpy(((char *)lsp->clsrp->recbuf + offset), buf, bufsize);
  94.  
  95.     /* write field */
  96.     if (ls_rcputf(lsp, lsp->clspos, offset, buf, bufsize) == -1) {
  97.         LSEPRINT;
  98.         return -1;
  99.     }
  100.  
  101.     errno = 0;
  102.     return 0;
  103. }
  104.