LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-05-2004, 07:43 AM   #1
ppy
LQ Newbie
 
Registered: Nov 2004
Location: India,Bangalore
Posts: 5

Rep: Reputation: 0
stat system call mode checking


Hello,

I am writing a part of the problem code : Can anybody tell me what is wrong in this code ?

if (st.st_mode != (S_IFCHR | S_IRUSR | S_IWUSR | S_IWGRP)) {

printf("Mode is not set for the device\n");
printf("Actual mode = %o\n",st.st_mode);
}
Is the comparison correct ?
mode of the device is 777.
printf always prints : Actual mode =0620 even if i change the mode of the device using chmod from command line.

Why is this ?

Regards,
ppy
 
Old 11-05-2004, 09:24 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Odd...it works for me:
Code:
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>

int main(void)
{
  struct stat st;

  if(stat("testfile", &st) == -1)
  {
    perror("stat()");
    return 1;
  }

  printf("%o\n", st.st_mode & ~S_IFMT);
  return 0;
}
Code:
itsme@itsme:~/C$ touch testfile
itsme@itsme:~/C$ ls -l testfile
-rw-r--r--  1 itsme users 0 2004-11-05 07:23 testfile
itsme@itsme:~/C$ ./mode
644
itsme@itsme:~/C$ chmod 0600 testfile
itsme@itsme:~/C$ ls -l testfile
-rw-------  1 itsme users 0 2004-11-05 07:23 testfile
itsme@itsme:~/C$ ./mode
600
 
  


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
using system call ej25 Programming 9 11-30-2004 11:45 AM
new system call soul2 Linux - General 1 11-03-2004 02:41 PM
Linux stat to Windows Stat sridurai Programming 3 09-24-2004 04:07 PM
Is it possible to use system() and get the return value from the system call newguy21 Programming 1 08-11-2004 01:37 PM
Load average and system stat question WeNdeL Linux - General 3 04-28-2004 11:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:48 PM.

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