mirror of
https://github.com/vattam/BSDGames.git
synced 2025-12-20 19:04:49 +00:00
Initial revision
git-svn-id: file:///srv/svn/joey/bsdgames-trunk@5086 a4a2c43b-8ac3-0310-8836-e0e880c912e2
This commit is contained in:
7
lib/Makefrag
Normal file
7
lib/Makefrag
Normal file
@@ -0,0 +1,7 @@
|
||||
# Makefrag - makefile fragment for lib
|
||||
|
||||
# No special rules needed, but we need these dummy targets
|
||||
|
||||
lib_all:
|
||||
|
||||
lib_install:
|
||||
36
lib/fgetln.c
Normal file
36
lib/fgetln.c
Normal file
@@ -0,0 +1,36 @@
|
||||
/* fgetln.c - bsd-games implementation of fgetln */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
char *
|
||||
fgetln(FILE *stream, size_t *len)
|
||||
{
|
||||
static char *buf = NULL;
|
||||
static size_t buflen = 0;
|
||||
char *res;
|
||||
char *nbuf;
|
||||
if (buf == NULL) {
|
||||
buf = (char *)malloc(buflen = 1024);
|
||||
if (buf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
buf[buflen - 1] = 1;
|
||||
res = fgets(buf, buflen, stream);
|
||||
if (res == NULL)
|
||||
return NULL;
|
||||
while (buf[buflen - 1] == 0) { /* long line */
|
||||
nbuf = realloc(buf, buflen * 2);
|
||||
if (nbuf == NULL)
|
||||
return NULL;
|
||||
buf = nbuf;
|
||||
buflen *= 2;
|
||||
buf[buflen - 1] = 1;
|
||||
res = fgets(buf + buflen/2 - 1, buflen/2 + 1, stream);
|
||||
if (res == NULL)
|
||||
return NULL;
|
||||
}
|
||||
*len = strlen(buf);
|
||||
return buf;
|
||||
}
|
||||
26
lib/getloadavg.c
Normal file
26
lib/getloadavg.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* getloadavg.c - bsd-games implementation of getloadavg */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int
|
||||
getloadavg(double loadavg[], int nelem)
|
||||
{
|
||||
double load_averages[3];
|
||||
FILE *fp;
|
||||
int count;
|
||||
int i;
|
||||
int nc;
|
||||
fp = fopen("/proc/loadavg", "r");
|
||||
if (fp == NULL)
|
||||
return -1;
|
||||
count = fscanf(fp, "%lf%lf%lf", &(load_averages[0]), &(load_averages[1]),
|
||||
&(load_averages[2]));
|
||||
fclose(fp);
|
||||
if ((count == EOF) || (count == 0))
|
||||
return -1;
|
||||
nc = ((nelem < count) ? nelem : count);
|
||||
for (i = 0; i < nc; i++)
|
||||
loadavg[i] = load_averages[i];
|
||||
return nc;
|
||||
}
|
||||
23
lib/select.c
Normal file
23
lib/select.c
Normal file
@@ -0,0 +1,23 @@
|
||||
/* select.c - bsd-games emulation of BSD select for games that need it */
|
||||
|
||||
/* This uses __select, which works with libc5 and libc6. This is a
|
||||
* substitute for the version in libbsd from libc5, and is essentially
|
||||
* equivalent. */
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
int
|
||||
select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
|
||||
struct timeval *timeout)
|
||||
{
|
||||
struct timeval timeout_copy;
|
||||
struct timeval *timeout_ptr;
|
||||
if (timeout) {
|
||||
/* Copy to a temporary */
|
||||
timeout_copy = *timeout;
|
||||
timeout_ptr = &timeout_copy;
|
||||
} else {
|
||||
timeout_ptr = timeout;
|
||||
}
|
||||
return __select(nfds, readfds, writefds, exceptfds, timeout_ptr);
|
||||
}
|
||||
Reference in New Issue
Block a user