/* This file contains code for X-CHESS.
Copyright (C) 1986 Free Software Foundation, Inc.
This file is part of X-CHESS.
X-CHESS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY. No author or distributor
accepts responsibility to anyone for the consequences of using it
or for whether it serves any particular purpose or works at all,
unless he says so in writing. Refer to the X-CHESS General Public
License for full details.
Everyone is granted permission to copy, modify and redistribute
X-CHESS, but only under the conditions described in the
X-CHESS General Public License. A copy of this license is
supposed to have been given to you along with X-CHESS so you
can know your rights and responsibilities. It should be in a
file named COPYING. Among other things, the copyright notice
and this notice must be preserved on all copies. */
/* RCS Info: $Revision: 1.1 $ on $Date: 86/11/01 17:08:40 $
* $Source: /users/faustus/xchess/RCS/std.c,v $
* Copyright (c) 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
#include <sys/resource.h>
/* Create a copy of a string. */
p
= tmalloc(strlen(str
) + 1);
/* Determine whether sub is a substring of str. */
register char *str
, *sub
;
/* Malloc num bytes and initialize to zero. Fatal error if the space can't
s
= malloc((unsigned) num
);
fatal("malloc: can't allocate %d bytes", num
);
s
= realloc(ptr
, (unsigned) num
);
fatal("realloc: can't allocate %d bytes", num
);
/* Well, this won't be zeroed... Too bad... */
/* Append one character to a string. Don't check for overflow. */
i
= i
* 10 + *(str
++) - '0';
/* Case insensitive prefix. */
if ((isupper(*p
) ? tolower(*p
) : *p
) !=
(isupper(*s
) ? tolower(*s
) : *s
))
/* Case insensitive strcmp... */
if ((isupper(*p
) ? tolower(*p
) : *p
) !=
(isupper(*s
) ? tolower(*s
) : *s
))
/* Return the date. Return value is static data. */
char *timezone(), *asctime();
(void) gettimeofday(&tv
, &tz
);
tp
= localtime((time_t *) &tv
.tv_sec
);
tzn
= timezone(tz
.tz_minuteswest
, tp
->tm_isdst
);
sprintf(tbuf
, "%.20s", ap
);
buf
[strlen(buf
) - 1] = '\0'; /* Kill the nl. */
/* How many seconds have elapsed in running time. */
getrusage(RUSAGE_SELF
, &ruse
);
return (ruse
.ru_utime
.tv_sec
);
/* A few things that may not exist on non-unix systems. */
while ((*s
!= c
) && (*s
!= '\0'))
for (t
= s
; *t
!= '\0'; t
++);
while ((*t
!= c
) && (t
!= s
))
register char *from
, *to
;
/* This might not be around... If not then forget about sorting... */
while (**s
&& !isspace(**s
))
fputs("Internal Error: ", stderr
);
_doprnt(s
, &args
, stderr
);
s
= tmalloc(strlen(name
) + 2);
/* Copy the old environment... */
for (i
= 0; environ
[i
]; i
++)
if (prefix(s
, environ
[i
]))
xx
= (char **) tmalloc((i
+ 2) * sizeof (char *));
for (i
= 0; environ
[i
]; i
++)
xx
[i
] = tmalloc(strlen(name
) + strlen(value
) + 2);
sprintf(xx
[i
], "%s=%s", name
, value
);
struct passwd
*pw
= getpwuid(i
);
return (pw
? pw
->pw_name
: NULL
);
struct passwd
*pw
= getpwuid(i
);
return (pw
? pw
->pw_dir
: "/strange");
for (s
++, i
= 0; *s
!= '/'; s
++, i
++)
n
= tmalloc(strlen(s
) + strlen(pw
->pw_dir
) + 1);