⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memalign.c

📁 它通过提供glibc兼容使得应用程序移植到较小的c 库时相当得容易. 它能够应用到带虚拟存储的Linux和uClinux上.在大多数带MMU部件的平台上为使它更加紧凑,它也能够编译成共享库.uClib
💻 C
字号:
/* malloc.c - C standard library routine.   Copyright (c) 1989, 1993  Michael J. Haertel   You may redistribute this library under the terms of the   GNU Library General Public License (version 2 or any later   version) as published by the Free Software Foundation.   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED   WARRANTY.  IN PARTICULAR, THE AUTHOR MAKES NO REPRESENTATION OR   WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS   SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. */#define _GNU_SOURCE#include <features.h>#include <limits.h>#include <stddef.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include "malloc.h"#ifdef __UCLIBC_HAS_THREADS__#include <pthread.h>extern pthread_mutex_t __malloclock;# define LOCK	pthread_mutex_lock(&__malloclock)# define UNLOCK	pthread_mutex_unlock(&__malloclock);#else# define LOCK# define UNLOCK#endif__ptr_t memalign (size_t alignment, size_t size){    __ptr_t result;    unsigned long int adj;    result = malloc (size + alignment - 1);    if (result == NULL)	return NULL;    adj = (unsigned long int) ((unsigned long int) ((char *) result -		(char *) NULL)) % alignment;    if (adj != 0)    {	struct alignlist *l;	LOCK;	for (l = _aligned_blocks; l != NULL; l = l->next)	    if (l->aligned == NULL)		/* This slot is free.  Use it.  */		break;	if (l == NULL)	{	    l = (struct alignlist *) malloc (sizeof (struct alignlist));	    if (l == NULL) {		__free_unlocked (result);		UNLOCK;		return NULL;	    }	    l->next = _aligned_blocks;	    _aligned_blocks = l;	}	l->exact = result;	result = l->aligned = (char *) result + alignment - adj;	UNLOCK;    }    return result;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -