/* Functions from hack's utils library.
Copyright (C) 1989-1991 Free Software Foundation, Inc.
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, or (at your option)
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* These routines were written as part of a library (by hack), but since most
people don't have the library, here they are. */
#if defined(USG) || defined(STDC_HEADERS)
#define bcopy(src, dst, len) memcpy((dst), (src), (len))
#if defined(STDC_HEADERS)
/* Print an error message and exit */
fprintf(stderr
,"%s: ",myname
);
_doprnt(str
,&iggy
,stderr
);
vfprintf(stderr
,str
,iggy
);
fprintf(stderr
,"%s: ",myname
);
_doprnt(str
,&iggy
,stderr
);
vfprintf(stderr
,str
,iggy
);
/* Store information about files opened with ck_fopen
so that error messages from ck_fread, etc can print the
name of the file that had the error */
static struct id __id_s
[N_FILE
];
/* Internal routine to get a filename from __id_s */
return "{Unknown file pointer}";
/* Panic on failing fopen */
panic("Couldn't open file %s",name
);
free((VOID
*)__id_s
[n
].name
);
__id_s
[n
].name
=(char *)ck_malloc(strlen(name
)+1);
strcpy(__id_s
[n
].name
,name
);
if(__id_s
[n
].fp
==(FILE *)0)
panic("Internal error: too many files open");
__id_s
[n
].name
=(char *)ck_malloc(strlen(name
)+1);
strcpy(__id_s
[n
].name
,name
);
/* Panic on failing fwrite */
ck_fwrite(ptr
,size
,nmemb
,stream
)
if(fwrite(ptr
,size
,nmemb
,stream
)!=nmemb
)
panic("couldn't write %d items to %s",nmemb
,__fp_name(stream
));
/* Panic on failing fclose */
panic("Couldn't close %s",__fp_name(stream
));
/* Panic on failing malloc */
panic("Couldn't allocate memory");
/* Panic on failing realloc */
panic("Couldn't re-allocate memory");
/* Return a malloc()'d copy of a string */
ret
=(char *)ck_malloc(strlen(str
)+2);
#if !defined(USG) && !defined(STDC_HEADERS)
* memchr - search for a byte
memchr(s
, ucharwanted
, size
)
for (n
= size
; n
> 0; n
--)
if (((*scan
)&0xFF) == uc
)
#if !defined(STDC_HEADERS)
* memmove - copy bytes, being careful about overlap.
if (s
<= d
&& s
+ (size
-1) >= d
) {
/* Overlap, must copy right-to-left. */
for (n
= size
; n
> 0; n
--)
for (n
= size
; n
> 0; n
--)
/* Implement a variable sized buffer of 'stuff'. We don't know what it is,
nor do we care, as long as it doesn't mind being aligned by malloc. */
b
=(struct buffer
*)ck_malloc(sizeof(struct buffer
));
b
->allocated
=MIN_ALLOCATE
;
b
->b
=(char *)ck_malloc(MIN_ALLOCATE
);
if(b
->length
+n
>b
->allocated
) {
b
->b
=(char *)ck_realloc(b
->b
,b
->allocated
);
bcopy(p
,b
->b
+b
->length
,n
);
if(b
->length
+1>b
->allocated
) {
b
->b
=(char *)ck_realloc(b
->b
,b
->allocated
);