[SOLVED] Open a file from a c program using system call.
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
@jhwilliams
I got rid of the last error too! Now the code is error free, but the pathname i mentioned in open() isn't opening in a new window. The value of the variable fd(file descriptor) is now 3. Am i correct so far? Thanks.
@jhwilliams
I got rid of the last error too! Now the code is error free, but the pathname i mentioned in open() isn't opening in a new window. The value of the variable fd(file descriptor) is now 3. Am i correct so far? Thanks.
open() is used to start access to a file, for use with read() or write().
If you want to display the file in a graphical user interface, you could try just using evince, from the command line, instead of writing a C program.
To further clarify what jhwilliams said, the open() function simply creates a file descriptor (which your code assigns to fd). Subsequent to that, you can perform various operations on the file, such as reading, writing (but in this case not: O_RDONLY ), seeking, closing, etc. In each case, the file descriptor is used to identify the open file upon which your code is to operate. You will not visibly see anything to indicate that a file is open.
There is no windowing associated with the open() call on a file. Indeed, windowing is not part of the C programming language, per se. Windowing and other GUI oriented actions are done using functions compiled into special libraries for that purpose. There are numerous categories of such libraries, depending on such things as the underlying graphical subsystem (such as X), the OS (Windows vs Linux/X), etc. Most windowing systems are therefore quite non-portable across hardware and OS architectures.
Opening of files using the open() system call in C is, by contrast, quite portable. It is a fairly sure bet that any architecture that has some kind of filesystem and a C compiler will use the open() call to open files for reading or writing.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.