home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / 3b1 / volume02 / libbsd / part01 < prev    next >
Encoding:
Internet Message Format  |  1992-06-22  |  58.6 KB

  1. Path: comp-sources-3b1
  2. From: dave@galaxia.newport.ri.us (David H. Brierley)
  3. Subject:  v02i004:  BSD Compatibility Library for ATT 3B1, Part01/02
  4. Newsgroups: comp.sources.3b1
  5. Approved: dave@galaxia.newport.ri.us
  6. X-Checksum-Snefru: 0d0d3658 781cc586 3f88da6e a1f2bf49
  7.  
  8. Submitted-by: dave@galaxia.newport.ri.us (David H. Brierley)
  9. Posting-number: Volume 2, Issue 4
  10. Archive-name: libbsd/part01
  11.  
  12. This is a collection of library routines that have been found to be useful
  13. when porting software to the ATT 3B1.  It is probably at least partially
  14. useful on other machines as well.
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then unpack
  18. # it by saving it into a file and typing "sh file".  To overwrite existing
  19. # files, type "sh file -c".  You can also feed this as standard input via
  20. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  21. # will see the following message at the end:
  22. #        "End of archive 1 (of 2)."
  23. # Contents:  MANIFEST Makefile README README.getdate alloca.s cobj-gen
  24. #   defs.h dup2.c ffs.c fsync.c ftruncate.c getdtblsize.c gethostent.c
  25. #   gethostname.c gettimeofday.c index.c inet_addr.c inet_lnaof.c
  26. #   inet_mkaddr.c inet_netof.c inet_network.c inet_ntoa.c mktemp.c
  27. #   nap.c rename.c rindex.c rmdir.c setenv.c setlinebuf.c sigsetmask.c
  28. #   sigvec.c sigvec.h statfs.c strcasecmp.c strdup.c strerror.c
  29. #   writev.c
  30. # Wrapped by dave@galaxia on Sat Jun 13 15:23:35 1992
  31. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  32. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  33.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  34. else
  35. echo shar: Extracting \"'MANIFEST'\" \(1398 characters\)
  36. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  37. X   File Name        Archive #    Description
  38. X-----------------------------------------------------------
  39. X MANIFEST                   1    
  40. X Makefile                   1    
  41. X README                     1    
  42. X README.getdate             1    
  43. X alloca.s                   1    
  44. X cobj-gen                   1    
  45. X defs.h                     1    
  46. X dup2.c                     1    
  47. X ffs.c                      1    
  48. X fsync.c                    1    
  49. X ftruncate.c                1    
  50. X getdate.y                  2    
  51. X getdtblsize.c              1    
  52. X gethostent.c               1    
  53. X gethostname.c              1    
  54. X gettimeofday.c             1    
  55. X index.c                    1    
  56. X inet_addr.c                1    
  57. X inet_lnaof.c               1    
  58. X inet_mkaddr.c              1    
  59. X inet_netof.c               1    
  60. X inet_network.c             1    
  61. X inet_ntoa.c                1    
  62. X mkdir.c                    2    
  63. X mktemp.c                   1    
  64. X nap.c                      1    
  65. X random.c                   2    
  66. X rename.c                   1    
  67. X rindex.c                   1    
  68. X rmdir.c                    1    
  69. X setenv.c                   1    
  70. X setlinebuf.c               1    
  71. X sigsetmask.c               1    
  72. X sigvec.c                   1    
  73. X sigvec.h                   1    
  74. X statfs.c                   1    
  75. X strcasecmp.c               1    
  76. X strdup.c                   1    
  77. X strerror.c                 1    
  78. X strftime.3                 2    
  79. X strftime.c                 2    
  80. X writev.c                   1    
  81. END_OF_FILE
  82. if test 1398 -ne `wc -c <'MANIFEST'`; then
  83.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  84. fi
  85. # end of 'MANIFEST'
  86. fi
  87. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  88.   echo shar: Will not clobber existing file \"'Makefile'\"
  89. else
  90. echo shar: Extracting \"'Makefile'\" \(835 characters\)
  91. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  92. XAOBJS = alloca.o
  93. X# regenerate COBJS line by running cobj-gen
  94. XCOBJS =    dup2.o ffs.o fsync.o ftruncate.o getdate.o getdtblsize.o gethostent.o\
  95. X    gethostname.o gettimeofday.o index.o inet_addr.o inet_lnaof.o\
  96. X    inet_mkaddr.o inet_netof.o inet_network.o inet_ntoa.o mkdir.o mktemp.o\
  97. X    nap.o random.o rename.o rindex.o rmdir.o setenv.o setlinebuf.o\
  98. X    sigsetmask.o sigvec.o statfs.o strcasecmp.o strdup.o strerror.o\
  99. X    strftime.o writev.o
  100. X
  101. XCFLAGS = -O -DUSG -DSYSV -DUNIXPC
  102. X
  103. Xlibbsd.a:    $(COBJS) $(AOBJS)
  104. X    rm -f libbsd.a
  105. X    ar cr libbsd.a `lorder $(COBJS) $(AOBJS) | tsort`
  106. X
  107. X# syslog.o needs special options - make sure SYSLOG_KEY is the same as
  108. X# the value used when compiling syslogd
  109. Xsyslog.o:    syslog.c
  110. X    $(CC) $(CFLAGS) -DSYSV_IPC -DSYSLOG_KEY=42 -c syslog.c
  111. X
  112. Xinstall:    /usr/lib/libbsd.a
  113. X
  114. X/usr/lib/libbsd.a: libbsd.a
  115. X    mv libbsd.a /usr/lib/libbsd.a
  116. END_OF_FILE
  117. if test 835 -ne `wc -c <'Makefile'`; then
  118.     echo shar: \"'Makefile'\" unpacked with wrong size!
  119. fi
  120. # end of 'Makefile'
  121. fi
  122. if test -f 'README' -a "${1}" != "-c" ; then 
  123.   echo shar: Will not clobber existing file \"'README'\"
  124. else
  125. echo shar: Extracting \"'README'\" \(1023 characters\)
  126. sed "s/^X//" >'README' <<'END_OF_FILE'
  127. XThis directory contains library functions that have been found to be useful
  128. Xin porting programs to the AT&T Unix-pc/7300/3B1.  Most of them provide
  129. Xfunctions that are commonly found in BSD systems, a few of them provide
  130. Xfunctions normally found in more recent SysV release, and a few are just
  131. Xplain handy routines to have around.
  132. X
  133. XSome of the routines were copied directly from the free BSD sources, some
  134. Xwere collected from the net, and some were written by me.  If there is no
  135. Xattribution at the top of a particular source file, there is a strong
  136. Xprobability that I wrote it but that is not an absolute certainty.  As far
  137. Xas I know, all of these routines are public domain.  Some of them explicitly
  138. Xstate that in the comments, others have neither a copyright, a disclaimer,
  139. Xor even an author.
  140. X
  141. XMost of the routines do not have any documentation supplied with them
  142. Xbecause it is assumed that you are familiar with the BSD/SysV routine that
  143. Xthese routines are intended to replace.
  144. X
  145. XDave Brierley
  146. Xdave@galaxia.newport.ri.us
  147. END_OF_FILE
  148. if test 1023 -ne `wc -c <'README'`; then
  149.     echo shar: \"'README'\" unpacked with wrong size!
  150. fi
  151. # end of 'README'
  152. fi
  153. if test -f 'README.getdate' -a "${1}" != "-c" ; then 
  154.   echo shar: Will not clobber existing file \"'README.getdate'\"
  155. else
  156. echo shar: Extracting \"'README.getdate'\" \(2104 characters\)
  157. sed "s/^X//" >'README.getdate' <<'END_OF_FILE'
  158. X
  159. XWe've been using Steve Bellovin's getdate() routine in the Cronus project
  160. Xfor over a year.  This past summer Jim Berets and I cleaned up all the
  161. Xtimezones, cleaned up some int/long problems that others have found,
  162. Xreformatted the code and cleaned it up, and contacted Steve about what
  163. Xshould else needs to be done with it.
  164. X
  165. XUnfortunately, we didn't have the time to do anything much with Steve's
  166. Xcomments, other then document them in the code, and here (thanks to Steve
  167. Xfor letting me quote some email):
  168. X    Two things need to be done.  First, the purpose of getdate should be
  169. X    defined; many of its features were for a rather different purpose that
  170. X    it's used for today.  Specifically, I was implementing 'at' before
  171. X    there was such a thing, and I wanted the ability to specify relative
  172. X    intervals.  Thus, getdate accepts things like 'two weeks'.  I don't
  173. X    think that code is tremendously useful.  If it is, it could be
  174. X    strengthened by writing a better grammar, i.e., ``two weeks after
  175. X    monday'' -- currently, the word ``after'' isn't accept, and the
  176. X    relationship between the day of the week and the interval is
  177. X    peculiar.  And that in turn goes back to the central implementation
  178. X    failure:  it is restricted to a simple 'int' stack, because that's all
  179. X    that v6 yacc allowed.  There's also a lot of reliance on global
  180. X    variables, for the same reason.  Using a union as the stack type, one
  181. X    could store much better information, clean up the code, and make the
  182. X    semantics much clearer.  (As a trivial change, I suspect that the
  183. X    military time zones are wrong, as I took them from RFC822 (or maybe
  184. X    even 733), and I've since learned that those are incorrect.  I'd drop
  185. X    that entirely.) It might also be worth some effort to make the time
  186. X    zone stuff more compatible with the 4.3tahoe and the SysVR3.2 stuff,
  187. X    especially as regards the names of the zones.
  188. X
  189. X    It was also intended to let utter novices set the date on a UNIX
  190. X    machine after rebooting it and thus it accepted almost any rational
  191. X    form.
  192. X
  193. XHope you find this useful.
  194. X    /rich $alz
  195. END_OF_FILE
  196. if test 2104 -ne `wc -c <'README.getdate'`; then
  197.     echo shar: \"'README.getdate'\" unpacked with wrong size!
  198. fi
  199. # end of 'README.getdate'
  200. fi
  201. if test -f 'alloca.s' -a "${1}" != "-c" ; then 
  202.   echo shar: Will not clobber existing file \"'alloca.s'\"
  203. else
  204. echo shar: Extracting \"'alloca.s'\" \(573 characters\)
  205. sed "s/^X//" >'alloca.s' <<'END_OF_FILE'
  206. X# This is optimized for the Unix PC, it won't work on some other 68k systems.
  207. X# The "and.l &-4" could be changed to "and.l &-2" if you're only running the
  208. X# code on the Unix PC.  I use this same code when cross-compiling to a 68020
  209. X# system, thus the longword alignment.
  210. X
  211. X    global    alloca
  212. Xalloca:
  213. X    mov.l    (%sp)+,%a0    # pop return addr
  214. X    mov.l    (%sp),%d0    # get size argument
  215. X    and.l    &-4,%d0        # round size down to long word
  216. X    sub.l    %d0,%sp        # allocate by moving stack pointer
  217. X    mov.l    %sp,%d0        # return pointer in d0
  218. X    lea    -4(%sp),%sp    # allow caller to pop the arg
  219. X    jmp    (%a0)        # return
  220. END_OF_FILE
  221. if test 573 -ne `wc -c <'alloca.s'`; then
  222.     echo shar: \"'alloca.s'\" unpacked with wrong size!
  223. fi
  224. # end of 'alloca.s'
  225. fi
  226. if test -f 'cobj-gen' -a "${1}" != "-c" ; then 
  227.   echo shar: Will not clobber existing file \"'cobj-gen'\"
  228. else
  229. echo shar: Extracting \"'cobj-gen'\" \(313 characters\)
  230. sed "s/^X//" >'cobj-gen' <<'END_OF_FILE'
  231. X: 'sh or ksh'
  232. Xls *.[cly] | sed -e 's/\..$/.o/' |sort -u | awk '
  233. X    BEGIN { printf "COBJS ="; len = 0; space = "\t" }
  234. X    {
  235. X        if (len + length($0) > 70) {
  236. X        printf "\\\n"
  237. X        len = 0
  238. X        space = "\t"
  239. X        }
  240. X        printf "%s%s", space, $0
  241. X        space = " "
  242. X        len += (length($0) + 1)
  243. X    }
  244. X    END { if(len > 0) printf "\n" }'
  245. END_OF_FILE
  246. if test 313 -ne `wc -c <'cobj-gen'`; then
  247.     echo shar: \"'cobj-gen'\" unpacked with wrong size!
  248. fi
  249. chmod +x 'cobj-gen'
  250. # end of 'cobj-gen'
  251. fi
  252. if test -f 'defs.h' -a "${1}" != "-c" ; then 
  253.   echo shar: Will not clobber existing file \"'defs.h'\"
  254. else
  255. echo shar: Extracting \"'defs.h'\" \(0 characters\)
  256. sed "s/^X//" >'defs.h' <<'END_OF_FILE'
  257. END_OF_FILE
  258. if test 0 -ne `wc -c <'defs.h'`; then
  259.     echo shar: \"'defs.h'\" unpacked with wrong size!
  260. fi
  261. # end of 'defs.h'
  262. fi
  263. if test -f 'dup2.c' -a "${1}" != "-c" ; then 
  264.   echo shar: Will not clobber existing file \"'dup2.c'\"
  265. else
  266. echo shar: Extracting \"'dup2.c'\" \(526 characters\)
  267. sed "s/^X//" >'dup2.c' <<'END_OF_FILE'
  268. X/******************************************************************************
  269. Xdup2() under System V unixes:
  270. X
  271. X++Brandon
  272. X-- 
  273. XBrandon S. Allbery, moderator of comp.sources.misc         allbery@NCoast.ORG
  274. Xuunet!hal.cwru.edu!ncoast!allbery            ncoast!allbery@hal.cwru.edu
  275. X*******************************************************************************/
  276. X
  277. X
  278. X#include <fcntl.h>
  279. X
  280. Xdup2(fd1, fd2)
  281. X    int fd1, fd2;
  282. X{
  283. X    /* sanity check  -- added by dhb */
  284. X    if (fd1 == fd2) return (fd1);
  285. X    (void) close(fd2);
  286. X    return fcntl(fd1, F_DUPFD, fd2);
  287. X}
  288. END_OF_FILE
  289. if test 526 -ne `wc -c <'dup2.c'`; then
  290.     echo shar: \"'dup2.c'\" unpacked with wrong size!
  291. fi
  292. # end of 'dup2.c'
  293. fi
  294. if test -f 'ffs.c' -a "${1}" != "-c" ; then 
  295.   echo shar: Will not clobber existing file \"'ffs.c'\"
  296. else
  297. echo shar: Extracting \"'ffs.c'\" \(1143 characters\)
  298. sed "s/^X//" >'ffs.c' <<'END_OF_FILE'
  299. X/*
  300. X * Copyright (c) 1987 Regents of the University of California.
  301. X * All rights reserved.
  302. X *
  303. X * Redistribution and use in source and binary forms are permitted
  304. X * provided that the above copyright notice and this paragraph are
  305. X * duplicated in all such forms and that any documentation,
  306. X * advertising materials, and other materials related to such
  307. X * distribution and use acknowledge that the software was developed
  308. X * by the University of California, Berkeley.  The name of the
  309. X * University may not be used to endorse or promote products derived
  310. X * from this software without specific prior written permission.
  311. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  312. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  313. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  314. X */
  315. X
  316. X#if defined(LIBC_SCCS) && !defined(lint)
  317. Xstatic char sccsid[] = "@(#)ffs.c    5.2 (Berkeley) 6/27/88";
  318. X#endif /* LIBC_SCCS and not lint */
  319. X
  320. X/*
  321. X * ffs -- vax ffs instruction
  322. X */
  323. Xffs(mask)
  324. X    register long mask;
  325. X{
  326. X    register int cnt;
  327. X
  328. X    if (mask == 0)
  329. X        return(0);
  330. X    for (cnt = 1; !(mask & 1); cnt++)
  331. X        mask >>= 1;
  332. X    return(cnt);
  333. X}
  334. END_OF_FILE
  335. if test 1143 -ne `wc -c <'ffs.c'`; then
  336.     echo shar: \"'ffs.c'\" unpacked with wrong size!
  337. fi
  338. # end of 'ffs.c'
  339. fi
  340. if test -f 'fsync.c' -a "${1}" != "-c" ; then 
  341.   echo shar: Will not clobber existing file \"'fsync.c'\"
  342. else
  343. echo shar: Extracting \"'fsync.c'\" \(79 characters\)
  344. sed "s/^X//" >'fsync.c' <<'END_OF_FILE'
  345. X/* Too lazy to check if there is a sysv equiv to this */
  346. X
  347. Xfsync(){ return 0; }
  348. END_OF_FILE
  349. if test 79 -ne `wc -c <'fsync.c'`; then
  350.     echo shar: \"'fsync.c'\" unpacked with wrong size!
  351. fi
  352. # end of 'fsync.c'
  353. fi
  354. if test -f 'ftruncate.c' -a "${1}" != "-c" ; then 
  355.   echo shar: Will not clobber existing file \"'ftruncate.c'\"
  356. else
  357. echo shar: Extracting \"'ftruncate.c'\" \(1344 characters\)
  358. sed "s/^X//" >'ftruncate.c' <<'END_OF_FILE'
  359. X#include <sys/types.h>
  360. X#include <sys/stat.h>
  361. X#include <errno.h>
  362. X#include <fcntl.h>
  363. X#include <unistd.h>
  364. X
  365. Xint
  366. Xftruncate(fd, length)
  367. Xint     fd;     /* file descriptor */
  368. Xoff_t   length; /* length to set file to */
  369. X{
  370. X#ifdef    F_FREESP
  371. X        extern  long    lseek();
  372. X
  373. X        struct  flock   fl;
  374. X        struct  stat    filebuf;
  375. X
  376. X        if (fstat(fd, &filebuf) < 0)
  377. X                return(-1);
  378. X
  379. X        if (filebuf.st_size < length) {
  380. X                /* extend file length */
  381. X
  382. X                if ((lseek(fd, (length - 1), SEEK_SET)) < 0)
  383. X                        return(-1);
  384. X
  385. X                /* write a "0" byte */
  386. X
  387. X                if ((write(fd, "", 1)) != 1)
  388. X                        return(-1);
  389. X        } else {
  390. X                /* truncate length */
  391. X
  392. X                fl.l_whence = 0;
  393. X                fl.l_len = 0;
  394. X                fl.l_start = length;
  395. X                fl.l_type = F_WRLCK;    /* write lock on file space */
  396. X
  397. X                /*
  398. X                 * This relies on the UNDOCUMENTED F_FREESP argument to
  399. X                 * fcntl(2), which truncates the file so that it ends at the
  400. X                 * position indicated by fl.l_start.
  401. X                 *
  402. X                 * Will minor miracles never cease?
  403. X                 */
  404. X
  405. X        if (fcntl(fd, F_FREESP, &fl) < 0)
  406. X            return(-1);
  407. X
  408. X        }
  409. X        return(0);
  410. X#else
  411. X    return(-1);
  412. X#endif
  413. X
  414. X}
  415. END_OF_FILE
  416. if test 1344 -ne `wc -c <'ftruncate.c'`; then
  417.     echo shar: \"'ftruncate.c'\" unpacked with wrong size!
  418. fi
  419. # end of 'ftruncate.c'
  420. fi
  421. if test -f 'getdtblsize.c' -a "${1}" != "-c" ; then 
  422.   echo shar: Will not clobber existing file \"'getdtblsize.c'\"
  423. else
  424. echo shar: Extracting \"'getdtblsize.c'\" \(56 characters\)
  425. sed "s/^X//" >'getdtblsize.c' <<'END_OF_FILE'
  426. X#include <stdio.h>
  427. X
  428. Xgetdtablesize()
  429. X{
  430. X    return _NFILE;
  431. X}
  432. END_OF_FILE
  433. if test 56 -ne `wc -c <'getdtblsize.c'`; then
  434.     echo shar: \"'getdtblsize.c'\" unpacked with wrong size!
  435. fi
  436. # end of 'getdtblsize.c'
  437. fi
  438. if test -f 'gethostent.c' -a "${1}" != "-c" ; then 
  439.   echo shar: Will not clobber existing file \"'gethostent.c'\"
  440. else
  441. echo shar: Extracting \"'gethostent.c'\" \(3269 characters\)
  442. sed "s/^X//" >'gethostent.c' <<'END_OF_FILE'
  443. X/*
  444. X * Copyright (c) 1985, 1988 Regents of the University of California.
  445. X * All rights reserved.
  446. X *
  447. X * Redistribution and use in source and binary forms are permitted
  448. X * provided that this notice is preserved and that due credit is given
  449. X * to the University of California at Berkeley. The name of the University
  450. X * may not be used to endorse or promote products derived from this
  451. X * software without specific prior written permission. This software
  452. X * is provided ``as is'' without express or implied warranty.
  453. X */
  454. X
  455. X#if defined(LIBC_SCCS) && !defined(lint)
  456. Xstatic char sccsid[] = "@(#)gethostnamadr.c    6.32 (Berkeley) 4/12/88";
  457. X#endif /* LIBC_SCCS and not lint */
  458. X
  459. X#include <sys/param.h>
  460. X#include <sys/socket.h>
  461. X#include <netinet/in.h>
  462. X#include <ctype.h>
  463. X#include <netdb.h>
  464. X#include <stdio.h>
  465. X
  466. X#ifdef    USG
  467. X#define    bcmp    memcmp
  468. X#endif
  469. X
  470. X#define    MAXALIASES    35
  471. X#define    MAXADDRS    35
  472. X
  473. Xstatic char *h_addr_ptrs[MAXADDRS + 1];
  474. X
  475. Xstatic struct hostent host;
  476. Xstatic char *host_aliases[MAXALIASES];
  477. Xstatic char hostbuf[BUFSIZ+1];
  478. Xstatic char HOSTDB[] = "/etc/hosts";
  479. Xstatic FILE *hostf = NULL;
  480. Xstatic char hostaddr[MAXADDRS];
  481. Xstatic char *host_addrs[2];
  482. Xstatic int stayopen = 0;
  483. Xstatic char *any();
  484. X
  485. Xsethostent(f)
  486. X    int f;
  487. X{
  488. X    if (hostf == NULL)
  489. X        hostf = fopen(HOSTDB, "r" );
  490. X    else
  491. X        rewind(hostf);
  492. X    stayopen |= f;
  493. X}
  494. X
  495. Xendhostent()
  496. X{
  497. X    if (hostf && !stayopen) {
  498. X        (void) fclose(hostf);
  499. X        hostf = NULL;
  500. X    }
  501. X}
  502. X
  503. Xstruct hostent *
  504. Xgethostent()
  505. X{
  506. X    char *p;
  507. X    register char *cp, **q;
  508. X
  509. X    if (hostf == NULL && (hostf = fopen(HOSTDB, "r" )) == NULL)
  510. X        return (NULL);
  511. Xagain:
  512. X    if ((p = fgets(hostbuf, BUFSIZ, hostf)) == NULL)
  513. X        return (NULL);
  514. X    if (*p == '#')
  515. X        goto again;
  516. X    cp = any(p, "#\n");
  517. X    if (cp == NULL)
  518. X        goto again;
  519. X    *cp = '\0';
  520. X    cp = any(p, " \t");
  521. X    if (cp == NULL)
  522. X        goto again;
  523. X    *cp++ = '\0';
  524. X    /* THIS STUFF IS INTERNET SPECIFIC */
  525. X#if BSD >= 43 || defined(h_addr)    /* new-style hostent structure */
  526. X    host.h_addr_list = host_addrs;
  527. X#endif
  528. X    host.h_addr = hostaddr;
  529. X    *((u_long *)host.h_addr) = inet_addr(p);
  530. X    host.h_length = sizeof (u_long);
  531. X#ifdef    AF_INET
  532. X    host.h_addrtype = AF_INET;
  533. X#else
  534. X    host.h_addrtype = 0;
  535. X#endif
  536. X    while (*cp == ' ' || *cp == '\t')
  537. X        cp++;
  538. X    host.h_name = cp;
  539. X    q = host.h_aliases = host_aliases;
  540. X    cp = any(cp, " \t");
  541. X    if (cp != NULL) 
  542. X        *cp++ = '\0';
  543. X    while (cp && *cp) {
  544. X        if (*cp == ' ' || *cp == '\t') {
  545. X            cp++;
  546. X            continue;
  547. X        }
  548. X        if (q < &host_aliases[MAXALIASES - 1])
  549. X            *q++ = cp;
  550. X        cp = any(cp, " \t");
  551. X        if (cp != NULL)
  552. X            *cp++ = '\0';
  553. X    }
  554. X    *q = NULL;
  555. X    return (&host);
  556. X}
  557. X
  558. Xstatic char *
  559. Xany(cp, match)
  560. X    register char *cp;
  561. X    char *match;
  562. X{
  563. X    register char *mp, c;
  564. X
  565. X    while (c = *cp) {
  566. X        for (mp = match; *mp; mp++)
  567. X            if (*mp == c)
  568. X                return (cp);
  569. X        cp++;
  570. X    }
  571. X    return ((char *)0);
  572. X}
  573. X
  574. Xstruct hostent *
  575. Xgethostbyname(name)
  576. X    char *name;
  577. X{
  578. X    register struct hostent *p;
  579. X    register char **cp;
  580. X    
  581. X    sethostent(0);
  582. X    while (p = gethostent()) {
  583. X        if (strcasecmp(p->h_name, name) == 0)
  584. X            break;
  585. X        for (cp = p->h_aliases; *cp != 0; cp++)
  586. X            if (strcasecmp(*cp, name) == 0)
  587. X                goto found;
  588. X    }
  589. Xfound:
  590. X    endhostent();
  591. X    return (p);
  592. X}
  593. X
  594. Xstruct hostent *
  595. Xgethostbyaddr(addr, len, type)
  596. X    char *addr;
  597. X    int len, type;
  598. X{
  599. X    register struct hostent *p;
  600. X
  601. X    sethostent(0);
  602. X    while (p = gethostent())
  603. X        if (p->h_addrtype == type && !bcmp(p->h_addr, addr, len))
  604. X            break;
  605. X    endhostent();
  606. X    return (p);
  607. X}
  608. END_OF_FILE
  609. if test 3269 -ne `wc -c <'gethostent.c'`; then
  610.     echo shar: \"'gethostent.c'\" unpacked with wrong size!
  611. fi
  612. # end of 'gethostent.c'
  613. fi
  614. if test -f 'gethostname.c' -a "${1}" != "-c" ; then 
  615.   echo shar: Will not clobber existing file \"'gethostname.c'\"
  616. else
  617. echo shar: Extracting \"'gethostname.c'\" \(264 characters\)
  618. sed "s/^X//" >'gethostname.c' <<'END_OF_FILE'
  619. X#include <sys/utsname.h>
  620. X
  621. Xstatic struct utsname name;
  622. X
  623. Xgethostname (hostname, maxlen)
  624. Xchar           *hostname;
  625. Xint             maxlen;
  626. X{
  627. X
  628. X    if (uname (&name) == -1) {
  629. X    return (-1);
  630. X    }
  631. X
  632. X    (void) strncpy (hostname, name.nodename, maxlen);
  633. X    return (0);
  634. X
  635. X}
  636. END_OF_FILE
  637. if test 264 -ne `wc -c <'gethostname.c'`; then
  638.     echo shar: \"'gethostname.c'\" unpacked with wrong size!
  639. fi
  640. # end of 'gethostname.c'
  641. fi
  642. if test -f 'gettimeofday.c' -a "${1}" != "-c" ; then 
  643.   echo shar: Will not clobber existing file \"'gettimeofday.c'\"
  644. else
  645. echo shar: Extracting \"'gettimeofday.c'\" \(761 characters\)
  646. sed "s/^X//" >'gettimeofday.c' <<'END_OF_FILE'
  647. X/*
  648. X *    SystemV simulation of bsd's gettimeofday(2).
  649. X *
  650. X *    Thad Floryan, 24-June-1990.
  651. X */
  652. X
  653. X#include <sys/types.h>
  654. X#include <sys/times.h>
  655. X#include <sys/time.h>
  656. X
  657. Xgettimeofday( tp, tz )
  658. X    struct timeval *tp;    /* long tv_sec  secs since 1-jan-1970    */
  659. X            /* long tv_usec microseconds fraction    */
  660. X    struct timezone *tz;/* int tz_minuteswest of GMT        */
  661. X            /* int tz_dsttime = DST_* if apply DST    */
  662. X{
  663. X    extern long time(), times();
  664. X    extern long timezone;
  665. X    struct tms dummy;
  666. X
  667. X    tp->tv_sec = time((long *) 0);
  668. X    tp->tv_usec = (times(&dummy) % 60L) * 16666L; /* 1/60 = .016666 S */
  669. X    if (tz != (struct timezone *)0) {
  670. X    tz->tz_minuteswest = (int) (timezone / 60L);  /* convert sec to min */
  671. X    tz->tz_dsttime = DST_USA;        /* assume USA DST handling */
  672. X    }
  673. X}
  674. END_OF_FILE
  675. if test 761 -ne `wc -c <'gettimeofday.c'`; then
  676.     echo shar: \"'gettimeofday.c'\" unpacked with wrong size!
  677. fi
  678. # end of 'gettimeofday.c'
  679. fi
  680. if test -f 'index.c' -a "${1}" != "-c" ; then 
  681.   echo shar: Will not clobber existing file \"'index.c'\"
  682. else
  683. echo shar: Extracting \"'index.c'\" \(1131 characters\)
  684. sed "s/^X//" >'index.c' <<'END_OF_FILE'
  685. X/*
  686. X * Copyright (c) 1988 Regents of the University of California.
  687. X * All rights reserved.
  688. X *
  689. X * Redistribution and use in source and binary forms are permitted
  690. X * provided that the above copyright notice and this paragraph are
  691. X * duplicated in all such forms and that any documentation,
  692. X * advertising materials, and other materials related to such
  693. X * distribution and use acknowledge that the software was developed
  694. X * by the University of California, Berkeley.  The name of the
  695. X * University may not be used to endorse or promote products derived
  696. X * from this software without specific prior written permission.
  697. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  698. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  699. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  700. X */
  701. X
  702. X#if defined(LIBC_SCCS) && !defined(lint)
  703. Xstatic char sccsid[] = "@(#)index.c    5.4 (Berkeley) 6/27/88";
  704. X#endif /* LIBC_SCCS and not lint */
  705. X
  706. X#include <stdio.h>
  707. X
  708. Xchar *
  709. Xindex(p, ch)
  710. X    register char *p, ch;
  711. X{
  712. X    for (;; ++p) {
  713. X        if (*p == ch)
  714. X            return(p);
  715. X        if (!*p)
  716. X            return((char *)NULL);
  717. X    }
  718. X    /* NOTREACHED */
  719. X}
  720. END_OF_FILE
  721. if test 1131 -ne `wc -c <'index.c'`; then
  722.     echo shar: \"'index.c'\" unpacked with wrong size!
  723. fi
  724. # end of 'index.c'
  725. fi
  726. if test -f 'inet_addr.c' -a "${1}" != "-c" ; then 
  727.   echo shar: Will not clobber existing file \"'inet_addr.c'\"
  728. else
  729. echo shar: Extracting \"'inet_addr.c'\" \(2819 characters\)
  730. sed "s/^X//" >'inet_addr.c' <<'END_OF_FILE'
  731. X/*
  732. X * Copyright (c) 1983 Regents of the University of California.
  733. X * All rights reserved.
  734. X *
  735. X * Redistribution and use in source and binary forms are permitted
  736. X * provided that the above copyright notice and this paragraph are
  737. X * duplicated in all such forms and that any documentation,
  738. X * advertising materials, and other materials related to such
  739. X * distribution and use acknowledge that the software was developed
  740. X * by the University of California, Berkeley.  The name of the
  741. X * University may not be used to endorse or promote products derived
  742. X * from this software without specific prior written permission.
  743. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  744. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  745. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  746. X */
  747. X
  748. X#if defined(LIBC_SCCS) && !defined(lint)
  749. Xstatic char sccsid[] = "@(#)inet_addr.c    5.6 (Berkeley) 6/27/88";
  750. X#endif /* LIBC_SCCS and not lint */
  751. X
  752. X#include <sys/types.h>
  753. X#include <ctype.h>
  754. X#include <netinet/in.h>
  755. X
  756. X/*
  757. X * Internet address interpretation routine.
  758. X * All the network library routines call this
  759. X * routine to interpret entries in the data bases
  760. X * which are expected to be an address.
  761. X * The value returned is in network order.
  762. X */
  763. Xu_long
  764. Xinet_addr(cp)
  765. X    register char *cp;
  766. X{
  767. X    register u_long val, base, n;
  768. X    register char c;
  769. X    u_long parts[4], *pp = parts;
  770. X
  771. Xagain:
  772. X    /*
  773. X     * Collect number up to ``.''.
  774. X     * Values are specified as for C:
  775. X     * 0x=hex, 0=octal, other=decimal.
  776. X     */
  777. X    val = 0; base = 10;
  778. X    if (*cp == '0') {
  779. X        if (*++cp == 'x' || *cp == 'X')
  780. X            base = 16, cp++;
  781. X        else
  782. X            base = 8;
  783. X    }
  784. X    while (c = *cp) {
  785. X        if (isdigit(c)) {
  786. X            val = (val * base) + (c - '0');
  787. X            cp++;
  788. X            continue;
  789. X        }
  790. X        if (base == 16 && isxdigit(c)) {
  791. X            val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A'));
  792. X            cp++;
  793. X            continue;
  794. X        }
  795. X        break;
  796. X    }
  797. X    if (*cp == '.') {
  798. X        /*
  799. X         * Internet format:
  800. X         *    a.b.c.d
  801. X         *    a.b.c    (with c treated as 16-bits)
  802. X         *    a.b    (with b treated as 24 bits)
  803. X         */
  804. X        if (pp >= parts + 4)
  805. X            return (INADDR_NONE);
  806. X        *pp++ = val, cp++;
  807. X        goto again;
  808. X    }
  809. X    /*
  810. X     * Check for trailing characters.
  811. X     */
  812. X    if (*cp && !isspace(*cp))
  813. X        return (INADDR_NONE);
  814. X    *pp++ = val;
  815. X    /*
  816. X     * Concoct the address according to
  817. X     * the number of parts specified.
  818. X     */
  819. X    n = pp - parts;
  820. X    switch (n) {
  821. X
  822. X    case 1:                /* a -- 32 bits */
  823. X        val = parts[0];
  824. X        break;
  825. X
  826. X    case 2:                /* a.b -- 8.24 bits */
  827. X        val = (parts[0] << 24) | (parts[1] & 0xffffff);
  828. X        break;
  829. X
  830. X    case 3:                /* a.b.c -- 8.8.16 bits */
  831. X        val = (parts[0] << 24) | ((parts[1] & 0xff) << 16) |
  832. X            (parts[2] & 0xffff);
  833. X        break;
  834. X
  835. X    case 4:                /* a.b.c.d -- 8.8.8.8 bits */
  836. X        val = (parts[0] << 24) | ((parts[1] & 0xff) << 16) |
  837. X              ((parts[2] & 0xff) << 8) | (parts[3] & 0xff);
  838. X        break;
  839. X
  840. X    default:
  841. X        return (INADDR_NONE);
  842. X    }
  843. X    val = htonl(val);
  844. X    return (val);
  845. X}
  846. END_OF_FILE
  847. if test 2819 -ne `wc -c <'inet_addr.c'`; then
  848.     echo shar: \"'inet_addr.c'\" unpacked with wrong size!
  849. fi
  850. # end of 'inet_addr.c'
  851. fi
  852. if test -f 'inet_lnaof.c' -a "${1}" != "-c" ; then 
  853.   echo shar: Will not clobber existing file \"'inet_lnaof.c'\"
  854. else
  855. echo shar: Extracting \"'inet_lnaof.c'\" \(725 characters\)
  856. sed "s/^X//" >'inet_lnaof.c' <<'END_OF_FILE'
  857. X/*
  858. X * Copyright (c) 1983 Regents of the University of California.
  859. X * All rights reserved.  The Berkeley software License Agreement
  860. X * specifies the terms and conditions for redistribution.
  861. X */
  862. X
  863. X#if defined(LIBC_SCCS) && !defined(lint)
  864. Xstatic char sccsid[] = "@(#)inet_lnaof.c    5.2 (Berkeley) 3/9/86";
  865. X#endif LIBC_SCCS and not lint
  866. X
  867. X#include <sys/types.h>
  868. X#include <netinet/in.h>
  869. X
  870. X/*
  871. X * Return the local network address portion of an
  872. X * internet address; handles class a/b/c network
  873. X * number formats.
  874. X */
  875. Xinet_lnaof(in)
  876. X    struct in_addr in;
  877. X{
  878. X    register u_long i = ntohl(in.s_addr);
  879. X
  880. X    if (IN_CLASSA(i))
  881. X        return ((i)&IN_CLASSA_HOST);
  882. X    else if (IN_CLASSB(i))
  883. X        return ((i)&IN_CLASSB_HOST);
  884. X    else
  885. X        return ((i)&IN_CLASSC_HOST);
  886. X}
  887. END_OF_FILE
  888. if test 725 -ne `wc -c <'inet_lnaof.c'`; then
  889.     echo shar: \"'inet_lnaof.c'\" unpacked with wrong size!
  890. fi
  891. # end of 'inet_lnaof.c'
  892. fi
  893. if test -f 'inet_mkaddr.c' -a "${1}" != "-c" ; then 
  894.   echo shar: Will not clobber existing file \"'inet_mkaddr.c'\"
  895. else
  896. echo shar: Extracting \"'inet_mkaddr.c'\" \(869 characters\)
  897. sed "s/^X//" >'inet_mkaddr.c' <<'END_OF_FILE'
  898. X/*
  899. X * Copyright (c) 1983 Regents of the University of California.
  900. X * All rights reserved.  The Berkeley software License Agreement
  901. X * specifies the terms and conditions for redistribution.
  902. X */
  903. X
  904. X#if defined(LIBC_SCCS) && !defined(lint)
  905. Xstatic char sccsid[] = "@(#)inet_makeaddr.c    5.1 (Berkeley) 3/11/86";
  906. X#endif LIBC_SCCS and not lint
  907. X
  908. X#include <sys/types.h>
  909. X#include <netinet/in.h>
  910. X
  911. X/*
  912. X * Formulate an Internet address from network + host.  Used in
  913. X * building addresses stored in the ifnet structure.
  914. X */
  915. Xstruct in_addr
  916. Xinet_makeaddr(net, host)
  917. X    int net, host;
  918. X{
  919. X    u_long addr;
  920. X
  921. X    if (net < 128)
  922. X        addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST);
  923. X    else if (net < 65536)
  924. X        addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST);
  925. X    else
  926. X        addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST);
  927. X    addr = htonl(addr);
  928. X    return (*(struct in_addr *)&addr);
  929. X}
  930. END_OF_FILE
  931. if test 869 -ne `wc -c <'inet_mkaddr.c'`; then
  932.     echo shar: \"'inet_mkaddr.c'\" unpacked with wrong size!
  933. fi
  934. # end of 'inet_mkaddr.c'
  935. fi
  936. if test -f 'inet_netof.c' -a "${1}" != "-c" ; then 
  937.   echo shar: Will not clobber existing file \"'inet_netof.c'\"
  938. else
  939. echo shar: Extracting \"'inet_netof.c'\" \(761 characters\)
  940. sed "s/^X//" >'inet_netof.c' <<'END_OF_FILE'
  941. X/*
  942. X * Copyright (c) 1983 Regents of the University of California.
  943. X * All rights reserved.  The Berkeley software License Agreement
  944. X * specifies the terms and conditions for redistribution.
  945. X */
  946. X
  947. X#if defined(LIBC_SCCS) && !defined(lint)
  948. Xstatic char sccsid[] = "@(#)inet_netof.c    5.2 (Berkeley) 3/9/86";
  949. X#endif LIBC_SCCS and not lint
  950. X
  951. X#include <sys/types.h>
  952. X#include <netinet/in.h>
  953. X
  954. X/*
  955. X * Return the network number from an internet
  956. X * address; handles class a/b/c network #'s.
  957. X */
  958. Xinet_netof(in)
  959. X    struct in_addr in;
  960. X{
  961. X    register u_long i = ntohl(in.s_addr);
  962. X
  963. X    if (IN_CLASSA(i))
  964. X        return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);
  965. X    else if (IN_CLASSB(i))
  966. X        return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT);
  967. X    else
  968. X        return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
  969. X}
  970. END_OF_FILE
  971. if test 761 -ne `wc -c <'inet_netof.c'`; then
  972.     echo shar: \"'inet_netof.c'\" unpacked with wrong size!
  973. fi
  974. # end of 'inet_netof.c'
  975. fi
  976. if test -f 'inet_network.c' -a "${1}" != "-c" ; then 
  977.   echo shar: Will not clobber existing file \"'inet_network.c'\"
  978. else
  979. echo shar: Extracting \"'inet_network.c'\" \(1976 characters\)
  980. sed "s/^X//" >'inet_network.c' <<'END_OF_FILE'
  981. X/*
  982. X * Copyright (c) 1983 Regents of the University of California.
  983. X * All rights reserved.
  984. X *
  985. X * Redistribution and use in source and binary forms are permitted
  986. X * provided that the above copyright notice and this paragraph are
  987. X * duplicated in all such forms and that any documentation,
  988. X * advertising materials, and other materials related to such
  989. X * distribution and use acknowledge that the software was developed
  990. X * by the University of California, Berkeley.  The name of the
  991. X * University may not be used to endorse or promote products derived
  992. X * from this software without specific prior written permission.
  993. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  994. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  995. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  996. X */
  997. X
  998. X#if defined(LIBC_SCCS) && !defined(lint)
  999. Xstatic char sccsid[] = "@(#)inet_network.c    5.5 (Berkeley) 6/27/88";
  1000. X#endif /* LIBC_SCCS and not lint */
  1001. X
  1002. X#include <sys/types.h>
  1003. X#include <netinet/in.h>
  1004. X#include <ctype.h>
  1005. X
  1006. X/*
  1007. X * Internet network address interpretation routine.
  1008. X * The library routines call this routine to interpret
  1009. X * network numbers.
  1010. X */
  1011. Xu_long
  1012. Xinet_network(cp)
  1013. X    register char *cp;
  1014. X{
  1015. X    register u_long val, base, n;
  1016. X    register char c;
  1017. X    u_long parts[4], *pp = parts;
  1018. X    register int i;
  1019. X
  1020. Xagain:
  1021. X    val = 0; base = 10;
  1022. X    if (*cp == '0')
  1023. X        base = 8, cp++;
  1024. X    if (*cp == 'x' || *cp == 'X')
  1025. X        base = 16, cp++;
  1026. X    while (c = *cp) {
  1027. X        if (isdigit(c)) {
  1028. X            val = (val * base) + (c - '0');
  1029. X            cp++;
  1030. X            continue;
  1031. X        }
  1032. X        if (base == 16 && isxdigit(c)) {
  1033. X            val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A'));
  1034. X            cp++;
  1035. X            continue;
  1036. X        }
  1037. X        break;
  1038. X    }
  1039. X    if (*cp == '.') {
  1040. X        if (pp >= parts + 4)
  1041. X            return (INADDR_NONE);
  1042. X        *pp++ = val, cp++;
  1043. X        goto again;
  1044. X    }
  1045. X    if (*cp && !isspace(*cp))
  1046. X        return (INADDR_NONE);
  1047. X    *pp++ = val;
  1048. X    n = pp - parts;
  1049. X    if (n > 4)
  1050. X        return (INADDR_NONE);
  1051. X    for (val = 0, i = 0; i < n; i++) {
  1052. X        val <<= 8;
  1053. X        val |= parts[i] & 0xff;
  1054. X    }
  1055. X    return (val);
  1056. X}
  1057. END_OF_FILE
  1058. if test 1976 -ne `wc -c <'inet_network.c'`; then
  1059.     echo shar: \"'inet_network.c'\" unpacked with wrong size!
  1060. fi
  1061. # end of 'inet_network.c'
  1062. fi
  1063. if test -f 'inet_ntoa.c' -a "${1}" != "-c" ; then 
  1064.   echo shar: Will not clobber existing file \"'inet_ntoa.c'\"
  1065. else
  1066. echo shar: Extracting \"'inet_ntoa.c'\" \(681 characters\)
  1067. sed "s/^X//" >'inet_ntoa.c' <<'END_OF_FILE'
  1068. X/*
  1069. X * Copyright (c) 1983 Regents of the University of California.
  1070. X * All rights reserved.  The Berkeley software License Agreement
  1071. X * specifies the terms and conditions for redistribution.
  1072. X */
  1073. X
  1074. X#if defined(LIBC_SCCS) && !defined(lint)
  1075. Xstatic char sccsid[] = "@(#)inet_ntoa.c    5.2 (Berkeley) 3/9/86";
  1076. X#endif LIBC_SCCS and not lint
  1077. X
  1078. X/*
  1079. X * Convert network-format internet address
  1080. X * to base 256 d.d.d.d representation.
  1081. X */
  1082. X#include <sys/types.h>
  1083. X#include <netinet/in.h>
  1084. X
  1085. Xchar *
  1086. Xinet_ntoa(in)
  1087. X    struct in_addr in;
  1088. X{
  1089. X    static char b[18];
  1090. X    register char *p;
  1091. X
  1092. X    p = (char *)∈
  1093. X#define    UC(b)    (((int)b)&0xff)
  1094. X    sprintf(b, "%d.%d.%d.%d", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3]));
  1095. X    return (b);
  1096. X}
  1097. END_OF_FILE
  1098. if test 681 -ne `wc -c <'inet_ntoa.c'`; then
  1099.     echo shar: \"'inet_ntoa.c'\" unpacked with wrong size!
  1100. fi
  1101. # end of 'inet_ntoa.c'
  1102. fi
  1103. if test -f 'mktemp.c' -a "${1}" != "-c" ; then 
  1104.   echo shar: Will not clobber existing file \"'mktemp.c'\"
  1105. else
  1106. echo shar: Extracting \"'mktemp.c'\" \(2486 characters\)
  1107. sed "s/^X//" >'mktemp.c' <<'END_OF_FILE'
  1108. X/*
  1109. X * Copyright (c) 1987 Regents of the University of California.
  1110. X * All rights reserved.
  1111. X *
  1112. X * Redistribution and use in source and binary forms are permitted
  1113. X * provided that the above copyright notice and this paragraph are
  1114. X * duplicated in all such forms and that any documentation,
  1115. X * advertising materials, and other materials related to such
  1116. X * distribution and use acknowledge that the software was developed
  1117. X * by the University of California, Berkeley.  The name of the
  1118. X * University may not be used to endorse or promote products derived
  1119. X * from this software without specific prior written permission.
  1120. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  1121. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  1122. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  1123. X */
  1124. X
  1125. X#if defined(LIBC_SCCS) && !defined(lint)
  1126. Xstatic char sccsid[] = "@(#)mktemp.c    5.7 (Berkeley) 6/27/88";
  1127. X#endif /* LIBC_SCCS and not lint */
  1128. X
  1129. X#include <sys/types.h>
  1130. X#include <sys/file.h>
  1131. X#include <sys/stat.h>
  1132. X#include <errno.h>
  1133. X#include <stdio.h>
  1134. X#include <ctype.h>
  1135. X
  1136. X#ifdef    SYSV
  1137. X#include <fcntl.h>
  1138. X#endif
  1139. X
  1140. X#define    YES    1
  1141. X#define    NO    0
  1142. X
  1143. Xmkstemp(as)
  1144. X    char    *as;
  1145. X{
  1146. X    int    fd;
  1147. X
  1148. X    return (_gettemp(as, &fd) ? fd : -1);
  1149. X}
  1150. X
  1151. Xchar *
  1152. Xmktemp(as)
  1153. X    char    *as;
  1154. X{
  1155. X    return(_gettemp(as, (int *)NULL) ? as : (char *)NULL);
  1156. X}
  1157. X
  1158. Xstatic
  1159. X_gettemp(as, doopen)
  1160. X    char    *as;
  1161. X    register int    *doopen;
  1162. X{
  1163. X    extern int    errno;
  1164. X    register char    *start, *trv;
  1165. X    struct stat    sbuf;
  1166. X    u_int    pid;
  1167. X
  1168. X    pid = getpid();
  1169. X
  1170. X    /* extra X's get set to 0's */
  1171. X    for (trv = as; *trv; ++trv);
  1172. X    while (*--trv == 'X') {
  1173. X        *trv = (pid % 10) + '0';
  1174. X        pid /= 10;
  1175. X    }
  1176. X
  1177. X    /*
  1178. X     * check for write permission on target directory; if you have
  1179. X     * six X's and you can't write the directory, this will run for
  1180. X     * a *very* long time.
  1181. X     */
  1182. X    for (start = ++trv; trv > as && *trv != '/'; --trv);
  1183. X    if (*trv == '/') {
  1184. X        *trv = '\0';
  1185. X        if (stat(as, &sbuf) || !(sbuf.st_mode & S_IFDIR))
  1186. X            return(NO);
  1187. X        *trv = '/';
  1188. X    }
  1189. X    else if (stat(".", &sbuf) == -1)
  1190. X        return(NO);
  1191. X
  1192. X    for (;;) {
  1193. X        if (doopen) {
  1194. X            if ((*doopen = open(as, O_CREAT|O_EXCL|O_RDWR, 0600)) >= 0)
  1195. X            return(YES);
  1196. X            if (errno != EEXIST)
  1197. X            return(NO);
  1198. X        }
  1199. X        else if (stat(as, &sbuf))
  1200. X            return(errno == ENOENT ? YES : NO);
  1201. X
  1202. X        /* tricky little algorithm for backward compatibility */
  1203. X        for (trv = start;;) {
  1204. X            if (!*trv)
  1205. X                return(NO);
  1206. X            if (*trv == 'z')
  1207. X                *trv++ = 'a';
  1208. X            else {
  1209. X                if (isdigit(*trv))
  1210. X                    *trv = 'a';
  1211. X                else
  1212. X                    ++*trv;
  1213. X                break;
  1214. X            }
  1215. X        }
  1216. X    }
  1217. X    /*NOTREACHED*/
  1218. X}
  1219. END_OF_FILE
  1220. if test 2486 -ne `wc -c <'mktemp.c'`; then
  1221.     echo shar: \"'mktemp.c'\" unpacked with wrong size!
  1222. fi
  1223. # end of 'mktemp.c'
  1224. fi
  1225. if test -f 'nap.c' -a "${1}" != "-c" ; then 
  1226.   echo shar: Will not clobber existing file \"'nap.c'\"
  1227. else
  1228. echo shar: Extracting \"'nap.c'\" \(457 characters\)
  1229. sed "s/^X//" >'nap.c' <<'END_OF_FILE'
  1230. X/*
  1231. X * nap - suspend execution for a short period
  1232. X *
  1233. X * Similar in function to sleep() except the argument is
  1234. X * specified in milliseconds.
  1235. X */
  1236. X
  1237. Xnap (milli)
  1238. Xunsigned int    milli;
  1239. X{
  1240. X    static int      fd = 0;
  1241. X    unsigned int    ticks;
  1242. X
  1243. X    if (fd == 0) {
  1244. X    fd = open ("/dev/nap", 0);
  1245. X    }
  1246. X
  1247. X    if (fd == -1) {
  1248. X    ticks = (milli * 0.001) + 1;
  1249. X    (void) sleep (ticks);
  1250. X    }
  1251. X    else {
  1252. X    ticks = (milli * 0.06) + 1;
  1253. X    (void) read (fd, (char *) 0, ticks);
  1254. X    }
  1255. X
  1256. X}
  1257. END_OF_FILE
  1258. if test 457 -ne `wc -c <'nap.c'`; then
  1259.     echo shar: \"'nap.c'\" unpacked with wrong size!
  1260. fi
  1261. # end of 'nap.c'
  1262. fi
  1263. if test -f 'rename.c' -a "${1}" != "-c" ; then 
  1264.   echo shar: Will not clobber existing file \"'rename.c'\"
  1265. else
  1266. echo shar: Extracting \"'rename.c'\" \(377 characters\)
  1267. sed "s/^X//" >'rename.c' <<'END_OF_FILE'
  1268. X/* rename.c -- file renaming routine for systems without rename(2)
  1269. X *
  1270. X * Written by reading the System V Interface Definition, not the code.
  1271. X *
  1272. X * Totally public domain.
  1273. X *
  1274. X */
  1275. X/* LINTLIBRARY */
  1276. X
  1277. Xint rename(from,to)
  1278. Xregister char *from, *to;
  1279. X{
  1280. X    (void) unlink(to);
  1281. X    if (link(from, to) < 0)
  1282. X    return(-1);
  1283. X
  1284. X    (void) unlink(from);
  1285. X    return(0);
  1286. X}
  1287. X
  1288. X/* rename.c ends here */
  1289. END_OF_FILE
  1290. if test 377 -ne `wc -c <'rename.c'`; then
  1291.     echo shar: \"'rename.c'\" unpacked with wrong size!
  1292. fi
  1293. # end of 'rename.c'
  1294. fi
  1295. if test -f 'rindex.c' -a "${1}" != "-c" ; then 
  1296.   echo shar: Will not clobber existing file \"'rindex.c'\"
  1297. else
  1298. echo shar: Extracting \"'rindex.c'\" \(1158 characters\)
  1299. sed "s/^X//" >'rindex.c' <<'END_OF_FILE'
  1300. X/*
  1301. X * Copyright (c) 1988 Regents of the University of California.
  1302. X * All rights reserved.
  1303. X *
  1304. X * Redistribution and use in source and binary forms are permitted
  1305. X * provided that the above copyright notice and this paragraph are
  1306. X * duplicated in all such forms and that any documentation,
  1307. X * advertising materials, and other materials related to such
  1308. X * distribution and use acknowledge that the software was developed
  1309. X * by the University of California, Berkeley.  The name of the
  1310. X * University may not be used to endorse or promote products derived
  1311. X * from this software without specific prior written permission.
  1312. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  1313. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  1314. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  1315. X */
  1316. X
  1317. X#if defined(LIBC_SCCS) && !defined(lint)
  1318. Xstatic char sccsid[] = "@(#)rindex.c    5.4 (Berkeley) 6/27/88";
  1319. X#endif /* LIBC_SCCS and not lint */
  1320. X
  1321. X#include <stdio.h>
  1322. X
  1323. Xchar *
  1324. Xrindex(p, ch)
  1325. X    register char *p, ch;
  1326. X{
  1327. X    register char *save;
  1328. X
  1329. X    for (save = NULL;; ++p) {
  1330. X        if (*p == ch)
  1331. X            save = p;
  1332. X        if (!*p)
  1333. X            return(save);
  1334. X    }
  1335. X    /* NOTREACHED */
  1336. X}
  1337. END_OF_FILE
  1338. if test 1158 -ne `wc -c <'rindex.c'`; then
  1339.     echo shar: \"'rindex.c'\" unpacked with wrong size!
  1340. fi
  1341. # end of 'rindex.c'
  1342. fi
  1343. if test -f 'rmdir.c' -a "${1}" != "-c" ; then 
  1344.   echo shar: Will not clobber existing file \"'rmdir.c'\"
  1345. else
  1346. echo shar: Extracting \"'rmdir.c'\" \(489 characters\)
  1347. sed "s/^X//" >'rmdir.c' <<'END_OF_FILE'
  1348. X/* rmdir.c -- remove a directory.
  1349. X *
  1350. X * Written by reading the System V Interface Definition, not the code.
  1351. X *
  1352. X * Totally public domain.
  1353. X *
  1354. X */
  1355. X/*LINTLIBRARY*/
  1356. X
  1357. Xint rmdir(dir)
  1358. Xchar *dir;
  1359. X{
  1360. X    extern char *malloc();
  1361. X    char *path = malloc(strlen(dir) + 25);
  1362. X    int status;
  1363. X
  1364. X    if (path == (char *)0)
  1365. X    status = -1;
  1366. X    else
  1367. X    {
  1368. X    (void) sprintf(path, "/bin/rmdir %s 2>/dev/null", dir);
  1369. X    status = system(path);
  1370. X    }
  1371. X    (void) free(path);
  1372. X    return(status);
  1373. X}
  1374. X
  1375. X/* rmdir.c ends here */
  1376. END_OF_FILE
  1377. if test 489 -ne `wc -c <'rmdir.c'`; then
  1378.     echo shar: \"'rmdir.c'\" unpacked with wrong size!
  1379. fi
  1380. # end of 'rmdir.c'
  1381. fi
  1382. if test -f 'setenv.c' -a "${1}" != "-c" ; then 
  1383.   echo shar: Will not clobber existing file \"'setenv.c'\"
  1384. else
  1385. echo shar: Extracting \"'setenv.c'\" \(395 characters\)
  1386. sed "s/^X//" >'setenv.c' <<'END_OF_FILE'
  1387. X#include <stdio.h>
  1388. X#include <malloc.h>
  1389. X#include <string.h>
  1390. X
  1391. Xsetenv (name, value)
  1392. Xchar           *name;
  1393. Xchar           *value;
  1394. X{
  1395. X    auto char      *buf;
  1396. X
  1397. X    buf = malloc (strlen (name) + strlen (value) + 2);
  1398. X    if (buf == NULL) {
  1399. X    fprintf (stderr, "Unable to allocate dynamic memory for setenv\n");
  1400. X    exit (1);
  1401. X    }
  1402. X
  1403. X    (void) sprintf (buf, "%s=%s", name, value);
  1404. X    (void) putenv (buf);
  1405. X
  1406. X}
  1407. END_OF_FILE
  1408. if test 395 -ne `wc -c <'setenv.c'`; then
  1409.     echo shar: \"'setenv.c'\" unpacked with wrong size!
  1410. fi
  1411. # end of 'setenv.c'
  1412. fi
  1413. if test -f 'setlinebuf.c' -a "${1}" != "-c" ; then 
  1414.   echo shar: Will not clobber existing file \"'setlinebuf.c'\"
  1415. else
  1416. echo shar: Extracting \"'setlinebuf.c'\" \(194 characters\)
  1417. sed "s/^X//" >'setlinebuf.c' <<'END_OF_FILE'
  1418. X#include <stdio.h>
  1419. X
  1420. Xextern char    *malloc ();
  1421. X
  1422. Xvoid
  1423. Xsetlinebuf (fp)
  1424. XFILE           *fp;
  1425. X{
  1426. X    char           *buf;
  1427. X
  1428. X    buf = malloc (BUFSIZ);
  1429. X
  1430. X    (void) setvbuf (fp, buf, _IOLBF, BUFSIZ);
  1431. X
  1432. X}
  1433. END_OF_FILE
  1434. if test 194 -ne `wc -c <'setlinebuf.c'`; then
  1435.     echo shar: \"'setlinebuf.c'\" unpacked with wrong size!
  1436. fi
  1437. # end of 'setlinebuf.c'
  1438. fi
  1439. if test -f 'sigsetmask.c' -a "${1}" != "-c" ; then 
  1440.   echo shar: Will not clobber existing file \"'sigsetmask.c'\"
  1441. else
  1442. echo shar: Extracting \"'sigsetmask.c'\" \(1302 characters\)
  1443. sed "s/^X//" >'sigsetmask.c' <<'END_OF_FILE'
  1444. X/*
  1445. X * Procedure: sigsetmask
  1446. X *
  1447. X * Function:
  1448. X * This is a very crude attempt at mimicing the BSD sigsetmask facility.  It
  1449. X * is not really all that close in functionality since the BSD sigsetmask
  1450. X * facility causes the specified signals to be "blocked" whereas this routine
  1451. X * is causing them to be "ignored".  There are most assuredly race conditions
  1452. X * in this code that I have chosen to totally ignore.
  1453. X * 
  1454. X * Despite all of that, this routine should suffice for most programs.
  1455. X *
  1456. X * Author: David H. Brierley
  1457. X *         dave@galaxia.newport.ri.us
  1458. X */
  1459. X
  1460. X#include <signal.h>
  1461. X
  1462. Xstatic int      current_mask = 0;
  1463. Xstatic int      (*func[NSIG]) ();
  1464. X
  1465. Xsigsetmask (mask)
  1466. Xint             mask;
  1467. X{
  1468. X    int             old_mask;
  1469. X    int             signo;
  1470. X
  1471. X    /*
  1472. X     * First, restore any signals I blocked before.
  1473. X     */
  1474. X    for (signo = 1; signo < NSIG; ++signo) {
  1475. X    if (current_mask & (1 << (signo - 1))) {
  1476. X        (void) signal (signo, func[signo]);
  1477. X    }
  1478. X    }
  1479. X
  1480. X    /*
  1481. X     * Save current mask as old mask for return value.
  1482. X     */
  1483. X    old_mask = current_mask;
  1484. X    current_mask = mask;
  1485. X
  1486. X    /*
  1487. X     * Block (ignore) all specified signals.
  1488. X     */
  1489. X    for (signo = 1; signo < NSIG; ++signo) {
  1490. X    if (current_mask & (1 << (signo - 1))) {
  1491. X        func[signo] = signal (signo, SIG_IGN);
  1492. X    }
  1493. X    }
  1494. X
  1495. X    return (old_mask);
  1496. X
  1497. X}
  1498. END_OF_FILE
  1499. if test 1302 -ne `wc -c <'sigsetmask.c'`; then
  1500.     echo shar: \"'sigsetmask.c'\" unpacked with wrong size!
  1501. fi
  1502. # end of 'sigsetmask.c'
  1503. fi
  1504. if test -f 'sigvec.c' -a "${1}" != "-c" ; then 
  1505.   echo shar: Will not clobber existing file \"'sigvec.c'\"
  1506. else
  1507. echo shar: Extracting \"'sigvec.c'\" \(271 characters\)
  1508. sed "s/^X//" >'sigvec.c' <<'END_OF_FILE'
  1509. X#include <sys/types.h>
  1510. X#include <sys/time.h>
  1511. X#include "sigvec.h"
  1512. X
  1513. Xsigvec(sig, vec, ovec)
  1514. Xint sig;
  1515. Xstruct sigvec *vec, *ovec;
  1516. X{
  1517. Xint (*hold)(), (*signal())();
  1518. X
  1519. X    hold = signal(sig, vec->sv_handler);
  1520. X    if (ovec)
  1521. X        ovec->sv_handler = signal(sig, vec->sv_handler);
  1522. X    return 0;
  1523. X}
  1524. END_OF_FILE
  1525. if test 271 -ne `wc -c <'sigvec.c'`; then
  1526.     echo shar: \"'sigvec.c'\" unpacked with wrong size!
  1527. fi
  1528. # end of 'sigvec.c'
  1529. fi
  1530. if test -f 'sigvec.h' -a "${1}" != "-c" ; then 
  1531.   echo shar: Will not clobber existing file \"'sigvec.h'\"
  1532. else
  1533. echo shar: Extracting \"'sigvec.h'\" \(1036 characters\)
  1534. sed "s/^X//" >'sigvec.h' <<'END_OF_FILE'
  1535. X/*
  1536. X * Signal vector "template" used in sigvec call.
  1537. X */
  1538. Xstruct    sigvec {
  1539. X    int    (*sv_handler)();    /* signal handler */
  1540. X    int    sv_mask;        /* signal mask to apply */
  1541. X    int    sv_flags;        /* see signal options below */
  1542. X};
  1543. X#define sv_onstack sv_flags    /* isn't compatibility wonderful! */
  1544. X
  1545. X/*
  1546. X * Structure used in sigstack call.
  1547. X */
  1548. Xstruct    sigstack {
  1549. X    char    *ss_sp;            /* signal stack pointer */
  1550. X    int    ss_onstack;        /* current status */
  1551. X};
  1552. X
  1553. X/*
  1554. X * Information pushed on stack when a signal is delivered.
  1555. X * This is used by the kernel to restore state following
  1556. X * execution of the signal handler.  It is also made available
  1557. X * to the handler to allow it to properly restore state if
  1558. X * a non-standard exit is performed.
  1559. X */
  1560. Xstruct    sigcontext {
  1561. X    int    sc_onstack;        /* sigstack state to restore */
  1562. X    int    sc_mask;        /* signal mask to restore */
  1563. X    int    sc_sp;            /* sp to restore */
  1564. X    int    sc_pc;            /* pc to retore */
  1565. X    int    sc_ps;            /* psl to restore */
  1566. X};
  1567. X
  1568. X/*
  1569. X * Macro for converting signal number to a mask suitable for sigblock().
  1570. X */
  1571. X#define sigmask(m)    (1 << ((m)-1))
  1572. END_OF_FILE
  1573. if test 1036 -ne `wc -c <'sigvec.h'`; then
  1574.     echo shar: \"'sigvec.h'\" unpacked with wrong size!
  1575. fi
  1576. # end of 'sigvec.h'
  1577. fi
  1578. if test -f 'statfs.c' -a "${1}" != "-c" ; then 
  1579.   echo shar: Will not clobber existing file \"'statfs.c'\"
  1580. else
  1581. echo shar: Extracting \"'statfs.c'\" \(4816 characters\)
  1582. sed "s/^X//" >'statfs.c' <<'END_OF_FILE'
  1583. X#include <stdio.h>
  1584. X#include <sys/types.h>
  1585. X#include <sys/stat.h>
  1586. X#include <sys/filsys.h>
  1587. X#include <sys/param.h>
  1588. X#include <sys/statfs.h>
  1589. X#include <mnttab.h>
  1590. X
  1591. X#define MNTTAB        "/etc/mnttab"
  1592. X#define INOPERBLK    (512 / sizeof (struct dinode))
  1593. X
  1594. X/*
  1595. X * table for holding info about mounted file systems
  1596. X */
  1597. Xstruct mtable {
  1598. X    char            m_device[16];
  1599. X    char            m_filsys[16];
  1600. X    dev_t           m_dev;
  1601. X};
  1602. X
  1603. X
  1604. X/* declare external routines */
  1605. Xextern void     exit ();
  1606. Xextern void     perror ();
  1607. Xextern long     lseek ();
  1608. X
  1609. Xstruct mtable   m_info[NMOUNT];
  1610. Xint             m_size = -1;
  1611. X
  1612. Xint
  1613. Xstatfs (FileSystem, sbuf, length, flag)
  1614. Xchar           *FileSystem;
  1615. Xstruct statfs  *sbuf;
  1616. Xint             length;
  1617. Xint             flag;
  1618. X{
  1619. X    int             m_index;
  1620. X    int             tot;
  1621. X    int             used;
  1622. X    int             avail;
  1623. X    double          pct;
  1624. X    struct filsys   fsys;
  1625. X    int             fd;
  1626. X    int             type;
  1627. X
  1628. X    /*
  1629. X     * read the mount table
  1630. X     */
  1631. X    if (m_size == -1) {
  1632. X    m_size = read_mtab (m_info);
  1633. X    }
  1634. X
  1635. X    /* sync 3 times on the console if you want me,     */
  1636. X    /* twice on the pipe if the answer is no.         */
  1637. X    sync ();
  1638. X    sync ();
  1639. X
  1640. X    m_index = fscheck (FileSystem, m_info, m_size);
  1641. X    if (m_index == -1) {
  1642. X    return (-1);
  1643. X    }
  1644. X
  1645. X    if ((fd = open (m_info[m_index].m_device)) == -1) {
  1646. X    perror ("df");
  1647. X    (void) printf ("%s: unable to open device\n", m_info[m_index].m_device);
  1648. X    return (-1);
  1649. X    }
  1650. X
  1651. X    /*
  1652. X     * Read and validate the super-block
  1653. X     */
  1654. X    if (lseek (fd, 512L, 0) == -1L) {
  1655. X    perror ("df");
  1656. X    (void) printf ("%s: unable to seek to super-block\n", m_info[m_index].m_device);
  1657. X    (void) close (fd);
  1658. X    return (-1);
  1659. X    }
  1660. X
  1661. X    if (read (fd, &fsys, sizeof (fsys)) != sizeof (fsys)) {
  1662. X    perror ("df");
  1663. X    (void) printf ("%s: i/o error reading super-block\n", m_info[m_index].m_device);
  1664. X    (void) close (fd);
  1665. X    return (-1);
  1666. X    }
  1667. X    (void) close (fd);
  1668. X
  1669. X    if (sbcheck (&fsys) == -1) {
  1670. X    (void) printf ("%s: invalid super-block\n", m_info[m_index].m_device);
  1671. X    return (-1);
  1672. X    }
  1673. X
  1674. X    type = Fs1b;
  1675. X    if (fsys.s_magic == FsMAGIC) {
  1676. X    type = fsys.s_type;
  1677. X    }
  1678. X
  1679. X    sbuf -> f_files = fsys.s_tinode;
  1680. X    switch (type) {
  1681. X    case Fs1b:
  1682. X    sbuf -> f_bsize = 512;
  1683. X    break;
  1684. X    case Fs2b:
  1685. X    sbuf -> f_bsize = 1024;
  1686. X    break;
  1687. X    default:
  1688. X    sbuf -> f_bsize = 512;
  1689. X    }
  1690. X
  1691. X    return (0);
  1692. X
  1693. X}
  1694. X
  1695. X/*
  1696. X * Routine: sbcheck
  1697. X *
  1698. X * Perform various sanity checks on the fields in the super block.
  1699. X * This is to prevent things like reading a non-filesystem format
  1700. X * floppy.
  1701. X *
  1702. X */
  1703. X
  1704. Xsbcheck (fsys)
  1705. Xstruct filsys  *fsys;
  1706. X{
  1707. X
  1708. X    if (fsys -> s_isize & 0x8000) {
  1709. X    return (-1);
  1710. X    }
  1711. X    if (fsys -> s_fsize < 0) {
  1712. X    return (-1);
  1713. X    }
  1714. X    if (fsys -> s_isize >= fsys -> s_fsize) {
  1715. X    return (-1);
  1716. X    }
  1717. X    if (fsys -> s_nfree > NICFREE) {
  1718. X    return (-1);
  1719. X    }
  1720. X    if (fsys -> s_ninode > NICINOD) {
  1721. X    return (-1);
  1722. X    }
  1723. X    if (fsys -> s_tfree >= fsys -> s_fsize) {
  1724. X    return (-1);
  1725. X    }
  1726. X    if (fsys -> s_tfree < 0) {
  1727. X    return (-1);
  1728. X    }
  1729. X    if (fsys -> s_tinode >= fsys -> s_fsize) {
  1730. X    return (-1);
  1731. X    }
  1732. X
  1733. X    return (0);
  1734. X
  1735. X}
  1736. X
  1737. X/* declare external routines */
  1738. Xextern void     exit ();
  1739. Xextern void     perror ();
  1740. Xextern long     lseek ();
  1741. X
  1742. X/*
  1743. X * Routine: read_mtab
  1744. X *
  1745. X * Read the mount table and extract info about each file
  1746. X * system.  The file system is also "stat"ed to extract
  1747. X * the device number.
  1748. X *
  1749. X */
  1750. X
  1751. Xread_mtab (info)
  1752. Xstruct mtable   info[];
  1753. X{
  1754. X    int             n;
  1755. X    int             fd;
  1756. X    struct mnttab   mtab;
  1757. X    struct stat     sbuf;
  1758. X
  1759. X#define    L_DEV        (sizeof(mtab.mt_dev))
  1760. X#define L_FILSYS    (sizeof(mtab.mt_filsys))
  1761. X
  1762. X    if ((fd = open (MNTTAB, 0)) == -1) {
  1763. X    perror ("df");
  1764. X    (void) printf ("Unable to open file %s\n", MNTTAB);
  1765. X    exit (1);
  1766. X    }
  1767. X
  1768. X    n = 0;
  1769. X    while (read (fd, &mtab, sizeof (mtab)) == sizeof (mtab)) {
  1770. X    (void) strcpy (info[n].m_device, "/dev/");
  1771. X    (void) strncat (info[n].m_device, mtab.mt_dev, L_DEV);
  1772. X    info[n].m_device[L_DEV] = '\0';
  1773. X    (void) strncpy (info[n].m_filsys, mtab.mt_filsys, L_FILSYS);
  1774. X    info[n].m_filsys[L_FILSYS] = '\0';
  1775. X    if (stat (info[n].m_device, &sbuf) == -1) {
  1776. X        continue;
  1777. X    }
  1778. X    info[n].m_dev = sbuf.st_rdev;
  1779. X    n++;
  1780. X    }
  1781. X
  1782. X    (void) close (fd);
  1783. X    return (n);
  1784. X
  1785. X}
  1786. X
  1787. X /*
  1788. X  * Routine: fscheck
  1789. X  * 
  1790. X  * Check to see if the specified path name is part of a mounted filesystem or
  1791. X  * is a special device file.  If so, print out the info.  If not, print out
  1792. X  * an error message.
  1793. X  * 
  1794. X  */
  1795. X
  1796. Xint
  1797. Xfscheck (DirName, m_info, m_size)
  1798. Xchar           *DirName;
  1799. Xstruct mtable   m_info[];
  1800. Xint             m_size;
  1801. X{
  1802. X    struct stat     sbuf;
  1803. X    int             n;
  1804. X
  1805. X    if (stat (DirName, &sbuf) == -1) {
  1806. X    perror ("df");
  1807. X    (void) printf ("%s: unable to access file\n", DirName);
  1808. X    return (-1);
  1809. X    }
  1810. X
  1811. X    for (n = 0; n < m_size; n++) {
  1812. X    if (sbuf.st_dev == m_info[n].m_dev) {
  1813. X        return (n);
  1814. X    }
  1815. X    }
  1816. X
  1817. X    (void) printf ("%s: mounted on unknown device\n", DirName);
  1818. X    return (-1);
  1819. X
  1820. X}
  1821. END_OF_FILE
  1822. if test 4816 -ne `wc -c <'statfs.c'`; then
  1823.     echo shar: \"'statfs.c'\" unpacked with wrong size!
  1824. fi
  1825. # end of 'statfs.c'
  1826. fi
  1827. if test -f 'strcasecmp.c' -a "${1}" != "-c" ; then 
  1828.   echo shar: Will not clobber existing file \"'strcasecmp.c'\"
  1829. else
  1830. echo shar: Extracting \"'strcasecmp.c'\" \(3767 characters\)
  1831. sed "s/^X//" >'strcasecmp.c' <<'END_OF_FILE'
  1832. X/*
  1833. X * Copyright (c) 1987 Regents of the University of California.
  1834. X * All rights reserved.
  1835. X *
  1836. X * Redistribution and use in source and binary forms are permitted
  1837. X * provided that the above copyright notice and this paragraph are
  1838. X * duplicated in all such forms and that any documentation,
  1839. X * advertising materials, and other materials related to such
  1840. X * distribution and use acknowledge that the software was developed
  1841. X * by the University of California, Berkeley.  The name of the
  1842. X * University may not be used to endorse or promote products derived
  1843. X * from this software without specific prior written permission.
  1844. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  1845. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  1846. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  1847. X */
  1848. X
  1849. X#if defined(LIBC_SCCS) && !defined(lint)
  1850. Xstatic char sccsid[] = "@(#)strcasecmp.c    5.6 (Berkeley) 6/27/88";
  1851. X#endif /* LIBC_SCCS and not lint */
  1852. X
  1853. X#include <sys/types.h>
  1854. X
  1855. X/*
  1856. X * This array is designed for mapping upper and lower case letter
  1857. X * together for a case independent comparison.  The mappings are
  1858. X * based upon ascii character sequences.
  1859. X */
  1860. Xstatic u_char charmap[] = {
  1861. X    '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
  1862. X    '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
  1863. X    '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
  1864. X    '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
  1865. X    '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
  1866. X    '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
  1867. X    '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
  1868. X    '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
  1869. X    '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  1870. X    '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  1871. X    '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  1872. X    '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
  1873. X    '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  1874. X    '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  1875. X    '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  1876. X    '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
  1877. X    '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
  1878. X    '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
  1879. X    '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
  1880. X    '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
  1881. X    '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
  1882. X    '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
  1883. X    '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
  1884. X    '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
  1885. X    '\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
  1886. X    '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
  1887. X    '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
  1888. X    '\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337',
  1889. X    '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
  1890. X    '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
  1891. X    '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
  1892. X    '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
  1893. X};
  1894. X
  1895. Xstrcasecmp(s1, s2)
  1896. X    char *s1, *s2;
  1897. X{
  1898. X    register u_char    *cm = charmap,
  1899. X            *us1 = (u_char *)s1,
  1900. X            *us2 = (u_char *)s2;
  1901. X
  1902. X    while (cm[*us1] == cm[*us2++])
  1903. X        if (*us1++ == '\0')
  1904. X            return(0);
  1905. X    return(cm[*us1] - cm[*--us2]);
  1906. X}
  1907. X
  1908. Xstrncasecmp(s1, s2, n)
  1909. X    char *s1, *s2;
  1910. X    register int n;
  1911. X{
  1912. X    register u_char    *cm = charmap,
  1913. X            *us1 = (u_char *)s1,
  1914. X            *us2 = (u_char *)s2;
  1915. X
  1916. X    while (--n >= 0 && cm[*us1] == cm[*us2++])
  1917. X        if (*us1++ == '\0')
  1918. X            return(0);
  1919. X    return(n < 0 ? 0 : cm[*us1] - cm[*--us2]);
  1920. X}
  1921. END_OF_FILE
  1922. if test 3767 -ne `wc -c <'strcasecmp.c'`; then
  1923.     echo shar: \"'strcasecmp.c'\" unpacked with wrong size!
  1924. fi
  1925. # end of 'strcasecmp.c'
  1926. fi
  1927. if test -f 'strdup.c' -a "${1}" != "-c" ; then 
  1928.   echo shar: Will not clobber existing file \"'strdup.c'\"
  1929. else
  1930. echo shar: Extracting \"'strdup.c'\" \(1410 characters\)
  1931. sed "s/^X//" >'strdup.c' <<'END_OF_FILE'
  1932. X/*
  1933. X * From: dag@persoft.com (Daniel A. Glasser)
  1934. X * Date: 18 Feb 91 15:41:59 GMT
  1935. X * Organization: Persoft, Inc.
  1936. X * 
  1937. X * A shorter version (assuming declarations of malloc(), strlen(), and strcpy(),
  1938. X * and a definition for NULL in some header file or preceeding this function
  1939. X * in the source file is:
  1940. X * 
  1941. X * I did add one more error check, and I used some shorthand (the assignment
  1942. X * within the if()) that some people may take exception to, however this is
  1943. X * just about as efficient (code wise) as you can get and still insure
  1944. X * robust behavior of the function.  If you drop the NULL check on the
  1945. X * original, you can have it even smaller but at the risk that the strcpy
  1946. X * or strlen call will die a horrible death.
  1947. X * -- 
  1948. X *         Daniel A. Glasser  |  Persoft, Inc.  |  dag@persoft.com
  1949. X *              "Their brains were small, and they died."
  1950. X */
  1951. X
  1952. X#include <string.h>
  1953. X#include <malloc.h>
  1954. X
  1955. X#ifndef    NULL
  1956. X# define NULL 0
  1957. X#endif
  1958. X
  1959. Xchar *strdup(orig)    /* Allocate a new copy of a string     */
  1960. Xchar *orig;        /* a pointer to the original string     */
  1961. X{
  1962. X    char *copy;    /* where we keep the copy.        */
  1963. X
  1964. X    if (orig == (char *)NULL)    /* If the original is NULL    */
  1965. X        return (char *)NULL;    /* so is the result.        */
  1966. X
  1967. X    if (copy = malloc((strlen(orig) + 1) * sizeof(char)))
  1968. X        strcpy(copy, orig);    /* if malloc() worked, copy the    */
  1969. X                    /* string data.            */
  1970. X    return copy;            /* return the result of malloc() */
  1971. X} /* end of strdup() */
  1972. END_OF_FILE
  1973. if test 1410 -ne `wc -c <'strdup.c'`; then
  1974.     echo shar: \"'strdup.c'\" unpacked with wrong size!
  1975. fi
  1976. # end of 'strdup.c'
  1977. fi
  1978. if test -f 'strerror.c' -a "${1}" != "-c" ; then 
  1979.   echo shar: Will not clobber existing file \"'strerror.c'\"
  1980. else
  1981. echo shar: Extracting \"'strerror.c'\" \(1152 characters\)
  1982. sed "s/^X//" >'strerror.c' <<'END_OF_FILE'
  1983. X/*
  1984. X * Copyright (c) 1989 The Regents of the University of California.
  1985. X * All rights reserved.
  1986. X *
  1987. X * Redistribution and use in source and binary forms are permitted
  1988. X * provided that the above copyright notice and this paragraph are
  1989. X * duplicated in all such forms and that any documentation,
  1990. X * advertising materials, and other materials related to such
  1991. X * distribution and use acknowledge that the software was developed
  1992. X * by the University of California, Berkeley.  The name of the
  1993. X * University may not be used to endorse or promote products derived
  1994. X * from this software without specific prior written permission.
  1995. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  1996. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  1997. X * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  1998. X */
  1999. X
  2000. X#include <string.h>
  2001. X
  2002. X/*
  2003. X * Return the error message corresponding to some error number.
  2004. X */
  2005. Xchar *
  2006. Xstrerror(e)
  2007. X    int e;
  2008. X{
  2009. X    extern int sys_nerr;
  2010. X    extern char *sys_errlist[];
  2011. X    static char unknown[30];
  2012. X
  2013. X    if ((unsigned)e < sys_nerr)
  2014. X        return (sys_errlist[e]);
  2015. X    (void) sprintf(unknown, "Unknown error: %d", e);
  2016. X    return (unknown);
  2017. X}
  2018. END_OF_FILE
  2019. if test 1152 -ne `wc -c <'strerror.c'`; then
  2020.     echo shar: \"'strerror.c'\" unpacked with wrong size!
  2021. fi
  2022. # end of 'strerror.c'
  2023. fi
  2024. if test -f 'writev.c' -a "${1}" != "-c" ; then 
  2025.   echo shar: Will not clobber existing file \"'writev.c'\"
  2026. else
  2027. echo shar: Extracting \"'writev.c'\" \(1183 characters\)
  2028. sed "s/^X//" >'writev.c' <<'END_OF_FILE'
  2029. X/*
  2030. X * writev emulation for System V
  2031. X *
  2032. X * Based on an implementation by Andy Poling.  This version modified to
  2033. X * collect all the data and then issue a single write to the output file.
  2034. X * This was done to more closely emulate BSD because the BSD version is
  2035. X * an actual system call.
  2036. X *
  2037. X * David H. Brierley, dave@galaxia.newport.ri.us
  2038. X */
  2039. X
  2040. X#include <sys/types.h>
  2041. X#include <sys/uio.h>
  2042. X
  2043. X#ifndef    NULL
  2044. X#define    NULL    0
  2045. X#endif
  2046. X
  2047. Xstatic char    *io_buffer = NULL;
  2048. Xstatic unsigned int io_max = 0;
  2049. Xextern char    *malloc ();
  2050. X
  2051. Xwritev (d, iov, iovcnt)
  2052. Xint             d;
  2053. Xstruct iovec   *iov;
  2054. Xint             iovcnt;
  2055. X{
  2056. X    int             i, r, sum;
  2057. X
  2058. X    sum = 0;
  2059. X    for (i = 0; i < iovcnt; ++i) {
  2060. X    sum += iov[i].iov_len;
  2061. X    }
  2062. X    if (sum > io_max) {
  2063. X    if (io_buffer != NULL) {
  2064. X        (void) free (io_buffer);
  2065. X    }
  2066. X    /* always round up to 1K boundary */
  2067. X    io_max = ((sum + 1023) / 1024) * 1024;
  2068. X    io_buffer = malloc (io_max);
  2069. X    if (io_buffer == NULL) {
  2070. X        perror ("writev");
  2071. X        return (-1);
  2072. X    }
  2073. X    }
  2074. X
  2075. X    sum = 0;
  2076. X    for (i = 0; i < iovcnt; i++) {
  2077. X    (void) memcpy (io_buffer + sum, iov[i].iov_base, iov[i].iov_len);
  2078. X    sum += iov[i].iov_len;
  2079. X    }
  2080. X
  2081. X    r = write (d, io_buffer, sum);
  2082. X    return (r);
  2083. X}
  2084. END_OF_FILE
  2085. if test 1183 -ne `wc -c <'writev.c'`; then
  2086.     echo shar: \"'writev.c'\" unpacked with wrong size!
  2087. fi
  2088. # end of 'writev.c'
  2089. fi
  2090. echo shar: End of archive 1 \(of 2\).
  2091. cp /dev/null ark1isdone
  2092. MISSING=""
  2093. for I in 1 2 ; do
  2094.     if test ! -f ark${I}isdone ; then
  2095.     MISSING="${MISSING} ${I}"
  2096.     fi
  2097. done
  2098. if test "${MISSING}" = "" ; then
  2099.     echo You have unpacked both archives.
  2100.     rm -f ark[1-9]isdone
  2101. else
  2102.     echo You still need to unpack the following archives:
  2103.     echo "        " ${MISSING}
  2104. fi
  2105. ##  End of shell archive.
  2106. exit 0
  2107.  
  2108. -- 
  2109. David H. Brierley
  2110. Home: dave@galaxia.newport.ri.us; Work: dhb@quahog.ssd.ray.com
  2111. Send comp.sources.3b1 submissions to comp-sources-3b1@galaxia.newport.ri.us
  2112. %% Can I be excused, my brain is full. **
  2113.