lib.c
上传用户:julian
上传日期:2007-01-04
资源大小:22k
文件大小:5k
- /*
- File: tcpproxy/lib.c
- Version 1.0
-
- Copyright (C) 1999 by Wolfgang Zekoll <wzk@quietsche-entchen.de>
- This source 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, or (at your option)
- any later version.
- This source 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., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include <unistd.h>
- #include <time.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include "lib.h"
- #define DEBUG(x)
- void *allocate(size_t size)
- {
- void *p;
- if ((p = malloc(size)) == NULL) {
- fprintf (stderr, "%s: memory allocation errorn", program);
- exit (-1);
- }
- memset(p, 0, size);
- return (p);
- }
- void *reallocate(void *p, size_t size)
- {
- if ((p = realloc(p, size)) == NULL) {
- fprintf (stderr, "%s: memory allocation errorn", program);
- exit (-1);
- }
- return (p);
- }
- static unsigned int lower[256], upper[256];
- static int _init_upper()
- {
- unsigned int c;
-
- DEBUG( fprintf (stderr, "init upper[]n"); )
- for (c = 0; c < 256; c++)
- upper[c] = c;
- DEBUG( fprintf (stderr, "init uppercase lettersn"); )
- for (c = 'a'; c < 'z'+1; c++)
- upper[c] = 'A' + (c - 'a');
- DEBUG( fprintf (stderr, "init umlauten"); )
- upper[c = (unsigned char) '