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