home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / CBASE101.ZIP / LSEQ101.ZIP / LSGETRF.C < prev    next >
Text File  |  1990-06-20  |  2KB  |  97 lines

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