Lines 62-67
Link Here
|
62 |
#include <pwd.h> |
62 |
#include <pwd.h> |
63 |
#include <stdio.h> |
63 |
#include <stdio.h> |
64 |
#include <stdlib.h> |
64 |
#include <stdlib.h> |
|
|
65 |
#include <unistd.h> |
65 |
#include <time.h> |
66 |
#include <time.h> |
66 |
#include <pthread.h> |
67 |
#include <pthread.h> |
67 |
#include <netdb.h> |
68 |
#include <netdb.h> |
Lines 74-79
Link Here
|
74 |
|
75 |
|
75 |
/* exercises some reentrant libc-fucntions */ |
76 |
/* exercises some reentrant libc-fucntions */ |
76 |
|
77 |
|
|
|
78 |
#ifndef IRIX |
77 |
extern "C" |
79 |
extern "C" |
78 |
{ |
80 |
{ |
79 |
struct tm *localtime_r(const time_t *timep, struct tm *buffer); |
81 |
struct tm *localtime_r(const time_t *timep, struct tm *buffer); |
Lines 82-87
Link Here
|
82 |
struct hostent *gethostbyname_r(const char *name, struct hostent *result, |
84 |
struct hostent *gethostbyname_r(const char *name, struct hostent *result, |
83 |
char *buffer, int buflen, int *h_errnop); |
85 |
char *buffer, int buflen, int *h_errnop); |
84 |
} |
86 |
} |
|
|
87 |
#endif |
85 |
|
88 |
|
86 |
static int go; |
89 |
static int go; |
87 |
|
90 |
|
Lines 95-104
Link Here
|
95 |
struct passwd stpwd; |
98 |
struct passwd stpwd; |
96 |
struct hostent sthostent; |
99 |
struct hostent sthostent; |
97 |
int nerr; |
100 |
int nerr; |
|
|
101 |
#ifdef IRIX |
102 |
struct passwd *pwresult; |
103 |
#endif |
98 |
|
104 |
|
99 |
printf("starting thread 1 ...\n"); |
105 |
printf("starting thread 1 ...\n"); |
100 |
while (go) { |
106 |
while (go) { |
|
|
107 |
#ifdef IRIX |
108 |
getpwnam_r("hr", &stpwd, buffer, sizeof(buffer), &pwresult); |
109 |
#else |
101 |
getpwnam_r("hr", &stpwd, buffer, sizeof(buffer)); |
110 |
getpwnam_r("hr", &stpwd, buffer, sizeof(buffer)); |
|
|
111 |
#endif |
102 |
gethostbyname_r("blauwal", &sthostent, buffer, sizeof(buffer), &nerr); |
112 |
gethostbyname_r("blauwal", &sthostent, buffer, sizeof(buffer), &nerr); |
103 |
time(&nepoch); |
113 |
time(&nepoch); |
104 |
localtime_r(&nepoch, &sttm); |
114 |
localtime_r(&nepoch, &sttm); |
Lines 114-123
Link Here
|
114 |
struct passwd stpwd; |
124 |
struct passwd stpwd; |
115 |
struct hostent sthostent; |
125 |
struct hostent sthostent; |
116 |
int nerr; |
126 |
int nerr; |
|
|
127 |
#ifdef IRIX |
128 |
struct passwd *pwresult; |
129 |
#endif |
117 |
|
130 |
|
118 |
printf("starting thread 2 ...\n"); |
131 |
printf("starting thread 2 ...\n"); |
119 |
while(go) { |
132 |
while(go) { |
|
|
133 |
#ifdef IRIX |
134 |
getpwnam_r("hr", &stpwd, buffer, sizeof(buffer), &pwresult); |
135 |
#else |
120 |
getpwnam_r("mh", &stpwd, buffer, sizeof(buffer)); |
136 |
getpwnam_r("mh", &stpwd, buffer, sizeof(buffer)); |
|
|
137 |
#endif |
121 |
gethostbyname_r("hr-1242", &sthostent, buffer, sizeof(buffer), &nerr); |
138 |
gethostbyname_r("hr-1242", &sthostent, buffer, sizeof(buffer), &nerr); |
122 |
time(&nepoch); |
139 |
time(&nepoch); |
123 |
localtime_r(&nepoch, &sttm); |
140 |
localtime_r(&nepoch, &sttm); |
Lines 150-156
Link Here
|
150 |
|
167 |
|
151 |
pwd = (struct passwd*)malloc(sizeof(struct passwd)); |
168 |
pwd = (struct passwd*)malloc(sizeof(struct passwd)); |
152 |
|
169 |
|
|
|
170 |
#ifdef IRIX |
171 |
getpwnam_r("hr", pwd, buffer, sizeof(buffer), &pres1); |
172 |
#else |
153 |
pres1 = getpwnam_r("hr", pwd, buffer, sizeof(buffer)); |
173 |
pres1 = getpwnam_r("hr", pwd, buffer, sizeof(buffer)); |
|
|
174 |
#endif |
154 |
|
175 |
|
155 |
sleep(3); |
176 |
sleep(3); |
156 |
|
177 |
|
Lines 207-223
Link Here
|
207 |
printf("Day of week: %d\n", ptm->tm_wday); |
228 |
printf("Day of week: %d\n", ptm->tm_wday); |
208 |
printf("Day in the year: %d\n", ptm->tm_yday); |
229 |
printf("Day in the year: %d\n", ptm->tm_yday); |
209 |
printf("Daylight saving time: %d\n", ptm->tm_isdst); |
230 |
printf("Daylight saving time: %d\n", ptm->tm_isdst); |
|
|
231 |
#ifdef IRIX |
232 |
tzset(); |
233 |
printf("Timezone: %s\n", tzname[1]); |
234 |
#else |
235 |
|
210 |
#ifdef NETBSD |
236 |
#ifdef NETBSD |
211 |
printf("Timezone: %s\n", ptm->tm_zone); |
237 |
printf("Timezone: %s\n", ptm->tm_zone); |
212 |
#else |
238 |
#else |
213 |
printf("Timezone: %s\n", ptm->tm_name); |
239 |
printf("Timezone: %s\n", ptm->tm_name); |
214 |
#endif |
240 |
#endif |
215 |
|
241 |
|
|
|
242 |
#endif |
243 |
|
216 |
free(ptm); |
244 |
free(ptm); |
217 |
|
245 |
|
218 |
phostent = (struct hostent*)malloc(sizeof(struct hostent)); |
246 |
phostent = (struct hostent*)malloc(sizeof(struct hostent)); |
219 |
|
247 |
|
220 |
pres3 = gethostbyname_r("blauwal", phostent, buffer, sizeof(buffer), h_errno); |
248 |
pres3 = gethostbyname_r("blauwal", phostent, buffer, sizeof(buffer), &h_errno); |
221 |
|
249 |
|
222 |
if (pres3) { |
250 |
if (pres3) { |
223 |
printf("Official Hostname: %s\n", phostent->h_name); |
251 |
printf("Official Hostname: %s\n", phostent->h_name); |
Lines 234-240
Link Here
|
234 |
|
262 |
|
235 |
/* test boundary conditions */ |
263 |
/* test boundary conditions */ |
236 |
char smallbuf[23]; /* buffer to small */ |
264 |
char smallbuf[23]; /* buffer to small */ |
237 |
pres3 = gethostbyname_r("blauwal", phostent, smallbuf, sizeof(smallbuf), h_errno); |
265 |
pres3 = gethostbyname_r("blauwal", phostent, smallbuf, sizeof(smallbuf), &h_errno); |
238 |
if (!pres3) { |
266 |
if (!pres3) { |
239 |
perror("Expect ERANGE"); |
267 |
perror("Expect ERANGE"); |
240 |
} |
268 |
} |