swapop.c revision 7c2fbfb345896881c631598ee3852ce9ce33fb07
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/***********************************************************************
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* This software is part of the ast package *
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin* Copyright (c) 1985-2008 AT&T Intellectual Property *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* and is licensed under the *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Common Public License, Version 1.0 *
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin* by AT&T Intellectual Property *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* A copy of the License is available at *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Information and Software Systems Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* AT&T Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Florham Park NJ *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Glenn Fowler <gsf@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* David Korn <dgk@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Phong Vo <kpv@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin***********************************************************************/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Glenn Fowler
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * AT&T Research
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * internal representation conversion support
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * return the swap operation for external to internal conversion
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * if size<0 then (-size) used and (-size==4)&&(op==3) => op=7
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * this is a workaround for 4 byte magic predicting 8 byte swap
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinswapop(const void* internal, const void* external, int size)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int op;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int z;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((z = size) < 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (z <= 1)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (z <= sizeof(intmax_t))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!memcmp(internal, swapmem(op, external, tmp, z), z))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return -1;