Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


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

Rep: Reputation: 0
stat system call mode checking


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 ?

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

Rep: Reputation: 59 works for me:
#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)
    return 1;

  printf("%o\n", st.st_mode & ~S_IFMT);
  return 0;
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
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


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
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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:41 PM.

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