file - I/O



  • hi,

    wie ueberpueft open folgendes:
    das file ist O_RDONLY abgespeichert, der user will das file aber mit O_TRUNC, O_WRONLY oder O_RDWR oeffnen:

    file
    permissions ---------------------- passed flags beim open --------------------------
    if( ( oflags & O_RDONLY ) && ( ( oflags & O_TRUNC ) || ( oflags & O_WRONLY ) || ( oflags & O_RDWR ) ) ){

    in der fcntl findet man folgende flags:

    #ifndef	_FCNTL_H
    # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
    #endif
    
    #include <sys/types.h>
    #ifdef __USE_GNU
    # include <bits/uio.h>
    #endif
    
    /* open/fcntl - O_SYNC is only implemented on blocks devices and on files
       located on an ext2 file system */
    #define O_ACCMODE	   0003
    #define O_RDONLY	     00
    #define O_WRONLY	     01
    #define O_RDWR		     02
    #define O_CREAT		   0100	/* not fcntl */
    #define O_EXCL		   0200	/* not fcntl */
    #define O_NOCTTY	   0400	/* not fcntl */
    #define O_TRUNC		  01000	/* not f
    

    wie soll man damit

    if( ( oflags & O_RDONLY ) && ( ( oflags & O_TRUNC  ) || ( oflags & O_WRONLY ) || ( oflags & O_RDWR   ) ) ){
    

    pruefen wenn O_RDONLY ja 0 ist?



  • Was genau ist die Frage?



  • Hallo zusammen,

    Auf den ersten Blick macht die Verzweigung wirklich keinen Sinn. Das Ergebnis der Konjunktion n und 0, für beliebiges n, liefert immer den Wahrheitswert FALSCH, und somit ist die Bedingung der if-Verzweigung immer falsch.

    Grüße Martin



  • robert1 schrieb:

    wie soll man damit

    if( ( oflags & O_RDONLY ) && ( ( oflags & O_TRUNC  ) || ( oflags & O_WRONLY ) || ( oflags & O_RDWR   ) ) ){
    

    pruefen wenn O_RDONLY ja 0 ist?

    if (oflags)
    {
       // irgendein bit gesetzt
    }
    else
    {
       // file ist O_RDONLY geöffnet
    
    }
    

    🙂


Anmelden zum Antworten