isfd.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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: isfd.c /main/3 1995/10/23 11:39:10 rswiston $ */
  28. /*
  29. * Copyright (c) 1988 by Sun Microsystems, Inc.
  30. */
  31. /*
  32. * isfd.c
  33. *
  34. * Description:
  35. * The ISAM file descriptors (isfd) are used as index to a table of
  36. * pointers to File Access Block objects. Isfd.c maintains the table
  37. * of the pointers (isfdtab).
  38. *
  39. */
  40. #include "isam_impl.h"
  41. static Fab *isfdtab[MAXISFD]; /* Table of pointers */
  42. /*
  43. * _isfd_insert(fab)
  44. *
  45. * Insert a pointer to an Fab object to table of ISAM file descriptors.
  46. * Return an ISAM file descriptor, or NOISFD if the table is full.
  47. */
  48. Isfd
  49. _isfd_insert(Fab *fab)
  50. {
  51. Isfd i;
  52. for (i = 0; i < MAXISFD; i++) {
  53. if (isfdtab[i] == NULL) /* Empty entry found */
  54. break;
  55. }
  56. if (i == MAXISFD)
  57. return (NOISFD); /* isfdtab is full */
  58. isfdtab[i] = fab;
  59. return (i);
  60. }
  61. /*
  62. * _isfd_find(isfd)
  63. *
  64. * Return a pointer to Fab object associated with the ISAM file
  65. * descriptor isfd. If isfd is not a file descriptor of an open ISAM file,
  66. * return NULL.
  67. */
  68. Fab *
  69. _isfd_find(Isfd isfd)
  70. {
  71. if (isfd < 0 || isfd >= MAXISFD || isfdtab[isfd] == NULL)
  72. return (NULL);
  73. else
  74. return (isfdtab[isfd]);
  75. }
  76. /*
  77. * _isfd_delete(isfd)
  78. *
  79. * Delete an entry from isfdtab. No check is made the entry exists.
  80. */
  81. void
  82. _isfd_delete(Isfd isfd)
  83. {
  84. if (isfd >= 0 && isfd < MAXISFD)
  85. isfdtab[isfd] = NULL;
  86. }