This file is indexed.

/usr/lib/eso-midas/17FEB/test/os/atestosx.c is in eso-midas-testdata 17.02pl1.2-2build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
/*===========================================================================
  Copyright (C) 1995-2005 European Southern Observatory (ESO)
 
  This program is free software; you can redistribute it and/or 
  modify it under the terms of the GNU General Public License as 
  published by the Free Software Foundation; either version 2 of 
  the License, or (at your option) any later version.
 
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
 
  You should have received a copy of the GNU General Public 
  License along with this program; if not, write to the Free 
  Software Foundation, Inc., 675 Massachusetts Ave, Cambridge, 
  MA 02139, USA.
 
  Correspondence concerning ESO-MIDAS should be addressed as follows:
	Internet e-mail: midas@eso.org
	Postal address: European Southern Observatory
			Data Management Division 
			Karl-Schwarzschild-Strasse 2
			D 85748 Garching bei Muenchen 
			GERMANY
===========================================================================*/

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.TYPE        Module
.NAME        atestosx.c
.LANGUAGE    C
.AUTHOR      Carlos Guirao. IPG-ESO Garching
.CATEGORY    Tests of host operating system interfaces. 
.COMMENTS    Automatic osx test. 
	     This test exercises the functions of the module "osx".
	
.REMARKS     A hanged condition has been detected for this test. It happens
	     when a procces is waiting for data to come from a socket, and
	     the connection is already stablished with a sender. If the
	     sender, for any reason, denies the data, the procces will hang
	     forever (or CTRL-C). SIGALRM does not work for this porpose
	     because the system call "read" ignores it when there is a 
	     stablished connection.
.ENVIRONment UNIX

.VERSION 1.1 05-Jul-1990   Implementation     C. Guirao
051021		last modif

------------------------------------------------------------*/

#include <stdio.h>
#include <errno.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <osparms.h>

#ifndef S_IFSOCK		/* defined in stat.h if Unix domain sockets */
  static char socket_name[] = "00"; 	/* for PC/SCO without local sockets */
# define OSX_OPEN_MODE NETW
#else
  static char socket_name[] = "/tmp/mtape";
# define OSX_OPEN_MODE LOCAL
#endif

#define LOWER 0
#define UPPER 1

#define PATTERNA '0'
#define PATTERNB 'a'
#define PATTERNC 'B'
#define PATTERND 'b'

char *osmsg();

#define PERROR { printf("\tERROR: %s\n",osmsg()); ospexit(1); }
#define PRINTF(string) { fflush(stdout); printf(string); fflush(stdout); sleep(1); }

#define SIZEBUF 1024
char *buf;
int sizebuf;

void timeout(k)
int  k;
{
	printf("(TIMEOUT)\n");
	exit(-1);
}

static int readn(fd, ptr, nbytes) 
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.PURPOSE Read "n" bytest from a descriptor. Use in place of 
	 read() when fd is a stream socket
.RETURNS If succesful, the number of bytes actaully read is 
	 returned. Otherwise, a -1 is returned.
.REMARKS System dependencies:
 -- UNIX: read(2)
------------------------------------------------------------*/
register int fd;
register char *ptr;
register int nbytes;
{
	int nleft, nread;
	int st;
	
	nleft = nbytes;
	while (nleft > 0) {
		/*
		if ( (st = osxinfo(fd,0,0)) == -1) PERROR
        	if (st == NODATA) break;
		*/
		nread = osxread(fd, ptr, nleft);
		if (nread < 0)		/* error, return < 0 */
			return(nread);
		
		nleft -= nread;
		ptr += nread;
	}
	return(nbytes - nleft);		/* return >= 0 */
}


