imapext-2007

diff src/ansilib/memmove2.c @ 0:ada5e610ab86

imap-2007e
author yuuji@gentei.org
date Mon, 14 Sep 2009 15:17:45 +0900
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/ansilib/memmove2.c	Mon Sep 14 15:17:45 2009 +0900
     1.3 @@ -0,0 +1,49 @@
     1.4 +/* ========================================================================
     1.5 + * Copyright 1988-2006 University of Washington
     1.6 + *
     1.7 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.8 + * you may not use this file except in compliance with the License.
     1.9 + * You may obtain a copy of the License at
    1.10 + *
    1.11 + *     http://www.apache.org/licenses/LICENSE-2.0
    1.12 + *
    1.13 + * 
    1.14 + * ========================================================================
    1.15 + */
    1.16 +
    1.17 +/*
    1.18 + * Program:	Memory move when no bcopy()
    1.19 + *
    1.20 + * Author:	Mark Crispin
    1.21 + *		Networks and Distributed Computing
    1.22 + *		Computing & Communications
    1.23 + *		University of Washington
    1.24 + *		Administration Building, AG-44
    1.25 + *		Seattle, WA  98195
    1.26 + *		Internet: MRC@CAC.Washington.EDU
    1.27 + *
    1.28 + * Date:	11 May 1989
    1.29 + * Last Edited:	30 August 2006
    1.30 + */
    1.31 +
    1.32 +/* Copy memory block
    1.33 + * Accepts: destination pointer
    1.34 + *	    source pointer
    1.35 + *	    length
    1.36 + * Returns: destination pointer
    1.37 + */
    1.38 +
    1.39 +void *memmove (void *s,void *ct,size_t n)
    1.40 +{
    1.41 +  char *dp,*sp;
    1.42 +  int i;
    1.43 +  unsigned long dest = (unsigned long) s;
    1.44 +  unsigned long src = (unsigned long) ct;
    1.45 +  if (((dest < src) && ((dest + n) < src)) ||
    1.46 +      ((dest > src) && ((src + n) < dest))) return (void *) memcpy (s,ct,n);
    1.47 +  dp = (char *) s;
    1.48 +  sp = (char *) ct;
    1.49 +  if (dest < src) for (i = 0; i < n; ++i) dp[i] = sp[i];
    1.50 +  else if (dest > src) for (i = n - 1; i >= 0; --i) dp[i] = sp[i];
    1.51 +  return s;
    1.52 +}

UW-IMAP'd extensions by yuuji