flinklib
flinklib: flink C library for Linux
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
open_close.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <getopt.h>
5 #include <ctype.h>
6 
7 #include <flinklib.h>
8 
9 #define DEFAULT_DEV "/dev/flink0"
10 
11 int main(int argc, char* argv[]) {
12  flink_dev* dev;
13  char* dev_name = DEFAULT_DEV;
14  char c;
15 
16  /* Compute command line arguments */
17  while((c = getopt(argc, argv, "d:")) != -1) {
18  switch(c) {
19  case 'd': // device
20  dev_name = optarg;
21  break;
22  case '?':
23  if(optopt == 'd') fprintf(stderr, "Option -%c requires an argument.\n", optopt);
24  else if(isprint(optopt)) fprintf (stderr, "Unknown option `-%c'.\n", optopt);
25  else fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
26  return -1;
27  default:
28  abort();
29  }
30  }
31 
32  printf("Opening device %s...\n", dev_name);
33  dev = flink_open(dev_name);
34  if(dev == NULL) {
35  printf("Failed to open device!\n");
36  return -1;
37  }
38 
39  printf("Closing device %s...\n", dev_name);
40  flink_close(dev);
41 
42  return EXIT_SUCCESS;
43 }
flink_dev * flink_open(const char *file_name)
Opens a flink device file.
Definition: base.c:112
int flink_close(flink_dev *dev)
Close an open flink device.
Definition: base.c:145
#define EXIT_SUCCESS
Definition: flinklib.h:117
int main(int argc, char *argv[])
Definition: open_close.c:11
#define DEFAULT_DEV
Definition: open_close.c:9