allow only owner access to a file

Posted on 2003-02-21
Medium Priority
Last Modified: 2010-04-15
Hi all,

I'm writing a C program that needs to be portable to different platforms (runnable in any ANSI C enviornment). I need to create a file and set the permission to only allow owner access. I don't know what functions I can use from the c runtime library to do that. And I don't know if I can use any other type of libraries. Could someone give me some suggestions?

Thanks a lot!
Question by:emshelly
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Assisted Solution

gj62 earned 100 total points
ID: 7994047
The C-runtime library does not have any functions that will do this for you - they are OS specific, if they exist at all on the platform.

Do you have specific platforms you are targeting?
LVL 86

Accepted Solution

jkr earned 100 total points
ID: 7994290
If you are using UN*X, use 'chmod()' like

#include <sys/types.h>
#include <sys/stat.h>

chmod ( "/home/me/myfile.txt", S_IRUSR | S_IWUSR);
LVL 22

Expert Comment

ID: 7994748
Many operating systems don't have even the concept of "owner"-- like PCDOS, Win95/98/Me.

If your program has to run on these systems, you're going to have to make your own user-level security.

This means you'll have to set up your own username/password file and have your program look up users before granting access to the file.

*Or* you could encrypt the file with a key of the user's choosing, which has its own advantages and disadvantages.

It's not a trivial thing, but not too hard to do.  I guess too it depends on exactly how secure these files have to be.

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 8010969
Currently the application is for Linux and Solaris. Later it will need to also support Windows. Thanks for all your help! They are all helpful. Is it possible to award points to more than one person?


Author Comment

ID: 8010981
By the way, do you guys know how to make the file invisible?

Thanks again!
LVL 20

Expert Comment

ID: 10011279
Nothing has happened on this question in over 10 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
split points between gj62 and jkr.


EE Cleanup Volunteer

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question