File: lin_write.c

package info (click to toggle)
clif 0.92-4
  • links: PTS
  • area: main
  • in suites: potato
  • size: 3,580 kB
  • ctags: 2,814
  • sloc: ansic: 31,040; yacc: 4,961; lex: 659; makefile: 390; sh: 60
file content (84 lines) | stat: -rw-r--r-- 1,424 bytes parent folder | download | duplicates (7)
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
#include <stdio.h>
#include <rpc/rpc.h>
#include "lin.h"

#define O_RDONLY 00
#define O_WRONLY 01

main(argc,argv)
     int argc;
     char **argv;
{
  CLIENT *cl;
  int *result;
  static int i,j;
  static remote_o_struct ros;
  static remote_r_w_struct rrws,*res;

  if(argc<3)
    {
      fprintf(stderr,"usage: host device\n");
      exit(0);
    }
  
  if((cl = clnt_create(argv[1],REMOTEDEVICE,REMOTEVERS,"tcp")) == NULL)
    {
      clnt_pcreateerror(argv[1]);
      exit(1);
    }
  
  ros.device=argv[2];
  ros.flags=O_WRONLY;
  if((result=remote_open_1(&ros,cl)) == NULL)
    {
      clnt_perror(cl,argv[1]);
      exit(1);
    }
  if(*result == -1)
    {
      printf("bad open\n");
      exit(1);
    }
  rrws.fd = *result;
  rrws.bytes = 2;

  for(i=0;i<5;i++)
    {
      for(j=0;j<4096;j++)
	{
	  *(short *)rrws.buf = (short)j;
	  
	  if((result=remote_write_1(&rrws,cl)) == NULL)
	    {
	      clnt_perror(cl,argv[1]);
	      exit(1);
	    }
	  if(*result == -1)
	    {
	      printf("bad write\n");
	      exit(1);
	    }
	}
      for(j=4095;j>=0;j--)
	{
	  *(short *)rrws.buf = (short)j;
 
	  if((result = remote_write_1(&rrws,cl)) == NULL)
	    {
	      clnt_perror(cl,argv[1]);
	      exit(1);
	    }
	  if(*result == -1)
	    {
	      printf("bad write\n");
	      exit(1);
	    }
	}
      }

  if((result=remote_close_1(&rrws.fd,cl)) == NULL)
    {
      clnt_perror(cl,argv[1]);
      exit(1);
    }
}