main(argc,argv)
int argc;
int **argv;
{

	char input[80], name[80], *pname;
	int fdn, fd;
	int nbytes;
	static char *channame[2];
	static struct stat statbuf;
	int childpid;
	int st;

	channame[1]="localhost";
	signal(SIGALRM,timeout);

	printf("**********************************************\n");
	printf("****** AUTOMATIC TEST FOR OSX INTERFACE ******\n");
	printf("****** LOCAL MODE. USING SOCKETS.       ******\n");
	printf("**********************************************\n\n");

	printf("Deleting socket files: %s if existing... ", 
		socket_name);
	if (stat(socket_name,&statbuf) == 0 )
		if (unlink(socket_name) < 0)  PERROR
	PRINTF("OK\n");

	sizebuf=SIZEBUF;
	printf("Allocating memory for buffers...");
	if ( (buf = (char *)malloc((size_t)(sizebuf+1))) == (char *)0)  PERROR
	else 	printf("OK\n");

	/* First step: open & close mode*/
	printf("\n************** Testing open & close\n");

	printf("Opening a normal file.... ");
	if ( (fdn = open(socket_name,O_CREAT,S_IREAD|S_IWRITE)) < 0) PERROR
	else	PRINTF("OK\n");

	printf("Opening a socket in READ mode, over a normal file.... ");
	channame[0]=socket_name;
	if ( (fd = osxopen(channame,LOCAL|IPC_READ)) != -1) {
		printf("ERROR: Return code != -1\n");
		osxclose(fd);
		ospexit(1);
		}
	else	PRINTF("OK\n");

	printf("Opening a socket in WRITE mode, over a normal file.... ");
	channame[0]=socket_name;
	if ( (fd = osxopen(channame,LOCAL|IPC_WRITE)) != -1) {
		printf("ERROR: Return code != -1\n");
		osxclose(fd);
		ospexit(1);
		}
	else	PRINTF("OK\n");

	printf("Closing and unlinking the normal file.... ");
	if ( close(fdn) < 0) PERROR 
	if (unlink(socket_name) < 0) PERROR
	PRINTF("OK\n");

	printf("\nOpening a socket in READ mode.... ");
	channame[0]=socket_name;
	if ( (fd = osxopen(channame,OSX_OPEN_MODE|IPC_READ)) == -1) PERROR
	else	PRINTF("OK\n");

	printf("Reading status from socket.... ");
	if ( (st = osxinfo(fd,0,0)) == -1) PERROR
        if (st == NOCONN) { PRINTF("OK\n"); }
	else printf("ERROR: Return code != %d\n",NOCONN);

	printf("Closing the socket in READ mode.... ");
	if ( osxclose(fd) == -1) PERROR
	else	PRINTF("OK\n");

	printf("\nTrying to open a socket in WRITE mode.... ");
	channame[0]=socket_name;
	if ( (fd = osxopen(channame,OSX_OPEN_MODE|IPC_WRITE)) != -1) {
		printf("ERROR: Return code != -1\n");
		osxclose(fd);
		ospexit(1);
		}
	else	PRINTF("OK\n");

	printf("\nOpening a socket (once).... ");
	channame[0]=socket_name;
	if ( (fd = osxopen(channame,OSX_OPEN_MODE|IPC_READ)) == -1) PERROR
	else	PRINTF("OK\n");

	/* PC/SCO with NETW socket returns -1 Address already in use 
	printf("Trying to open the same socket mode (twice).... ");
	channame[0]=socket_name;
	if ( (fd = osxopen(channame,OSX_OPEN_MODE|IPC_READ)) == -1) PERROR
	else	PRINTF("OK\n");
	*/

	printf("Closing the socket (once).... ");
	if ( osxclose(fd) == -1) PERROR
	else	PRINTF("OK\n");

	printf("Trying to close the same socket (twice).... ");
	if ( osxclose(fd) != -1) {
		PRINTF("ERROR: Return code != -1\n");
		ospexit(1);
		}
	else	PRINTF("OK\n");

	printf("\nOpening a socket in READ mode.... ");
	channame[0]=socket_name;
	if ( (fd = osxopen(channame,OSX_OPEN_MODE|IPC_READ)) == -1) PERROR
	else	PRINTF("OK\n");

	printf("Trying to read something... ");
	fflush(stdout);
	alarm(5);
	if ( osxread(fd,buf,1) != -1) {
		PRINTF("ERROR: Return code != -1\n");
		ospexit(1);
		}
	else	PRINTF("OK\n");
	alarm(0);

	printf("Trying to write something... ");
	if ( osxwrite(fd,buf,1) != -1) {
		PRINTF("ERROR: Return code != -1n");
		ospexit(1);
		}
	else	PRINTF("OK\n");

	printf("Closing the socket in READ mode.... ");
	if ( osxclose(fd) == -1) PERROR
	else	PRINTF("OK\n");
	
	printf("\nDoing a fork for server & client \n");
	
	if ( (childpid = fork()) < 0) PERROR
	else if (childpid == 0) {
		child_task();
		ospexit(0);
		}

	father_task();
	printf("**********************************************\n");
	printf("****** END OF AUTOMATIC TEST FOR OSX    ******\n");
	printf("****** LOCAL MODE. USING SOCKETS.       ******\n");
	printf("**********************************************\n\n");
}

