dtsrswab.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. /*
  24. * COMPONENT_NAME: austext
  25. *
  26. * FUNCTIONS: swab_dbrec
  27. * swab_objrec
  28. *
  29. * ORIGINS: 27
  30. *
  31. * (C) COPYRIGHT International Business Machines Corp. 1996
  32. * All Rights Reserved
  33. * Licensed Materials - Property of IBM
  34. * US Government Users Restricted Rights - Use, duplication or
  35. * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  36. */
  37. /********************* DTSRSWAB.C **********************************
  38. * $XConsortium: dtsrswab.c /main/2 1996/10/28 13:58:11 drk $
  39. * July 1996.
  40. * These functions byte swap and other manipulations on
  41. * DtSearch or_... structures to ensure that database records
  42. * are maintained in a canonical format no matter what machine
  43. * they are used on.
  44. * The functions use the standard htonl, htons, ntohl, and ntohs
  45. * network conversion functions for byte order neutrality.
  46. * They use the DtSrINT16 and DtSrINT32 typedefs in Search.h
  47. * to control integer size.
  48. * The external database records are in the canonical,
  49. * big-endian "network" order.
  50. * So that they can be defined as "null" macros on big endian machines,
  51. * the functions (1) always byte swap in place and (2) always succeed.
  52. *
  53. * $Log$
  54. */
  55. #include <cde_config.h>
  56. #include <Dt/SearchP.h>
  57. /********************************/
  58. /* */
  59. /* swab_objrec */
  60. /* */
  61. /********************************/
  62. void swab_objrec (struct or_objrec *rec, SWABDIR direction)
  63. {
  64. #if defined(WORDS_BIGENDIAN)
  65. return;
  66. #else
  67. if (direction == NTOH) {
  68. NTOHL (rec->or_objflags);
  69. NTOHL (rec->or_objuflags);
  70. NTOHL (rec->or_objsize);
  71. NTOHL (rec->or_objdate);
  72. NTOHL (rec->or_objsecmask);
  73. NTOHS (rec->or_objaccess);
  74. NTOHS (rec->or_objtype);
  75. NTOHS (rec->or_objcost);
  76. NTOHS (rec->or_objhdroffset);
  77. NTOHS (rec->or_objeureka);
  78. }
  79. else { /* going the other direction */
  80. HTONL (rec->or_objflags);
  81. HTONL (rec->or_objuflags);
  82. HTONL (rec->or_objsize);
  83. HTONL (rec->or_objdate);
  84. HTONL (rec->or_objsecmask);
  85. HTONS (rec->or_objaccess);
  86. HTONS (rec->or_objtype);
  87. HTONS (rec->or_objcost);
  88. HTONS (rec->or_objhdroffset);
  89. HTONS (rec->or_objeureka);
  90. }
  91. return;
  92. #endif /* WORDS_BIGENDIAN */
  93. } /* swab_objrec() */
  94. /********************************/
  95. /* */
  96. /* swab_dbrec */
  97. /* */
  98. /********************************/
  99. void swab_dbrec (struct or_dbrec *rec, SWABDIR direction)
  100. {
  101. #if defined(WORDS_BIGENDIAN)
  102. return;
  103. #else
  104. if (direction == NTOH) {
  105. NTOHL (rec->or_dbflags);
  106. NTOHL (rec->or_dbuflags);
  107. NTOHL (rec->or_reccount);
  108. NTOHL (rec->or_maxdba);
  109. NTOHL (rec->or_availd99);
  110. NTOHL (rec->or_unavaild99);
  111. NTOHL (rec->or_hufid);
  112. NTOHL (rec->or_dbsecmask);
  113. NTOHS (rec->or_dbotype);
  114. NTOHS (rec->or_compflags);
  115. NTOHS (rec->or_dbaccess);
  116. NTOHS (rec->or_minwordsz);
  117. NTOHS (rec->or_maxwordsz);
  118. NTOHS (rec->or_recslots);
  119. NTOHS (rec->or_fzkeysz);
  120. NTOHS (rec->or_abstrsz);
  121. NTOHS (rec->or_language);
  122. }
  123. else { /* going the other direction */
  124. HTONL (rec->or_dbflags);
  125. HTONL (rec->or_dbuflags);
  126. HTONL (rec->or_reccount);
  127. HTONL (rec->or_maxdba);
  128. HTONL (rec->or_availd99);
  129. HTONL (rec->or_unavaild99);
  130. HTONL (rec->or_hufid);
  131. HTONL (rec->or_dbsecmask);
  132. HTONS (rec->or_dbotype);
  133. HTONS (rec->or_compflags);
  134. HTONS (rec->or_dbaccess);
  135. HTONS (rec->or_minwordsz);
  136. HTONS (rec->or_maxwordsz);
  137. HTONS (rec->or_recslots);
  138. HTONS (rec->or_fzkeysz);
  139. HTONS (rec->or_abstrsz);
  140. HTONS (rec->or_language);
  141. }
  142. return;
  143. #endif /* WORDS_BIGENDIAN */
  144. } /* swab_dbrec() */
  145. /********************* DTSRSWAB.C **********************************/