A little more verbose in marc dump.
[egate.git] / util / gip.c
1 /* Gateway kernel
2  * Europagate, 1995
3  *
4  * $Log: gip.c,v $
5  * Revision 1.2  1995/03/27 12:52:18  adam
6  * A little more verbose in marc dump.
7  *
8  * Revision 1.1  1995/03/27  08:24:58  adam
9  * New module gip: Gateway IPc module.
10  * New module gw-db: Gateway hash-db module (user information table).
11  *
12  */
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <assert.h>
17 #include <string.h>
18 #include <unistd.h>
19 #include <fcntl.h>
20 #include <sys/file.h>
21 #include <sys/stat.h>
22 #include <errno.h>
23
24 #include <gip.h>
25
26 GIP gip_initialize (const char *name)
27 {
28     GIP gip = malloc (sizeof(*gip));
29
30     if (!gip)
31         return NULL;
32     if (!(gip->name = malloc (strlen(name)+1)))
33     {
34         free (gip);
35         return NULL;
36     }
37     strcpy (gip->name, name);
38     gip->ret = mknod (gip->name, S_IFIFO|0666, 0);
39     gip->errno = errno;
40     return gip;
41 }
42
43 int gip_destroy (GIP gip)
44 {
45     assert (gip);
46
47     free (gip->name);
48     free (gip);
49     return 0;
50 }
51
52 int gip_infileno (GIP gip)
53 {
54     return gip->rfd;
55 }
56
57 int gip_errno (GIP gip)
58 {
59     return gip->errno;
60 }
61
62 int gip_read (GIP gip, char *buf, size_t count)
63 {
64     int r, no = 0;
65     while (no < count)
66     {
67         r = read (gip->rfd, buf+no, count-no);
68         if (r == -1)
69         {
70             gip->errno = errno;
71             return -1;
72         }
73         no += r;
74     }
75     return 0;
76 }
77
78 int gip_write (GIP gip, const char *buf, size_t count)
79 {
80     int r, no = 0;
81     while (no < count)
82     {
83         r = write (gip->wfd, buf+no, count-no);
84         if (r == -1)
85         {
86             gip->errno = errno;
87             return -1;
88         }
89         no += r;
90     }
91     return 0;
92 }
93
94 int gip_wline (GIP gip, const char *buf)
95 {
96     return gip_write (gip, buf, strlen(buf));
97 }
98