home *** CD-ROM | disk | FTP | other *** search
/ PC Press 1997 July / Sezamfile97_1.iso / msdos / c / cbase11.a03 / CBASE11.ZIP / LSEQ / LSGETRF.C < prev    next >
C/C++ Source or Header  |  1993-01-01  |  3KB  |  108 lines

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