386BSD 0.1 development
[unix-history] / usr / othersrc / contrib / isode / compat / general.c.org
CommitLineData
48435ab0
WJ
1/* general.c - general utilities for emulation of 4.2BSD */
2
3#ifndef lint
4static char *rcsid = "$Header: /f/osi/compat/RCS/general.c,v 7.3 91/02/22 09:15:10 mrose Interim $";
5#endif
6
7/*
8 * $Header: /f/osi/compat/RCS/general.c,v 7.3 91/02/22 09:15:10 mrose Interim $
9 *
10 *
11 * $Log: general.c,v $
12 * Revision 7.3 91/02/22 09:15:10 mrose
13 * Interim 6.8
14 *
15 * Revision 7.2 91/02/12 18:30:43 mrose
16 * update
17 *
18 * Revision 7.1 91/01/14 13:33:48 mrose
19 * loader
20 *
21 * Revision 7.0 89/11/23 21:23:00 mrose
22 * Release 6.0
23 *
24 */
25
26/*
27 * NOTICE
28 *
29 * Acquisition, use, and distribution of this module and related
30 * materials are subject to the restrictions of a license agreement.
31 * Consult the Preface in the User's Manual for the full terms of
32 * this agreement.
33 *
34 */
35
36
37/* LINTLIBRARY */
38
39#include <stdio.h>
40#include "general.h"
41#include "manifest.h"
42
43/* \f Berkeley UNIX: 4.2 */
44
45#ifdef BSD42
46
47/* Simply including "general.h" is sufficient. */
48
49int _general_stub () {};
50
51#endif
52
53/* \f non-Berkeley UNIX */
54
55#ifndef BSDLIBC
56
57#ifndef lint
58
59struct qelem {
60 struct qelem *q_forw;
61 struct qelem *q_back;
62 char q_data[1]; /* extensible */
63};
64
65
66insque (elem, pred)
67struct qelem *elem,
68 *pred;
69{
70 pred -> q_forw -> q_back = elem;
71 elem -> q_forw = pred -> q_forw;
72 elem -> q_back = pred;
73 pred -> q_forw = elem;
74}
75
76
77remque (elem)
78struct qelem *elem;
79{
80 elem -> q_forw -> q_back = elem -> q_back;
81 elem -> q_back -> q_forw = elem -> q_forw;
82}
83
84#endif
85#endif
86
87/* \f DUP2 */
88
89#ifndef BSD42
90#ifdef SYS5
91#include <fcntl.h>
92#endif
93
94
95extern int errno;
96
97
98int dup2 (d1, d2)
99register int d1,
100 d2;
101{
102 int d;
103
104 if (d1 == d2)
105 return OK;
106
107 (void) close (d2);
108#ifdef F_DUPFD
109 if ((d = fcntl (d1, F_DUPFD, d2)) == NOTOK)
110 return NOTOK;
111#else
112 if ((d = dup2_aux (d1, d2)) == NOTOK)
113 return NOTOK;
114#endif
115 if (d == d2)
116 return OK;
117
118 errno = 0;
119 return NOTOK;
120}
121
122
123#ifndef F_DUPFD
124dup2_aux (d1, d2)
125int d1,
126 d2;
127{
128 int fd,
129 result;
130
131 if ((fd = dup (d1)) == NOTOK || fd == d2)
132 return fd;
133
134 result = dup2_aux (d1, d2);
135
136 (void) close (fd);
137
138 return result;
139}
140#endif
141#endif
142
143/* \f BYTEORDER */
144
145#ifndef SWABLIB
146
147/* ROS and HP-UX don't seem to have these in libc.a */
148
149#undef ntohs
150u_short ntohs (netshort) u_short netshort; { return netshort; }
151
152#undef htons
153u_short htons (hostshort) u_short hostshort; { return hostshort; }
154
155#undef ntohl
156u_long ntohl (netlong) u_long netlong; { return netlong; }
157
158#undef htonl
159u_long htonl (hostlong) u_long hostlong; { return hostlong; }
160
161#endif