Android Training Course (15)

Source: Internet
Author: User

What can I do by calling this function in the main function? How is this function implemented? The following describes the functions and production of this function. The Code is as follows:

#001 void open_devnull_stdio (void)

#002 {

#003 int fd;

#004 static const char * name = "/dev/_ null __";

This Code specifies the name of the device node to be created. This is a null device.

 

#005 if (mknod (name, S_IFCHR | 0600, (1 <8) | 3) = 0 ){

This line calls the mknod function to create a device node/dev/_ null __. An empty node is regarded as the output black hole. It cannot be entered, and the characters written to it will never be full.

 

#006 fd = open (name, O_RDWR );

This line of code is to open an empty device for reading and writing.

 

#007 unlink (name );

This line of code deletes a name from the file system. If the name is the last connection to the file and no other process opens the file, the file corresponding to the name will be deleted.

 

#008 if (fd> = 0 ){

#009 dup2 (fd, 0 );

#010 dup2 (fd, 1 );

#011 dup2 (fd, 2 );

#012 if (fd> 2 ){

#013 close (fd );

#014}

#015 return;

#016}

This code is used to check whether the empty device is successfully turned on and whether the device is successfully redirected. If yes, the system returns the result.

 

 

#017}

#018

#019 exit (1 );

This line of code exits when an error occurs when an empty device node is created.

 

#020}

#021

 

With the above code, you can create a/dev/_ null device and test whether the device is successfully created.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.