Demo entry 6771881

c

   

Submitted by anonymous on Nov 22, 2018 at 07:53
Language: C. Code size: 755 Bytes.

int main(int argc, char *argv[])
{
	int otg_fd = 0;
	int switch_fd =0;
	int ret = 0;
	char buf[2];
	otg_fd = open(OTG_PATH, O_WRONLY, 0777);
	if(otg_fd < 0)
	{
		printf("yjx open otg fail \n");
		return 0;
	}
	switch_fd = open(SWITCH_PATH,O_RDONLY,0777);
	if(switch_fd < 0)
	{
		printf("yjx open switch_fd fail \n");
		return 0;
	}

	ret = read(switch_fd, buf, 2);
	printf("yjx read first ret : %d \n", ret);
	if(buf[0] == '1')
	{
		ret = write(otg_fd, buf, 2);
		printf("yjx write otg : %d \n", ret);
	}

	
	while(1)
	{
		ret = read(switch_fd, buf, 2);
		printf("yjx read ret : %d \n", ret);
		
		ret = write(otg_fd, buf, 2);
		printf("yjx write otg : %d \n", ret);
	}
	return 0;
}
//yujixuan@wind-mobi.com 2018 0505

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).