Also the code could stand a bit more error checking / testing. sprintf() for example returns an int, negative number for failure, and I also believe it sets errno. Or on success it returns the number of bytes written, not including the terminating null.
Anyway, since you're not testing for a negative number on the return value of sprintf(), you have no idea if it's failing or not . . . That, and there's probably more I missed, because I only briefly "reviewed" the code. Seems overly long winded though . . . On Sun, Feb 7, 2016 at 2:30 PM, Przemek Klosowski < [email protected]> wrote: > On Sun, Feb 7, 2016 at 3:03 AM, <[email protected]> wrote: > > Hi Everyone, > > > > I am new to beaglebone black linux and looking for some support for the > > issue I am facing. I have been following Derek Molleys video tutorials on > > how to configure and program the GPIO's here > > > http://derekmolloy.ie/beaglebone/beaglebone-gpio-programming-on-arm-embedded-linux/ > . > > Everything was going fine, until I encountered this weird bug that has > to do > > something with the memory segments I believe. Searched on net and came > > across someone who had faced the same issue here > > https://groups.google.com/forum/#!topic/beagleboard/Xe-oIuQOeI8, did the > > respective changes in the code as suggested, yet I keep getting > > segmentation fault error and the execution stops while displaying "Could > not > > set the direction of the pin". Here is the code I am trying to fix, > > > > > sprintf(Inputpin_dir,"sys/class/gpio/gpio%d/direction",inputpin); > >... > > //Set the direction of the pin > > if((ButtonHandle = fopen(Inputpin_dir, "rb+"))==NULL) > > { > > printf("Could not set the direction\n"); > > return 1;----------------> Control comes here and display > "Could not set the direction and segmentation fault > > } > > The value for the sysfs node is not correct (you're missing the > initial /). I don't know where the SEGV comes from: compile with with > the -g flag and run under gdb, and it'll tell you which line is the > SEGV in. > > -- > For more options, visit http://beagleboard.org/discuss > --- > You received this message because you are subscribed to the Google Groups > "BeagleBoard" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- For more options, visit http://beagleboard.org/discuss --- You received this message because you are subscribed to the Google Groups "BeagleBoard" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
