genlib.c

来自「The art and science of c_source code!」· C语言 代码 · 共 64 行

C
64
字号
/* * File: genlib.c * Version: 1.0 * Last modified on Fri Jul 15 15:45:52 1994 by eroberts * ----------------------------------------------------- * This file implements the general C library package.  See the * interface description in genlib.h for details. */#include <stdio.h>#include <stddef.h>#include <string.h>#include <stdarg.h>#include "genlib.h"/* * Constants: * ---------- * ErrorExitStatus -- Status value used in exit call */#define ErrorExitStatus 1/* Section 1 -- Define new "primitive" types *//* * Constant: UNDEFINED * ------------------- * This entry defines the target of the UNDEFINED constant. */char undefined_object[] = "UNDEFINED";/* Section 2 -- Memory allocation */void *GetBlock(size_t nbytes){    void *result;    result = malloc(nbytes);    if (result == NULL) Error("No memory available");    return (result);}void FreeBlock(void *ptr){    free(ptr);}/* Section 3 -- Basic error handling */void Error(string msg, ...){    va_list args;    va_start(args, msg);    fprintf(stderr, "Error: ");    vfprintf(stderr, msg, args);    fprintf(stderr, "\n");    va_end(args);    exit(ErrorExitStatus);}

⌨️ 快捷键说明

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