blib.c,v
./abermud/RCS/blib.c,v · 3.5 KB
From the archive abermud-89.tar.gz
Download the archive « Back to the archive contents
head 1.2;
access ;
symbols ;
locks ; strict;
comment @ * @;
1.2
date 89.07.03.08.17.14; author rsalz; state Exp;
branches ;
next 1.1;
1.1
date 89.03.13.09.35.25; author rsalz; state Exp;
branches ;
next ;
desc
@@
1.2
log
@Incorporate many fixes by Jussi <eloranta@@tukki.jyu.fi>,
and some minor tweaks by Rich.
@
text
@/*
** Random functions and utilities
** This emulates some useful parts of the B system library, etc.
** Not everyone needs everything here, but it's too hard to split
** things up into pieces...
*/
/* LINTLIBRARY */
#include "kernel.h"
#include <errno.h>
#include <sys/file.h>
#ifdef RCSID
static char RCS[] =
"$Header: blib.c,v 1.1 89/03/13 09:35:25 rsalz Exp $";
#endif /* RCSID */
GetFields(p, Data1, Data2)
register char *p;
register char *Data1;
register char *Data2;
{
while ((*Data1 = *p++) != '.')
Data1++;
*Data1 = '\0';
if (Data2) {
while (*p && *p != '.')
*Data2++ = *p++;
*Data2 = '\0';
}
}
/*
** Emulate Honeywell random-access files.
*/
sec_read(unit, block, pos, len)
FILE *unit;
int *block, pos, len;
{
(void)fseek(unit, (long)(pos * 64 * sizeof (int)), 0);
(void)fread((char *) block, len * sizeof (int), 1, unit);
}
sec_write(unit, block, pos, len)
FILE *unit;
int *block, pos, len;
{
(void)fseek(unit, (long)(pos * 64 * sizeof (int)), 0);
(void)fwrite((char *) block, len * sizeof(int), 1, unit);
}
/*
** Clear screen.
*/
cls()
{
(void)system("exec clear");
}
/*
** Convert a string to lowercase.
*/
char *
lowercase(str)
register char *str;
{
register char *p;
for (p = str; *p; p++)
if (isupper(*p))
*p = tolower(*p);
return str;
}
/*
** Get memory
*/
int *
xmalloc(i)
int i;
{
int *p;
/* NOSTRICT "warning: possible pointer alignment problem" */
if ((p = (int *)malloc((unsigned int)i)) == NULL) {
(void)fprintf(stderr, "No room to allo %d bytes.\n", i);
abort();
}
return p;
}
closelock(file)
FILE *file;
{
/* Don't need to unlock, it goes away when the file's closed, and
* we might not have always locked it.
flock(fileno(file), LOCK_UN);
*/
(void)fclose(file);
}
FILE *
openlock(file, perm)
char *file;
char *perm;
{
FILE *unit;
for (errno = 0; (unit = fopen(file, perm)) == NULL && errno == EINTR; )
; /* INTERRUPTED SYSTEM CALL CATCH */
if (unit == NULL || EQ(perm, "r"))
return unit;
while (flock(fileno(unit), LOCK_EX) == -1 && errno == EINTR)
; /* INTERRUPTED SYSTEM CALL CATCH */
if (errno == ENOSPC)
crapup("PANIC exit device full");
#ifdef ESTALE
if (errno == ESTALE || errno == EHOSTUNREACH || errno == EHOSTDOWN)
crapup("PANIC exit access failure, NFS gone for a snooze");
#endif /* ESTALE */
return unit;
}
#ifdef notdef
/*
** This is a C routine, often missing from Unix C compilers
** So we add our own version here
*/
char *
strchr(str, ch)
register char *str, ch;
{
for (; *str; str++)
if (*str == ch)
return str;
return NULL;
}
/*
** Get my username, replaces standard clib function which is a security
** hole on sun machines due to /ec/utmp access settings
*/
char *
cuserid(str)
char *str;
{
static char ary[128];
char *p;
getpw(getuid(), ary);
if (p = strchr(ary, ':'))
*p = '\0';
if (str)
strcpy(str, ary);
return ary;
}
#endif /* notdef */
@
1.1
log
@Initial revision
@
text
@d13 1
a13 1
"$Header$";
d26 5
a30 2
if (Data2)
(void)strcpy(Data2, p);
@