Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/ioctl.h>
- #include "006_cnt.h"
- void up_dev( int fd ) {
- if ( ioctl( fd, CNT_UP ) == -1 )
- perror( "006_app up_dev" );
- }
- void down_dev( int fd ) {
- if ( ioctl( fd, CNT_DOWN ) == -1 )
- perror( "006_app down_dev" );
- }
- int main( int argc, char *argv[] ) {
- char *file_name = "/dev/Danh_LedDev";
- int fd;
- enum {
- o_up,
- o_down
- } option;
- if ( argc == 1 )
- option = o_up;
- else if ( argc == 2 ) {
- if ( strcmp( argv[1], "-u" ) == 0 )
- option = o_up;
- else if ( strcmp( agrv[1], "-d" ) == 0 )
- option = o_down;
- else {
- fprintf( stderr, "Invalid operation\n");
- return 1;
- }
- }
- else {
- fprintf( stderr, "Invalid operation\n" );
- return 1;
- }
- fd = open( file_name, O_RDWR );
- if ( fd == -1 ) {
- perror( "006_app open" );
- return 2;
- }
- switch ( option ) {
- case o_up:
- up_dev( fd );
- break;
- case o_down:
- down_dev( fd );
- break;
- default:
- break;
- }
- close( fd );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement