home *** CD-ROM | disk | FTP | other *** search
/ Frostbyte's 1980s DOS Shareware Collection / floppyshareware.zip / floppyshareware / DOOG / CBASE09.ZIP / LSEQ.ZIP / LSPUTRF.C < prev    next >
Text File  |  1989-08-30  |  2KB  |  101 lines

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