father_task()
{
	int fd;
	int nbytes;
	char *channame[2];

	/* This is the father procces */
	printf("I am the father.\n");
	channame[0]=socket_name;
	channame[1]="localhost";

	printf("\n************** Using client ---> server transfer\n");
	if ( (fd = osxopen(channame,OSX_OPEN_MODE|IPC_READ)) == -1) {
		printf("Open socket in read mode... FAILED.\n");
		PERROR
		}
	else	printf("Open socket in read mode... OK\n");

	PRINTF("Waiting connection from client\n");
	alarm(10);
	while( osxinfo(fd,0,0) == NOCONN ) ;
	PRINTF("Connection from client... OK\n");
	alarm(0);

	if ( (nbytes = testread(fd,buf,SIZEBUF,PATTERNA,LOWER)) != SIZEBUF) {
		PRINTF("Reading pattern A in socket... FAILED.\n");
		if (nbytes != -1) 
			printf("\tError: Only %d bytes read !!!\n",nbytes);
		ospexit(1);
		}
	else	PRINTF("Reading pattern A in socket... OK\n");

	if ( (nbytes = testread(fd,buf,SIZEBUF,PATTERNB,LOWER)) != SIZEBUF) {
		PRINTF("Reading pattern B in socket... FAILED.\n");
		if (nbytes != -1) 
			printf("\tError: Only %d bytes read !!!\n",nbytes);
		ospexit(1);
		}
	else	PRINTF("Reading pattern B in socket... OK\n");

	if ( (nbytes=testread(fd,buf,SIZEBUF/2,PATTERNC,LOWER)) != SIZEBUF/2) {
		PRINTF("Reading (1/2) pattern C in socket... FAILED.\n");
		if (nbytes != -1)
			printf("\tError: Only %d bytes read !!!\n",nbytes);
		ospexit(1);
		}
	else	PRINTF("Reading pattern C (1/2) in socket... OK\n");

	if ( (nbytes=testread(fd,buf,SIZEBUF/2,PATTERNC,LOWER)) != SIZEBUF/2) {
		PRINTF("Reading (2/2) pattern C in socket... FAILED.\n");
		if (nbytes != -1)
			printf("\tError: Only %d bytes read !!!\n",nbytes);
		ospexit(1);
		}
	else	PRINTF("Reading pattern C (2/2) in socket... OK\n");

	if ((nbytes=testwrite(fd,buf,SIZEBUF,PATTERNA,LOWER)) != SIZEBUF) {
		printf("Writting pattern A in socket... FAILED.\n");
		if (nbytes != -1)
			printf("\tError: only %d bytes written!!!\n",nbytes);
		ospexit(1);
		}
	else	printf("Writting pattern A in socket... OK\n");

        alarm(10);
        if ( (nbytes = osxread(fd,buf,SIZEBUF)) != 0) {
                PRINTF("Reading EOF in socket... FAILED.\n");
                if (nbytes != -1)
                        printf("%d bytes read !!!\n",nbytes);
                else    PERROR
                ospexit(1);
                }
        else    PRINTF("Reading EOF in socket... OK\n");
        alarm(0);

	printf("\n************** Using server ---> client transfer\n");

	PRINTF("Waiting connection from client\n");
	alarm(10);
	while( osxinfo(fd,0,0) == NOCONN ) ;
	PRINTF("Connection from client... OK\n");
	alarm(0);

	if ((nbytes=testwrite(fd,buf,SIZEBUF/2,PATTERNA,LOWER)) != SIZEBUF/2) {
		printf("Writting pattern A (1/2) in socket... FAILED.\n");
		if (nbytes != -1)
			printf("\tError: only %d bytes written!!!\n",nbytes);
		ospexit(1);
		}
	else	printf("Writting pattern A (1/2) in socket... OK\n");

	if ((nbytes=testwrite(fd,buf,SIZEBUF/2,PATTERNA,LOWER)) != SIZEBUF/2) {
		printf("Writting pattern A (2/2) in socket... FAILED.\n");
		if (nbytes != -1)
			printf("\tError: only %d bytes written!!!\n",nbytes);
		ospexit(1);
		}
	else	printf("Writting pattern A (2/2) in socket... OK\n");

	if ((nbytes=testwrite(fd,buf,SIZEBUF,PATTERNB,LOWER)) != SIZEBUF) {
		printf("Writting pattern B in socket... FAILED.\n");
		if (nbytes != -1)
			printf("\tError: only %d bytes written!!!\n",nbytes);
		ospexit(1);
		}
	else	printf("Writting pattern B in socket... OK\n");

	if ((nbytes=testwrite(fd,buf,SIZEBUF,PATTERNC,LOWER)) != SIZEBUF) {
		printf("Writting pattern C in socket... FAILED.\n");
		if (nbytes != -1)
			printf("\tError: only %d bytes written!!!\n",nbytes);
		ospexit(1);
		}
	else	printf("Writting pattern C in socket... OK\n");

        alarm(10);
        if ( (nbytes = osxread(fd,buf,SIZEBUF)) != 0) {
                PRINTF("Reading EOF in socket... FAILED.\n");
                if (nbytes != -1)
                        printf("%d bytes read !!!\n",nbytes);
                else    PERROR
                ospexit(1);
                }
        else    PRINTF("Reading EOF in socket... OK\n");
        alarm(0);

	printf("\n************** Using server <--> client transfer\n");
	
	PRINTF("Waiting connection from client\n");
	alarm(10);
	while (osxinfo(fd,0,0) == NOCONN) ;
	PRINTF("Connection from client... OK\n");
        alarm(0);

	if ((nbytes=testwrite(fd,buf,SIZEBUF,PATTERNB,UPPER)) != SIZEBUF) {
		printf("Writting pattern B in socket... FAILED.\n");
		if (nbytes != -1) 
			printf("\tError: only %d bytes written!!!\n",nbytes);
		ospexit(1);
		}
	else	printf("Writting pattern B in socket... OK\n");

	if ( (nbytes=testread(fd,buf,SIZEBUF,PATTERNC,LOWER)) != SIZEBUF) {
		PRINTF("Reading pattern C in socket... FAILED.\n");
		if (nbytes != -1)
			printf("\tError: Only %d bytes read !!!\n",nbytes);
		ospexit(1);
		}
	else	PRINTF("Reading pattern C in socket... OK\n");

	if ( (nbytes=testread(fd,buf,SIZEBUF,PATTERNA,LOWER)) != SIZEBUF) {
		PRINTF("Reading pattern A in socket... FAILED.\n");
		if (nbytes != -1)
			printf("\tError: Only %d bytes read !!!\n",nbytes);
		ospexit(1);
		}
	else	PRINTF("Reading pattern A in socket... OK\n");

	if ((nbytes=testwrite(fd,buf,SIZEBUF,PATTERNC,UPPER)) != SIZEBUF) {
		printf("Writting pattern C in socket... FAILED.\n");
		if (nbytes != -1) 
			printf("\tError: only %d bytes written!!!\n",nbytes);
		ospexit(1);
		}
	else	printf("Writting pattern C in socket... OK\n");

        alarm(10);
        if ( (nbytes = osxread(fd,buf,SIZEBUF)) != 0) {
                PRINTF("Reading EOF in socket... FAILED.\n");
                if (nbytes != -1)
                        printf("%d bytes read !!!\n",nbytes);
                else    PERROR
                ospexit(1);
                }
        else    PRINTF("Reading EOF in socket... OK\n");
        alarm(0);

	if ( osxclose(fd) == -1) {
		printf("Closing socket write mode... FAILED.\n");
		PERROR
		}
	printf("Closing socket write mode... OK\n\n");
	sleep(2);

	/* Wait for child to finish */
	printf("****** Waiting for child proccess to die\n");
	wait(0);
	printf("****** End of father proccess\n");
}

