isfab.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
  24. /*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
  25. /*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
  26. /*%% (c) Copyright 1993, 1994 Novell, Inc. */
  27. /*%% $XConsortium: isfab.c /main/3 1995/10/23 11:38:24 rswiston $ */
  28. /*
  29. * Copyright (c) 1988 by Sun Microsystems, Inc.
  30. */
  31. /*
  32. * isfab.c
  33. *
  34. * Description:
  35. * The ISAM file access block functions.
  36. *
  37. */
  38. #include <stdlib.h>
  39. #include "isam_impl.h"
  40. /*
  41. * fab = *fab_new(isfname, mode, varlen, minreclen, maxreclen)
  42. *
  43. * Fab_new() creates an File access block (fab object) that is used
  44. * for all subsequent operations in this file. Return a pointer to
  45. * the fab object, or NULL in the case of an error.
  46. * isfname, Local path on the host
  47. * varlen, 0/1 flag
  48. */
  49. Fab *
  50. _fab_new(char *isfname, enum openmode openmode, Bool varlen, int minreclen, int maxreclen)
  51. {
  52. Fab *fab;
  53. /* Allocate memory for the fab object. */
  54. fab = (Fab *) _ismalloc(sizeof(*fab));
  55. memset((char *)fab, 0, sizeof(*fab));
  56. if (fab == NULL) {
  57. iserrno = EFATAL;
  58. return (NULL);
  59. }
  60. /* Set fields in the fab objects. */
  61. fab->openmode = openmode;
  62. fab->varlength = varlen;
  63. fab->minreclen = minreclen;
  64. fab->maxreclen = maxreclen;
  65. fab->isfname = _isallocstring(isfname);
  66. if (fab->isfname == NULL) {
  67. free((char *)fab);
  68. iserrno = EFATAL;
  69. return (NULL);
  70. }
  71. return (fab);
  72. }
  73. void
  74. _fab_destroy(Fab *fab)
  75. {
  76. assert(fab != NULL);
  77. assert(fab->isfname != NULL);
  78. _isfreestring(fab->isfname);
  79. _bytearr_free(&fab->isfhandle);
  80. _bytearr_free(&fab->curpos);
  81. free((char *)fab);
  82. }