swixteen  0.03
Switch a lamp on/off with X10 RF commands
 All Files Functions Variables Macros Pages
GpioUnExport.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <fcntl.h>
5 #include <unistd.h>
6 
7 #include "../Sysfs/Sysfs.h"
8 #include "../config.h"
9 
10 #define BUFFER_MAX 3 /* pin 0 .. 99 and a trailing zero */
11 
17 int GpioUnExport(int Pin)
18  {
19  char buffer[BUFFER_MAX];
20  ssize_t BytesToWrite;
21  ssize_t BytesWritten;
22  int fd;
23 
24  fd = open("/sys/class/gpio/unexport", O_WRONLY);
25  if (fd == -1)
26  {
27  fprintf(stderr, "201309202231 Failed to open unexport for writing, are you root?\n");
28  return(-1);
29  }
30 
31  BytesToWrite = snprintf(buffer, BUFFER_MAX, "%d", Pin);
32  BytesWritten = write(fd, buffer, BytesToWrite);
33 
34  if( BytesWritten != BytesToWrite )
35  {
36  fprintf( stderr, "201309210100 Encountered short write\n" );
37  fprintf( stderr, "201309231033 BytesToWrite was %i, BytesWritten was %i\n", (int)BytesToWrite, (int)BytesWritten );
38  return(-2);
39  }
40 
41  close(fd);
42  return(0);
43  }
44