child_task()
{
	int fd;
	int nbytes;
	char *channame[2];

	printf("I AM THE CHILD.\n");
	channame[0]=socket_name;
	channame[1]="localhost";

	alarm(10);
	while ( (fd = osxopen(channame,OSX_OPEN_MODE|IPC_WRITE)) == -1) ;
	alarm(0);
	printf("OPEN SOCKET IN WRITE MODE... OK\n");

	if ( (nbytes = testwrite(fd,buf,SIZEBUF,PATTERNA,UPPER)) != SIZEBUF) {
		printf("WRITING PATTERN A IN SOCKET... FAILED.\n");
		if (nbytes != -1)
			printf("\tERROR: ONLY %d BYTES WRITTEN!!!\n",nbytes);
		ospexit(1);
	}
	else	printf("WRITING PATTERN A IN SOCKET... OK\n");
	
	if ( (nbytes = testwrite(fd,buf,SIZEBUF,PATTERNB,UPPER)) != SIZEBUF) {
		printf("WRITING PATTERN B IN SOCKET... FAILED.\n");
		if (nbytes != -1) 
			printf("\tERROR: ONLY %d BYTES WRITTEN!!!\n",nbytes);
		ospexit(1);
	}
	else	printf("WRITING PATTERN B IN SOCKET... OK\n");

	if ( (nbytes = testwrite(fd,buf,SIZEBUF,PATTERNC,UPPER)) != SIZEBUF) {
		printf("WRITING PATTERN C IN SOCKET... FAILED.\n");
		if (nbytes != -1) 
			printf("\tERROR: ONLY %d BYTES WRITTEN!!!\n",nbytes);
		ospexit(1);
		}
	else	printf("WRITING PATTERN C IN SOCKET... OK\n");

	if ( (nbytes = testread(fd,buf,SIZEBUF,PATTERNA,UPPER)) != SIZEBUF) {
		PRINTF("READING PATTERN A IN SOCKET... FAILED.\n");
		if (nbytes != -1) 
			printf("\tERROR: ONLY %d BYTES READ !!!\n",nbytes);
		ospexit(1);
		}
	else	PRINTF("READING PATTERN A IN SOCKET... OK\n");

	if ( osxclose(fd) == -1) {
		printf("CLOSING THE SOCKET WRITE MODE ... FAILED.\n");
		PERROR
		}
	printf("CLOSING THE SOCKET WRITE MODE... OK\n");

	alarm(10);
	while ( (fd = osxopen(channame,OSX_OPEN_MODE|IPC_WRITE)) == -1) ;
	printf("OPEN SOCKET IN WRITE MODE... OK\n");
	alarm(0);

	if ( (nbytes = testread(fd,buf,SIZEBUF,PATTERNA,UPPER)) != SIZEBUF) {
		PRINTF("READING PATTERN A IN SOCKET... FAILED.\n");
		if (nbytes != -1) 
			printf("\tERROR: ONLY %d BYTES READ !!!\n",nbytes);
		ospexit(1);
		}
	else	PRINTF("READING PATTERN A IN SOCKET... OK\n");

	if ( (nbytes = testread(fd,buf,SIZEBUF,PATTERNB,UPPER)) != SIZEBUF) {
		PRINTF("READING PATTERN B IN SOCKET... FAILED.\n");
		if (nbytes != -1) 
			printf("\tERROR: ONLY %d BYTES READ !!!\n",nbytes);
		ospexit(1);
		}
	else	PRINTF("READING PATTERN B IN SOCKET... OK\n");

	if ( (nbytes = testread(fd,buf,SIZEBUF,PATTERNC,UPPER)) != SIZEBUF) {
		PRINTF("READING PATTERN C IN SOCKET... FAILED.\n");
		if (nbytes != -1) 
			printf("\tERROR: ONLY %d BYTES READ !!!\n",nbytes);
		ospexit(1);
		}
	else	PRINTF("READING PATTERN C IN SOCKET... OK\n");

	if ( osxclose(fd) == -1) {
		printf("CLOSING THE SOCKET WRITE MODE ... FAILED.\n");
		PERROR
		}
	printf("CLOSING THE SOCKET WRITE MODE... OK\n");

	/*
	alarm(10);
	PRINTF("WAITING DISCONNECTION FROM SERVER... ");
	if ( (fd = osxopen(channame,OSX_OPEN_MODE|IPC_WRITE)) == -1) PERROR
	while( osxread(fd,buf,1) != -1 ) ;
	PRINTF("OK\n");
	alarm(0);
	*/

	sleep(2);
	if ( (fd = osxopen(channame,OSX_OPEN_MODE|IPC_WRITE)) == -1) {
		printf("OPEN SOCKET IN WRITE MODE...  FAILED.\n");
		PERROR
		}
	else	printf("OPEN SOCKET 0 IN WRITE MODE... OK\n");

	if ( (nbytes = testread(fd,buf,SIZEBUF,PATTERNB,UPPER)) != SIZEBUF) {
		PRINTF("READING PATTERN B IN SOCKET... FAILED.\n");
		if (nbytes != -1) 
			printf("\tERROR: ONLY %d BYTES READ !!!\n",nbytes);
		ospexit(1);
		}
	else	PRINTF("READING PATTERN B IN SOCKET... OK\n");


	if ( (nbytes = testwrite(fd,buf,SIZEBUF,PATTERNC,UPPER)) != SIZEBUF) {
		printf("WRITING PATTERN C IN SOCKET... FAILED.\n");
		if (nbytes != -1) 
			printf("\tERROR: ONLY %d BYTES WRITTEN!!!\n",nbytes);
		ospexit(1);
		}
	else	printf("WRITING PATTERN C IN SOCKET... OK\n");

	if ( (nbytes = testwrite(fd,buf,SIZEBUF,PATTERNA,UPPER)) != SIZEBUF) {
		printf("WRITING PATTERN A IN SOCKET... FAILED.\n");
		if (nbytes != -1) 
			printf("\tERROR: ONLY %d BYTES WRITTEN!!!\n",nbytes);
		ospexit(1);
		}
	else	printf("WRITING PATTERN A IN SOCKET... OK\n");

	if ( (nbytes = testread(fd,buf,SIZEBUF,PATTERNC,UPPER)) != SIZEBUF) {
		PRINTF("READING PATTERN C IN SOCKET... FAILED.\n");
		if (nbytes != -1) 
			printf("\tERROR: ONLY %d BYTES READ !!!\n",nbytes);
		ospexit(1);
		}
	else	PRINTF("READING PATTERN C IN SOCKET... OK\n");

	if ( osxclose(fd) == -1) {
		printf("CLOSING THE SOCKET WRITE MODE ... FAILED.\n");
		PERROR
		}
	printf("CLOSING THE SOCKET WRITE MODE... OK\n");

	sleep(2);
	printf("****** END OF CHILD PROCCESS\n");
}


