LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 01-24-2016, 07:09 AM   #1
Jasson
LQ Newbie
 
Registered: Jan 2016
Posts: 15

Rep: Reputation: Disabled
fcntl.h => close(); doesn´t exist


Hello there,

i could make it to a point to switch GPIO Pins on a B-Pi from the command line.

Primarily i want to do this from user code.
I found this
http://www.wiki.xilinx.com/GPIO+User+Space+App
telling to use fcntl.h The point is, neigther me nor my compile can find a routine "close(fd)"; I have looked in the fcntl.h directly and in
#include <sys/cdefs.h>
#include <sys/types.h>
#include <linux/fcntl.h>
which are included by the header.

Actually on first try i simply used the fopen and fprintf way, but my programm crashes then...

best regards!
 
Old 01-24-2016, 07:55 AM   #2
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
http://linux.die.net/man/2/close

Close is declared in unistd.h not fcntl.h
 
Old 01-24-2016, 08:09 AM   #3
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
fcntl.h should be included directly ie
Code:
#include <unistd.h>
#include <fcntl.h>
not
Code:
...
#include <linux/fcntl.h>
See:
http://linux.die.net/man/2/fcntl
 
Old 01-24-2016, 01:15 PM   #4
Jasson
LQ Newbie
 
Registered: Jan 2016
Posts: 15

Original Poster
Rep: Reputation: Disabled
hm... okay, then the problem is something else.
Looks like in my Qt Envoironment the close() method closes the App.
I need to tell the compiler that i´m refering to the close method from
unistd.h
But i´m wondering how to do that without a namespace...
 
Old 01-24-2016, 01:20 PM   #5
Jasson
LQ Newbie
 
Registered: Jan 2016
Posts: 15

Original Poster
Rep: Reputation: Disabled
Of course i´m not the first "Qt-ler" having this issue...
https://bytes.com/topic/c/answers/85...nt-unistd-h-qt
writing
::close(int)
did it
 
Old 01-24-2016, 01:48 PM   #6
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
Can you not use
Code:
FILE* fd=NULL;

fd=fopen(filepath,"w");
if(fd!=NULL)
   {

...

      fclose(fd);
   }
Which opens a file at 'filepath' for writing.
 
Old 01-25-2016, 12:36 PM   #7
Jasson
LQ Newbie
 
Registered: Jan 2016
Posts: 15

Original Poster
Rep: Reputation: Disabled
I tried that, but the program crashes then. Plus the other How-To´s on this are doing it different.

But what annoys me, is that i need root level for writing to the export file. So the App needs to run as root, which is not possible by the programm itself.
Where is the sense in providing a driver but saying me i´m not allowed to use it by default...
 
Old 01-25-2016, 02:17 PM   #8
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
Quote:
Originally Posted by Jasson View Post
... But what annoys me, is that i need root level for writing to the export file ...
All the stuff in /sys/* is used by the system and indiscriminate writing to it can seriously screw with your system if not completely fubar it, it is perfectly normal to need admin privileges to write to /sys/* otherwise anyone logged on could do pretty much what they want, complain to the author of the article about not making it clear that you would need root access.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
fcntl doesn't return after signal processed. When using F_SETFLW john.wythe@activant.com Linux - General 0 12-15-2011 03:03 PM
I can't believe it doesn't exist such a feature !! louma Linux - Software 12 07-17-2008 06:27 PM
mplayer 'close all' doesn't close anything allelopath Linux - Software 2 12-08-2005 09:40 AM
fd0 doesn't exist databuilders Linux - Hardware 2 09-11-2004 09:17 PM
/bin/sh doesn't exist??? silv3rhat Linux - Newbie 2 12-31-2003 04:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 02:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration