DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T b

⟦2485f47f1⟧ TextFile

    Length: 3114 (0xc2a)
    Types: TextFile
    Names: »blib.c«

Derivation

└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
    └─⟦this⟧ »EUUGD18/General/Abermud/blib.c« 

TextFile

/*
**  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((*Data2 = *p) != '.' && *p) p++, Data2++;
      *Data2 = '\0';
    }
/*	(void)strcpy(Data2, p); */
}


/*
**  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 */