testread(fd,buffer,size,pattern,type)
int fd;
char *buffer;
int size;
char pattern;
int type;
{
	int i, j, nbytes;
	for(i=0; i<size; i++) buffer[i] = 0;

	if ( (nbytes = readn(fd,buffer,size)) < 0) {	
		if (type == UPPER)
			printf("\tERROR READING A BUFFER: %s\n",osmsg());
		else 	printf("\tError reading a buffer: %s\n",osmsg());
		return(-1);
		}
	else	{
		for(i=0; i<nbytes; i++) {
		if ( buf[i] != pattern ) {
			if (type == UPPER)
				printf("\tPATTERN MISTMATCH: READ[%d]='%c'; EXPECTED '%c'\n", i, buf[i], pattern);
			else
				printf("\tPattern mistmatch: read[%d]='%c'; expected '%c'\n", i, buf[i], pattern);
			return(-1);
			}
		}
	}
	return(nbytes);
}

testwrite(fd,buffer,size,pattern,type)
int fd;
char *buffer;
int size;
char pattern;
int type;
{
	int i, j, nbytes;
	for(i=0; i<size; i++) buffer[i] = pattern;

	if ( (nbytes = osxwrite(fd,buffer,size)) != size) {	
		if (type == UPPER)
			printf("\tERROR WRITING A BUFFER: %s\n",osmsg());
		else 	printf("\tError writing a buffer: %s\n",osmsg());
		return(-1);
		}
	return(nbytes);
}