PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > with st_mode in sys/stat.h
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
with st_mode in sys/stat.h

Réponse
 
LinkBack Outils de la discussion
Vieux 11/05/2008, 12h05   #1
Deniz Dogan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut with st_mode in sys/stat.h

Hello.

I have a question regarding the st_mode field of the "stat" struct in
sys/stat.h. I'd like to know how to use the S_IRWXU, S_IRWXG and
S_IRWXO flags to mask the mode_t value into human readable form such
as 755, 644, etc. Currently I do something similar to this:

usr_t = (mod & S_IRWXU);

usr_r = (mod & S_IRUSR);
usr_w = (mod & S_IWUSR);
usr_x = (mod & S_IXUSR);

However, this does not produce the required result. Any is
appreciated.

/Deniz Dogan
  Réponse avec citation
Vieux 11/05/2008, 12h21   #2
Spiros Bousbouras
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with st_mode in sys/stat.h

On 11 May, 12:05, Deniz Dogan <kristn...@gmail.com> wrote:
> Hello.
>
> I have a question regarding the st_mode field of the "stat" struct in
> sys/stat.h. I'd like to know how to use the S_IRWXU, S_IRWXG and
> S_IRWXO flags to mask the mode_t value into human readable form such
> as 755, 644, etc. Currently I do something similar to this:
>
> usr_t = (mod & S_IRWXU);
>
> usr_r = (mod & S_IRUSR);
> usr_w = (mod & S_IWUSR);
> usr_x = (mod & S_IXUSR);
>
> However, this does not produce the required result. Any is
> appreciated.


We only deal with standard C here. For this sort of
question you should go to comp.unix.programmer

  Réponse avec citation
Vieux 11/05/2008, 12h25   #3
Jens Thoms Toerring
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with st_mode in sys/stat.h

Deniz Dogan <kristnjov@gmail.com> wrote:
> I have a question regarding the st_mode field of the "stat" struct in
> sys/stat.h.


I guess you're not aware that this isn't really a question about
C but looks more like one about POSIX, so comp.unix.programmer
would be more appropriate to ask in.

> I'd like to know how to use the S_IRWXU, S_IRWXG and
> S_IRWXO flags to mask the mode_t value into human readable form such
> as 755, 644, etc. Currently I do something similar to this:


> usr_t = (mod & S_IRWXU);


> usr_r = (mod & S_IRUSR);
> usr_w = (mod & S_IWUSR);
> usr_x = (mod & S_IXUSR);


> However, this does not produce the required result. Any is
> appreciated.


What about something like

mode = ( ( ( stat.st_mode & S_IRUSR ) ? 1 : 0 ) << 8 )
| ( ( ( stat.st_mode & S_IWUSR ) ? 1 : 0 ) << 7 )
| ( ( ( stat.st_mode & S_IXUSR ) ? 1 : 0 ) << 6 )
| ( ( ( stat.st_mode & S_IRGRP ) ? 1 : 0 ) << 5 )
| ( ( ( stat.st_mode & S_IWGRP ) ? 1 : 0 ) << 4 )
| ( ( ( stat.st_mode & S_IXGRP ) ? 1 : 0 ) << 3 )
| ( ( ( stat.st_mode & S_IROTH ) ? 1 : 0 ) << 2 )
| ( ( ( stat.st_mode & S_IWOTH ) ? 1 : 0 ) << 1 )
| ( ( ( stat.st_mode & S_IXOTH ) ? 1 : 0 ) << 0 );

and then printing the result as an octal number?

Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
  Réponse avec citation
Vieux 11/05/2008, 15h31   #4
vippstar@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with st_mode in sys/stat.h

On May 11, 2:05 pm, Deniz Dogan <kristn...@gmail.com> wrote:
> Hello.
>
> I have a question regarding the st_mode field of the "stat" struct in
> sys/stat.h. I'd like to know how to use the S_IRWXU, S_IRWXG and
> S_IRWXO flags to mask the mode_t value into human readable form such
> as 755, 644, etc. Currently I do something similar to this:
>
> usr_t = (mod & S_IRWXU);
>
> usr_r = (mod & S_IRUSR);
> usr_w = (mod & S_IWUSR);
> usr_x = (mod & S_IXUSR);
>
> However, this does not produce the required result. Any is
> appreciated.

Off-topic for this newsgroup, comp.unix.programmer would be more
appropriate, but you can certainly cast mode_t to (unsigned long) and
use sprintf and %lo.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 23h17.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10988 seconds with 12 queries