isaddprimary.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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: isaddprimary.c /main/3 1995/10/23 11:33:35 rswiston $ */
  28. /* @(#)isaddprimary.c 1.7 93/09/07
  29. * Copyright (c) 1988 by Sun Microsystems, Inc.
  30. */
  31. /*
  32. * isaddprimary.c
  33. *
  34. * Description:
  35. * Add secondary index to ISAM file
  36. */
  37. #include "isam_impl.h"
  38. #include <sys/time.h>
  39. Static int _am_addprimary();
  40. /*
  41. * err = isaddprimary(isfd, keydesc)
  42. *
  43. * Isaddprimary() is used to add primary index to ISAM file.
  44. *
  45. * This call is not part of the X/OPEN sprec.
  46. *
  47. * Errors:
  48. * EBADKEY error in keydesc
  49. * EDUPL there are duplicate keys and the keydesc does not allow
  50. * duplicate keys
  51. * EKEXISTS key with the same key descriptor already exists
  52. * EKEXISTS the ISAM file already has a primary index.
  53. * ENOTEXCL ISAM file is not open in exclusive mode
  54. * ENOTOPEN the ISAM file is not open in ISINOUT mode.
  55. * EACCES Cannot create index file because of UNIX error.
  56. */
  57. int
  58. isaddprimary(int isfd, struct keydesc *keydesc)
  59. {
  60. Fab *fab;
  61. int ret;
  62. /*
  63. * Get File Access Block.
  64. */
  65. if ((fab = _isfd_find(isfd)) == NULL) {
  66. _setiserrno2(ENOTOPEN, '9', '0');
  67. return (ISERROR);
  68. }
  69. /*
  70. * Check that the open mode was ISOUTPUT
  71. */
  72. if (fab->openmode != OM_INOUT) {
  73. _setiserrno2(ENOTOPEN, '9', '0');
  74. return (ISERROR);
  75. }
  76. ret = _am_addprimary(fab, keydesc);
  77. _seterr_errcode(&fab->errcode);
  78. return (ret); /* Successful write */
  79. }
  80. Static int _am_addprimary(Fab *fab, struct keydesc *keydesc)
  81. {
  82. return (_amaddprimary(&fab->isfhandle, keydesc, &fab->errcode));
  83. }