c - GPIO sample code for Linux -
static int gpiounexport(int pin) { char buffer[buffer_max]; ssize_t bytes_written; int fd; fd = open("/sys/class/gpio/unexport", o_wronly); if (-1 == fd) { fprintf(stderr, "failed open unexport writing!\n"); return(-1); } bytes_written = snprintf(buffer, buffer_max, "%d", pin); write(fd, buffer, bytes_written); close(fd); return(0); } i have few questions relate above gpio code
1)why use ssize_t? why not use int?
2)is /sys/class/gpio/unexport" system file? if not it?
3)snprintf prints somethings buffer, write function redundant? or write function can differently?
4) instead of using open, can use ioctl function instead?
i have no idea why code sample uses
ssize_t; return type ofsnprintfintusingintbetter (to avoid implicit cast).ssize_tsigned , in cases @ least largeintthere no harm done.yes, system file on linux. writing number of gpio pin file "unexport" gpio pin generic gpio driver, making driver declare not handle pin more (allowing other gpio drivers use it).
you use
dprintfwrite directly file descriptorfd, not need temporary buffer.dprintfless known otherprintfvariants maybe that's why author of original code decided use intermediate buffer instead , call standard low-levelwritefunction.what sort of
ioctlfunction mean?
Comments
Post a Comment