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

📄 cmclib.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************** * * Module Name: cmclib - Local implementation of C library functions * $Revision: 28 $ * *****************************************************************************//* *  Copyright (C) 2000 R. Byron Moore * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include "acpi.h"#include "acevents.h"#include "achware.h"#include "acnamesp.h"#include "acinterp.h"#include "amlcode.h"/* * These implementations of standard C Library routines can optionally be * used if a C library is not available.  In general, they are less efficient * than an inline or assembly implementation */#define _COMPONENT          MISCELLANEOUS	 MODULE_NAME         ("cmclib")#ifndef ACPI_USE_SYSTEM_CLIBRARY/******************************************************************************* * * FUNCTION:    strlen * * PARAMETERS:  String              - Null terminated string * * RETURN:      Length * * DESCRIPTION: Returns the length of the input string * ******************************************************************************/NATIVE_UINTacpi_cm_strlen (	const NATIVE_CHAR       *string){	NATIVE_UINT             length = 0;	/* Count the string until a null is encountered */	while (*string) {		length++;		string++;	}	return (length);}/******************************************************************************* * * FUNCTION:    strcpy * * PARAMETERS:  Dst_string      - Target of the copy *              Src_string      - The source string to copy * * RETURN:      Dst_string * * DESCRIPTION: Copy a null terminated string * ******************************************************************************/NATIVE_CHAR *acpi_cm_strcpy (	NATIVE_CHAR             *dst_string,	const NATIVE_CHAR       *src_string){	NATIVE_CHAR             *string = dst_string;	/* Move bytes brute force */	while (*src_string) {		*string = *src_string;		string++;		src_string++;	}	/* Null terminate */	*string = 0;	return (dst_string);}/******************************************************************************* * * FUNCTION:    strncpy * * PARAMETERS:  Dst_string      - Target of the copy *              Src_string      - The source string to copy *              Count           - Maximum # of bytes to copy * * RETURN:      Dst_string * * DESCRIPTION: Copy a null terminated string, with a maximum length * ******************************************************************************/NATIVE_CHAR *acpi_cm_strncpy (	NATIVE_CHAR             *dst_string,	const NATIVE_CHAR       *src_string,	NATIVE_UINT             count){	NATIVE_CHAR             *string = dst_string;	/* Copy the string */	for (string = dst_string;		count && (count--, (*string++ = *src_string++)); )	{;}	/* Pad with nulls if necessary */	while (count--) {		*string = 0;		string++;	}	/* Return original pointer */	return (dst_string);}/******************************************************************************* * * FUNCTION:    strcmp * * PARAMETERS:  String1         - First string *              String2         - Second string * * RETURN:      Index where strings mismatched, or 0 if strings matched * * DESCRIPTION: Compare two null terminated strings * ******************************************************************************/u32acpi_cm_strcmp (	const NATIVE_CHAR       *string1,	const NATIVE_CHAR       *string2){	for ( ; (*string1 == *string2); string2++) {		if (!*string1++) {			return (0);		}	}	return ((unsigned char) *string1 - (unsigned char) *string2);}/******************************************************************************* * * FUNCTION:    strncmp * * PARAMETERS:  String1         - First string *              String2         - Second string *              Count           - Maximum # of bytes to compare * * RETURN:      Index where strings mismatched, or 0 if strings matched * * DESCRIPTION: Compare two null terminated strings, with a maximum length * ******************************************************************************/u32acpi_cm_strncmp (	const NATIVE_CHAR       *string1,	const NATIVE_CHAR       *string2,	NATIVE_UINT             count){	for ( ; count-- && (*string1 == *string2); string2++) {		if (!*string1++) {			return (0);		}	}	return ((count == -1) ? 0 : ((unsigned char) *string1 -		(unsigned char) *string2));}/******************************************************************************* * * FUNCTION:    Strcat * * PARAMETERS:  Dst_string      - Target of the copy *              Src_string      - The source string to copy * * RETURN:      Dst_string * * DESCRIPTION: Append a null terminated string to a null terminated string * ******************************************************************************/NATIVE_CHAR *acpi_cm_strcat (	NATIVE_CHAR             *dst_string,	const NATIVE_CHAR       *src_string){	NATIVE_CHAR             *string;	/* Find end of the destination string */	for (string = dst_string; *string++; ) { ; }	/* Concatinate the string */	for (--string; (*string++ = *src_string++); ) { ; }	return (dst_string);}/******************************************************************************* * * FUNCTION:    strncat * * PARAMETERS:  Dst_string      - Target of the copy *              Src_string      - The source string to copy *              Count           - Maximum # of bytes to copy * * RETURN:      Dst_string * * DESCRIPTION: Append a null terminated string to a null terminated string, *              with a maximum count. * ******************************************************************************/NATIVE_CHAR *acpi_cm_strncat (	NATIVE_CHAR             *dst_string,	const NATIVE_CHAR       *src_string,	NATIVE_UINT             count){	NATIVE_CHAR             *string;	if (count) {		/* Find end of the destination string */		for (string = dst_string; *string++; ) { ; }		/* Concatinate the string */		for (--string; (*string++ = *src_string++) && --count; ) { ; }		/* Null terminate if necessary */		if (!count) {			*string = 0;		}	}	return (dst_string);}/******************************************************************************* * * FUNCTION:    memcpy * * PARAMETERS:  Dest        - Target of the copy *              Src         - Source buffer to copy *              Count       - Number of bytes to copy * * RETURN:      Dest * * DESCRIPTION: Copy arbitrary bytes of memory * ******************************************************************************/void *acpi_cm_memcpy (	void                    *dest,	const void              *src,	NATIVE_UINT             count){	NATIVE_CHAR             *new = (NATIVE_CHAR *) dest;	NATIVE_CHAR             *old = (NATIVE_CHAR *) src;	while (count) {		*new = *old;		new++;		old++;		count--;	}	return (dest);}/******************************************************************************* * * FUNCTION:    memset * * PARAMETERS:  Dest        - Buffer to set *              Value       - Value to set each byte of memory *              Count       - Number of bytes to set * * RETURN:      Dest * * DESCRIPTION: Initialize a buffer to a known value. * ******************************************************************************/void *acpi_cm_memset (	void                    *dest,	u32                     value,	NATIVE_UINT             count){	NATIVE_CHAR             *new = (NATIVE_CHAR *) dest;	while (count) {		*new = (char) value;		new++;		count--;	}	return (dest);}#define NEGATIVE    1#define POSITIVE    0#define _ACPI_XA     0x00    /* extra alphabetic - not supported */#define _ACPI_XS     0x40    /* extra space */#define _ACPI_BB     0x00    /* BEL, BS, etc. - not supported */#define _ACPI_CN     0x20    /* CR, FF, HT, NL, VT */#define _ACPI_DI     0x04    /* '0'-'9' */#define _ACPI_LO     0x02    /* 'a'-'z' */#define _ACPI_PU     0x10    /* punctuation */#define _ACPI_SP     0x08    /* space */#define _ACPI_UP     0x01    /* 'A'-'Z' */#define _ACPI_XD     0x80    /* '0'-'9', 'A'-'F', 'a'-'f' */static const u8 _acpi_ctype[257] = {	_ACPI_CN,            /* 0x0      0.     */	_ACPI_CN,            /* 0x1      1.     */	_ACPI_CN,            /* 0x2      2.     */	_ACPI_CN,            /* 0x3      3.     */	_ACPI_CN,            /* 0x4      4.     */	_ACPI_CN,            /* 0x5      5.     */	_ACPI_CN,            /* 0x6      6.     */	_ACPI_CN,            /* 0x7      7.     */	_ACPI_CN,            /* 0x8      8.     */	_ACPI_CN|_ACPI_SP,   /* 0x9      9.     */	_ACPI_CN|_ACPI_SP,   /* 0xA     10.     */	_ACPI_CN|_ACPI_SP,   /* 0xB     11.     */	_ACPI_CN|_ACPI_SP,   /* 0xC     12.     */	_ACPI_CN|_ACPI_SP,   /* 0xD     13.     */	_ACPI_CN,            /* 0xE     14.     */	_ACPI_CN,            /* 0xF     15.     */	_ACPI_CN,            /* 0x10    16.     */	_ACPI_CN,            /* 0x11    17.     */	_ACPI_CN,            /* 0x12    18.     */	_ACPI_CN,            /* 0x13    19.     */	_ACPI_CN,            /* 0x14    20.     */	_ACPI_CN,            /* 0x15    21.     */	_ACPI_CN,            /* 0x16    22.     */	_ACPI_CN,            /* 0x17    23.     */	_ACPI_CN,            /* 0x18    24.     */	_ACPI_CN,            /* 0x19    25.     */	_ACPI_CN,            /* 0x1A    26.     */	_ACPI_CN,            /* 0x1B    27.     */

⌨️ 快捷键说明

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