?? memory.c
字號(hào):
/* * This file is part of John the Ripper password cracker, * Copyright (c) 1996-98 by Solar Designer */#include <stdio.h>#include <stdlib.h>#include <string.h>#include "arch.h"#include "misc.h"#include "memory.h"unsigned int mem_saving_level = 0;void *mem_alloc(size_t size){ void *res; if (!(res = malloc(size))) pexit("malloc"); return res;}void mem_free(void **ptr){ if (*ptr) free(*ptr); *ptr = NULL;}void *mem_alloc_tiny(size_t size, size_t align){ static unsigned long buffer, bufree = 0; unsigned long start, end;#if ARCH_ALLOWS_UNALIGNED if (mem_saving_level > 2) align = MEM_ALIGN_NONE;#endif start = buffer + --align; start &= ~align; end = start + size; if (bufree >= end - buffer) { bufree -= end - buffer; buffer = end; } else if (size + align <= MEM_ALLOC_SIZE && bufree <= MEM_ALLOC_MAX) { buffer = (unsigned long)mem_alloc(MEM_ALLOC_SIZE); bufree = MEM_ALLOC_SIZE; return mem_alloc_tiny(size, align + 1); } else start = ((unsigned long) mem_alloc(size + align) + align) & ~align; return (void *)start;}void *mem_alloc_copy(size_t size, size_t align, void *src){ return memcpy(mem_alloc_tiny(size, align), src, size);}char *str_alloc_copy(char *src){ size_t size; if (!src || !*src) return ""; size = strlen(src) + 1; return (char *)memcpy(mem_alloc_tiny(size, MEM_ALIGN_NONE), src, size);}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -