Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <unistd.h>
  4. #include <string.h>
  5. #include <sys/types.h>
  6. #include <sys/ioctl.h>
  7.  
  8. #include "006_cnt.h"
  9.  
  10. void up_dev( int fd ) {
  11. if ( ioctl( fd, CNT_UP ) == -1 )
  12. perror( "006_app up_dev" );
  13. }
  14.  
  15. void down_dev( int fd ) {
  16. if ( ioctl( fd, CNT_DOWN ) == -1 )
  17. perror( "006_app down_dev" );
  18. }
  19.  
  20. int main( int argc, char *argv[] ) {
  21. char *file_name = "/dev/Danh_LedDev";
  22. int fd;
  23.  
  24. enum {
  25. o_up,
  26. o_down
  27. } option;
  28.  
  29. if ( argc == 1 )
  30. option = o_up;
  31. else if ( argc == 2 ) {
  32. if ( strcmp( argv[1], "-u" ) == 0 )
  33. option = o_up;
  34. else if ( strcmp( agrv[1], "-d" ) == 0 )
  35. option = o_down;
  36. else {
  37. fprintf( stderr, "Invalid operation\n");
  38. return 1;
  39. }
  40. }
  41. else {
  42. fprintf( stderr, "Invalid operation\n" );
  43. return 1;
  44. }
  45.  
  46. fd = open( file_name, O_RDWR );
  47. if ( fd == -1 ) {
  48. perror( "006_app open" );
  49. return 2;
  50. }
  51.  
  52. switch ( option ) {
  53. case o_up:
  54. up_dev( fd );
  55. break;
  56. case o_down:
  57. down_dev( fd );
  58. break;
  59. default:
  60. break;
  61. }
  62.  
  63. close( fd );
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement