LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 01-26-2005, 10:45 AM   #1
rafiqul
Member
 
Registered: Jan 2005
Location: Chicago
Distribution: Fedora Core 4
Posts: 46

Rep: Reputation: 15
access() function call does not work


I am supposed to verify a file accesibilty, whether it is readable, or writable..so i used access() system call. It is not working...

Here is my check...

#define FILE "./file.txt"

//I am changing the permission as r only
chmod (FILE, S_IRUSR | S_IRGRP | S_IRGRP)

//I am checking here if it is read, or write able
if(access(FILE, W_OK) == 0)
{
//file is wrioteable
} else if(access(FILE, R_OK) == 0)
{
//file is readable
}

I was expecting file is readable only...how come it is writeable ?

Any idea ??
 
Old 01-26-2005, 02:28 PM   #2
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
A couple of things.

FILE is a data type used to declare file pointers, as such you should not use it as a macro

Next, ensure you include the correct library in your quote. I believe access is in the unistd.h library which was not included in the code supplied.

However I think your problem is that you are most likely running this code as root which supercedes the permissions on the file, so it always assumes a successful call to access, therefore it doesn't fall into the else if block of code.

BTW, this doesn't really belong in the Newbie forum.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to call another function from a function? geminigal Programming 4 04-21-2005 10:41 PM
Port check function call mrsharky Linux - Networking 4 04-15-2005 11:27 AM
No Matching Function for Call ! vipinsharma Programming 2 07-05-2004 01:58 PM
how to call function?? harpal Programming 3 04-29-2003 05:59 AM
help passing char* to function call PTBmilo Programming 4 03-16-2003 07:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:15 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