Bug fix.
[egate.git] / util / gipc.c
1 /* Gateway kernel
2  * Europagate, 1995
3  *
4  * $Log: gipc.c,v $
5  * Revision 1.2  1995/03/28 08:03:46  adam
6  * Non-blocking open used when sync is set.
7  *
8  * Revision 1.1  1995/03/27  08:24:59  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
21 #include <gip.h>
22
23 GIP gipc_initialize (const char *name)
24 {
25     return gip_initialize (name);
26 }
27
28 int gipc_destroy (GIP gip)
29 {
30     return gip_destroy (gip);
31 }
32
33 int gipc_open (GIP gip, const char *server, int sync)
34 {
35     if (sync) 
36     {
37         gip->rfd = open (gip->name, O_RDONLY);
38         gip->wfd = open (server, O_WRONLY);
39     }
40     else
41     {
42         gip->wfd = open (server, O_WRONLY|O_NONBLOCK);
43         gip->rfd = open (gip->name, O_RDONLY|O_NONBLOCK);
44     }
45     if (gip->rfd == -1)
46         return -1;
47     if (gip->wfd == -1)
48         return -2;
49     fcntl (gip->wfd, F_SETFL, ~(O_NONBLOCK|O_APPEND));
50     fcntl (gip->rfd, F_SETFL, ~(O_NONBLOCK|O_APPEND));
51     return 0;
52 }
53
54 int gipc_close (GIP gip)
55 {
56     if (gip->rfd != -1)
57         close (gip->rfd);
58     if (gip->wfd != -1)
59         close (gip->wfd);
60     return 0;
61 }