iscurpos.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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: iscurpos.c /main/3 1995/10/23 11:37:08 rswiston $ */
  28. /*
  29. * Copyright (c) 1988 by Sun Microsystems, Inc.
  30. */
  31. /*
  32. * @(#)iscurpos.c 1.2 95/01/06
  33. *
  34. * Description:
  35. * Save and restore current record position functions.
  36. */
  37. #include "isam_impl.h"
  38. #include <sys/file.h>
  39. /*
  40. * err = isgetcurpos(isfd, len, buf)
  41. *
  42. * Get current record position and save it in user buffer.
  43. *
  44. * The user buffer buf is filled with (if the information is N bytes):
  45. * buf[0], buf[1] total length as u_short (set to N + 2)
  46. * buf[2] .. buf[N + 1] current record position information
  47. */
  48. int
  49. isgetcurpos(int isfd, int *len, char **buf)
  50. {
  51. Fab *fab;
  52. u_short total_len;
  53. /*
  54. * Get File Access Block.
  55. */
  56. if ((fab = _isfd_find(isfd)) == NULL) {
  57. _setiserrno2(ENOTOPEN, '9', '0');
  58. return (ISERROR);
  59. }
  60. total_len = sizeof(total_len) + fab->curpos.length;
  61. if (*buf != NULL && *len < (int)total_len) {
  62. _setiserrno2(E2BIG, '9', '0');
  63. return (ISERROR);
  64. }
  65. if (*buf == NULL) {
  66. *len = total_len;
  67. *buf = _ismalloc((unsigned int)total_len);
  68. }
  69. memcpy(*buf, (char *) &total_len, sizeof(total_len));
  70. memcpy(*buf+sizeof(total_len), fab->curpos.data, (int)fab->curpos.length);
  71. return (ISOK);
  72. }
  73. /*
  74. * err = issetcurpos(isfd, buf)
  75. *
  76. * Get current record position and save it in user buffer.
  77. */
  78. int
  79. issetcurpos(int isfd, char *buf)
  80. {
  81. Fab *fab;
  82. u_short len;
  83. /*
  84. * Get File Access Block.
  85. */
  86. if ((fab = _isfd_find(isfd)) == NULL) {
  87. _setiserrno2(ENOTOPEN, '9', '0');
  88. return (ISERROR);
  89. }
  90. memcpy((char *)&len, buf, sizeof(len));
  91. len -= sizeof (len);
  92. _bytearr_free(&fab->curpos);
  93. fab->curpos = _bytearr_new(len, buf + sizeof(len));
  94. return (ISOK);
  95. }