home *** CD-ROM | disk | FTP | other *** search
- /* hinttab.c -- functions for dealing with hinttab
- Copyright (C) 1989 David MacKenzie
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 1, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-
- #include "hint.h"
-
- static int fd = -1;
- static off_t offset;
-
- /* Open (rewind if already open) the hinttab for reading and writing. */
-
- void
- sethtent ()
- {
- if (fd == -1)
- {
- fd = open (HINTTAB, O_RDWR);
- if (fd == -1)
- pfatal (HINTTAB);
- }
- else
- {
- offset = 0;
- if (lseek (fd, offset, 0) == -1)
- pfatal (HINTTAB);
- }
- }
-
- /* Open the hinttab for appending. */
-
- void
- sethtapp ()
- {
- if (fd != -1)
- close (fd);
- fd = open (HINTTAB, O_WRONLY | O_APPEND);
- if (fd == -1)
- pfatal (HINTTAB);
- offset = 0;
- }
-
- /* Return a pointer to the hinttab entry matching `tty', or
- NULL if none do.
- The offset into hinttab will be left pointing to the start of the
- matching entry. */
-
- struct hinttab *
- gethttty (tty)
- char *tty;
- {
- static struct hinttab h;
-
- while (offset = lseek (fd, (off_t) 0, 1),
- read (fd, &h, sizeof (h)) == sizeof (h))
- {
- if (!strcmp (tty, h.h_tty))
- {
- /* Seek back to the start of the record. */
- lseek (fd, offset, 0);
- return &h;
- }
- }
- return NULL;
- }
-
- /* Update the current entry (the last one matched by gethttty). */
-
- void
- writehtent (h)
- struct hinttab *h;
- {
- if (write (fd, h, sizeof (*h)) != sizeof (*h))
- pfatal (HINTTAB);
- }
-
- /* Close the hinttab. */
-
- void
- endhtent ()
- {
- close (fd);
- fd = -1;
- }
-